Source for my MapleSolaxiaV2 (v83 MapleStory).
This commit is contained in:
ronancpl
2015-11-02 23:17:21 -02:00
parent 324982e94f
commit 972517e7b2
1675 changed files with 261831 additions and 0 deletions

View File

@@ -0,0 +1,127 @@
package net.server;
import java.io.Console;
import java.io.FileOutputStream;
import java.io.IOException;
/**
*
* @author kevintjuh93
*/
public class CreateINI {
public static void main(String args[]) {
StringBuilder sb = new StringBuilder();
String nextline = "\r\n";//Because I can, and it's free.
byte worlds;
Console con = System.console();
System.out.println("Welcome to MoopleDEV's .ini creator\r\n\r\n");
sb.append("#MoopleDEV's INI file. Do NOT modify it if you are an idiot (:\r\n");
sb.append("#Flag types: 0 = nothing, 1 = event, 2 = new, 3 = hot\r\n\r\n");
System.out.println("Flag types: 0 = nothing, 1 = event, 2 = new, 3 = hot\r\n\r\n");
worlds = Byte.parseByte(con.readLine("Number of worlds: "));
sb.append("worlds=").append(worlds).append("\r\n\r\n");
System.out.println("\r\n");
for (byte b = 0; b < worlds; b++) {
sb.append("#Properties for world ").append(b).append("\r\n");
System.out.println("Properties for world " + b);
if (b > 1) {
System.out.println("Make sure you create a npc folder for this world!");
}
sb.append("flag").append(b).append("=").append(
Integer.parseInt(con.readLine(" Flag: "))).append("\r\n");
sb.append("servermessage").append(b).append("=").append(
con.readLine(" Server message: ")).append("\r\n");
sb.append("eventmessage").append(b).append("=").append(
con.readLine(" Event message: ")).append("\r\n");
sb.append("whyamirecommended").append(b).append("=").append(
con.readLine(" Recommend message: ")).append("\r\n");
sb.append("channels").append(b).append("=").append(
Byte.parseByte(con.readLine(" Number of channels: "))).append("\r\n");
sb.append("exprate").append(b).append("=").append(
Integer.parseInt(con.readLine(" Exp rate: "))).append("\r\n");
sb.append("droprate").append(b).append("=").append(
Integer.parseInt(con.readLine(" Drop rate: "))).append("\r\n");
sb.append("mesorate").append(b).append("=").append(
Integer.parseInt(con.readLine(" Meso rate: "))).append("\r\n");
sb.append("bossdroprate").append(b).append("=").append(
Integer.parseInt(con.readLine(" Boss drop rate: "))).append("\r\n");
System.out.println(nextline);
sb.append("\r\n");
}
sb.append("\r\n").append("gmserver=").append(Boolean.parseBoolean(con.readLine("Do you want a GM Server? (true/false)")));
FileOutputStream out = null;
try {
out = new FileOutputStream("moople.ini", false);
out.write(sb.toString().getBytes());
} catch (Exception ex) {
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException ex) {
}
}
sb = new StringBuilder();
try {
System.out.println("\r\nYou are about to set the Java Heap Size, if you don't know what it is, type '?'.");
String heapsize = con.readLine("Java Heap Size (in MB): ");
while (heapsize.equals("?")) {
System.out.println("\r\n");
System.out.println("WikiAnswers: Java heap is the heap size allocated to JVM applications which takes care of the new objects being created. If the objects being created exceed the heap size, it will throw an error saying memoryOutof Bound\r\n");
System.out.println("I recommend using 64 bit with the heap size around 4000, if you have 4 gb RAM.");
heapsize = con.readLine("Java Heap Size (in MB): ");
}
String linux = con.readLine("\r\nAre you using a Linux platform or not? (y/n):");
while (!linux.equals("y") && !linux.equals("n")) {
System.out.println("Type 'y' if you use linux else type 'n'.");
linux = con.readLine("Are you using a Linux platform or not? (y/n):");
}
if (linux.equals("n")) {
out = new FileOutputStream("launch_server.bat", false);
sb.append("@echo off").append("\r\n").append("@title MoopleDEV Server v83").append("\r\n");
sb.append("set CLASSPATH=.;dist\\*\r\n");
sb.append("java -Xmx").append(heapsize).append("m -Dwzpath=wz\\ net.server.Server\r\n");
sb.append("pause");
} else {//test
out = new FileOutputStream("launch_server.sh", false);
sb.append("#!/bin/sh").append("\r\n\r\n");
sb.append("export CLASSPATH=\".:dist/*\" \r\n\r\n");
sb.append("java -Dwzpath=wz/ \\\r\n");
sb.append("-Xmx").append(heapsize).append("m ").append("net.server.Server");
System.out.println("Use DOS2UNIX command to convert the .sh file once again.");
}
out.write(sb.toString().getBytes());
} catch (Exception ex) {
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException ex) {
}
}
System.out.println("\r\nMake sure that ServerConstants in modified too, and clean+compiled before you start the server.");
System.out.println("If you want other settings; restart this .bat or modify the moople.ini");
}
}

View File

@@ -0,0 +1,82 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
*
* @author Danny//changed to map :3
*/
public class PlayerBuffStorage {
private int id = (int) (Math.random() * 100);
private final Lock mutex = new ReentrantLock();
private Map<Integer, List<PlayerBuffValueHolder>> buffs = new HashMap<Integer, List<PlayerBuffValueHolder>>();
public void addBuffsToStorage(int chrid, List<PlayerBuffValueHolder> toStore) {
mutex.lock();
try {
buffs.put(chrid, toStore);//Old one will be replace if it's in here.
} finally {
mutex.unlock();
}
}
public List<PlayerBuffValueHolder> getBuffsFromStorage(int chrid) {
mutex.lock();
try {
return buffs.remove(chrid);
} finally {
mutex.unlock();
}
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final PlayerBuffStorage other = (PlayerBuffStorage) obj;
if (id != other.id) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,38 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server;
import server.MapleStatEffect;
/**
*
* @author Danny
*/
public class PlayerBuffValueHolder {
public long startTime;
public MapleStatEffect effect;
public PlayerBuffValueHolder(long startTime, MapleStatEffect effect) {
this.startTime = startTime;
this.effect = effect;
}
}

View File

@@ -0,0 +1,38 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server;
/**
*
* @author Danny
*/
public class PlayerCoolDownValueHolder {
public int skillId;
public long startTime;
public long length;
public PlayerCoolDownValueHolder(int skillId, long startTime, long length) {
this.skillId = skillId;
this.startTime = startTime;
this.length = length;
}
}

View File

@@ -0,0 +1,36 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 ~ 2010 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation. You may not use, modify
or distribute this program under any other version of the
GNU Affero General Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server;
import client.MapleDisease;
public class PlayerDiseaseValueHolder {//Thanks Celino
public long startTime;
public long length;
public MapleDisease disease;
public PlayerDiseaseValueHolder(final MapleDisease disease, final long startTime, final long length) {
this.disease = disease;
this.startTime = startTime;
this.length = length;
}
}

View File

@@ -0,0 +1,103 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server;
import client.MapleCharacter;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class PlayerStorage {
private final ReentrantReadWriteLock locks = new ReentrantReadWriteLock();
private final Lock rlock = locks.readLock();
private final Lock wlock = locks.writeLock();
private final Map<Integer, MapleCharacter> storage = new LinkedHashMap<>();
public void addPlayer(MapleCharacter chr) {
wlock.lock();
try {
storage.put(chr.getId(), chr);
} finally {
wlock.unlock();
}
}
public MapleCharacter removePlayer(int chr) {
wlock.lock();
try {
return storage.remove(chr);
} finally {
wlock.unlock();
}
}
public MapleCharacter getCharacterByName(String name) {
rlock.lock();
try {
for (MapleCharacter chr : storage.values()) {
if (chr.getName().toLowerCase().equals(name.toLowerCase()))
return chr;
}
return null;
} finally {
rlock.unlock();
}
}
public MapleCharacter getCharacterById(int id) {
rlock.lock();
try {
return storage.get(id);
} finally {
rlock.unlock();
}
}
public Collection<MapleCharacter> getAllCharacters() {
rlock.lock();
try {
return storage.values();
} finally {
rlock.unlock();
}
}
public final void disconnectAll() {
wlock.lock();
try {
final Iterator<MapleCharacter> chrit = storage.values().iterator();
while (chrit.hasNext()) {
chrit.next().getClient().disconnect(true, false);
chrit.remove();
}
} finally {
wlock.unlock();
}
}
public int getSize(){
return storage.size();
}
}

View File

@@ -0,0 +1,90 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import client.MapleJob;
import tools.DatabaseConnection;
/**
* @author Matze
* @author Quit
*/
public class RankingWorker implements Runnable {
private Connection con;
private long lastUpdate = System.currentTimeMillis();
public void run() {
try {
con = DatabaseConnection.getConnection();
con.setAutoCommit(false);
updateRanking(null);
for (int i = 0; i < 3; i += 2) {
for (int j = 1; j < 6; j++) {
updateRanking(MapleJob.getById(i * 500 + 100 * j));
}
}
con.commit();
con.setAutoCommit(true);
lastUpdate = System.currentTimeMillis();
} catch (SQLException ex) {
try {
con.rollback();
con.setAutoCommit(true);
} catch (SQLException ex2) {
}
}
}
private void updateRanking(MapleJob job) throws SQLException {
String sqlCharSelect = "SELECT c.id, " + (job != null ? "c.jobRank, c.jobRankMove" : "c.rank, c.rankMove") + ", a.lastlogin AS lastlogin, a.loggedin FROM characters AS c LEFT JOIN accounts AS a ON c.accountid = a.id WHERE c.gm = 0 ";
if (job != null) {
sqlCharSelect += "AND c.job DIV 100 = ? ";
}
sqlCharSelect += "ORDER BY c.level DESC , c.exp DESC , c.fame DESC , c.meso DESC";
PreparedStatement charSelect = con.prepareStatement(sqlCharSelect);
if (job != null) {
charSelect.setInt(1, job.getId() / 100);
}
ResultSet rs = charSelect.executeQuery();
PreparedStatement ps = con.prepareStatement("UPDATE characters SET " + (job != null ? "jobRank = ?, jobRankMove = ? " : "rank = ?, rankMove = ? ") + "WHERE id = ?");
int rank = 0;
while (rs.next()) {
int rankMove = 0;
rank++;
if (rs.getLong("lastlogin") < lastUpdate || rs.getInt("loggedin") > 0) {
rankMove = rs.getInt((job != null ? "jobRankMove" : "rankMove"));
}
rankMove += rs.getInt((job != null ? "jobRank" : "rank")) - rank;
ps.setInt(1, rank);
ps.setInt(2, rankMove);
ps.setInt(3, rs.getInt("id"));
ps.executeUpdate();
}
rs.close();
charSelect.close();
ps.close();
}
}

605
src/net/server/Server.java Normal file
View File

@@ -0,0 +1,605 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import net.MapleServerHandler;
import net.mina.MapleCodecFactory;
import net.server.channel.Channel;
import net.server.guild.MapleAlliance;
import net.server.guild.MapleGuild;
import net.server.guild.MapleGuildCharacter;
import net.server.world.World;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.buffer.SimpleBufferAllocator;
import org.apache.mina.core.filterchain.IoFilter;
import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import server.CashShop.CashItemFactory;
import server.MapleItemInformationProvider;
import server.TimerManager;
import tools.DatabaseConnection;
import tools.FilePrinter;
import tools.Pair;
import client.MapleCharacter;
import client.SkillFactory;
import constants.ServerConstants;
import server.quest.MapleQuest;
public class Server implements Runnable {
private IoAcceptor acceptor;
private List<Map<Integer, String>> channels = new LinkedList<>();
private List<World> worlds = new ArrayList<>();
private Properties subnetInfo = new Properties();
private static Server instance = null;
private List<Pair<Integer, String>> worldRecommendedList = new LinkedList<>();
private Map<Integer, MapleGuild> guilds = new LinkedHashMap<>();
private PlayerBuffStorage buffStorage = new PlayerBuffStorage();
private Map<Integer, MapleAlliance> alliances = new LinkedHashMap<>();
private boolean online = false;
public static long uptime = System.currentTimeMillis();
public static Server getInstance() {
if (instance == null) {
instance = new Server();
}
return instance;
}
public boolean isOnline() {
return online;
}
public List<Pair<Integer, String>> worldRecommendedList() {
return worldRecommendedList;
}
public void removeChannel(int worldid, int channel) {
channels.remove(channel);
World world = worlds.get(worldid);
if (world != null) {
world.removeChannel(channel);
}
}
public Channel getChannel(int world, int channel) {
return worlds.get(world).getChannel(channel);
}
public List<Channel> getChannelsFromWorld(int world) {
return worlds.get(world).getChannels();
}
public List<Channel> getAllChannels() {
List<Channel> channelz = new ArrayList<>();
for (World world : worlds) {
for (Channel ch : world.getChannels()) {
channelz.add(ch);
}
}
return channelz;
}
public String getIP(int world, int channel) {
return channels.get(world).get(channel);
}
@Override
public void run() {
Properties p = new Properties();
try {
p.load(new FileInputStream("world.ini"));
} catch (Exception e) {
System.out.println("Please start create_server.bat");
System.exit(0);
}
System.out.println("MapleSolaxia v" + ServerConstants.VERSION + " starting up.\r\n");
if(ServerConstants.SHUTDOWNHOOK)
Runtime.getRuntime().addShutdownHook(new Thread(shutdown(false)));
DatabaseConnection.getConnection();
Connection c = DatabaseConnection.getConnection();
try {
PreparedStatement ps = c.prepareStatement("UPDATE accounts SET loggedin = 0");
ps.executeUpdate();
ps.close();
ps = c.prepareStatement("UPDATE characters SET HasMerchant = 0");
ps.executeUpdate();
ps.close();
} catch (SQLException sqle) {
}
IoBuffer.setUseDirectBuffer(false);
IoBuffer.setAllocator(new SimpleBufferAllocator());
acceptor = new NioSocketAcceptor();
acceptor.getFilterChain().addLast("codec", (IoFilter) new ProtocolCodecFilter(new MapleCodecFactory()));
TimerManager tMan = TimerManager.getInstance();
tMan.start();
tMan.register(tMan.purge(), 300000);//Purging ftw...
tMan.register(new RankingWorker(), ServerConstants.RANKING_INTERVAL);
long timeToTake = System.currentTimeMillis();
SkillFactory.loadAllSkills();
System.out.println("Skills loaded in " + ((System.currentTimeMillis() - timeToTake) / 1000.0) + " seconds");
timeToTake = System.currentTimeMillis();
MapleItemInformationProvider.getInstance().getAllItems();
CashItemFactory.getSpecialCashItems();
System.out.println("Items loaded in " + ((System.currentTimeMillis() - timeToTake) / 1000.0) + " seconds\r\n");
timeToTake = System.currentTimeMillis();
MapleQuest.loadAllQuest();
System.out.println("Quest loaded in " + ((System.currentTimeMillis() - timeToTake) / 1000.0) + " seconds\r\n");
try {
for (int i = 0; i < Integer.parseInt(p.getProperty("worlds")); i++) {
System.out.println("Starting world " + i);
World world = new World(i,
Integer.parseInt(p.getProperty("flag" + i)),
p.getProperty("eventmessage" + i),
ServerConstants.EXP_RATE,
ServerConstants.DROP_RATE,
ServerConstants.MESO_RATE,
ServerConstants.BOSS_DROP_RATE);
worldRecommendedList.add(new Pair<>(i, p.getProperty("whyamirecommended" + i)));
worlds.add(world);
channels.add(new LinkedHashMap<Integer, String>());
for (int j = 0; j < Integer.parseInt(p.getProperty("channels" + i)); j++) {
int channelid = j + 1;
Channel channel = new Channel(i, channelid);
world.addChannel(channel);
channels.get(i).put(channelid, channel.getIP());
}
world.setServerMessage(p.getProperty("servermessage" + i));
System.out.println("Finished loading world " + i + "\r\n");
}
} catch (Exception e) {
System.out.println("Error in moople.ini, start CreateINI.bat to re-make the file.");
e.printStackTrace();//For those who get errors
System.exit(0);
}
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
acceptor.setHandler(new MapleServerHandler());
try {
acceptor.bind(new InetSocketAddress(8484));
} catch (IOException ex) {
ex.printStackTrace();
}
System.out.println("Listening on port 8484\r\n\r\n");
System.out.println("Solaxia is now online.");
online = true;
}
public void shutdown() {
try {
TimerManager.getInstance().stop();
acceptor.unbind();
} catch (NullPointerException e) {
FilePrinter.printError(FilePrinter.EXCEPTION_CAUGHT, e);
}
System.out.println("Server offline.");
System.exit(0);// BOEIEND :D
}
public static void main(String args[]) {
Server.getInstance().run();
}
public Properties getSubnetInfo() {
return subnetInfo;
}
public MapleAlliance getAlliance(int id) {
synchronized (alliances) {
if (alliances.containsKey(id)) {
return alliances.get(id);
}
return null;
}
}
public void addAlliance(int id, MapleAlliance alliance) {
synchronized (alliances) {
if (!alliances.containsKey(id)) {
alliances.put(id, alliance);
}
}
}
public void disbandAlliance(int id) {
synchronized (alliances) {
MapleAlliance alliance = alliances.get(id);
if (alliance != null) {
for (Integer gid : alliance.getGuilds()) {
guilds.get(gid).setAllianceId(0);
}
alliances.remove(id);
}
}
}
public void allianceMessage(int id, final byte[] packet, int exception, int guildex) {
MapleAlliance alliance = alliances.get(id);
if (alliance != null) {
for (Integer gid : alliance.getGuilds()) {
if (guildex == gid) {
continue;
}
MapleGuild guild = guilds.get(gid);
if (guild != null) {
guild.broadcast(packet, exception);
}
}
}
}
public boolean addGuildtoAlliance(int aId, int guildId) {
MapleAlliance alliance = alliances.get(aId);
if (alliance != null) {
alliance.addGuild(guildId);
return true;
}
return false;
}
public boolean removeGuildFromAlliance(int aId, int guildId) {
MapleAlliance alliance = alliances.get(aId);
if (alliance != null) {
alliance.removeGuild(guildId);
return true;
}
return false;
}
public boolean setAllianceRanks(int aId, String[] ranks) {
MapleAlliance alliance = alliances.get(aId);
if (alliance != null) {
alliance.setRankTitle(ranks);
return true;
}
return false;
}
public boolean setAllianceNotice(int aId, String notice) {
MapleAlliance alliance = alliances.get(aId);
if (alliance != null) {
alliance.setNotice(notice);
return true;
}
return false;
}
public boolean increaseAllianceCapacity(int aId, int inc) {
MapleAlliance alliance = alliances.get(aId);
if (alliance != null) {
alliance.increaseCapacity(inc);
return true;
}
return false;
}
public Set<Integer> getChannelServer(int world) {
return new HashSet<>(channels.get(world).keySet());
}
public byte getHighestChannelId() {
byte highest = 0;
for (Iterator<Integer> it = channels.get(0).keySet().iterator(); it.hasNext();) {
Integer channel = it.next();
if (channel != null && channel.intValue() > highest) {
highest = channel.byteValue();
}
}
return highest;
}
public int createGuild(int leaderId, String name) {
return MapleGuild.createGuild(leaderId, name);
}
public MapleGuild getGuild(int id, int world, MapleGuildCharacter mgc) {
synchronized (guilds) {
if (guilds.get(id) != null) {
return guilds.get(id);
}
MapleGuild g = new MapleGuild(id, world);
if (g.getId() == -1) {
return null;
}
if (mgc != null) {
g.setOnline(mgc.getId(), true, mgc.getChannel());
}
guilds.put(id, g);
return g;
}
}
public void clearGuilds() {//remake
synchronized (guilds) {
guilds.clear();
}
//for (List<Channel> world : worlds.values()) {
//reloadGuildCharacters();
}
public void setGuildMemberOnline(MapleGuildCharacter mgc, boolean bOnline, int channel) {
MapleGuild g = getGuild(mgc.getGuildId(), mgc.getWorld(), mgc);
g.setOnline(mgc.getId(), bOnline, channel);
}
public int addGuildMember(MapleGuildCharacter mgc) {
MapleGuild g = guilds.get(mgc.getGuildId());
if (g != null) {
return g.addGuildMember(mgc);
}
return 0;
}
public boolean setGuildAllianceId(int gId, int aId) {
MapleGuild guild = guilds.get(gId);
if (guild != null) {
guild.setAllianceId(aId);
return true;
}
return false;
}
public void leaveGuild(MapleGuildCharacter mgc) {
MapleGuild g = guilds.get(mgc.getGuildId());
if (g != null) {
g.leaveGuild(mgc);
}
}
public void guildChat(int gid, String name, int cid, String msg) {
MapleGuild g = guilds.get(gid);
if (g != null) {
g.guildChat(name, cid, msg);
}
}
public void changeRank(int gid, int cid, int newRank) {
MapleGuild g = guilds.get(gid);
if (g != null) {
g.changeRank(cid, newRank);
}
}
public void expelMember(MapleGuildCharacter initiator, String name, int cid) {
MapleGuild g = guilds.get(initiator.getGuildId());
if (g != null) {
g.expelMember(initiator, name, cid);
}
}
public void setGuildNotice(int gid, String notice) {
MapleGuild g = guilds.get(gid);
if (g != null) {
g.setGuildNotice(notice);
}
}
public void memberLevelJobUpdate(MapleGuildCharacter mgc) {
MapleGuild g = guilds.get(mgc.getGuildId());
if (g != null) {
g.memberLevelJobUpdate(mgc);
}
}
public void changeRankTitle(int gid, String[] ranks) {
MapleGuild g = guilds.get(gid);
if (g != null) {
g.changeRankTitle(ranks);
}
}
public void setGuildEmblem(int gid, short bg, byte bgcolor, short logo, byte logocolor) {
MapleGuild g = guilds.get(gid);
if (g != null) {
g.setGuildEmblem(bg, bgcolor, logo, logocolor);
}
}
public void disbandGuild(int gid) {
synchronized (guilds) {
MapleGuild g = guilds.get(gid);
g.disbandGuild();
guilds.remove(gid);
}
}
public boolean increaseGuildCapacity(int gid) {
MapleGuild g = guilds.get(gid);
if (g != null) {
return g.increaseCapacity();
}
return false;
}
public void gainGP(int gid, int amount) {
MapleGuild g = guilds.get(gid);
if (g != null) {
g.gainGP(amount);
}
}
public void guildMessage(int gid, byte[] packet) {
guildMessage(gid, packet, -1);
}
public void guildMessage(int gid, byte[] packet, int exception) {
MapleGuild g = guilds.get(gid);
if(g != null) {
g.broadcast(packet, exception);
}
}
public PlayerBuffStorage getPlayerBuffStorage() {
return buffStorage;
}
public void deleteGuildCharacter(MapleGuildCharacter mgc) {
setGuildMemberOnline(mgc, false, (byte) -1);
if (mgc.getGuildRank() > 1) {
leaveGuild(mgc);
} else {
disbandGuild(mgc.getGuildId());
}
}
public void reloadGuildCharacters(int world) {
World worlda = getWorld(world);
for (MapleCharacter mc : worlda.getPlayerStorage().getAllCharacters()) {
if (mc.getGuildId() > 0) {
setGuildMemberOnline(mc.getMGC(), true, worlda.getId());
memberLevelJobUpdate(mc.getMGC());
}
}
worlda.reloadGuildSummary();
}
public void broadcastMessage(final byte[] packet) {
for (Channel ch : getChannelsFromWorld(0)) {
ch.broadcastPacket(packet);
}
}
public void broadcastGMMessage(final byte[] packet) {
for (Channel ch : getChannelsFromWorld(0)) {
ch.broadcastGMPacket(packet);
}
}
public boolean isGmOnline() {
for (Channel ch : getChannelsFromWorld(0)) {
for (MapleCharacter player : ch.getPlayerStorage().getAllCharacters()) {
if (player.isGM()){
return true;
}
}
}
return false;
}
public World getWorld(int id) {
return worlds.get(id);
}
public List<World> getWorlds() {
return worlds;
}
public final Runnable shutdown(final boolean restart) {//only once :D
return new Runnable() {
@Override
public void run() {
System.out.println((restart ? "Restarting" : "Shutting down") + " the server!\r\n");
if (getWorlds() == null) return;//already shutdown
for (World w : getWorlds()) {
w.shutdown();
}
/*for (World w : getWorlds()) {
while (w.getPlayerStorage().getAllCharacters().size() > 0) {
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
System.err.println("FUCK MY LIFE");
}
}
}
for (Channel ch : getAllChannels()) {
while (ch.getConnectedClients() > 0) {
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
System.err.println("FUCK MY LIFE");
}
}
}*/
TimerManager.getInstance().purge();
TimerManager.getInstance().stop();
for (Channel ch : getAllChannels()) {
while (!ch.finishedShutdown()) {
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
System.err.println("FUCK MY LIFE");
}
}
}
worlds.clear();
worlds = null;
channels.clear();
channels = null;
worldRecommendedList.clear();
worldRecommendedList = null;
System.out.println("Worlds + Channels are offline.");
acceptor.unbind();
acceptor = null;
if (!restart) {
System.exit(0);
} else {
System.out.println("\r\nRestarting the server....\r\n");
try {
instance.finalize();//FUU I CAN AND IT'S FREE
} catch (Throwable ex) {
}
instance = null;
System.gc();
getInstance().run();//DID I DO EVERYTHING?! D:
}
}
};
}
}

View File

@@ -0,0 +1,306 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel;
import java.io.File;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
import net.MapleServerHandler;
import net.mina.MapleCodecFactory;
import net.server.PlayerStorage;
import net.server.world.MapleParty;
import net.server.world.MaplePartyCharacter;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.buffer.SimpleBufferAllocator;
import org.apache.mina.core.filterchain.IoFilter;
import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.transport.socket.SocketSessionConfig;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import provider.MapleDataProviderFactory;
import scripting.event.EventScriptManager;
import server.TimerManager;
import server.events.gm.MapleEvent;
import server.expeditions.MapleExpedition;
import server.expeditions.MapleExpeditionType;
import server.maps.HiredMerchant;
import server.maps.MapleMap;
import server.maps.MapleMapFactory;
import tools.MaplePacketCreator;
import client.MapleCharacter;
import constants.ServerConstants;
public final class Channel {
private int port = 7575;
private PlayerStorage players = new PlayerStorage();
private int world, channel;
private IoAcceptor acceptor;
private String ip, serverMessage;
private MapleMapFactory mapFactory;
private EventScriptManager eventSM;
private Map<Integer, HiredMerchant> hiredMerchants = new HashMap<>();
private final Map<Integer, Integer> storedVars = new HashMap<>();
private ReentrantReadWriteLock merchant_lock = new ReentrantReadWriteLock(true);
private List<MapleExpedition> expeditions = new ArrayList<>();
private List<MapleExpeditionType> expedType = new ArrayList<>();
private MapleEvent event;
private boolean finishedShutdown = false;
public Channel(final int world, final int channel) {
this.world = world;
this.channel = channel;
this.mapFactory = new MapleMapFactory(MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/Map.wz")), MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/String.wz")), world, channel);
try {
eventSM = new EventScriptManager(this, getEvents());
port = 7575 + this.channel - 1;
port += (world * 100);
ip = ServerConstants.HOST + ":" + port;
IoBuffer.setUseDirectBuffer(false);
IoBuffer.setAllocator(new SimpleBufferAllocator());
acceptor = new NioSocketAcceptor();
TimerManager.getInstance().register(new respawnMaps(), 10000);
acceptor.setHandler(new MapleServerHandler(world, channel));
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
acceptor.getFilterChain().addLast("codec", (IoFilter) new ProtocolCodecFilter(new MapleCodecFactory()));
acceptor.bind(new InetSocketAddress(port));
((SocketSessionConfig) acceptor.getSessionConfig()).setTcpNoDelay(true);
for (MapleExpeditionType exped : MapleExpeditionType.values()) {
expedType.add(exped);
}
eventSM.init();
System.out.println(" Channel " + getId() + ": Listening on port " + port);
} catch (Exception e) {
e.printStackTrace();
}
}
public void reloadEventScriptManager(){
eventSM.cancel();
eventSM = null;
eventSM = new EventScriptManager(this, getEvents());
eventSM.init();
}
public final void shutdown() {
try {
System.out.println("Shutting down Channel " + channel + " on World " + world);
closeAllMerchants();
players.disconnectAll();
acceptor.unbind();
finishedShutdown = true;
System.out.println("Successfully shut down Channel " + channel + " on World " + world + "\r\n");
} catch (Exception e) {
System.err.println("Error while shutting down Channel " + channel + " on World " + world + "\r\n" + e);
}
}
public void closeAllMerchants() {
WriteLock wlock = merchant_lock.writeLock();
wlock.lock();
try {
final Iterator<HiredMerchant> hmit = hiredMerchants.values().iterator();
while (hmit.hasNext()) {
hmit.next().forceClose();
hmit.remove();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
wlock.unlock();
}
}
public MapleMapFactory getMapFactory() {
return mapFactory;
}
public int getWorld() {
return world;
}
public void addPlayer(MapleCharacter chr) {
players.addPlayer(chr);
chr.announce(MaplePacketCreator.serverMessage(serverMessage));
}
public PlayerStorage getPlayerStorage() {
return players;
}
public void removePlayer(MapleCharacter chr) {
players.removePlayer(chr.getId());
}
public int getConnectedClients() {
return players.getAllCharacters().size();
}
public void broadcastPacket(final byte[] data) {
for (MapleCharacter chr : players.getAllCharacters()) {
chr.announce(data);
}
}
public final int getId() {
return channel;
}
public String getIP() {
return ip;
}
public MapleEvent getEvent() {
return event;
}
public void setEvent(MapleEvent event) {
this.event = event;
}
public EventScriptManager getEventSM() {
return eventSM;
}
public void broadcastGMPacket(final byte[] data) {
for (MapleCharacter chr : players.getAllCharacters()) {
if (chr.isGM()) {
chr.announce(data);
}
}
}
public List<MapleCharacter> getPartyMembers(MapleParty party) {
List<MapleCharacter> partym = new ArrayList<>(8);
for (MaplePartyCharacter partychar : party.getMembers()) {
if (partychar.getChannel() == getId()) {
MapleCharacter chr = getPlayerStorage().getCharacterByName(partychar.getName());
if (chr != null) {
partym.add(chr);
}
}
}
return partym;
}
public class respawnMaps implements Runnable {
@Override
public void run() {
for (Entry<Integer, MapleMap> map : mapFactory.getMaps().entrySet()) {
map.getValue().respawn();
}
}
}
public Map<Integer, HiredMerchant> getHiredMerchants() {
return hiredMerchants;
}
public void addHiredMerchant(int chrid, HiredMerchant hm) {
WriteLock wlock = merchant_lock.writeLock();
wlock.lock();
try {
hiredMerchants.put(chrid, hm);
} finally {
wlock.unlock();
}
}
public void removeHiredMerchant(int chrid) {
WriteLock wlock = merchant_lock.writeLock();
wlock.lock();
try {
hiredMerchants.remove(chrid);
} finally {
wlock.unlock();
}
}
public int[] multiBuddyFind(int charIdFrom, int[] characterIds) {
List<Integer> ret = new ArrayList<>(characterIds.length);
PlayerStorage playerStorage = getPlayerStorage();
for (int characterId : characterIds) {
MapleCharacter chr = playerStorage.getCharacterById(characterId);
if (chr != null) {
if (chr.getBuddylist().containsVisible(charIdFrom)) {
ret.add(characterId);
}
}
}
int[] retArr = new int[ret.size()];
int pos = 0;
for (Integer i : ret) {
retArr[pos++] = i.intValue();
}
return retArr;
}
public List<MapleExpedition> getExpeditions() {
return expeditions;
}
public boolean isConnected(String name) {
return getPlayerStorage().getCharacterByName(name) != null;
}
public boolean finishedShutdown() {
return finishedShutdown;
}
public void setServerMessage(String message) {
this.serverMessage = message;
broadcastPacket(MaplePacketCreator.serverMessage(message));
}
private static String [] getEvents(){
List<String> events = new ArrayList<String>();
for (File file : new File("scripts/event").listFiles()){
events.add(file.getName().substring(0, file.getName().length() - 3));
}
return events.toArray(new String[0]);
}
public int getStoredVar(int key) {
if(storedVars.containsKey(key))
return storedVars.get(key);
return 0;
}
public void setStoredVar(int key, int val) {
this.storedVars.put(key, val);
}
}

View File

@@ -0,0 +1,47 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel;
/**
*
* @author Frz
*/
public class CharacterIdChannelPair {
private int charid;
private int channel;
public CharacterIdChannelPair() {
}
public CharacterIdChannelPair(int charid, int channel) {
this.charid = charid;
this.channel = channel;
}
public int getCharacterId() {
return charid;
}
public int getChannel() {
return channel;
}
}

View File

@@ -0,0 +1,793 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.AbstractMaplePacketHandler;
import server.MapleItemInformationProvider;
import server.MapleStatEffect;
import server.TimerManager;
import server.life.Element;
import server.life.ElementalEffectiveness;
import server.life.MapleMonster;
import server.life.MapleMonsterInformationProvider;
import server.life.MobSkill;
import server.life.MobSkillFactory;
import server.life.MonsterDropEntry;
import server.maps.MapleMap;
import server.maps.MapleMapItem;
import server.maps.MapleMapObject;
import server.maps.MapleMapObjectType;
import server.partyquest.Pyramid;
import tools.MaplePacketCreator;
import tools.Pair;
import tools.Randomizer;
import tools.data.input.LittleEndianAccessor;
import client.MapleBuffStat;
import client.MapleCharacter;
import client.MapleJob;
import client.MapleStat;
import client.Skill;
import client.SkillFactory;
import client.autoban.AutobanFactory;
import client.inventory.Equip;
import client.inventory.Item;
import client.inventory.MapleInventoryType;
import client.status.MonsterStatus;
import client.status.MonsterStatusEffect;
import constants.GameConstants;
import constants.ItemConstants;
import constants.skills.Aran;
import constants.skills.Assassin;
import constants.skills.Bandit;
import constants.skills.Bishop;
import constants.skills.BlazeWizard;
import constants.skills.Bowmaster;
import constants.skills.Brawler;
import constants.skills.Buccaneer;
import constants.skills.ChiefBandit;
import constants.skills.Cleric;
import constants.skills.Corsair;
import constants.skills.Crossbowman;
import constants.skills.Crusader;
import constants.skills.DawnWarrior;
import constants.skills.DragonKnight;
import constants.skills.Evan;
import constants.skills.FPArchMage;
import constants.skills.FPMage;
import constants.skills.FPWizard;
import constants.skills.Fighter;
import constants.skills.Gunslinger;
import constants.skills.Hermit;
import constants.skills.Hero;
import constants.skills.Hunter;
import constants.skills.ILArchMage;
import constants.skills.ILMage;
import constants.skills.Marauder;
import constants.skills.Marksman;
import constants.skills.NightLord;
import constants.skills.NightWalker;
import constants.skills.Outlaw;
import constants.skills.Page;
import constants.skills.Paladin;
import constants.skills.Ranger;
import constants.skills.Rogue;
import constants.skills.Shadower;
import constants.skills.Sniper;
import constants.skills.Spearman;
import constants.skills.SuperGM;
import constants.skills.ThunderBreaker;
import constants.skills.WhiteKnight;
import constants.skills.WindArcher;
public abstract class AbstractDealDamageHandler extends AbstractMaplePacketHandler {
public static class AttackInfo {
public int numAttacked, numDamage, numAttackedAndDamage, skill, skilllevel, stance, direction, rangedirection, charge, display;
public Map<Integer, List<Integer>> allDamage;
public boolean isHH = false, isTempest = false, ranged, magic;
public int speed = 4;
public Point position = new Point();
public MapleStatEffect getAttackEffect(MapleCharacter chr, Skill theSkill) {
Skill mySkill = theSkill;
if (mySkill == null) {
mySkill = SkillFactory.getSkill(GameConstants.getHiddenSkill(skill));
}
int skillLevel = chr.getSkillLevel(mySkill);
if (mySkill.getId() % 10000000 == 1020) {
if (chr.getPartyQuest() instanceof Pyramid) {
if (((Pyramid) chr.getPartyQuest()).useSkill()) {
skillLevel = 1;
}
}
}
if (skillLevel == 0) {
return null;
}
if (display > 80) { //Hmm
if (!theSkill.getAction()) {
AutobanFactory.FAST_ATTACK.autoban(chr, "WZ Edit; adding action to a skill: " + display);
return null;
}
}
return mySkill.getEffect(skillLevel);
}
}
protected synchronized void applyAttack(AttackInfo attack, final MapleCharacter player, int attackCount) {
Skill theSkill = null;
MapleStatEffect attackEffect = null;
final int job = player.getJob().getId();
try {
if (player.isBanned()) {
return;
}
if (attack.skill != 0) {
theSkill = SkillFactory.getSkill(GameConstants.getHiddenSkill(attack.skill)); //returns back the skill id if its not a hidden skill so we are gucci
attackEffect = attack.getAttackEffect(player, theSkill);
if (attackEffect == null) {
player.getClient().announce(MaplePacketCreator.enableActions());
return;
}
if (player.getMp() < attackEffect.getMpCon()) {
AutobanFactory.MPCON.addPoint(player.getAutobanManager(), "Skill: " + attack.skill + "; Player MP: " + player.getMp() + "; MP Needed: " + attackEffect.getMpCon());
}
if (attack.skill != Cleric.HEAL) {
if (player.isAlive()) {
if(attack.skill == NightWalker.POISON_BOMB) // Poison Bomb
attackEffect.applyTo(player, new Point(attack.position.x, attack.position.y));
else
attackEffect.applyTo(player);
} else {
player.getClient().announce(MaplePacketCreator.enableActions());
}
}
int mobCount = attackEffect.getMobCount();
if (attack.skill == DawnWarrior.FINAL_ATTACK || attack.skill == Page.FINAL_ATTACK_BW || attack.skill == Page.FINAL_ATTACK_SWORD || attack.skill == Fighter.FINAL_ATTACK_SWORD
|| attack.skill == Fighter.FINAL_ATTACK_AXE || attack.skill == Spearman.FINAL_ATTACK_SPEAR || attack.skill == Spearman.FINAL_ATTACK_POLEARM || attack.skill == WindArcher.FINAL_ATTACK
|| attack.skill == DawnWarrior.FINAL_ATTACK || attack.skill == Hunter.FINAL_ATTACK || attack.skill == Crossbowman.FINAL_ATTACK) {
mobCount = 15;//:(
}
if (attack.skill == Aran.HIDDEN_FULL_DOUBLE || attack.skill == Aran.HIDDEN_FULL_TRIPLE || attack.skill == Aran.HIDDEN_OVER_DOUBLE || attack.skill == Aran.HIDDEN_OVER_TRIPLE) {
mobCount = 12;
}
if (attack.numAttacked > mobCount) {
AutobanFactory.MOB_COUNT.autoban(player, "Skill: " + attack.skill + "; Count: " + attack.numAttacked + " Max: " + attackEffect.getMobCount());
return;
}
}
if (!player.isAlive()) {
return;
}
//WTF IS THIS F3,1
/*if (attackCount != attack.numDamage && attack.skill != ChiefBandit.MESO_EXPLOSION && attack.skill != NightWalker.VAMPIRE && attack.skill != WindArcher.WIND_SHOT && attack.skill != Aran.COMBO_SMASH && attack.skill != Aran.COMBO_PENRIL && attack.skill != Aran.COMBO_TEMPEST && attack.skill != NightLord.NINJA_AMBUSH && attack.skill != Shadower.NINJA_AMBUSH) {
return;
}*/
int totDamage = 0;
final MapleMap map = player.getMap();
if (attack.skill == ChiefBandit.MESO_EXPLOSION) {
int delay = 0;
for (Integer oned : attack.allDamage.keySet()) {
MapleMapObject mapobject = map.getMapObject(oned.intValue());
if (mapobject != null && mapobject.getType() == MapleMapObjectType.ITEM) {
final MapleMapItem mapitem = (MapleMapItem) mapobject;
if (mapitem.getMeso() == 0) { //Maybe it is possible some how?
return;
}
synchronized (mapitem) {
if (mapitem.isPickedUp()) {
return;
}
TimerManager.getInstance().schedule(new Runnable() {
@Override
public void run() {
map.removeMapObject(mapitem);
map.broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 4, 0), mapitem.getPosition());
mapitem.setPickedUp(true);
}
}, delay);
delay += 100;
}
} else if (mapobject != null && mapobject.getType() != MapleMapObjectType.MONSTER) {
return;
}
}
}
for (Integer oned : attack.allDamage.keySet()) {
final MapleMonster monster = map.getMonsterByOid(oned.intValue());
if (monster != null) {
double distance = player.getPosition().distanceSq(monster.getPosition());
double distanceToDetect = 200000.0;
if(attack.ranged)
distanceToDetect += 400000;
if(attack.magic)
distanceToDetect += 200000;
if(player.getJob().isA(MapleJob.ARAN1))
distanceToDetect += 200000; // Arans have extra range over normal warriors.
if(attack.skill == Aran.COMBO_SMASH || attack.skill == Aran.BODY_PRESSURE)
distanceToDetect += 40000;
if(attack.skill == Bishop.GENESIS || attack.skill == ILArchMage.BLIZZARD || attack.skill == FPArchMage.METEOR_SHOWER)
distanceToDetect += 275000;
if(attack.skill == Hero.BRANDISH || attack.skill == DragonKnight.SPEAR_CRUSHER || attack.skill == DragonKnight.POLE_ARM_CRUSHER);
distanceToDetect += 40000;
if(attack.skill == DragonKnight.DRAGON_ROAR || attack.skill == SuperGM.SUPER_DRAGON_ROAR)
distanceToDetect += 250000;
if(attack.skill == Shadower.BOOMERANG_STEP)
distanceToDetect += 60000;
if(distance > distanceToDetect) {
AutobanFactory.DISTANCE_HACK.alert(player, "Distance Sq to monster: " + distance + " SID: " + attack.skill + " MID: " + monster.getId());
}
int totDamageToOneMonster = 0;
List<Integer> onedList = attack.allDamage.get(oned);
for (Integer eachd : onedList) {
if(eachd < 0)
eachd += Integer.MAX_VALUE;
totDamageToOneMonster += eachd;
}
totDamage += totDamageToOneMonster;
player.checkMonsterAggro(monster);
if (player.getBuffedValue(MapleBuffStat.PICKPOCKET) != null && (attack.skill == 0 || attack.skill == Rogue.DOUBLE_STAB || attack.skill == Bandit.SAVAGE_BLOW || attack.skill == ChiefBandit.ASSAULTER || attack.skill == ChiefBandit.BAND_OF_THIEVES || attack.skill == Shadower.ASSASSINATE || attack.skill == Shadower.TAUNT || attack.skill == Shadower.BOOMERANG_STEP)) {
Skill pickpocket = SkillFactory.getSkill(ChiefBandit.PICKPOCKET);
int delay = 0;
final int maxmeso = player.getBuffedValue(MapleBuffStat.PICKPOCKET).intValue();
for (Integer eachd : onedList) {
eachd += Integer.MAX_VALUE;
if (pickpocket.getEffect(player.getSkillLevel(pickpocket)).makeChanceResult()) {
final Integer eachdf;
if(eachd < 0)
eachdf = eachd + Integer.MAX_VALUE;
else
eachdf = eachd;
TimerManager.getInstance().schedule(new Runnable() {
@Override
public void run() {
player.getMap().spawnMesoDrop(Math.min((int) Math.max(((double) eachdf / (double) 20000) * (double) maxmeso, (double) 1), maxmeso), new Point((int) (monster.getPosition().getX() + Randomizer.nextInt(100) - 50), (int) (monster.getPosition().getY())), monster, player, true, (byte) 2);
}
}, delay);
delay += 100;
}
}
} else if (attack.skill == Marauder.ENERGY_DRAIN || attack.skill == ThunderBreaker.ENERGY_DRAIN || attack.skill == NightWalker.VAMPIRE || attack.skill == Assassin.DRAIN) {
player.addHP(Math.min(monster.getMaxHp(), Math.min((int) ((double) totDamage * (double) SkillFactory.getSkill(attack.skill).getEffect(player.getSkillLevel(SkillFactory.getSkill(attack.skill))).getX() / 100.0), player.getMaxHp() / 2)));
} else if (attack.skill == Bandit.STEAL) {
Skill steal = SkillFactory.getSkill(Bandit.STEAL);
if (monster.getStolen().size() < 1) { // One steal per mob <3
if (Math.random() < 0.3 && steal.getEffect(player.getSkillLevel(steal)).makeChanceResult()) { //Else it drops too many cool stuff :(
List<MonsterDropEntry> toSteals = MapleMonsterInformationProvider.getInstance().retrieveDrop(monster.getId());
Collections.shuffle(toSteals);
int toSteal = toSteals.get(rand(0, (toSteals.size() - 1))).itemId;
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
Item item;
if (ItemConstants.getInventoryType(toSteal).equals(MapleInventoryType.EQUIP)) {
item = ii.randomizeStats((Equip) ii.getEquipById(toSteal));
} else {
item = new Item(toSteal, (byte) 0, (short) 1, -1);
}
player.getMap().spawnItemDrop(monster, player, item, monster.getPosition(), false, false);
monster.addStolen(toSteal);
}
}
} else if (attack.skill == FPArchMage.FIRE_DEMON) {
monster.setTempEffectiveness(Element.ICE, ElementalEffectiveness.WEAK, SkillFactory.getSkill(FPArchMage.FIRE_DEMON).getEffect(player.getSkillLevel(SkillFactory.getSkill(FPArchMage.FIRE_DEMON))).getDuration() * 1000);
} else if (attack.skill == ILArchMage.ICE_DEMON) {
monster.setTempEffectiveness(Element.FIRE, ElementalEffectiveness.WEAK, SkillFactory.getSkill(ILArchMage.ICE_DEMON).getEffect(player.getSkillLevel(SkillFactory.getSkill(ILArchMage.ICE_DEMON))).getDuration() * 1000);
} else if (attack.skill == Outlaw.HOMING_BEACON || attack.skill == Corsair.BULLSEYE) {
player.setMarkedMonster(monster.getObjectId());
player.announce(MaplePacketCreator.giveBuff(1, attack.skill, Collections.singletonList(new Pair<>(MapleBuffStat.HOMING_BEACON, monster.getObjectId()))));
}
if (job == 2111 || job == 2112) {
if (player.getBuffedValue(MapleBuffStat.WK_CHARGE) != null) {
Skill snowCharge = SkillFactory.getSkill(Aran.SNOW_CHARGE);
if (totDamageToOneMonster > 0) {
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.SPEED, snowCharge.getEffect(player.getSkillLevel(snowCharge)).getX()), snowCharge, null, false);
monster.applyStatus(player, monsterStatusEffect, false, snowCharge.getEffect(player.getSkillLevel(snowCharge)).getY() * 1000);
}
}
}
if (player.getBuffedValue(MapleBuffStat.HAMSTRING) != null) {
Skill hamstring = SkillFactory.getSkill(Bowmaster.HAMSTRING);
if (hamstring.getEffect(player.getSkillLevel(hamstring)).makeChanceResult()) {
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.SPEED, hamstring.getEffect(player.getSkillLevel(hamstring)).getX()), hamstring, null, false);
monster.applyStatus(player, monsterStatusEffect, false, hamstring.getEffect(player.getSkillLevel(hamstring)).getY() * 1000);
}
}
if (player.getBuffedValue(MapleBuffStat.SLOW) != null) {
Skill slow = SkillFactory.getSkill(Evan.SLOW);
if (slow.getEffect(player.getSkillLevel(slow)).makeChanceResult()) {
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.SPEED, slow.getEffect(player.getSkillLevel(slow)).getX()), slow, null, false);
monster.applyStatus(player, monsterStatusEffect, false, slow.getEffect(player.getSkillLevel(slow)).getY() * 60 * 1000);
}
}
if (player.getBuffedValue(MapleBuffStat.BLIND) != null) {
Skill blind = SkillFactory.getSkill(Marksman.BLIND);
if (blind.getEffect(player.getSkillLevel(blind)).makeChanceResult()) {
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.ACC, blind.getEffect(player.getSkillLevel(blind)).getX()), blind, null, false);
monster.applyStatus(player, monsterStatusEffect, false, blind.getEffect(player.getSkillLevel(blind)).getY() * 1000);
}
}
if (job == 121 || job == 122) {
for (int charge = 1211005; charge < 1211007; charge++) {
Skill chargeSkill = SkillFactory.getSkill(charge);
if (player.isBuffFrom(MapleBuffStat.WK_CHARGE, chargeSkill)) {
if (totDamageToOneMonster > 0) {
if (charge == WhiteKnight.BW_ICE_CHARGE || charge == WhiteKnight.SWORD_ICE_CHARGE) {
monster.setTempEffectiveness(Element.ICE, ElementalEffectiveness.WEAK, chargeSkill.getEffect(player.getSkillLevel(chargeSkill)).getY() * 1000);
break;
}
if (charge == WhiteKnight.BW_FIRE_CHARGE || charge == WhiteKnight.SWORD_FIRE_CHARGE) {
monster.setTempEffectiveness(Element.FIRE, ElementalEffectiveness.WEAK, chargeSkill.getEffect(player.getSkillLevel(chargeSkill)).getY() * 1000);
break;
}
}
}
}
if (job == 122) {
for (int charge = 1221003; charge < 1221004; charge++) {
Skill chargeSkill = SkillFactory.getSkill(charge);
if (player.isBuffFrom(MapleBuffStat.WK_CHARGE, chargeSkill)) {
if (totDamageToOneMonster > 0) {
monster.setTempEffectiveness(Element.HOLY, ElementalEffectiveness.WEAK, chargeSkill.getEffect(player.getSkillLevel(chargeSkill)).getY() * 1000);
break;
}
}
}
}
} else if (player.getBuffedValue(MapleBuffStat.COMBO_DRAIN) != null) {
Skill skill;
if (player.getBuffedValue(MapleBuffStat.COMBO_DRAIN) != null) {
skill = SkillFactory.getSkill(21100005);
player.setHp(player.getHp() + ((totDamage * skill.getEffect(player.getSkillLevel(skill)).getX()) / 100), true);
player.updateSingleStat(MapleStat.HP, player.getHp());
}
} else if (job == 412 || job == 422 || job == 1411) {
Skill type = SkillFactory.getSkill(player.getJob().getId() == 412 ? 4120005 : (player.getJob().getId() == 1411 ? 14110004 : 4220005));
if (player.getSkillLevel(type) > 0) {
MapleStatEffect venomEffect = type.getEffect(player.getSkillLevel(type));
for (int i = 0; i < attackCount; i++) {
if (venomEffect.makeChanceResult()) {
if (monster.getVenomMulti() < 3) {
monster.setVenomMulti((monster.getVenomMulti() + 1));
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.POISON, 1), type, null, false);
monster.applyStatus(player, monsterStatusEffect, false, venomEffect.getDuration(), true);
}
}
}
}
} else if (job == 521 || job == 522) { // from what I can gather this is how it should work
if (!monster.isBoss()) {
Skill type = SkillFactory.getSkill(Outlaw.FLAME_THROWER);
if (player.getSkillLevel(type) > 0) {
MapleStatEffect DoT = type.getEffect(player.getSkillLevel(type));
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.POISON, 1), type, null, false);
monster.applyStatus(player, monsterStatusEffect, true, DoT.getDuration(), false);
}
}
} else if (job >= 311 && job <= 322) {
if (!monster.isBoss()) {
Skill mortalBlow;
if (job == 311 || job == 312) {
mortalBlow = SkillFactory.getSkill(Ranger.MORTAL_BLOW);
} else {
mortalBlow = SkillFactory.getSkill(Sniper.MORTAL_BLOW);
}
if (player.getSkillLevel(mortalBlow) > 0) {
MapleStatEffect mortal = mortalBlow.getEffect(player.getSkillLevel(mortalBlow));
if (monster.getHp() <= (monster.getStats().getHp() * mortal.getX()) / 100) {
if (Randomizer.rand(1, 100) <= mortal.getY()) {
monster.getMap().killMonster(monster, player, true);
}
}
}
}
}
if (attack.skill != 0) {
if (attackEffect.getFixDamage() != -1) {
if (totDamageToOneMonster != attackEffect.getFixDamage() && totDamageToOneMonster != 0) {
AutobanFactory.FIX_DAMAGE.autoban(player, String.valueOf(totDamageToOneMonster) + " damage");
}
}
}
if (totDamageToOneMonster > 0 && attackEffect != null && attackEffect.getMonsterStati().size() > 0) {
if (attackEffect.makeChanceResult()) {
monster.applyStatus(player, new MonsterStatusEffect(attackEffect.getMonsterStati(), theSkill, null, false), attackEffect.isPoison(), attackEffect.getDuration());
}
}
if (attack.isHH && !monster.isBoss()) {
map.damageMonster(player, monster, monster.getHp() - 1);
} else if (attack.isHH) {
int HHDmg = (player.calculateMaxBaseDamage(player.getTotalWatk()) * (SkillFactory.getSkill(Paladin.HEAVENS_HAMMER).getEffect(player.getSkillLevel(SkillFactory.getSkill(Paladin.HEAVENS_HAMMER))).getDamage() / 100));
map.damageMonster(player, monster, (int) (Math.floor(Math.random() * (HHDmg / 5) + HHDmg * .8)));
} else if(attack.isTempest && !monster.isBoss()) {
map.damageMonster(player, monster, monster.getHp());
} else if(attack.isTempest) {
int TmpDmg = (player.calculateMaxBaseDamage(player.getTotalWatk()) * (SkillFactory.getSkill(Aran.COMBO_TEMPEST).getEffect(player.getSkillLevel(SkillFactory.getSkill(Aran.COMBO_TEMPEST))).getDamage() / 100));
map.damageMonster(player, monster, (int) (Math.floor(Math.random() * (TmpDmg / 5) + TmpDmg * .8)));
} else {
map.damageMonster(player, monster, totDamageToOneMonster);
}
if (monster.isBuffed(MonsterStatus.WEAPON_REFLECT)) {
for (int i = 0; i < monster.getSkills().size(); i++) {
if (monster.getSkills().get(i).left == 145) {
MobSkill toUse = MobSkillFactory.getMobSkill(monster.getSkills().get(i).left, monster.getSkills().get(i).right);
player.addHP(-toUse.getX());
map.broadcastMessage(player, MaplePacketCreator.damagePlayer(0, monster.getId(), player.getId(), toUse.getX(), 0, 0, false, 0, true, monster.getObjectId(), 0, 0), true);
}
}
}
if (monster.isBuffed(MonsterStatus.MAGIC_REFLECT)) {
for (int i = 0; i < monster.getSkills().size(); i++) {
if (monster.getSkills().get(i).left == 145) {
MobSkill toUse = MobSkillFactory.getMobSkill(monster.getSkills().get(i).left, monster.getSkills().get(i).right);
player.addMP(-toUse.getY());
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
protected AttackInfo parseDamage(LittleEndianAccessor lea, MapleCharacter chr, boolean ranged, boolean magic) {
//2C 00 00 01 91 A1 12 00 A5 57 62 FC E2 75 99 10 00 47 80 01 04 01 C6 CC 02 DD FF 5F 00
AttackInfo ret = new AttackInfo();
lea.readByte();
ret.numAttackedAndDamage = lea.readByte();
ret.numAttacked = (ret.numAttackedAndDamage >>> 4) & 0xF;
ret.numDamage = ret.numAttackedAndDamage & 0xF;
ret.allDamage = new HashMap<>();
ret.skill = lea.readInt();
ret.ranged = ranged;
ret.magic = magic;
if (ret.skill > 0) {
ret.skilllevel = chr.getSkillLevel(ret.skill);
}
if (ret.skill == Evan.ICE_BREATH || ret.skill == Evan.FIRE_BREATH || ret.skill == FPArchMage.BIG_BANG || ret.skill == ILArchMage.BIG_BANG || ret.skill == Bishop.BIG_BANG || ret.skill == Gunslinger.GRENADE || ret.skill == Brawler.CORKSCREW_BLOW || ret.skill == ThunderBreaker.CORKSCREW_BLOW || ret.skill == NightWalker.POISON_BOMB) {
ret.charge = lea.readInt();
} else {
ret.charge = 0;
}
if (ret.skill == Paladin.HEAVENS_HAMMER) {
ret.isHH = true;
} else if(ret.skill == Aran.COMBO_TEMPEST) {
ret.isTempest = true;
}
lea.skip(8);
ret.display = lea.readByte();
ret.direction = lea.readByte();
ret.stance = lea.readByte();
if (ret.skill == ChiefBandit.MESO_EXPLOSION) {
if (ret.numAttackedAndDamage == 0) {
lea.skip(10);
int bullets = lea.readByte();
for (int j = 0; j < bullets; j++) {
int mesoid = lea.readInt();
lea.skip(1);
ret.allDamage.put(Integer.valueOf(mesoid), null);
}
return ret;
} else {
lea.skip(6);
}
for (int i = 0; i < ret.numAttacked + 1; i++) {
int oid = lea.readInt();
if (i < ret.numAttacked) {
lea.skip(12);
int bullets = lea.readByte();
List<Integer> allDamageNumbers = new ArrayList<>();
for (int j = 0; j < bullets; j++) {
int damage = lea.readInt();
allDamageNumbers.add(Integer.valueOf(damage));
}
ret.allDamage.put(Integer.valueOf(oid), allDamageNumbers);
lea.skip(4);
} else {
int bullets = lea.readByte();
for (int j = 0; j < bullets; j++) {
int mesoid = lea.readInt();
lea.skip(1);
ret.allDamage.put(Integer.valueOf(mesoid), null);
}
}
}
return ret;
}
if (ranged) {
lea.readByte();
ret.speed = lea.readByte();
lea.readByte();
ret.rangedirection = lea.readByte();
lea.skip(7);
if (ret.skill == Bowmaster.HURRICANE || ret.skill == Marksman.PIERCING_ARROW || ret.skill == Corsair.RAPID_FIRE || ret.skill == WindArcher.HURRICANE) {
lea.skip(4);
}
} else {
lea.readByte();
ret.speed = lea.readByte();
lea.skip(4);
}
int calcDmgMax = 0;
// Find the base damage to base futher calculations on.
// Several skills have their own formula in this section.
if(magic && ret.skill != 0) {
calcDmgMax = (chr.getTotalMagic() * chr.getTotalMagic() / 1000 + chr.getTotalMagic()) / 30 + chr.getTotalInt() / 200;
} else if(ret.skill == 4001344 || ret.skill == NightWalker.LUCKY_SEVEN || ret.skill == NightLord.TRIPLE_THROW) {
calcDmgMax = (chr.getTotalLuk() * 5) * chr.getTotalWatk() / 100;
} else if(ret.skill == DragonKnight.DRAGON_ROAR) {
calcDmgMax = (chr.getTotalStr() * 4 + chr.getTotalDex()) * chr.getTotalWatk() / 100;
} else if(ret.skill == NightLord.VENOMOUS_STAR || ret.skill == Shadower.VENOMOUS_STAB) {
calcDmgMax = (int) (18.5 * (chr.getTotalStr() + chr.getTotalLuk()) + chr.getTotalDex() * 2) / 100 * chr.calculateMaxBaseDamage(chr.getTotalWatk());
} else {
calcDmgMax = chr.calculateMaxBaseDamage(chr.getTotalWatk());
}
if(ret.skill != 0) {
Skill skill = SkillFactory.getSkill(ret.skill);
MapleStatEffect effect = skill.getEffect(ret.skilllevel);
if (magic) {
// Since the skill is magic based, use the magic formula
if(chr.getJob() == MapleJob.IL_ARCHMAGE || chr.getJob() == MapleJob.IL_MAGE) {
int skillLvl = chr.getSkillLevel(ILMage.ELEMENT_AMPLIFICATION);
if(skillLvl > 0)
calcDmgMax = calcDmgMax * SkillFactory.getSkill(ILMage.ELEMENT_AMPLIFICATION).getEffect(skillLvl).getY() / 100;
} else if(chr.getJob() == MapleJob.FP_ARCHMAGE || chr.getJob() == MapleJob.FP_MAGE) {
int skillLvl = chr.getSkillLevel(FPMage.ELEMENT_AMPLIFICATION);
if(skillLvl > 0)
calcDmgMax = calcDmgMax * SkillFactory.getSkill(FPMage.ELEMENT_AMPLIFICATION).getEffect(skillLvl).getY() / 100;
} else if(chr.getJob() == MapleJob.BLAZEWIZARD3 || chr.getJob() == MapleJob.BLAZEWIZARD4) {
int skillLvl = chr.getSkillLevel(BlazeWizard.ELEMENT_AMPLIFICATION);
if(skillLvl > 0)
calcDmgMax = calcDmgMax * SkillFactory.getSkill(BlazeWizard.ELEMENT_AMPLIFICATION).getEffect(skillLvl).getY() / 100;
} else if(chr.getJob() == MapleJob.EVAN7 || chr.getJob() == MapleJob.EVAN8 || chr.getJob() == MapleJob.EVAN9 || chr.getJob() == MapleJob.EVAN10) {
int skillLvl = chr.getSkillLevel(Evan.MAGIC_AMPLIFICATION);
if(skillLvl > 0)
calcDmgMax = calcDmgMax * SkillFactory.getSkill(Evan.MAGIC_AMPLIFICATION).getEffect(skillLvl).getY() / 100;
}
calcDmgMax *= effect.getMatk();
if(ret.skill == Cleric.HEAL) {
// This formula is still a bit wonky, but it is fairly accurate.
calcDmgMax = (int) Math.round((chr.getTotalInt() * 4.8 + chr.getTotalLuk() * 4) * chr.getTotalMagic() / 1000);
calcDmgMax = calcDmgMax * effect.getHp() / 100;
}
} else if(ret.skill == Hermit.SHADOW_MESO) {
// Shadow Meso also has its own formula
calcDmgMax = effect.getMoneyCon() * 10;
calcDmgMax = (int) Math.floor(calcDmgMax * 1.5);
} else {
// Normal damage formula for skills
calcDmgMax = calcDmgMax * effect.getDamage() / 100;
}
}
Integer comboBuff = chr.getBuffedValue(MapleBuffStat.COMBO);
if(comboBuff != null && comboBuff > 0) {
int oid = chr.isCygnus() ? DawnWarrior.COMBO : Crusader.COMBO;
int advcomboid = chr.isCygnus() ? DawnWarrior.ADVANCED_COMBO : Hero.ADVANCED_COMBO;
if(comboBuff > 6) {
// Advanced Combo
MapleStatEffect ceffect = SkillFactory.getSkill(advcomboid).getEffect(chr.getSkillLevel(advcomboid));
calcDmgMax = (int) Math.floor(calcDmgMax * (ceffect.getDamage() + 50) / 100 + 0.20 + (comboBuff - 5) * 0.04);
} else {
// Normal Combo
MapleStatEffect ceffect = SkillFactory.getSkill(oid).getEffect(chr.getSkillLevel(oid));
calcDmgMax = (int) Math.floor(calcDmgMax * (ceffect.getDamage() + 50) / 100 + Math.floor((comboBuff - 1) * (chr.getSkillLevel(oid) / 6)) / 100);
}
if(GameConstants.isFinisherSkill(ret.skill)) {
// Finisher skills do more damage based on how many orbs the player has.
int orbs = comboBuff - 1;
if(orbs == 2)
calcDmgMax *= 1.2;
else if(orbs == 3)
calcDmgMax *= 1.54;
else if(orbs == 4)
calcDmgMax *= 2;
else if(orbs >= 5)
calcDmgMax *= 2.5;
}
}
if(chr.getEnergyBar() == 15000) {
int energycharge = chr.isCygnus() ? ThunderBreaker.ENERGY_CHARGE : Marauder.ENERGY_CHARGE;
MapleStatEffect ceffect = SkillFactory.getSkill(energycharge).getEffect(chr.getSkillLevel(energycharge));
calcDmgMax *= ceffect.getDamage() / 100;
}
if(chr.getMapId() >= 914000000 && chr.getMapId() <= 914000500) {
calcDmgMax += 80000; // Aran Tutorial.
}
boolean canCrit = false;
if(chr.getJob().isA((MapleJob.BOWMAN)) || chr.getJob().isA(MapleJob.THIEF) || chr.getJob().isA(MapleJob.NIGHTWALKER1) || chr.getJob().isA(MapleJob.WINDARCHER1) || chr.getJob() == MapleJob.ARAN3 || chr.getJob() == MapleJob.ARAN4 || chr.getJob() == MapleJob.MARAUDER || chr.getJob() == MapleJob.BUCCANEER) {
canCrit = true;
}
if(chr.getBuffEffect(MapleBuffStat.SHARP_EYES) != null) {
// Any class that has sharp eyes can crit. Also, since it stacks with normal crit go ahead
// and calc it in.
canCrit = true;
calcDmgMax *= 1.4;
}
boolean shadowPartner = false;
if(chr.getBuffEffect(MapleBuffStat.SHADOWPARTNER) != null)
shadowPartner = true;
if(ret.skill != 0) {
int fixed = ret.getAttackEffect(chr, SkillFactory.getSkill(ret.skill)).getFixDamage();
if(fixed > 0)
calcDmgMax = fixed;
}
for (int i = 0; i < ret.numAttacked; i++) {
int oid = lea.readInt();
lea.skip(14);
List<Integer> allDamageNumbers = new ArrayList<>();
MapleMonster monster = chr.getMap().getMonsterByOid(oid);
if(chr.getBuffEffect(MapleBuffStat.WK_CHARGE) != null) {
// Charge, so now we need to check elemental effectiveness
int sourceID = chr.getBuffSource(MapleBuffStat.WK_CHARGE);
int level = chr.getBuffedValue(MapleBuffStat.WK_CHARGE);
if(monster != null) {
if(sourceID == WhiteKnight.BW_FIRE_CHARGE || sourceID == WhiteKnight.SWORD_FIRE_CHARGE) {
if(monster.getStats().getEffectiveness(Element.FIRE) == ElementalEffectiveness.WEAK) {
calcDmgMax *= 1.05 + level * 0.015;
}
} else if(sourceID == WhiteKnight.BW_ICE_CHARGE || sourceID == WhiteKnight.SWORD_ICE_CHARGE) {
if(monster.getStats().getEffectiveness(Element.ICE) == ElementalEffectiveness.WEAK) {
calcDmgMax *= 1.05 + level * 0.015;
}
} else if(sourceID == WhiteKnight.BW_LIT_CHARGE || sourceID == WhiteKnight.SWORD_LIT_CHARGE) {
if(monster.getStats().getEffectiveness(Element.LIGHTING) == ElementalEffectiveness.WEAK) {
calcDmgMax *= 1.05 + level * 0.015;
}
} else if(sourceID == Paladin.BW_HOLY_CHARGE || sourceID == Paladin.SWORD_HOLY_CHARGE) {
if(monster.getStats().getEffectiveness(Element.HOLY) == ElementalEffectiveness.WEAK) {
calcDmgMax *= 1.2 + level * 0.015;
}
}
} else {
// Since we already know the skill has an elemental attribute, but we dont know if the monster is weak or not, lets
// take the safe approach and just assume they are weak.
calcDmgMax *= 1.5;
}
}
if(ret.skill != 0) {
Skill skill = SkillFactory.getSkill(ret.skill);
if(skill.getElement() != Element.NEUTRAL && chr.getBuffedValue(MapleBuffStat.ELEMENTAL_RESET) == null) {
// The skill has an element effect, so we need to factor that in.
if(monster != null) {
ElementalEffectiveness eff = monster.getEffectiveness(skill.getElement());
if(eff == ElementalEffectiveness.WEAK) {
calcDmgMax *= 1.5;
} else if(eff == ElementalEffectiveness.STRONG) {
//calcDmgMax *= 0.5;
}
} else {
// Since we already know the skill has an elemental attribute, but we dont know if the monster is weak or not, lets
// take the safe approach and just assume they are weak.
calcDmgMax *= 1.5;
}
}
if(ret.skill == FPWizard.POISON_BREATH || ret.skill == FPMage.POISON_MIST || ret.skill == FPArchMage.FIRE_DEMON || ret.skill == ILArchMage.ICE_DEMON) {
if(monster != null) {
// Turns out poison is completely server side, so I don't know why I added this. >.<
//calcDmgMax = monster.getHp() / (70 - chr.getSkillLevel(skill));
}
} else if(ret.skill == Hermit.SHADOW_WEB) {
if(monster != null) {
calcDmgMax = monster.getHp() / (50 - chr.getSkillLevel(skill));
}
}
}
for (int j = 0; j < ret.numDamage; j++) {
int damage = lea.readInt();
int hitDmgMax = calcDmgMax;
if(ret.skill == Buccaneer.BARRAGE) {
if(j > 3)
hitDmgMax *= Math.pow(2, (j - 3));
}
if(shadowPartner) {
// For shadow partner, the second half of the hits only do 50% damage. So calc that
// in for the crit effects.
if(j >= ret.numDamage / 2) {
hitDmgMax *= 0.5;
}
}
if(ret.skill == Marksman.SNIPE) {
damage = 195000 + Randomizer.nextInt(5000);
hitDmgMax = 200000;
}
int maxWithCrit = hitDmgMax;
if(canCrit) // They can crit, so up the max.
maxWithCrit *= 2;
// Warn if the damage is over 1.5x what we calculated above.
if(damage > maxWithCrit * 1.5) {
AutobanFactory.DAMAGE_HACK.alert(chr, "DMG: " + damage + " MaxDMG: " + maxWithCrit + " SID: " + ret.skill + " MobID: " + (monster != null ? monster.getId() : "null") + " Map: " + chr.getMap().getMapName() + " (" + chr.getMapId() + ")");
}
// Add a ab point if its over 5x what we calculated.
if(damage > maxWithCrit * 5) {
AutobanFactory.DAMAGE_HACK.addPoint(chr.getAutobanManager(), "DMG: " + damage + " MaxDMG: " + maxWithCrit + " SID: " + ret.skill + " MobID: " + (monster != null ? monster.getId() : "null") + " Map: " + chr.getMap().getMapName() + " (" + chr.getMapId() + ")");
}
if (ret.skill == Marksman.SNIPE || (canCrit && damage > hitDmgMax)) {
// If the skill is a crit, inverse the damage to make it show up on clients.
damage = -Integer.MAX_VALUE + damage - 1;
}
allDamageNumbers.add(damage);
}
if (ret.skill != Corsair.RAPID_FIRE || ret.skill != Aran.HIDDEN_FULL_DOUBLE || ret.skill != Aran.HIDDEN_FULL_TRIPLE || ret.skill != Aran.HIDDEN_OVER_DOUBLE || ret.skill != Aran.HIDDEN_OVER_TRIPLE) {
lea.skip(4);
}
ret.allDamage.put(Integer.valueOf(oid), allDamageNumbers);
}
if (ret.skill == NightWalker.POISON_BOMB) { // Poison Bomb
lea.skip(4);
ret.position.setLocation(lea.readShort(), lea.readShort());
}
return ret;
}
private static int rand(int l, int u) {
return (int) ((Math.random() * (u - l + 1)) + l);
}
}

View File

@@ -0,0 +1,160 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import net.AbstractMaplePacketHandler;
import server.maps.AnimatedMapleMapObject;
import server.movement.AbsoluteLifeMovement;
import server.movement.ChangeEquip;
import server.movement.JumpDownMovement;
import server.movement.LifeMovement;
import server.movement.LifeMovementFragment;
import server.movement.RelativeLifeMovement;
import server.movement.TeleportMovement;
import tools.data.input.LittleEndianAccessor;
public abstract class AbstractMovementPacketHandler extends AbstractMaplePacketHandler {
protected List<LifeMovementFragment> parseMovement(LittleEndianAccessor lea) {
List<LifeMovementFragment> res = new ArrayList<>();
byte numCommands = lea.readByte();
for (byte i = 0; i < numCommands; i++) {
byte command = lea.readByte();
switch (command) {
case 0: // normal move
case 5:
case 17: { // Float
short xpos = lea.readShort();
short ypos = lea.readShort();
short xwobble = lea.readShort();
short ywobble = lea.readShort();
short unk = lea.readShort();
byte newstate = lea.readByte();
short duration = lea.readShort();
AbsoluteLifeMovement alm = new AbsoluteLifeMovement(command, new Point(xpos, ypos), duration, newstate);
alm.setUnk(unk);
alm.setPixelsPerSecond(new Point(xwobble, ywobble));
res.add(alm);
break;
}
case 1:
case 2:
case 6: // fj
case 12:
case 13: // Shot-jump-back thing
case 16: // Float
case 18:
case 19: // Springs on maps
case 20: // Aran Combat Step
case 22: {
short xpos = lea.readShort();
short ypos = lea.readShort();
byte newstate = lea.readByte();
short duration = lea.readShort();
RelativeLifeMovement rlm = new RelativeLifeMovement(command, new Point(xpos, ypos), duration, newstate);
res.add(rlm);
break;
}
case 3:
case 4: // tele... -.-
case 7: // assaulter
case 8: // assassinate
case 9: // rush
case 11: //chair
{
// case 14: {
short xpos = lea.readShort();
short ypos = lea.readShort();
short xwobble = lea.readShort();
short ywobble = lea.readShort();
byte newstate = lea.readByte();
TeleportMovement tm = new TeleportMovement(command, new Point(xpos, ypos), newstate);
tm.setPixelsPerSecond(new Point(xwobble, ywobble));
res.add(tm);
break;
}
case 14:
lea.skip(9); // jump down (?)
break;
case 10: // Change Equip
res.add(new ChangeEquip(lea.readByte()));
break;
/*case 11: { // Chair
short xpos = lea.readShort();
short ypos = lea.readShort();
short unk = lea.readShort();
byte newstate = lea.readByte();
short duration = lea.readShort();
ChairMovement cm = new ChairMovement(command, new Point(xpos, ypos), duration, newstate);
cm.setUnk(unk);
res.add(cm);
break;
}*/
case 15: {
short xpos = lea.readShort();
short ypos = lea.readShort();
short xwobble = lea.readShort();
short ywobble = lea.readShort();
short unk = lea.readShort();
short fh = lea.readShort();
byte newstate = lea.readByte();
short duration = lea.readShort();
JumpDownMovement jdm = new JumpDownMovement(command, new Point(xpos, ypos), duration, newstate);
jdm.setUnk(unk);
jdm.setPixelsPerSecond(new Point(xwobble, ywobble));
jdm.setFH(fh);
res.add(jdm);
break;
}
case 21: {//Causes aran to do weird stuff when attacking o.o
/*byte newstate = lea.readByte();
short unk = lea.readShort();
AranMovement am = new AranMovement(command, null, unk, newstate);
res.add(am);*/
lea.skip(3);
break;
}
default:
System.out.println("Unhandled Case:" + command);
return null;
}
}
return res;
}
protected void updatePosition(List<LifeMovementFragment> movement, AnimatedMapleMapObject target, int yoffset) {
for (LifeMovementFragment move : movement) {
if (move instanceof LifeMovement) {
if (move instanceof AbsoluteLifeMovement) {
Point position = ((LifeMovement) move).getPosition();
position.y += yoffset;
target.setPosition(position);
}
target.setStance(((LifeMovement) move).getNewstate());
}
}
}
}

View File

@@ -0,0 +1,51 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import constants.ServerConstants;
import client.MapleCharacter;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author Jay Estrella
*/
public final class AcceptFamilyHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!ServerConstants.USE_FAMILY_SYSTEM){
return;
}
//System.out.println(slea.toString());
int inviterId = slea.readInt();
//String inviterName = slea.readMapleAsciiString();
MapleCharacter inviter = c.getWorldServer().getPlayerStorage().getCharacterById(inviterId);
if (inviter != null) {
inviter.getClient().announce(MaplePacketCreator.sendFamilyJoinResponse(true, c.getPlayer().getName()));
}
c.announce(MaplePacketCreator.sendFamilyMessage(0, 0));
}
}

View File

@@ -0,0 +1,35 @@
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author kevintjuh93
*/
public class AdminChatHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!c.getPlayer().isGM()) {//if ( (signed int)CWvsContext::GetAdminLevel((void *)v294) > 2 )
return;
}
byte mode = slea.readByte();
//not saving slides...
byte[] packet = MaplePacketCreator.serverNotice(slea.readByte(), slea.readMapleAsciiString());//maybe I should make a check for the slea.readByte()... but I just hope gm's don't fuck things up :)
switch (mode) {
case 0:// /alertall, /noticeall, /slideall
c.getWorldServer().broadcastPacket(packet);
break;
case 1:// /alertch, /noticech, /slidech
c.getChannelServer().broadcastPacket(packet);
break;
case 2:// /alertm /alertmap, /noticem /noticemap, /slidem /slidemap
c.getPlayer().getMap().broadcastMessage(packet);
break;
}
}
}

View File

@@ -0,0 +1,185 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import java.util.Arrays;
import java.util.List;
import net.AbstractMaplePacketHandler;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import server.life.MapleLifeFactory;
import server.life.MapleMonster;
import server.maps.MapleMapObject;
import server.maps.MapleMapObjectType;
import server.quest.MapleQuest;
import tools.MaplePacketCreator;
import tools.Randomizer;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleCharacter;
import client.MapleClient;
import client.inventory.MapleInventory;
import client.inventory.MapleInventoryType;
public final class AdminCommandHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!c.getPlayer().isGM()) {
return;
}
byte mode = slea.readByte();
String victim;
MapleCharacter target;
switch (mode) {
case 0x00: // Level1~Level8 & Package1~Package2
int[][] toSpawn = MapleItemInformationProvider.getInstance().getSummonMobs(slea.readInt());
for (int z = 0; z < toSpawn.length; z++) {
int[] toSpawnChild = toSpawn[z];
if (Randomizer.nextInt(101) <= toSpawnChild[1]) {
c.getPlayer().getMap().spawnMonsterOnGroudBelow(MapleLifeFactory.getMonster(toSpawnChild[0]), c.getPlayer().getPosition());
}
}
c.announce(MaplePacketCreator.enableActions());
break;
case 0x01: { // /d (inv)
byte type = slea.readByte();
MapleInventory in = c.getPlayer().getInventory(MapleInventoryType.getByType(type));
for (short i = 1; i <= in.getSlotLimit(); i++) { //TODO What is the point of this loop?
if (in.getItem(i) != null) {
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.getByType(type), i, in.getItem(i).getQuantity(), false);
}
return;
}
break;
}
case 0x02: // Exp
c.getPlayer().setExp(slea.readInt());
break;
case 0x03: // /ban <name>
c.getPlayer().yellowMessage("Please use !ban <IGN> <Reason>");
break;
case 0x04: // /block <name> <duration (in days)> <HACK/BOT/AD/HARASS/CURSE/SCAM/MISCONDUCT/SELL/ICASH/TEMP/GM/IPROGRAM/MEGAPHONE>
victim = slea.readMapleAsciiString();
int type = slea.readByte(); //reason
int duration = slea.readInt();
String description = slea.readMapleAsciiString();
String reason = c.getPlayer().getName() + " used /ban to ban";
target = c.getChannelServer().getPlayerStorage().getCharacterByName(victim);
if (target != null) {
String readableTargetName = MapleCharacter.makeMapleReadable(target.getName());
String ip = target.getClient().getSession().getRemoteAddress().toString().split(":")[0];
reason += readableTargetName + " (IP: " + ip + ")";
if (duration == -1) {
target.ban(description + " " + reason);
} else {
target.block(type, duration, description);
target.sendPolice(duration, reason, 6000);
}
c.announce(MaplePacketCreator.getGMEffect(4, (byte) 0));
} else if (MapleCharacter.ban(victim, reason, false)) {
c.announce(MaplePacketCreator.getGMEffect(4, (byte) 0));
} else {
c.announce(MaplePacketCreator.getGMEffect(6, (byte) 1));
}
break;
case 0x10: // /h, information by vana (and tele mode f1) ... hide ofcourse
c.getPlayer().Hide(slea.readByte() == 1);
break;
case 0x11: // Entering a map
switch (slea.readByte()) {
case 0:// /u
StringBuilder sb = new StringBuilder("USERS ON THIS MAP: ");
for (MapleCharacter mc : c.getPlayer().getMap().getCharacters()) {
sb.append(mc.getName());
sb.append(" ");
}
c.getPlayer().message(sb.toString());
break;
case 12:// /uclip and entering a map
break;
}
break;
case 0x12: // Send
victim = slea.readMapleAsciiString();
int mapId = slea.readInt();
c.getChannelServer().getPlayerStorage().getCharacterByName(victim).changeMap(c.getChannelServer().getMapFactory().getMap(mapId));
break;
case 0x15: // Kill
int mobToKill = slea.readInt();
int amount = slea.readInt();
List<MapleMapObject> monsterx = c.getPlayer().getMap().getMapObjectsInRange(c.getPlayer().getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.MONSTER));
for (int x = 0; x < amount; x++) {
MapleMonster monster = (MapleMonster) monsterx.get(x);
if (monster.getId() == mobToKill) {
c.getPlayer().getMap().killMonster(monster, c.getPlayer(), true);
monster.giveExpToCharacter(c.getPlayer(), monster.getExp(), true, 1);
}
}
break;
case 0x16: // Questreset
MapleQuest.getInstance(slea.readShort()).reset(c.getPlayer());
break;
case 0x17: // Summon
int mobId = slea.readInt();
int quantity = slea.readInt();
for (int i = 0; i < quantity; i++) {
c.getPlayer().getMap().spawnMonsterOnGroudBelow(MapleLifeFactory.getMonster(mobId), c.getPlayer().getPosition());
}
break;
case 0x18: // Maple & Mobhp
int mobHp = slea.readInt();
c.getPlayer().dropMessage("Monsters HP");
List<MapleMapObject> monsters = c.getPlayer().getMap().getMapObjectsInRange(c.getPlayer().getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.MONSTER));
for (MapleMapObject mobs : monsters) {
MapleMonster monster = (MapleMonster) mobs;
if (monster.getId() == mobHp) {
c.getPlayer().dropMessage(monster.getName() + ": " + monster.getHp());
}
}
break;
case 0x1E: // Warn
victim = slea.readMapleAsciiString();
String message = slea.readMapleAsciiString();
target = c.getChannelServer().getPlayerStorage().getCharacterByName(victim);
if (target != null) {
target.getClient().announce(MaplePacketCreator.serverNotice(1, message));
c.announce(MaplePacketCreator.getGMEffect(0x1E, (byte) 1));
} else {
c.announce(MaplePacketCreator.getGMEffect(0x1E, (byte) 0));
}
break;
case 0x24:// /Artifact Ranking
break;
case 0x77: //Testing purpose
if (slea.available() == 4) {
System.out.println(slea.readInt());
} else if (slea.available() == 2) {
System.out.println(slea.readShort());
}
break;
default:
System.out.println("New GM packet encountered (MODE : " + mode + ": " + slea.toString());
break;
}
}
}

View File

@@ -0,0 +1,34 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import tools.data.input.SeekableLittleEndianAccessor;
public final class AdminLogHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
//harhar
}
}

View File

@@ -0,0 +1,182 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import net.SendOpcode;
import net.server.Server;
import net.server.guild.MapleAlliance;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import tools.data.output.MaplePacketLittleEndianWriter;
/**
*
* @author XoticStory
*/
public final class AllianceOperationHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleAlliance alliance = null;
if (c.getPlayer().getGuild() != null && c.getPlayer().getGuild().getAllianceId() > 0) {
alliance = Server.getInstance().getAlliance(c.getPlayer().getGuild().getAllianceId());
}
if (alliance == null) {
c.getPlayer().dropMessage("You are not in an alliance.");
c.announce(MaplePacketCreator.enableActions());
return;
} else if (c.getPlayer().getMGC().getAllianceRank() > 2 || !alliance.getGuilds().contains(c.getPlayer().getGuildId())) {
c.announce(MaplePacketCreator.enableActions());
return;
}
switch (slea.readByte()) {
case 0x01:
Server.getInstance().allianceMessage(alliance.getId(), sendShowInfo(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId()), -1, -1);
break;
case 0x02: { // Leave Alliance
if (c.getPlayer().getGuild().getAllianceId() == 0 || c.getPlayer().getGuildId() < 1 || c.getPlayer().getGuildRank() != 1) {
return;
}
Server.getInstance().allianceMessage(alliance.getId(), sendChangeGuild(c.getPlayer().getGuildId(), c.getPlayer().getId(), c.getPlayer().getGuildId(), 2), -1, -1);
break;
}
case 0x03: // send alliance invite
String charName = slea.readMapleAsciiString();
int channel;
channel = c.getWorldServer().find(charName);
if (channel == -1) {
c.getPlayer().dropMessage("The player is not online.");
} else {
MapleCharacter victim = Server.getInstance().getChannel(c.getWorld(), channel).getPlayerStorage().getCharacterByName(charName);
if (victim.getGuildId() == 0) {
c.getPlayer().dropMessage("The person you are trying to invite does not have a guild.");
} else if (victim.getGuildRank() != 1) {
c.getPlayer().dropMessage("The player is not the leader of his/her guild.");
} else {
Server.getInstance().allianceMessage(alliance.getId(), sendInvitation(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), slea.readMapleAsciiString()), -1, -1);
}
}
break;
case 0x04: {
int guildid = slea.readInt();
// slea.readMapleAsciiString();//guild name
if (c.getPlayer().getGuild().getAllianceId() != 0 || c.getPlayer().getGuildRank() != 1 || c.getPlayer().getGuildId() < 1) {
return;
}
Server.getInstance().allianceMessage(alliance.getId(), sendChangeGuild(guildid, c.getPlayer().getId(), c.getPlayer().getGuildId(), 0), -1, -1);
break;
}
case 0x06: { // Expel Guild
int guildid = slea.readInt();
int allianceid = slea.readInt();
if (c.getPlayer().getGuild().getAllianceId() == 0 || c.getPlayer().getGuild().getAllianceId() != allianceid) {
return;
}
Server.getInstance().allianceMessage(alliance.getId(), sendChangeGuild(allianceid, c.getPlayer().getId(), guildid, 1), -1, -1);
break;
}
case 0x07: { // Change Alliance Leader
if (c.getPlayer().getGuild().getAllianceId() == 0 || c.getPlayer().getGuildId() < 1) {
return;
}
Server.getInstance().allianceMessage(alliance.getId(), sendChangeLeader(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), slea.readInt()), -1, -1);
break;
}
case 0x08:
String ranks[] = new String[5];
for (int i = 0; i < 5; i++) {
ranks[i] = slea.readMapleAsciiString();
}
Server.getInstance().setAllianceRanks(alliance.getId(), ranks);
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.changeAllianceRankTitle(alliance.getId(), ranks), -1, -1);
break;
case 0x09: {
int int1 = slea.readInt();
byte byte1 = slea.readByte();
Server.getInstance().allianceMessage(alliance.getId(), sendChangeRank(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), int1, byte1), -1, -1);
break;
}
case 0x0A:
String notice = slea.readMapleAsciiString();
Server.getInstance().setAllianceNotice(alliance.getId(), notice);
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.allianceNotice(alliance.getId(), notice), -1, -1);
break;
default:
c.getPlayer().dropMessage("Feature not available");
}
alliance.saveToDB();
}
private static byte[] sendShowInfo(int allianceid, int playerid) {
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(SendOpcode.ALLIANCE_OPERATION.getValue());
mplew.write(0x02);
mplew.writeInt(allianceid);
mplew.writeInt(playerid);
return mplew.getPacket();
}
private static byte[] sendInvitation(int allianceid, int playerid, final String guildname) {
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(SendOpcode.ALLIANCE_OPERATION.getValue());
mplew.write(0x05);
mplew.writeInt(allianceid);
mplew.writeInt(playerid);
mplew.writeMapleAsciiString(guildname);
return mplew.getPacket();
}
private static byte[] sendChangeGuild(int allianceid, int playerid, int guildid, int option) {
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(SendOpcode.ALLIANCE_OPERATION.getValue());
mplew.write(0x07);
mplew.writeInt(allianceid);
mplew.writeInt(guildid);
mplew.writeInt(playerid);
mplew.write(option);
return mplew.getPacket();
}
private static byte[] sendChangeLeader(int allianceid, int playerid, int victim) {
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(SendOpcode.ALLIANCE_OPERATION.getValue());
mplew.write(0x08);
mplew.writeInt(allianceid);
mplew.writeInt(playerid);
mplew.writeInt(victim);
return mplew.getPacket();
}
private static byte[] sendChangeRank(int allianceid, int playerid, int int1, byte byte1) {
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(SendOpcode.ALLIANCE_OPERATION.getValue());
mplew.write(0x09);
mplew.writeInt(allianceid);
mplew.writeInt(playerid);
mplew.writeInt(int1);
mplew.writeInt(byte1);
return mplew.getPacket();
}
}

View File

@@ -0,0 +1,64 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import client.SkillFactory;
import constants.GameConstants;
import constants.skills.Aran;
import net.AbstractMaplePacketHandler;
import tools.data.input.SeekableLittleEndianAccessor;
public class AranComboHandler extends AbstractMaplePacketHandler {
@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
final MapleCharacter player = c.getPlayer();
int skillLevel = player.getSkillLevel(SkillFactory.getSkill(Aran.COMBO_ABILITY));
if (GameConstants.isAran(player.getJob().getId()) && (skillLevel > 0 || player.getJob().getId() == 2000)) {
final long currentTime = System.currentTimeMillis();
short combo = player.getCombo();
if ((currentTime - player.getLastCombo()) > 3000 && combo > 0) {
combo = 0;
}
combo++;
switch (combo) {
case 10:
case 20:
case 30:
case 40:
case 50:
case 60:
case 70:
case 80:
case 90:
case 100:
if (player.getJob().getId() != 2000 && (combo / 10) > skillLevel) break;
SkillFactory.getSkill(Aran.COMBO_ABILITY).getEffect(combo / 10).applyComboBuff(player, combo);
break;
}
player.setCombo(combo);
player.setLastCombo(currentTime);
}
}
}

View File

@@ -0,0 +1,53 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import server.life.MapleMonster;
import tools.data.input.SeekableLittleEndianAccessor;
public final class AutoAggroHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int oid = slea.readInt();
MapleMonster monster = c.getPlayer().getMap().getMonsterByOid(oid);
if(c.getPlayer().isHidden())
return; // Don't auto aggro GM's in hide...
if (monster != null && monster.getController() != null) {
if (!monster.isControllerHasAggro()) {
if (c.getPlayer().getMap().getCharacterById(monster.getController().getId()) == null) {
monster.switchController(c.getPlayer(), true);
} else {
monster.switchController(monster.getController(), true);
}
} else if (c.getPlayer().getMap().getCharacterById(monster.getController().getId()) == null) {
monster.switchController(c.getPlayer(), true);
}
} else if (monster != null && monster.getController() == null) {
monster.switchController(c.getPlayer(), true);
}
}
}

View File

@@ -0,0 +1,363 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import constants.ServerConstants;
import client.MapleCharacter;
import client.MapleClient;
import client.MapleJob;
import client.MapleStat;
import client.autoban.AutobanFactory;
import client.inventory.Equip;
import client.inventory.Item;
import client.inventory.MapleInventory;
import client.inventory.MapleInventoryType;
//import java.util.ArrayList;
import java.util.Collection;
//import java.util.List;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author Generic
*/
public class AutoAssignHandler extends AbstractMaplePacketHandler {
@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
MapleJob stance;
if(ServerConstants.USE_ANOTHER_AUTOASSIGN == true) {
int eqpStr = 0, eqpDex = 0, eqpLuk = 0;
int str = 0, dex = 0, luk = 0, int_ = 0;
MapleInventory iv = chr.getInventory(MapleInventoryType.EQUIPPED);
Collection<Item> equippedC = iv.list();
Equip nEquip;
for (Item item : equippedC) { //selecting the biggest AP value of each stat from each equipped item.
nEquip = (Equip)item;
if(nEquip.getStr() > eqpStr) eqpStr = nEquip.getStr();
str += nEquip.getStr();
if(nEquip.getDex() > eqpDex) eqpDex = nEquip.getDex();
dex += nEquip.getDex();
if(nEquip.getLuk() > eqpLuk) eqpLuk = nEquip.getLuk();
luk += nEquip.getLuk();
//if(nEquip.getInt() > eqpInt) eqpInt = nEquip.getInt(); //not needed...
int_ += nEquip.getInt();
}
//c.getPlayer().message("----------------------------------------SDL: " + eqpStr + eqpDex + eqpLuk + " BASE STATS --> STR: " + chr.getStr() + " DEX: " + chr.getDex() + " INT: " + chr.getInt() + " LUK: " + chr.getLuk());
//c.getPlayer().message("SUM EQUIP STATS -> STR: " + str + " DEX: " + dex + " LUK: " + luk + " INT: " + int_);
//---------- Ronan Lana's AUTOASSIGN -------------
//this method excels for possibility to assign APs properly and not blocking the requirements when swapping one guaranteed equipment.
if (chr.getRemainingAp() < 1) {
return;
}
stance = c.getPlayer().getJobStyle();
int prStat = 0, scStat = 0, trStat = 0, temp, tempAp = chr.getRemainingAp(), CAP;
MapleStat primary, secondary, tertiary = MapleStat.INT;
switch(stance) {
case MAGICIAN:
CAP = 165;
scStat = (chr.getLevel() + 3) - (chr.getLuk() + luk - eqpLuk);
if(scStat < 0) scStat = 0;
scStat = Math.min(scStat, tempAp);
if(tempAp > scStat) tempAp -= scStat;
else tempAp = 0;
prStat = tempAp;
int_ = prStat;
luk = scStat;
str = 0; dex = 0;
if(luk + chr.getLuk() > CAP) {
temp = luk + chr.getLuk() - CAP;
luk -= temp;
int_ += temp;
}
primary = MapleStat.INT;
secondary = MapleStat.LUK;
break;
case BOWMAN:
CAP = 125;
scStat = (chr.getLevel() + 5) - (chr.getStr() + str - eqpStr);
if(scStat < 0) scStat = 0;
scStat = Math.min(scStat, tempAp);
if(tempAp > scStat) tempAp -= scStat;
else tempAp = 0;
prStat = tempAp;
dex = prStat;
str = scStat;
int_ = 0; luk = 0;
if(str + chr.getStr() > CAP) {
temp = str + chr.getStr() - CAP;
str -= temp;
dex += temp;
}
primary = MapleStat.DEX;
secondary = MapleStat.STR;
break;
case GUNSLINGER:
case CROSSBOWMAN:
CAP = 120;
scStat = chr.getLevel() - (chr.getStr() + str - eqpStr);
if(scStat < 0) scStat = 0;
scStat = Math.min(scStat, tempAp);
if(tempAp > scStat) tempAp -= scStat;
else tempAp = 0;
prStat = tempAp;
dex = prStat;
str = scStat;
int_ = 0; luk = 0;
if(str + chr.getStr() > CAP) {
temp = str + chr.getStr() - CAP;
str -= temp;
dex += temp;
}
primary = MapleStat.DEX;
secondary = MapleStat.STR;
break;
case THIEF:
CAP = 160;
scStat = 0;
if(chr.getDex() < 80) {
scStat = (2 * chr.getLevel()) - (chr.getDex() + dex - eqpDex);
if(scStat < 0) scStat = 0;
scStat = Math.min(80 - chr.getDex(), scStat);
scStat = Math.min(tempAp, scStat);
tempAp -= scStat;
}
temp = (chr.getLevel() + 40) - Math.max(80, scStat + chr.getDex() + dex - eqpDex);
if(temp < 0) temp = 0;
temp = Math.min(tempAp, temp);
scStat += temp;
tempAp -= temp;
if(chr.getStr() >= Math.max(13, (int)(0.4 * chr.getLevel()))) {
if(chr.getStr() < 50) {
trStat = (chr.getLevel() - 10) - (chr.getStr() + str - eqpStr);
if(trStat < 0) trStat = 0;
trStat = Math.min(50 - chr.getStr(), trStat);
trStat = Math.min(tempAp, trStat);
tempAp -= trStat;
tertiary = MapleStat.STR;
}
temp = (20 + (chr.getLevel() / 2)) - Math.max(50, trStat + chr.getStr() + str - eqpStr);
if(temp < 0) temp = 0;
temp = Math.min(tempAp, temp);
trStat += temp;
tempAp -= temp;
}
prStat = tempAp;
luk = prStat;
dex = scStat;
str = trStat;
int_ = 0;
if(dex + chr.getDex() > CAP) {
temp = dex + chr.getDex() - CAP;
dex -= temp;
luk += temp;
}
if(str + chr.getStr() > CAP) {
temp = str + chr.getStr() - CAP;
str -= temp;
luk += temp;
}
primary = MapleStat.LUK;
secondary = MapleStat.DEX;
break;
case BRAWLER:
CAP = 120;
scStat = chr.getLevel() - (chr.getDex() + dex - eqpDex);
if(scStat < 0) scStat = 0;
scStat = Math.min(scStat, tempAp);
if(tempAp > scStat) tempAp -= scStat;
else tempAp = 0;
prStat = tempAp;
str = prStat;
dex = scStat;
int_ = 0; luk = 0;
if(dex + chr.getDex() > CAP) {
temp = dex + chr.getDex() - CAP;
dex -= temp;
str += temp;
}
primary = MapleStat.STR;
secondary = MapleStat.DEX;
break;
default: //warrior, beginner, ...
CAP = 80;
scStat = ((2 * chr.getLevel()) / 3) - (chr.getDex() + dex - eqpDex);
if(scStat < 0) scStat = 0;
scStat = Math.min(scStat, tempAp);
if(tempAp > scStat) tempAp -= scStat;
else tempAp = 0;
prStat = tempAp;
str = prStat;
dex = scStat;
int_ = 0; luk = 0;
if(dex + chr.getDex() > CAP) {
temp = dex + chr.getDex() - CAP;
dex -= temp;
str += temp;
}
primary = MapleStat.STR;
secondary = MapleStat.DEX;
}
//-------------------------------------------------------------------------------------
int total = 0;
int extras = 0;
total += trStat;
extras += gainStatByType(chr, tertiary, trStat);
total += scStat;
extras += gainStatByType(chr, secondary, scStat);
total += prStat;
extras += gainStatByType(chr, primary, prStat);
int remainingAp = (chr.getRemainingAp() - total) + extras;
chr.setRemainingAp(remainingAp);
chr.updateSingleStat(MapleStat.AVAILABLEAP, remainingAp);
c.announce(MaplePacketCreator.enableActions());
//----------------------------------------------------------------------------------------
c.announce(MaplePacketCreator.serverNotice(1, "Better AP applications detected:\r\nSTR: +" + str + "\r\nDEX: +" + dex + "\r\nINT: +" + int_ + "\r\nLUK: +" + luk));
}
else {
slea.skip(8);
if (chr.getRemainingAp() < 1) {
return;
}
int total = 0;
int extras = 0;
if(slea.available() < 16) {
AutobanFactory.PACKET_EDIT.alert(chr, "Didn't send full packet for Auto Assign.");
c.disconnect(false, false);
return;
}
for (int i = 0; i < 2; i++) {
int type = slea.readInt();
int tempVal = slea.readInt();
if (tempVal < 0 || tempVal > c.getPlayer().getRemainingAp()) {
return;
}
total += tempVal;
System.out.println(tempVal);
extras += gainStatByType(chr, MapleStat.getBy5ByteEncoding(type), tempVal);
}
int remainingAp = (chr.getRemainingAp() - total) + extras;
chr.setRemainingAp(remainingAp);
chr.updateSingleStat(MapleStat.AVAILABLEAP, remainingAp);
c.announce(MaplePacketCreator.enableActions());
}
}
private int gainStatByType(MapleCharacter chr, MapleStat type, int gain) {
int newVal = 0;
if (type.equals(MapleStat.STR)) {
newVal = chr.getStr() + gain;
if (newVal > ServerConstants.MAX_AP) {
chr.setStr(ServerConstants.MAX_AP);
} else {
chr.setStr(newVal);
}
} else if (type.equals(MapleStat.INT)) {
newVal = chr.getInt() + gain;
if (newVal > ServerConstants.MAX_AP) {
chr.setInt(ServerConstants.MAX_AP);
} else {
chr.setInt(newVal);
}
} else if (type.equals(MapleStat.LUK)) {
newVal = chr.getLuk() + gain;
if (newVal > ServerConstants.MAX_AP) {
chr.setLuk(ServerConstants.MAX_AP);
} else {
chr.setLuk(newVal);
}
} else if (type.equals(MapleStat.DEX)) {
newVal = chr.getDex() + gain;
if (newVal > ServerConstants.MAX_AP) {
chr.setDex(ServerConstants.MAX_AP);
} else {
chr.setDex(newVal);
}
}
if (newVal > ServerConstants.MAX_AP) {
chr.updateSingleStat(type, ServerConstants.MAX_AP);
return newVal - ServerConstants.MAX_AP;
}
chr.updateSingleStat(type, newVal);
return 0;
}
}

View File

@@ -0,0 +1,320 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import net.AbstractMaplePacketHandler;
import tools.DatabaseConnection;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class BBSOperationHandler extends AbstractMaplePacketHandler {
private String correctLength(String in, int maxSize) {
return in.length() > maxSize ? in.substring(0, maxSize) : in;
}
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (c.getPlayer().getGuildId() < 1) {
return;
}
byte mode = slea.readByte();
int localthreadid = 0;
switch (mode) {
case 0:
boolean bEdit = slea.readByte() == 1;
if (bEdit) {
localthreadid = slea.readInt();
}
boolean bNotice = slea.readByte() == 1;
String title = correctLength(slea.readMapleAsciiString(), 25);
String text = correctLength(slea.readMapleAsciiString(), 600);
int icon = slea.readInt();
if (icon >= 0x64 && icon <= 0x6a) {
if (c.getPlayer().getItemQuantity(5290000 + icon - 0x64, false) > 0) {
return;
}
} else if (icon < 0 || icon > 3) {
return;
}
if (!bEdit) {
newBBSThread(c, title, text, icon, bNotice);
} else {
editBBSThread(c, title, text, icon, localthreadid);
}
break;
case 1:
localthreadid = slea.readInt();
deleteBBSThread(c, localthreadid);
break;
case 2:
int start = slea.readInt();
listBBSThreads(c, start * 10);
break;
case 3: // list thread + reply, followed by id (int)
localthreadid = slea.readInt();
displayThread(c, localthreadid);
break;
case 4: // reply
localthreadid = slea.readInt();
text = correctLength(slea.readMapleAsciiString(), 25);
newBBSReply(c, localthreadid, text);
break;
case 5: // delete reply
slea.readInt(); // we don't use this
int replyid = slea.readInt();
deleteBBSReply(c, replyid);
break;
default:
//System.out.println("Unhandled BBS mode: " + slea.toString());
}
}
private static void listBBSThreads(MapleClient c, int start) {
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM bbs_threads WHERE guildid = ? ORDER BY localthreadid DESC")) {
ps.setInt(1, c.getPlayer().getGuildId());
try (ResultSet rs = ps.executeQuery()) {
c.announce(MaplePacketCreator.BBSThreadList(rs, start));
}
}
} catch (SQLException se) {
se.printStackTrace();
}
}
private static void newBBSReply(MapleClient c, int localthreadid, String text) {
if (c.getPlayer().getGuildId() <= 0) {
return;
}
Connection con = DatabaseConnection.getConnection();
try {
PreparedStatement ps = con.prepareStatement("SELECT threadid FROM bbs_threads WHERE guildid = ? AND localthreadid = ?");
ps.setInt(1, c.getPlayer().getGuildId());
ps.setInt(2, localthreadid);
ResultSet threadRS = ps.executeQuery();
if (!threadRS.next()) {
threadRS.close();
ps.close();
return;
}
int threadid = threadRS.getInt("threadid");
threadRS.close();
ps.close();
ps = con.prepareStatement("INSERT INTO bbs_replies " + "(`threadid`, `postercid`, `timestamp`, `content`) VALUES " + "(?, ?, ?, ?)");
ps.setInt(1, threadid);
ps.setInt(2, c.getPlayer().getId());
ps.setLong(3, System.currentTimeMillis());
ps.setString(4, text);
ps.execute();
ps.close();
ps = con.prepareStatement("UPDATE bbs_threads SET replycount = replycount + 1 WHERE threadid = ?");
ps.setInt(1, threadid);
ps.execute();
ps.close();
displayThread(c, localthreadid);
} catch (SQLException se) {
se.printStackTrace();
}
}
private static void editBBSThread(MapleClient client, String title, String text, int icon, int localthreadid) {
MapleCharacter c = client.getPlayer();
if (c.getGuildId() < 1) {
return;
}
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE bbs_threads SET `name` = ?, `timestamp` = ?, " + "`icon` = ?, " + "`startpost` = ? WHERE guildid = ? AND localthreadid = ? AND (postercid = ? OR ?)")) {
ps.setString(1, title);
ps.setLong(2, System.currentTimeMillis());
ps.setInt(3, icon);
ps.setString(4, text);
ps.setInt(5, c.getGuildId());
ps.setInt(6, localthreadid);
ps.setInt(7, c.getId());
ps.setBoolean(8, c.getGuildRank() < 3);
ps.execute();
}
displayThread(client, localthreadid);
} catch (SQLException se) {
se.printStackTrace();
}
}
private static void newBBSThread(MapleClient client, String title, String text, int icon, boolean bNotice) {
MapleCharacter c = client.getPlayer();
if (c.getGuildId() <= 0) {
return;
}
int nextId = 0;
try {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps;
if (!bNotice) {
ps = con.prepareStatement("SELECT MAX(localthreadid) AS lastLocalId FROM bbs_threads WHERE guildid = ?");
ps.setInt(1, c.getGuildId());
try (ResultSet rs = ps.executeQuery()) {
rs.next();
nextId = rs.getInt("lastLocalId") + 1;
}
ps.close();
}
ps = con.prepareStatement("INSERT INTO bbs_threads " + "(`postercid`, `name`, `timestamp`, `icon`, `startpost`, " + "`guildid`, `localthreadid`) " + "VALUES(?, ?, ?, ?, ?, ?, ?)");
ps.setInt(1, c.getId());
ps.setString(2, title);
ps.setLong(3, System.currentTimeMillis());
ps.setInt(4, icon);
ps.setString(5, text);
ps.setInt(6, c.getGuildId());
ps.setInt(7, nextId);
ps.execute();
ps.close();
displayThread(client, nextId);
} catch (SQLException se) {
se.printStackTrace();
}
}
public static void deleteBBSThread(MapleClient client, int localthreadid) {
MapleCharacter mc = client.getPlayer();
if (mc.getGuildId() <= 0) {
return;
}
Connection con = DatabaseConnection.getConnection();
try {
PreparedStatement ps = con.prepareStatement("SELECT threadid, postercid FROM bbs_threads WHERE guildid = ? AND localthreadid = ?");
ps.setInt(1, mc.getGuildId());
ps.setInt(2, localthreadid);
ResultSet threadRS = ps.executeQuery();
if (!threadRS.next()) {
threadRS.close();
ps.close();
return;
}
if (mc.getId() != threadRS.getInt("postercid") && mc.getGuildRank() > 2) {
threadRS.close();
ps.close();
return;
}
int threadid = threadRS.getInt("threadid");
ps.close();
ps = con.prepareStatement("DELETE FROM bbs_replies WHERE threadid = ?");
ps.setInt(1, threadid);
ps.execute();
ps.close();
ps = con.prepareStatement("DELETE FROM bbs_threads WHERE threadid = ?");
ps.setInt(1, threadid);
ps.execute();
threadRS.close();
ps.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
public static void deleteBBSReply(MapleClient client, int replyid) {
MapleCharacter mc = client.getPlayer();
if (mc.getGuildId() <= 0) {
return;
}
int threadid;
Connection con = DatabaseConnection.getConnection();
try {
PreparedStatement ps = con.prepareStatement("SELECT postercid, threadid FROM bbs_replies WHERE replyid = ?");
ps.setInt(1, replyid);
ResultSet rs = ps.executeQuery();
if (!rs.next()) {
rs.close();
ps.close();
return;
}
if (mc.getId() != rs.getInt("postercid") && mc.getGuildRank() > 2) {
rs.close();
ps.close();
return;
}
threadid = rs.getInt("threadid");
rs.close();
ps.close();
ps = con.prepareStatement("DELETE FROM bbs_replies WHERE replyid = ?");
ps.setInt(1, replyid);
ps.execute();
ps.close();
ps = con.prepareStatement("UPDATE bbs_threads SET replycount = replycount - 1 WHERE threadid = ?");
ps.setInt(1, threadid);
ps.execute();
ps.close();
displayThread(client, threadid, false);
} catch (SQLException se) {
se.printStackTrace();
}
}
public static void displayThread(MapleClient client, int threadid) {
displayThread(client, threadid, true);
}
public static void displayThread(MapleClient client, int threadid, boolean bIsThreadIdLocal) {
MapleCharacter mc = client.getPlayer();
if (mc.getGuildId() <= 0) {
return;
}
Connection con = DatabaseConnection.getConnection();
try {
PreparedStatement ps2;
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM bbs_threads WHERE guildid = ? AND " + (bIsThreadIdLocal ? "local" : "") + "threadid = ?")) {
ps.setInt(1, mc.getGuildId());
ps.setInt(2, threadid);
ResultSet threadRS = ps.executeQuery();
if (!threadRS.next()) {
threadRS.close();
ps.close();
return;
}
ResultSet repliesRS = null;
ps2 = null;
if (threadRS.getInt("replycount") >= 0) {
ps2 = con.prepareStatement("SELECT * FROM bbs_replies WHERE threadid = ?");
ps2.setInt(1, !bIsThreadIdLocal ? threadid : threadRS.getInt("threadid"));
repliesRS = ps2.executeQuery();
}
client.announce(MaplePacketCreator.showThread(bIsThreadIdLocal ? threadid : threadRS.getInt("localthreadid"), threadRS, repliesRS));
repliesRS.close();
}
if (ps2 != null) {
ps2.close();
}
} catch (SQLException se) {
se.printStackTrace();
} catch (RuntimeException re) {//btw we get this everytime for some reason, but replies work!
re.printStackTrace();
System.out.println("The number of reply rows does not match the replycount in thread.");
}
}
}

View File

@@ -0,0 +1,59 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import constants.skills.DarkKnight;
import java.util.Collection;
import net.AbstractMaplePacketHandler;
import server.maps.MapleSummon;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author BubblesDev
*/
public final class BeholderHandler extends AbstractMaplePacketHandler {//Summon Skills noobs
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
//System.out.println(slea.toString());
Collection<MapleSummon> summons = c.getPlayer().getSummons().values();
int oid = slea.readInt();
MapleSummon summon = null;
for (MapleSummon sum : summons) {
if (sum.getObjectId() == oid) {
summon = sum;
}
}
if (summon != null) {
int skillId = slea.readInt();
if (skillId == DarkKnight.AURA_OF_BEHOLDER) {
slea.readShort(); //Not sure.
} else if (skillId == DarkKnight.HEX_OF_BEHOLDER) {
slea.readByte(); //Not sure.
} //show to others here
} else {
c.getPlayer().getSummons().clear();
}
}
}

View File

@@ -0,0 +1,208 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.BuddyList;
import client.BuddyList.BuddyAddResult;
import client.BuddyList.BuddyOperation;
import static client.BuddyList.BuddyOperation.ADDED;
import client.BuddylistEntry;
import client.CharacterNameAndId;
import client.MapleCharacter;
import client.MapleClient;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import net.AbstractMaplePacketHandler;
import net.server.world.World;
import tools.DatabaseConnection;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public class BuddylistModifyHandler extends AbstractMaplePacketHandler {
private static class CharacterIdNameBuddyCapacity extends CharacterNameAndId {
private int buddyCapacity;
public CharacterIdNameBuddyCapacity(int id, String name, int buddyCapacity) {
super(id, name);
this.buddyCapacity = buddyCapacity;
}
public int getBuddyCapacity() {
return buddyCapacity;
}
}
private void nextPendingRequest(MapleClient c) {
CharacterNameAndId pendingBuddyRequest = c.getPlayer().getBuddylist().pollPendingRequest();
if (pendingBuddyRequest != null) {
c.announce(MaplePacketCreator.requestBuddylistAdd(pendingBuddyRequest.getId(), c.getPlayer().getId(), pendingBuddyRequest.getName()));
}
}
private CharacterIdNameBuddyCapacity getCharacterIdAndNameFromDatabase(String name) throws SQLException {
Connection con = DatabaseConnection.getConnection();
CharacterIdNameBuddyCapacity ret;
try (PreparedStatement ps = con.prepareStatement("SELECT id, name, buddyCapacity FROM characters WHERE name LIKE ?")) {
ps.setString(1, name);
try (ResultSet rs = ps.executeQuery()) {
ret = null;
if (rs.next()) {
ret = new CharacterIdNameBuddyCapacity(rs.getInt("id"), rs.getString("name"), rs.getInt("buddyCapacity"));
}
}
}
return ret;
}
@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int mode = slea.readByte();
MapleCharacter player = c.getPlayer();
BuddyList buddylist = player.getBuddylist();
if (mode == 1) { // add
String addName = slea.readMapleAsciiString();
String group = slea.readMapleAsciiString();
if (group.length() > 16 || addName.length() < 4 || addName.length() > 13) {
return; //hax.
}
BuddylistEntry ble = buddylist.get(addName);
if (ble != null && !ble.isVisible() && group.equals(ble.getGroup())) {
c.announce(MaplePacketCreator.serverNotice(1, "You already have \"" + ble.getName() + "\" on your Buddylist"));
} else if (buddylist.isFull() && ble == null) {
c.announce(MaplePacketCreator.serverNotice(1, "Your buddylist is already full"));
} else if (ble == null) {
try {
World world = c.getWorldServer();
CharacterIdNameBuddyCapacity charWithId;
int channel;
MapleCharacter otherChar = c.getChannelServer().getPlayerStorage().getCharacterByName(addName);
if (otherChar != null) {
channel = c.getChannel();
charWithId = new CharacterIdNameBuddyCapacity(otherChar.getId(), otherChar.getName(), otherChar.getBuddylist().getCapacity());
} else {
channel = world.find(addName);
charWithId = getCharacterIdAndNameFromDatabase(addName);
}
if (charWithId != null) {
BuddyAddResult buddyAddResult = null;
if (channel != -1) {
buddyAddResult = world.requestBuddyAdd(addName, c.getChannel(), player.getId(), player.getName());
} else {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) as buddyCount FROM buddies WHERE characterid = ? AND pending = 0");
ps.setInt(1, charWithId.getId());
ResultSet rs = ps.executeQuery();
if (!rs.next()) {
throw new RuntimeException("Result set expected");
} else if (rs.getInt("buddyCount") >= charWithId.getBuddyCapacity()) {
buddyAddResult = BuddyAddResult.BUDDYLIST_FULL;
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT pending FROM buddies WHERE characterid = ? AND buddyid = ?");
ps.setInt(1, charWithId.getId());
ps.setInt(2, player.getId());
rs = ps.executeQuery();
if (rs.next()) {
buddyAddResult = BuddyAddResult.ALREADY_ON_LIST;
}
rs.close();
ps.close();
}
if (buddyAddResult == BuddyAddResult.BUDDYLIST_FULL) {
c.announce(MaplePacketCreator.serverNotice(1, "\"" + addName + "\"'s Buddylist is full"));
} else {
int displayChannel;
displayChannel = -1;
int otherCid = charWithId.getId();
if (buddyAddResult == BuddyAddResult.ALREADY_ON_LIST && channel != -1) {
displayChannel = channel;
notifyRemoteChannel(c, channel, otherCid, ADDED);
} else if (buddyAddResult != BuddyAddResult.ALREADY_ON_LIST && channel == -1) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("INSERT INTO buddies (characterid, `buddyid`, `pending`) VALUES (?, ?, 1)")) {
ps.setInt(1, charWithId.getId());
ps.setInt(2, player.getId());
ps.executeUpdate();
}
}
buddylist.put(new BuddylistEntry(charWithId.getName(), group, otherCid, displayChannel, true));
c.announce(MaplePacketCreator.updateBuddylist(buddylist.getBuddies()));
}
} else {
c.announce(MaplePacketCreator.serverNotice(1, "A character called \"" + addName + "\" does not exist"));
}
} catch (SQLException e) {
}
} else {
ble.changeGroup(group);
c.announce(MaplePacketCreator.updateBuddylist(buddylist.getBuddies()));
}
} else if (mode == 2) { // accept buddy
int otherCid = slea.readInt();
if (!buddylist.isFull()) {
try {
int channel = c.getWorldServer().find(otherCid);//worldInterface.find(otherCid);
String otherName = null;
MapleCharacter otherChar = c.getChannelServer().getPlayerStorage().getCharacterById(otherCid);
if (otherChar == null) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT name FROM characters WHERE id = ?")) {
ps.setInt(1, otherCid);
try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) {
otherName = rs.getString("name");
}
}
}
} else {
otherName = otherChar.getName();
}
if (otherName != null) {
buddylist.put(new BuddylistEntry(otherName, "Default Group", otherCid, channel, true));
c.announce(MaplePacketCreator.updateBuddylist(buddylist.getBuddies()));
notifyRemoteChannel(c, channel, otherCid, ADDED);
}
} catch (SQLException e) {
}
}
nextPendingRequest(c);
} else if (mode == 3) { // delete
int otherCid = slea.readInt();
if (buddylist.containsVisible(otherCid)) {
notifyRemoteChannel(c, c.getWorldServer().find(otherCid), otherCid, BuddyOperation.DELETED);
}
buddylist.remove(otherCid);
c.announce(MaplePacketCreator.updateBuddylist(player.getBuddylist().getBuddies()));
nextPendingRequest(c);
}
}
private void notifyRemoteChannel(MapleClient c, int remoteChannel, int otherCid, BuddyOperation operation) {
MapleCharacter player = c.getPlayer();
if (remoteChannel != -1) {
c.getWorldServer().buddyChanged(otherCid, player.getId(), player.getName(), c.getChannel(), operation);
}
}
}

View File

@@ -0,0 +1,61 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import client.SkillFactory;
import constants.skills.Bishop;
import constants.skills.Bowmaster;
import constants.skills.Corsair;
import constants.skills.Evan;
import constants.skills.FPArchMage;
import constants.skills.ILArchMage;
import constants.skills.Marksman;
import constants.skills.WindArcher;
import net.AbstractMaplePacketHandler;
import net.MaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class CancelBuffHandler extends AbstractMaplePacketHandler implements MaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int sourceid = slea.readInt();
switch (sourceid) {
case FPArchMage.BIG_BANG:
case ILArchMage.BIG_BANG:
case Bishop.BIG_BANG:
case Bowmaster.HURRICANE:
case Marksman.PIERCING_ARROW:
case Corsair.RAPID_FIRE:
case WindArcher.HURRICANE:
case Evan.FIRE_BREATH:
case Evan.ICE_BREATH:
c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.skillCancel(c.getPlayer(), sourceid), false);
break;
default:
c.getPlayer().cancelEffect(SkillFactory.getSkill(sourceid).getEffect(1), false, -1);
break;
}
}
}

View File

@@ -0,0 +1,43 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class CancelChairHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int id = slea.readShort();
if (id == -1) { // Cancel Chair
c.getPlayer().setChair(0);
c.announce(MaplePacketCreator.cancelChair(-1));
c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.showChair(c.getPlayer().getId(), 0), false);
} else { // Use In-Map Chair
c.getPlayer().setChair(id);
c.announce(MaplePacketCreator.cancelChair(id));
}
}
}

View File

@@ -0,0 +1,45 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import tools.data.input.SeekableLittleEndianAccessor;
public final class CancelDebuffHandler extends AbstractMaplePacketHandler {//TIP: BAD STUFF LOL!
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
/*List<MapleDisease> diseases = c.getPlayer().getDiseases();
List<MapleDisease> diseases_ = new ArrayList<MapleDisease>();
for (MapleDisease disease : diseases) {
List<MapleDisease> disease_ = new ArrayList<MapleDisease>();
disease_.add(disease);
diseases_.add(disease);
c.announce(MaplePacketCreator.cancelDebuff(disease_));
c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.cancelForeignDebuff(c.getPlayer().getId(), disease_), false);
}
for (MapleDisease disease : diseases_) {
c.getPlayer().removeDisease(disease);
}*/
}
}

View File

@@ -0,0 +1,39 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import server.MapleItemInformationProvider;
import tools.data.input.SeekableLittleEndianAccessor;
public final class CancelItemEffectHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int itemId = -slea.readInt();
if (MapleItemInformationProvider.getInstance().noCancelMouse(itemId)) {
return;
}
c.getPlayer().cancelEffect(itemId);
}
}

View File

@@ -0,0 +1,347 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import client.MapleRing;
import client.inventory.Equip;
import client.inventory.Item;
import client.inventory.MapleInventory;
import client.inventory.MapleInventoryType;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import net.AbstractMaplePacketHandler;
import server.CashShop;
import server.CashShop.CashItem;
import server.CashShop.CashItemFactory;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class CashOperationHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
CashShop cs = chr.getCashShop();
if (!cs.isOpened()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
final int action = slea.readByte();
if (action == 0x03 || action == 0x1E) {
slea.readByte();
final int useNX = slea.readInt();
final int snCS = slea.readInt();
CashItem cItem = CashItemFactory.getItem(snCS);
if (cItem == null || !cItem.isOnSale() || cs.getCash(useNX) < cItem.getPrice()) {
return;
}
if (action == 0x03) { // Item
Item item = cItem.toItem();
cs.addToInventory(item);
c.announce(MaplePacketCreator.showBoughtCashItem(item, c.getAccID()));
} else { // Package
List<Item> cashPackage = CashItemFactory.getPackage(cItem.getItemId());
for (Item item : cashPackage) {
cs.addToInventory(item);
}
c.announce(MaplePacketCreator.showBoughtCashPackage(cashPackage, c.getAccID()));
}
cs.gainCash(useNX, -cItem.getPrice());
c.announce(MaplePacketCreator.showCash(chr));
} else if (action == 0x04) {//TODO check for gender
int birthday = slea.readInt();
CashItem cItem = CashItemFactory.getItem(slea.readInt());
Map<String, String> recipient = MapleCharacter.getCharacterFromDatabase(slea.readMapleAsciiString());
String message = slea.readMapleAsciiString();
if (!canBuy(cItem, cs.getCash(4)) || message.length() < 1 || message.length() > 73) {
return;
}
if (!checkBirthday(c, birthday)) {
c.announce(MaplePacketCreator.showCashShopMessage((byte) 0xC4));
return;
} else if (recipient == null) {
c.announce(MaplePacketCreator.showCashShopMessage((byte) 0xA9));
return;
} else if (recipient.get("accountid").equals(String.valueOf(c.getAccID()))) {
c.announce(MaplePacketCreator.showCashShopMessage((byte) 0xA8));
return;
}
cs.gift(Integer.parseInt(recipient.get("id")), chr.getName(), message, cItem.getSN());
c.announce(MaplePacketCreator.showGiftSucceed(recipient.get("name"), cItem));
cs.gainCash(4, -cItem.getPrice());
c.announce(MaplePacketCreator.showCash(chr));
try {
chr.sendNote(recipient.get("name"), chr.getName() + " has sent you a gift! Go check out the Cash Shop.", (byte) 0); //fame or not
} catch (SQLException ex) {
}
MapleCharacter receiver = c.getChannelServer().getPlayerStorage().getCharacterByName(recipient.get("name"));
if (receiver != null) receiver.showNote();
} else if (action == 0x05) { // Modify wish list
cs.clearWishList();
for (byte i = 0; i < 10; i++) {
int sn = slea.readInt();
CashItem cItem = CashItemFactory.getItem(sn);
if (cItem != null && cItem.isOnSale() && sn != 0) {
cs.addToWishList(sn);
}
}
c.announce(MaplePacketCreator.showWishList(chr, true));
} else if (action == 0x06) { // Increase Inventory Slots
slea.skip(1);
int cash = slea.readInt();
byte mode = slea.readByte();
if (mode == 0) {
byte type = slea.readByte();
if (cs.getCash(cash) < 4000) {
return;
}
if (chr.gainSlots(type, 4, false)) {
c.announce(MaplePacketCreator.showBoughtInventorySlots(type, chr.getSlots(type)));
cs.gainCash(cash, -4000);
c.announce(MaplePacketCreator.showCash(chr));
}
} else {
CashItem cItem = CashItemFactory.getItem(slea.readInt());
int type = (cItem.getItemId() - 9110000) / 1000;
if (!canBuy(cItem, cs.getCash(cash))) {
return;
}
if (chr.gainSlots(type, 8, false)) {
c.announce(MaplePacketCreator.showBoughtInventorySlots(type, chr.getSlots(type)));
cs.gainCash(cash, -cItem.getPrice());
c.announce(MaplePacketCreator.showCash(chr));
}
}
} else if (action == 0x07) { // Increase Storage Slots
slea.skip(1);
int cash = slea.readInt();
byte mode = slea.readByte();
if (mode == 0) {
if (cs.getCash(cash) < 4000) {
return;
}
if (chr.getStorage().gainSlots(4)) {
c.announce(MaplePacketCreator.showBoughtStorageSlots(chr.getStorage().getSlots()));
cs.gainCash(cash, -4000);
c.announce(MaplePacketCreator.showCash(chr));
}
} else {
CashItem cItem = CashItemFactory.getItem(slea.readInt());
if (!canBuy(cItem, cs.getCash(cash))) {
return;
}
if (chr.getStorage().gainSlots(8)) {
c.announce(MaplePacketCreator.showBoughtStorageSlots(chr.getStorage().getSlots()));
cs.gainCash(cash, -cItem.getPrice());
c.announce(MaplePacketCreator.showCash(chr));
}
}
} else if (action == 0x08) { // Increase Character Slots
slea.skip(1);
int cash = slea.readInt();
CashItem cItem = CashItemFactory.getItem(slea.readInt());
if (!canBuy(cItem, cs.getCash(cash)))
return;
if (c.gainCharacterSlot()) {
c.announce(MaplePacketCreator.showBoughtCharacterSlot(c.getCharacterSlots()));
cs.gainCash(cash, -cItem.getPrice());
c.announce(MaplePacketCreator.showCash(chr));
}
} else if (action == 0x0D) { // Take from Cash Inventory
Item item = cs.findByCashId(slea.readInt());
if (item == null) {
return;
}
if (chr.getInventory(MapleItemInformationProvider.getInstance().getInventoryType(item.getItemId())).addItem(item) != -1) {
cs.removeFromInventory(item);
c.announce(MaplePacketCreator.takeFromCashInventory(item));
if(item instanceof Equip) {
Equip equip = (Equip) item;
if(equip.getRingId() >= 0) {
MapleRing ring = MapleRing.loadFromDb(equip.getRingId());
if (ring.getItemId() > 1112012) {
chr.addFriendshipRing(ring);
} else {
chr.addCrushRing(ring);
}
}
}
}
} else if (action == 0x0E) { // Put into Cash Inventory
int cashId = slea.readInt();
slea.skip(4);
MapleInventory mi = chr.getInventory(MapleInventoryType.getByType(slea.readByte()));
Item item = mi.findByCashId(cashId);
if (item == null) {
return;
}
cs.addToInventory(item);
mi.removeSlot(item.getPosition());
c.announce(MaplePacketCreator.putIntoCashInventory(item, c.getAccID()));
} else if (action == 0x1D) { //crush ring (action 28)
slea.readInt();//Birthday
// if (checkBirthday(c, birthday)) { //We're using a default birthday, so why restrict rings to only people who know of it?
int toCharge = slea.readInt();
int SN = slea.readInt();
String recipient = slea.readMapleAsciiString();
String text = slea.readMapleAsciiString();
CashItem ring = CashItemFactory.getItem(SN);
MapleCharacter partner = c.getChannelServer().getPlayerStorage().getCharacterByName(recipient);
if (partner == null) {
chr.getClient().announce(MaplePacketCreator.serverNotice(1, "The partner you specified cannot be found.\r\nPlease make sure your partner is online and in the same channel."));
} else {
/* if (partner.getGender() == chr.getGender()) {
chr.dropMessage("You and your partner are the same gender, please buy a friendship ring.");
return;
}*/ //Gotta let them faggots marry too, hence why this is commented out <3
if(ring.toItem() instanceof Equip) {
Equip item = (Equip) ring.toItem();
int ringid = MapleRing.createRing(ring.getItemId(), chr, partner);
item.setRingId(ringid);
cs.addToInventory(item);
c.announce(MaplePacketCreator.showBoughtCashItem(item, c.getAccID()));
cs.gift(partner.getId(), chr.getName(), text, item.getSN(), (ringid + 1));
cs.gainCash(toCharge, -ring.getPrice());
chr.addCrushRing(MapleRing.loadFromDb(ringid));
try {
chr.sendNote(partner.getName(), text, (byte) 1);
} catch (SQLException ex) {
}
partner.showNote();
}
}
/* } else {
chr.dropMessage("The birthday you entered was incorrect.");
}*/
c.announce(MaplePacketCreator.showCash(c.getPlayer()));
} else if (action == 0x20) { // everything is 1 meso...
int itemId = CashItemFactory.getItem(slea.readInt()).getItemId();
if (chr.getMeso() > 0) {
if (itemId == 4031180 || itemId == 4031192 || itemId == 4031191) {
chr.gainMeso(-1, false);
MapleInventoryManipulator.addById(c, itemId, (short) 1);
c.announce(MaplePacketCreator.showBoughtQuestItem(itemId));
}
}
c.announce(MaplePacketCreator.showCash(c.getPlayer()));
} else if (action == 0x23) { //Friendship :3
slea.readInt(); //Birthday
// if (checkBirthday(c, birthday)) {
int payment = slea.readByte();
slea.skip(3); //0s
int snID = slea.readInt();
CashItem ring = CashItemFactory.getItem(snID);
String sentTo = slea.readMapleAsciiString();
int available = slea.readShort() - 1;
String text = slea.readAsciiString(available);
slea.readByte();
MapleCharacter partner = c.getChannelServer().getPlayerStorage().getCharacterByName(sentTo);
if (partner == null) {
chr.dropMessage("The partner you specified cannot be found.\r\nPlease make sure your partner is online and in the same channel.");
} else {
// Need to check to make sure its actually an equip and the right SN...
if(ring.toItem() instanceof Equip) {
Equip item = (Equip) ring.toItem();
int ringid = MapleRing.createRing(ring.getItemId(), chr, partner);
item.setRingId(ringid);
cs.addToInventory(item);
c.announce(MaplePacketCreator.showBoughtCashItem(item, c.getAccID()));
cs.gift(partner.getId(), chr.getName(), text, item.getSN(), (ringid + 1));
cs.gainCash(payment, -ring.getPrice());
chr.addFriendshipRing(MapleRing.loadFromDb(ringid));
try {
chr.sendNote(partner.getName(), text, (byte) 1);
} catch (SQLException ex) {
}
partner.showNote();
}
}
/* } else {
chr.dropMessage("The birthday you entered was incorrect.");
} */
c.announce(MaplePacketCreator.showCash(c.getPlayer()));
} else {
System.out.println(slea);
}
}
private static boolean checkBirthday(MapleClient c, int idate) {
int year = idate / 10000;
int month = (idate - year * 10000) / 100;
int day = idate - year * 10000 - month * 100;
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(0);
cal.set(year, month - 1, day);
return c.checkBirthDate(cal);
}
public static boolean canBuy(CashItem item, int cash) {
return item != null && item.isOnSale() && item.getPrice() <= cash && !blocked(item.getItemId());
}
public static boolean blocked(int id){
switch(id){ //All 2x exp cards
case 5211000:
case 5211004:
case 5211005:
case 5211006:
case 5211007:
case 5211008:
case 5211009:
case 5211010:
case 5211011:
case 5211012:
case 5211013:
case 5211014:
case 5211015:
case 5211016:
case 5211017:
case 5211018:
case 5211037:
case 5211038:
case 5211039:
case 5211040:
case 5211041:
case 5211042:
case 5211043:
case 5211044:
case 5211045:
case 5211049:
return true;
default:
return false;
}
}
}

View File

@@ -0,0 +1,48 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import net.AbstractMaplePacketHandler;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleClient;
import client.autoban.AutobanFactory;
/**
*
* @author Matze
*/
public final class ChangeChannelHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int channel = slea.readByte() + 1;
c.getPlayer().getAutobanManager().setTimestamp(6, slea.readInt(), 2);
if(c.getChannel() == channel) {
AutobanFactory.GENERAL.alert(c.getPlayer(), "CCing to same channel.");
c.disconnect(false, false);
return;
} else if (c.getPlayer().getCashShop().isOpened() || c.getPlayer().getMiniGame() != null || c.getPlayer().getPlayerShop() != null) {
return;
}
c.changeChannel(channel);
}
}

View File

@@ -0,0 +1,158 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import java.net.InetAddress;
import java.net.UnknownHostException;
import net.AbstractMaplePacketHandler;
import server.MapleInventoryManipulator;
import server.MaplePortal;
import server.MapleTrade;
import server.maps.MapleMap;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleCharacter;
import client.MapleClient;
import client.inventory.MapleInventoryType;
public final class ChangeMapHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
if (chr.isBanned()) {
return;
}
if (chr.getTrade() != null) {
MapleTrade.cancelTrade(chr);
}
if (slea.available() == 0) { //Cash Shop :)
if(!chr.getCashShop().isOpened()) {
c.disconnect(false, false);
return;
}
String[] socket = c.getChannelServer().getIP().split(":");
chr.getCashShop().open(false);
c.updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION);
try {
c.announce(MaplePacketCreator.getChannelChange(InetAddress.getByName(socket[0]), Integer.parseInt(socket[1])));
} catch (UnknownHostException ex) {
ex.printStackTrace();
}
} else {
if(chr.getCashShop().isOpened()) {
c.disconnect(false, false);
return;
}
try {
slea.readByte(); // 1 = from dying 0 = regular portals
int targetid = slea.readInt();
String startwp = slea.readMapleAsciiString();
MaplePortal portal = chr.getMap().getPortal(startwp);
slea.readByte();
boolean wheel = slea.readShort() > 0;
if (targetid != -1 && !chr.isAlive()) {
boolean executeStandardPath = true;
if (chr.getEventInstance() != null) {
executeStandardPath = chr.getEventInstance().revivePlayer(chr);
}
if (executeStandardPath) {
MapleMap to = chr.getMap();
if (wheel && chr.getItemQuantity(5510000, false) > 0) {
MapleInventoryManipulator.removeById(c, MapleInventoryType.CASH, 5510000, 1, true, false);
chr.announce(MaplePacketCreator.showWheelsLeft(chr.getItemQuantity(5510000, false)));
} else {
chr.cancelAllBuffs(false);
to = chr.getMap().getReturnMap();
chr.setStance(0);
}
chr.setHp(50);
chr.changeMap(to, to.getPortal(0));
}
} else if (targetid != -1 && chr.isGM()) {
MapleMap to = c.getChannelServer().getMapFactory().getMap(targetid);
chr.changeMap(to, to.getPortal(0));
} else if (targetid != -1 && !chr.isGM()) {//Thanks celino for saving me some time (:
final int divi = chr.getMapId() / 100;
boolean warp = false;
if (divi == 0) {
if (targetid == 10000) {
warp = true;
}
} else if (divi == 20100) {
if (targetid == 104000000) {
c.announce(MaplePacketCreator.lockUI(false));
c.announce(MaplePacketCreator.disableUI(false));
warp = true;
}
} else if (divi == 9130401) { // Only allow warp if player is already in Intro map, or else = hack
if (targetid == 130000000 || targetid / 100 == 9130401) { // Cygnus introduction
warp = true;
}
} else if (divi == 9140900) { // Aran Introduction
if (targetid == 914090011 || targetid == 914090012 || targetid == 914090013 || targetid == 140090000) {
warp = true;
}
} else if (divi / 10 == 1020) { // Adventurer movie clip Intro
if (targetid == 1020000) {
warp = true;
}
} else if(divi / 10 >= 980040 && divi / 10 <= 980045) {
if(targetid == 980040000) {
warp = true;
}
}
if (warp) {
final MapleMap to = c.getChannelServer().getMapFactory().getMap(targetid);
chr.changeMap(to, to.getPortal(0));
}
}
if (portal != null && !portal.getPortalStatus()) {
c.announce(MaplePacketCreator.blockedMessage(1));
c.announce(MaplePacketCreator.enableActions());
return;
}
if (chr.getMapId() == 109040004) {
chr.getFitness().resetTimes();
}
if (chr.getMapId() == 109030003 || chr.getMapId() == 109030103) {
chr.getOla().resetTimes();
}
if (portal != null) {
if(portal.getPosition().distanceSq(chr.getPosition()) > 400000) {
c.announce(MaplePacketCreator.enableActions());
return;
}
portal.enterPortal(c);
} else {
c.announce(MaplePacketCreator.enableActions());
}
//chr.setRates();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

View File

@@ -0,0 +1,50 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import server.MaplePortal;
import server.MapleTrade;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class ChangeMapSpecialHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
slea.readByte();
String startwp = slea.readMapleAsciiString();
slea.readShort();
MaplePortal portal = c.getPlayer().getMap().getPortal(startwp);
if (portal == null || c.getPlayer().portalDelay() > System.currentTimeMillis() || c.getPlayer().getBlockedPortals().contains(portal.getScriptName())) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (c.getPlayer().isBanned()) {
return;
}
if (c.getPlayer().getTrade() != null) {
MapleTrade.cancelTrade(c.getPlayer());
}
portal.enterPortal(c);
}
}

View File

@@ -0,0 +1,42 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import server.maps.MapleMapObject;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class CharInfoRequestHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
slea.readInt();
int cid = slea.readInt();
MapleMapObject target = c.getPlayer().getMap().getMapObject(cid);
if (target != null) {
if (target instanceof MapleCharacter) {
c.announce(MaplePacketCreator.charInfo((MapleCharacter) target));
}
}
}
}

View File

@@ -0,0 +1,45 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import client.MapleJob;
import net.AbstractMaplePacketHandler;
import scripting.npc.NPCScriptManager;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author kevintjuh93
*/
public class ClickGuideHandler extends AbstractMaplePacketHandler {
@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (c.getPlayer().getJob().equals(MapleJob.NOBLESSE)) {
NPCScriptManager.getInstance().start(c, 1101008, null);
} else {
NPCScriptManager.getInstance().start(c, 1202000, null);
}
}
}

View File

@@ -0,0 +1,38 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author Xterminator
*/
public final class CloseChalkboardHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
c.getPlayer().setChalkboard(null);
c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.useChalkboard(c.getPlayer(), true));
}
}

View File

@@ -0,0 +1,162 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import server.MapleStatEffect;
import server.TimerManager;
import tools.MaplePacketCreator;
import tools.Pair;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleBuffStat;
import client.MapleCharacter;
import client.MapleCharacter.CancelCooldownAction;
import client.MapleClient;
import client.MapleJob;
import client.MapleStat;
import client.Skill;
import client.SkillFactory;
import constants.GameConstants;
import constants.skills.Crusader;
import constants.skills.DawnWarrior;
import constants.skills.DragonKnight;
import constants.skills.Hero;
import constants.skills.NightWalker;
import constants.skills.Rogue;
import constants.skills.WindArcher;
public final class CloseRangeDamageHandler extends AbstractDealDamageHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter player = c.getPlayer();
player.setPetLootCd(System.currentTimeMillis());
/*long timeElapsed = System.currentTimeMillis() - player.getAutobanManager().getLastSpam(8);
if(timeElapsed < 300) {
AutobanFactory.FAST_ATTACK.alert(player, "Time: " + timeElapsed);
}
player.getAutobanManager().spam(8);*/
AttackInfo attack = parseDamage(slea, player, false, false);
if (player.getBuffEffect(MapleBuffStat.MORPH) != null) {
if(player.getBuffEffect(MapleBuffStat.MORPH).isMorphWithoutAttack()) {
// How are they attacking when the client won't let them?
player.getClient().disconnect(false, false);
return;
}
}
player.getMap().broadcastMessage(player, MaplePacketCreator.closeRangeAttack(player, attack.skill, attack.skilllevel, attack.stance, attack.numAttackedAndDamage, attack.allDamage, attack.speed, attack.direction, attack.display), false, true);
int numFinisherOrbs = 0;
Integer comboBuff = player.getBuffedValue(MapleBuffStat.COMBO);
if (GameConstants.isFinisherSkill(attack.skill)) {
if (comboBuff != null) {
numFinisherOrbs = comboBuff.intValue() - 1;
}
player.handleOrbconsume();
} else if (attack.numAttacked > 0) {
if (attack.skill != 1111008 && comboBuff != null) {
int orbcount = player.getBuffedValue(MapleBuffStat.COMBO);
int oid = player.isCygnus() ? DawnWarrior.COMBO : Crusader.COMBO;
int advcomboid = player.isCygnus() ? DawnWarrior.ADVANCED_COMBO : Hero.ADVANCED_COMBO;
Skill combo = SkillFactory.getSkill(oid);
Skill advcombo = SkillFactory.getSkill(advcomboid);
MapleStatEffect ceffect;
int advComboSkillLevel = player.getSkillLevel(advcombo);
if (advComboSkillLevel > 0) {
ceffect = advcombo.getEffect(advComboSkillLevel);
} else {
ceffect = combo.getEffect(player.getSkillLevel(combo));
}
if (orbcount < ceffect.getX() + 1) {
int neworbcount = orbcount + 1;
if (advComboSkillLevel > 0 && ceffect.makeChanceResult()) {
if (neworbcount <= ceffect.getX()) {
neworbcount++;
}
}
int duration = combo.getEffect(player.getSkillLevel(oid)).getDuration();
List<Pair<MapleBuffStat, Integer>> stat = Collections.singletonList(new Pair<>(MapleBuffStat.COMBO, neworbcount));
player.setBuffedValue(MapleBuffStat.COMBO, neworbcount);
duration -= (int) (System.currentTimeMillis() - player.getBuffedStarttime(MapleBuffStat.COMBO));
c.announce(MaplePacketCreator.giveBuff(oid, duration, stat));
player.getMap().broadcastMessage(player, MaplePacketCreator.giveForeignBuff(player.getId(), stat), false);
}
} else if (player.getSkillLevel(player.isCygnus() ? SkillFactory.getSkill(15100004) : SkillFactory.getSkill(5110001)) > 0 && (player.getJob().isA(MapleJob.MARAUDER) || player.getJob().isA(MapleJob.THUNDERBREAKER2))) {
for (int i = 0; i < attack.numAttacked; i++) {
player.handleEnergyChargeGain();
}
}
}
if (attack.numAttacked > 0 && attack.skill == DragonKnight.SACRIFICE) {
int totDamageToOneMonster = 0; // sacrifice attacks only 1 mob with 1 attack
final Iterator<List<Integer>> dmgIt = attack.allDamage.values().iterator();
if (dmgIt.hasNext()) {
totDamageToOneMonster = dmgIt.next().get(0).intValue();
}
int remainingHP = player.getHp() - totDamageToOneMonster * attack.getAttackEffect(player, null).getX() / 100;
if (remainingHP > 1) {
player.setHp(remainingHP);
} else {
player.setHp(1);
}
player.updateSingleStat(MapleStat.HP, player.getHp());
player.checkBerserk();
}
if (attack.numAttacked > 0 && attack.skill == 1211002) {
boolean advcharge_prob = false;
int advcharge_level = player.getSkillLevel(SkillFactory.getSkill(1220010));
if (advcharge_level > 0) {
advcharge_prob = SkillFactory.getSkill(1220010).getEffect(advcharge_level).makeChanceResult();
}
if (!advcharge_prob) {
player.cancelEffectFromBuffStat(MapleBuffStat.WK_CHARGE);
}
}
int attackCount = 1;
if (attack.skill != 0) {
attackCount = attack.getAttackEffect(player, null).getAttackCount();
}
if (numFinisherOrbs == 0 && GameConstants.isFinisherSkill(attack.skill)) {
return;
}
if (attack.skill > 0) {
Skill skill = SkillFactory.getSkill(attack.skill);
MapleStatEffect effect_ = skill.getEffect(player.getSkillLevel(skill));
if (effect_.getCooldown() > 0) {
if (player.skillisCooling(attack.skill)) {
return;
} else {
c.announce(MaplePacketCreator.skillCooldown(attack.skill, effect_.getCooldown()));
player.addCooldown(attack.skill, System.currentTimeMillis(), effect_.getCooldown() * 1000, TimerManager.getInstance().schedule(new CancelCooldownAction(player, attack.skill), effect_.getCooldown() * 1000));
}
}
}
if ((player.getSkillLevel(SkillFactory.getSkill(NightWalker.VANISH)) > 0 || player.getSkillLevel(SkillFactory.getSkill(WindArcher.WIND_WALK)) > 0 || player.getSkillLevel(SkillFactory.getSkill(Rogue.DARK_SIGHT)) > 0) && player.getBuffedValue(MapleBuffStat.DARKSIGHT) != null) {// && player.getBuffSource(MapleBuffStat.DARKSIGHT) != 9101004
player.cancelEffectFromBuffStat(MapleBuffStat.DARKSIGHT);
player.cancelBuffStats(MapleBuffStat.DARKSIGHT);
}
applyAttack(attack, player, attackCount);
}
}

View File

@@ -0,0 +1,85 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import server.events.gm.MapleCoconut;
import server.events.gm.MapleCoconuts;
import server.maps.MapleMap;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author kevintjuh93
*/
public final class CoconutHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
/*CB 00 A6 00 06 01
* A6 00 = coconut id
* 06 01 = ?
*/
int id = slea.readShort();
MapleMap map = c.getPlayer().getMap();
MapleCoconut event = map.getCoconut();
MapleCoconuts nut = event.getCoconut(id);
if (!nut.isHittable()){
return;
}
if (event == null){
return;
}
if (System.currentTimeMillis() < nut.getHitTime()){
return;
}
if (nut.getHits() > 2 && Math.random() < 0.4) {
if (Math.random() < 0.01 && event.getStopped() > 0) {
nut.setHittable(false);
event.stopCoconut();
map.broadcastMessage(MaplePacketCreator.hitCoconut(false, id, 1));
return;
}
nut.setHittable(false); // for sure :)
nut.resetHits(); // For next event (without restarts)
if (Math.random() < 0.05 && event.getBombings() > 0) {
map.broadcastMessage(MaplePacketCreator.hitCoconut(false, id, 2));
event.bombCoconut();
} else if (event.getFalling() > 0) {
map.broadcastMessage(MaplePacketCreator.hitCoconut(false, id, 3));
event.fallCoconut();
if (c.getPlayer().getTeam() == 0) {
event.addMapleScore();
map.broadcastMessage(MaplePacketCreator.serverNotice(5, c.getPlayer().getName() + " of Team Maple knocks down a coconut."));
} else {
event.addStoryScore();
map.broadcastMessage(MaplePacketCreator.serverNotice(5, c.getPlayer().getName() + " of Team Story knocks down a coconut."));
}
map.broadcastMessage(MaplePacketCreator.coconutScore(event.getMapleScore(), event.getStoryScore()));
}
} else {
nut.hit();
map.broadcastMessage(MaplePacketCreator.hitCoconut(false, id, 1));
}
}
}

View File

@@ -0,0 +1,119 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import java.sql.SQLException;
import client.MapleClient;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import net.AbstractMaplePacketHandler;
import server.MapleInventoryManipulator;
import tools.DatabaseConnection;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author Penguins (Acrylic)
*/
public final class CouponCodeHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
slea.skip(2);
String code = slea.readMapleAsciiString();
boolean validcode = false;
int type = -1;
int item = -1;
validcode = getNXCodeValid(code.toUpperCase(), validcode);
if (validcode) {
type = getNXCode(code, "type");
item = getNXCode(code, "item");
if (type != 5) {
try {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE nxcode SET `valid` = 0 WHERE code = " + code);
ps.executeUpdate();
ps.close();
ps = con.prepareStatement("UPDATE nxcode SET `user` = ? WHERE code = ?");
ps.setString(1, c.getPlayer().getName());
ps.setString(2, code);
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
}
}
switch (type) {
case 0:
case 1:
case 2:
c.getPlayer().getCashShop().gainCash(type, item);
break;
case 3:
c.getPlayer().getCashShop().gainCash(0, item);
c.getPlayer().getCashShop().gainCash(2, (item / 5000));
break;
case 4:
MapleInventoryManipulator.addById(c, item, (short) 1, null, -1, -1);
c.announce(MaplePacketCreator.showCouponRedeemedItem(item));
break;
case 5:
c.getPlayer().getCashShop().gainCash(0, item);
break;
}
c.announce(MaplePacketCreator.showCash(c.getPlayer()));
} else {
//c.announce(MaplePacketCreator.wrongCouponCode());
}
c.announce(MaplePacketCreator.enableCSUse());
}
private int getNXCode(String code, String type) {
int item = -1;
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT `" + type + "` FROM nxcode WHERE code = ?");
ps.setString(1, code);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
item = rs.getInt(type);
}
rs.close();
ps.close();
} catch (SQLException ex) {
}
return item;
}
private boolean getNXCodeValid(String code, boolean validcode) {
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT `valid` FROM nxcode WHERE code = ?");
ps.setString(1, code);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
validcode = rs.getInt("valid") != 0;
}
rs.close();
ps.close();
} catch (SQLException ex) {
}
return validcode;
}
}

View File

@@ -0,0 +1,51 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleBuffStat;
import client.MapleCharacter;
import client.MapleClient;
import client.SkillFactory;
import net.AbstractMaplePacketHandler;
import server.maps.MapleSummon;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class DamageSummonHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int skillid = slea.readInt(); //Bugged? might not be skillid.
int unkByte = slea.readByte();
int damage = slea.readInt();
int monsterIdFrom = slea.readInt();
if (SkillFactory.getSkill(skillid) != null) {
MapleCharacter player = c.getPlayer();
MapleSummon summon = player.getSummons().get(skillid);
if (summon != null) {
summon.addHP(-damage);
if (summon.getHP() <= 0) {
player.cancelEffectFromBuffStat(MapleBuffStat.PUPPET);
}
}
player.getMap().broadcastMessage(player, MaplePacketCreator.damageSummon(player.getId(), skillid, damage, unkByte, monsterIdFrom), summon.getPosition());
}
}
}

View File

@@ -0,0 +1,42 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author Xterminator
*/
public final class DenyGuildRequestHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
slea.readByte();
MapleCharacter cfrom = c.getChannelServer().getPlayerStorage().getCharacterByName(slea.readMapleAsciiString());
if (cfrom != null) {
cfrom.getClient().announce(MaplePacketCreator.denyGuildInvitation(c.getPlayer().getName()));
}
}
}

View File

@@ -0,0 +1,38 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class DenyPartyRequestHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
slea.readByte();
MapleCharacter cfrom = c.getChannelServer().getPlayerStorage().getCharacterByName(slea.readMapleAsciiString());
if (cfrom != null) {
cfrom.getClient().announce(MaplePacketCreator.partyStatusMessage(23, c.getPlayer().getName()));
}
}
}

View File

@@ -0,0 +1,166 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import client.MapleJob;
import client.MapleStat;
import client.Skill;
import client.SkillFactory;
import constants.skills.BlazeWizard;
import constants.skills.Brawler;
import constants.skills.DawnWarrior;
import constants.skills.Magician;
import constants.skills.Warrior;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class DistributeAPHandler extends AbstractMaplePacketHandler {
private static final int max = 32767;
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
slea.readInt();
int num = slea.readInt();
if (c.getPlayer().getRemainingAp() > 0) {
if (addStat(c, num)) {
c.getPlayer().setRemainingAp(c.getPlayer().getRemainingAp() - 1);
c.getPlayer().updateSingleStat(MapleStat.AVAILABLEAP, c.getPlayer().getRemainingAp());
}
}
c.announce(MaplePacketCreator.enableActions());
}
static boolean addStat(MapleClient c, int apTo) {
switch (apTo) {
case 64: // Str
if (c.getPlayer().getStr() >= max) {
return false;
}
c.getPlayer().addStat(1, 1);
break;
case 128: // Dex
if (c.getPlayer().getDex() >= max) {
return false;
}
c.getPlayer().addStat(2, 1);
break;
case 256: // Int
if (c.getPlayer().getInt() >= max) {
return false;
}
c.getPlayer().addStat(3, 1);
break;
case 512: // Luk
if (c.getPlayer().getLuk() >= max) {
return false;
}
c.getPlayer().addStat(4, 1);
break;
case 2048: // HP
addHP(c.getPlayer(), addHP(c));
break;
case 8192: // MP
addMP(c.getPlayer(), addMP(c));
break;
default:
c.announce(MaplePacketCreator.updatePlayerStats(MaplePacketCreator.EMPTY_STATUPDATE, true, c.getPlayer()));
return false;
}
return true;
}
static int addHP(MapleClient c) {
MapleCharacter player = c.getPlayer();
MapleJob job = player.getJob();
int MaxHP = player.getMaxHp();
if (player.getHpMpApUsed() > 9999 || MaxHP >= 30000) {
return MaxHP;
}
if (job.isA(MapleJob.WARRIOR) || job.isA(MapleJob.DAWNWARRIOR1) || job.isA(MapleJob.ARAN1)) {
Skill increaseHP = SkillFactory.getSkill(job.isA(MapleJob.DAWNWARRIOR1) ? DawnWarrior.MAX_HP_INCREASE : Warrior.IMPROVED_MAXHP);
int sLvl = player.getSkillLevel(increaseHP);
if(sLvl > 0)
MaxHP += increaseHP.getEffect(sLvl).getY();
MaxHP += 20;
} else if (job.isA(MapleJob.MAGICIAN) || job.isA(MapleJob.BLAZEWIZARD1)) {
MaxHP += 6;
} else if (job.isA(MapleJob.BOWMAN) || job.isA(MapleJob.WINDARCHER1) || job.isA(MapleJob.THIEF) || job.isA(MapleJob.NIGHTWALKER1)) {
MaxHP += 16;
} else if (job.isA(MapleJob.PIRATE) || job.isA(MapleJob.THUNDERBREAKER1)) {
Skill increaseHP = SkillFactory.getSkill(Brawler.IMPROVE_MAX_HP);
int sLvl = player.getSkillLevel(increaseHP);
if(sLvl > 0)
MaxHP += increaseHP.getEffect(sLvl).getY();
MaxHP += 18;
} else {
MaxHP += 8;
}
return MaxHP;
}
static int addMP(MapleClient c) {
MapleCharacter player = c.getPlayer();
int MaxMP = player.getMaxMp();
MapleJob job = player.getJob();
if (player.getHpMpApUsed() > 9999 || player.getMaxMp() >= 30000) {
return MaxMP;
}
if (job.isA(MapleJob.WARRIOR) || job.isA(MapleJob.DAWNWARRIOR1) || job.isA(MapleJob.ARAN1)) {
MaxMP += 2;
} else if (job.isA(MapleJob.MAGICIAN) || job.isA(MapleJob.BLAZEWIZARD1)) {
Skill increaseMP = SkillFactory.getSkill(job.isA(MapleJob.BLAZEWIZARD1) ? BlazeWizard.INCREASING_MAX_MP : Magician.IMPROVED_MAX_MP_INCREASE);
int sLvl = player.getSkillLevel(increaseMP);
if(sLvl > 0)
MaxMP += increaseMP.getEffect(sLvl).getY();
MaxMP += 18;
} else if (job.isA(MapleJob.BOWMAN) || job.isA(MapleJob.WINDARCHER1) || job.isA(MapleJob.THIEF) || job.isA(MapleJob.NIGHTWALKER1)) {
MaxMP += 10;
} else if (job.isA(MapleJob.PIRATE) || job.isA(MapleJob.THUNDERBREAKER1)) {
MaxMP += 14;
} else {
MaxMP += 6;
}
return MaxMP;
}
static void addHP(MapleCharacter player, int MaxHP) {
MaxHP = Math.min(30000, MaxHP);
player.setHpMpApUsed(player.getHpMpApUsed() + 1);
player.setMaxHp(MaxHP);
player.updateSingleStat(MapleStat.MAXHP, MaxHP);
}
static void addMP(MapleCharacter player, int MaxMP) {
MaxMP = Math.min(30000, MaxMP);
player.setHpMpApUsed(player.getHpMpApUsed() + 1);
player.setMaxMp(MaxMP);
player.updateSingleStat(MapleStat.MAXMP, MaxMP);
}
}

View File

@@ -0,0 +1,83 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import net.AbstractMaplePacketHandler;
import tools.FilePrinter;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleCharacter;
import client.MapleClient;
import client.MapleStat;
import client.Skill;
import client.SkillFactory;
import client.autoban.AutobanFactory;
import constants.GameConstants;
import constants.skills.Aran;
public final class DistributeSPHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
slea.readInt();
int skillid = slea.readInt();
if (skillid == Aran.HIDDEN_FULL_DOUBLE || skillid == Aran.HIDDEN_FULL_TRIPLE || skillid == Aran.HIDDEN_OVER_DOUBLE || skillid == Aran.HIDDEN_OVER_TRIPLE) {
c.getSession().write(MaplePacketCreator.enableActions());
return;
}
MapleCharacter player = c.getPlayer();
int remainingSp = player.getRemainingSpBySkill(GameConstants.getSkillBook(skillid/10000));
boolean isBeginnerSkill = false;
if ((!GameConstants.isPQSkillMap(player.getMapId()) && GameConstants.isPqSkill(skillid)) || (!player.isGM() && GameConstants.isGMSkills(skillid)) || (!GameConstants.isInJobTree(skillid, player.getJob().getId()) && !player.isGM())) {
AutobanFactory.PACKET_EDIT.alert(player, "tried to packet edit in distributing sp.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to use skill " + skillid + " without it being in their job.\r\n");
c.disconnect(true, false);
return;
}
if (skillid % 10000000 > 999 && skillid % 10000000 < 1003) {
int total = 0;
for (int i = 0; i < 3; i++) {
total += player.getSkillLevel(SkillFactory.getSkill(player.getJobType() * 10000000 + 1000 + i));
}
remainingSp = Math.min((player.getLevel() - 1), 6) - total;
isBeginnerSkill = true;
}
Skill skill = SkillFactory.getSkill(skillid);
int curLevel = player.getSkillLevel(skill);
if ((remainingSp > 0 && curLevel + 1 <= (skill.isFourthJob() ? player.getMasterLevel(skill) : skill.getMaxLevel()))) {
if (!isBeginnerSkill) {
player.setRemainingSp(player.getRemainingSpBySkill(GameConstants.getSkillBook(skillid/10000)) - 1, GameConstants.getSkillBook(skillid/10000));
}
player.updateSingleStat(MapleStat.AVAILABLESP, player.getRemainingSpBySkill(GameConstants.getSkillBook(skillid/10000)));
if (skill.getId() == Aran.FULL_SWING) {
player.changeSkillLevel(skill, (byte) (curLevel + 1), player.getMasterLevel(skill), player.getSkillExpiration(skill));
player.changeSkillLevel(SkillFactory.getSkill(Aran.HIDDEN_FULL_DOUBLE), (byte) player.getSkillLevel(skill), player.getMasterLevel(skill), player.getSkillExpiration(skill));
player.changeSkillLevel(SkillFactory.getSkill(Aran.HIDDEN_FULL_TRIPLE), (byte) player.getSkillLevel(skill), player.getMasterLevel(skill), player.getSkillExpiration(skill));
} else if (skill.getId() == Aran.OVER_SWING) {
player.changeSkillLevel(skill, (byte) (curLevel + 1), player.getMasterLevel(skill), player.getSkillExpiration(skill));
player.changeSkillLevel(SkillFactory.getSkill(Aran.HIDDEN_OVER_DOUBLE), (byte) player.getSkillLevel(skill), player.getMasterLevel(skill), player.getSkillExpiration(skill));
player.changeSkillLevel(SkillFactory.getSkill(Aran.HIDDEN_OVER_TRIPLE), (byte) player.getSkillLevel(skill), player.getMasterLevel(skill), player.getSkillExpiration(skill));
} else {
player.changeSkillLevel(skill, (byte) (curLevel + 1), player.getMasterLevel(skill), player.getSkillExpiration(skill));
}
}
}
}

View File

@@ -0,0 +1,48 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import server.maps.MapleDoor;
import server.maps.MapleMapObject;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author Matze
*/
public final class DoorHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int oid = slea.readInt();
boolean mode = (slea.readByte() == 0); // specifies if backwarp or not, 1 town to target, 0 target to town
for (MapleMapObject obj : c.getPlayer().getMap().getMapObjects()) {
if (obj instanceof MapleDoor) {
MapleDoor door = (MapleDoor) obj;
if (door.getOwner().getId() == oid) {
door.warp(c.getPlayer(), mode);
return;
}
}
}
}
}

View File

@@ -0,0 +1,400 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import client.autoban.AutobanFactory;
import client.inventory.Equip;
import client.inventory.Item;
import client.inventory.MapleInventoryType;
import constants.ItemConstants;
import constants.ServerConstants;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import net.AbstractMaplePacketHandler;
import net.server.channel.Channel;
import server.DueyPackages;
import server.MapleInventoryManipulator;
import tools.DatabaseConnection;
import tools.FilePrinter;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class DueyHandler extends AbstractMaplePacketHandler {
private enum Actions {
TOSERVER_SEND_ITEM(0x02),
TOSERVER_CLAIM_PACKAGE(0x04),
TOSERVER_REMOVE_PACKAGE(0x05),
TOSERVER_CLOSE_DUEY(0x07),
TOCLIENT_OPEN_DUEY(0x08),
TOCLIENT_NOT_ENOUGH_MESOS(0x0A),
TOCLIENT_NAME_DOES_NOT_EXIST(0x0C),
TOCLIENT_SAMEACC_ERROR(0x0D),
TOCLIENT_SUCCESSFULLY_SENT(0x12),
TOCLIENT_SUCCESSFUL_MSG(0x17),
TOCLIENT_PACKAGE_MSG(0x1B); // Ending byte; 4 if recieved. 3 if delete.
final byte code;
private Actions(int code) {
this.code = (byte) code;
}
public byte getCode() {
return code;
}
}
private static int getAccIdFromCNAME(String name, boolean accountid) {
try {
PreparedStatement ps;
String text = "SELECT id,accountid FROM characters WHERE name = ?";
if (accountid) {
text = "SELECT id,accountid FROM characters WHERE name = ?";
}
ps = DatabaseConnection.getConnection().prepareStatement(text);
ps.setString(1, name);
int id_;
try (ResultSet rs = ps.executeQuery()) {
if (!rs.next()) {
rs.close();
ps.close();
return -1;
}
id_ = accountid ? rs.getInt("accountid") : rs.getInt("id");
}
ps.close();
return id_;
} catch (SQLException e) {
e.printStackTrace();
}
return -1;
}
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!ServerConstants.USE_DUEY){
return;
}
byte operation = slea.readByte();
if (operation == Actions.TOSERVER_SEND_ITEM.getCode()) {
final int fee = 5000;
byte inventId = slea.readByte();
short itemPos = slea.readShort();
short amount = slea.readShort();
int mesos = slea.readInt();
String recipient = slea.readMapleAsciiString();
System.out.println(mesos + " " + fee + " " + getFee(mesos) + "/" + amount + " " + Integer.MAX_VALUE);
if (mesos < 0 || (long) mesos > Integer.MAX_VALUE || ((long) mesos + fee + getFee(mesos)) > Integer.MAX_VALUE || (amount < 1 && mesos == 0)) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with duey.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to use duey with mesos " + mesos + " and amount " + amount + "\r\n");
c.disconnect(true, false);
return;
}
int finalcost = mesos + fee + getFee(mesos);
boolean send = false;
if (c.getPlayer().getMeso() >= finalcost) {
int accid = getAccIdFromCNAME(recipient, true);
if (accid != -1) {
if (accid != c.getAccID()) {
c.getPlayer().gainMeso(-finalcost, false);
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SUCCESSFULLY_SENT.getCode()));
send = true;
} else {
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SAMEACC_ERROR.getCode()));
}
} else {
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_NAME_DOES_NOT_EXIST.getCode()));
}
} else {
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_NOT_ENOUGH_MESOS.getCode()));
}
boolean recipientOn = false;
MapleClient rClient = null;
int channel = c.getWorldServer().find(recipient);
if (channel > -1) {
recipientOn = true;
Channel rcserv = c.getWorldServer().getChannel(channel);
rClient = rcserv.getPlayerStorage().getCharacterByName(recipient).getClient();
}
if (send) {
if (inventId > 0) {
MapleInventoryType inv = MapleInventoryType.getByType(inventId);
Item item = c.getPlayer().getInventory(inv).getItem(itemPos);
if (item != null && c.getPlayer().getItemQuantity(item.getItemId(), false) >= amount) {
if (ItemConstants.isRechargable(item.getItemId())) {
MapleInventoryManipulator.removeFromSlot(c, inv, itemPos, item.getQuantity(), true);
} else {
MapleInventoryManipulator.removeFromSlot(c, inv, itemPos, amount, true, false);
}
addItemToDB(item, amount, mesos, c.getPlayer().getName(), getAccIdFromCNAME(recipient, false));
} else {
if (item != null) c.getPlayer().dropMessage(1, "You must assign up to " + c.getPlayer().getItemQuantity(item.getItemId(), false) + " of that item to send.");
return;
}
} else {
addMesoToDB(mesos, c.getPlayer().getName(), getAccIdFromCNAME(recipient, false));
}
if (recipientOn && rClient != null) {
rClient.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_PACKAGE_MSG.getCode()));
}
}
} else if (operation == Actions.TOSERVER_REMOVE_PACKAGE.getCode()) {
int packageid = slea.readInt();
removeItemFromDB(packageid);
c.announce(MaplePacketCreator.removeItemFromDuey(true, packageid));
} else if (operation == Actions.TOSERVER_CLAIM_PACKAGE.getCode()) {
int packageid = slea.readInt();
List<DueyPackages> packages = new LinkedList<>();
DueyPackages dp = null;
Connection con = DatabaseConnection.getConnection();
try {
DueyPackages dueypack;
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM dueypackages LEFT JOIN dueyitems USING (PackageId) WHERE PackageId = ?")) {
ps.setInt(1, packageid);
try (ResultSet rs = ps.executeQuery()) {
dueypack = null;
if (rs.next()) {
dueypack = getItemByPID(rs);
dueypack.setSender(rs.getString("SenderName"));
dueypack.setMesos(rs.getInt("Mesos"));
dueypack.setSentTime(rs.getString("TimeStamp"));
packages.add(dueypack);
}
}
}
dp = dueypack;
if(dp == null) {
System.out.println("Error: Null Duey package!");
return;
}
if (dp.getItem() != null) {
if (!MapleInventoryManipulator.checkSpace(c, dp.getItem().getItemId(), dp.getItem().getQuantity(), dp.getItem().getOwner())) {
c.getPlayer().dropMessage(1, "Your inventory is full");
c.announce(MaplePacketCreator.enableActions());
return;
} else {
MapleInventoryManipulator.addFromDrop(c, dp.getItem(), false);
}
}
long gainmesos = 0;
long totalmesos = (long) dp.getMesos() + (long) c.getPlayer().getMeso();
if (totalmesos < 0 || dp.getMesos() < 0) gainmesos = 0;
else {
totalmesos = Math.min(totalmesos, Integer.MAX_VALUE);
gainmesos = totalmesos - c.getPlayer().getMeso();
}
c.getPlayer().gainMeso((int)gainmesos, false);
removeItemFromDB(packageid);
c.announce(MaplePacketCreator.removeItemFromDuey(false, packageid));
} catch (SQLException e) {
e.printStackTrace();
}
}
}
private void addMesoToDB(int mesos, String sName, int recipientID) {
addItemToDB(null, 1, mesos, sName, recipientID);
}
private void addItemToDB(Item item, int quantity, int mesos, String sName, int recipientID) {
Connection con = DatabaseConnection.getConnection();
try {
try (PreparedStatement ps = con.prepareStatement("INSERT INTO dueypackages (RecieverId, SenderName, Mesos, TimeStamp, Checked, Type) VALUES (?, ?, ?, ?, ?, ?)")) {
ps.setInt(1, recipientID);
ps.setString(2, sName);
ps.setInt(3, mesos);
ps.setString(4, getCurrentDate());
ps.setInt(5, 1);
if (item == null) {
ps.setInt(6, 3);
ps.executeUpdate();
} else {
ps.setInt(6, item.getType());
ps.executeUpdate();
try (ResultSet rs = ps.getGeneratedKeys()) {
rs.next();
PreparedStatement ps2;
if (item.getType() == 1) { // equips
ps2 = con.prepareStatement("INSERT INTO dueyitems (PackageId, itemid, quantity, upgradeslots, level, str, dex, `int`, luk, hp, mp, watk, matk, wdef, mdef, acc, avoid, hands, speed, jump, owner) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
Equip eq = (Equip) item;
ps2.setInt(2, eq.getItemId());
ps2.setInt(3, 1);
ps2.setInt(4, eq.getUpgradeSlots());
ps2.setInt(5, eq.getLevel());
ps2.setInt(6, eq.getStr());
ps2.setInt(7, eq.getDex());
ps2.setInt(8, eq.getInt());
ps2.setInt(9, eq.getLuk());
ps2.setInt(10, eq.getHp());
ps2.setInt(11, eq.getMp());
ps2.setInt(12, eq.getWatk());
ps2.setInt(13, eq.getMatk());
ps2.setInt(14, eq.getWdef());
ps2.setInt(15, eq.getMdef());
ps2.setInt(16, eq.getAcc());
ps2.setInt(17, eq.getAvoid());
ps2.setInt(18, eq.getHands());
ps2.setInt(19, eq.getSpeed());
ps2.setInt(20, eq.getJump());
ps2.setString(21, eq.getOwner());
} else {
ps2 = con.prepareStatement("INSERT INTO dueyitems (PackageId, itemid, quantity, owner) VALUES (?, ?, ?, ?)");
ps2.setInt(2, item.getItemId());
ps2.setInt(3, quantity);
ps2.setString(4, item.getOwner());
}
ps2.setInt(1, rs.getInt(1));
ps2.executeUpdate();
ps2.close();
}
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public static List<DueyPackages> loadItems(MapleCharacter chr) {
List<DueyPackages> packages = new LinkedList<>();
Connection con = DatabaseConnection.getConnection();
try {
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM dueypackages dp LEFT JOIN dueyitems di ON dp.PackageId=di.PackageId WHERE RecieverId = ?")) {
ps.setInt(1, chr.getId());
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
DueyPackages dueypack = getItemByPID(rs);
dueypack.setSender(rs.getString("SenderName"));
dueypack.setMesos(rs.getInt("Mesos"));
dueypack.setSentTime(rs.getString("TimeStamp"));
packages.add(dueypack);
}
}
}
return packages;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
private String getCurrentDate() {
String date = "";
Calendar cal = Calendar.getInstance();
int day = cal.get(Calendar.DATE) - 1; // instant duey ?
int month = cal.get(Calendar.MONTH) + 1; // its an array of months.
int year = cal.get(Calendar.YEAR);
date += day < 9 ? "0" + day + "-" : "" + day + "-";
date += month < 9 ? "0" + month + "-" : "" + month + "-";
date += year;
return date;
}
private static int getFee(int meso) {
int fee = 0;
if (meso >= 10000000) {
fee = meso / 25;
} else if (meso >= 5000000) {
fee = meso * 3 / 100;
} else if (meso >= 1000000) {
fee = meso / 50;
} else if (meso >= 100000) {
fee = meso / 100;
} else if (meso >= 50000) {
fee = meso / 200;
}
return fee;
}
private void removeItemFromDB(int packageid) {
Connection con = DatabaseConnection.getConnection();
try {
PreparedStatement ps = con.prepareStatement("DELETE FROM dueypackages WHERE PackageId = ?");
ps.setInt(1, packageid);
ps.executeUpdate();
ps.close();
ps = con.prepareStatement("DELETE FROM dueyitems WHERE PackageId = ?");
ps.setInt(1, packageid);
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
private static DueyPackages getItemByPID(ResultSet rs) {
try {
DueyPackages dueypack;
if (rs.getInt("type") == 1) {
Equip eq = new Equip(rs.getInt("itemid"), (byte) 0, -1);
eq.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
eq.setLevel((byte) rs.getInt("level"));
eq.setStr((short) rs.getInt("str"));
eq.setDex((short) rs.getInt("dex"));
eq.setInt((short) rs.getInt("int"));
eq.setLuk((short) rs.getInt("luk"));
eq.setHp((short) rs.getInt("hp"));
eq.setMp((short) rs.getInt("mp"));
eq.setWatk((short) rs.getInt("watk"));
eq.setMatk((short) rs.getInt("matk"));
eq.setWdef((short) rs.getInt("wdef"));
eq.setMdef((short) rs.getInt("mdef"));
eq.setAcc((short) rs.getInt("acc"));
eq.setAvoid((short) rs.getInt("avoid"));
eq.setHands((short) rs.getInt("hands"));
eq.setSpeed((short) rs.getInt("speed"));
eq.setJump((short) rs.getInt("jump"));
eq.setOwner(rs.getString("owner"));
dueypack = new DueyPackages(rs.getInt("PackageId"), eq);
} else if (rs.getInt("type") == 2) {
Item newItem = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
newItem.setOwner(rs.getString("owner"));
dueypack = new DueyPackages(rs.getInt("PackageId"), newItem);
} else {
dueypack = new DueyPackages(rs.getInt("PackageId"));
}
return dueypack;
} catch (SQLException se) {
se.printStackTrace();
return null;
}
}
}

View File

@@ -0,0 +1,60 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation. You may not use, modify
or distribute this program under any other version of the
GNU Affero General Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import net.server.Server;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author Flav
*/
public class EnterCashShopHandler extends AbstractMaplePacketHandler {
@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
try {
MapleCharacter mc = c.getPlayer();
if (mc.getCashShop().isOpened()) return;
Server.getInstance().getPlayerBuffStorage().addBuffsToStorage(mc.getId(), mc.getAllBuffs());
mc.cancelBuffEffects();
mc.cancelExpirationTask();
c.announce(MaplePacketCreator.openCashShop(c, false));
mc.saveToDB();
mc.getCashShop().open(true);
mc.getMap().removePlayer(mc);
c.getChannelServer().removePlayer(mc);
c.announce(MaplePacketCreator.showCashInventory(c));
c.announce(MaplePacketCreator.showGifts(mc.getCashShop().loadGifts()));
c.announce(MaplePacketCreator.showWishList(mc, false));
c.announce(MaplePacketCreator.showCash(mc));
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,212 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.*;
import client.inventory.Equip;
import client.inventory.Item;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import constants.ServerConstants;
import net.AbstractMaplePacketHandler;
import net.server.Server;
import server.MTSItemInfo;
import tools.DatabaseConnection;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class EnterMTSHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!ServerConstants.USE_MTS){
return;
}
MapleCharacter chr = c.getPlayer();
if (!chr.isAlive()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (chr.getLevel() < 10) {
c.announce(MaplePacketCreator.blockedMessage2(5));
c.announce(MaplePacketCreator.enableActions());
return;
}
Server.getInstance().getPlayerBuffStorage().addBuffsToStorage(chr.getId(), chr.getAllBuffs());
chr.cancelExpirationTask();
chr.saveToDB();
chr.getMap().removePlayer(c.getPlayer());
try {
c.announce(MaplePacketCreator.openCashShop(c, true));
} catch (Exception ex) {
}
chr.getCashShop().open(true);// xD
c.announce(MaplePacketCreator.enableCSUse());
c.announce(MaplePacketCreator.MTSWantedListingOver(0, 0));
c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
List<MTSItemInfo> items = new ArrayList<>();
int pages = 0;
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM mts_items WHERE tab = 1 AND transfer = 0 ORDER BY id DESC LIMIT 16, 16");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
if (rs.getInt("type") != 1) {
Item i = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
i.setOwner(rs.getString("owner"));
items.add(new MTSItemInfo(i, rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
} else {
Equip equip = new Equip(rs.getInt("itemid"), (byte) rs.getInt("position"), -1);
equip.setOwner(rs.getString("owner"));
equip.setQuantity((short) 1);
equip.setAcc((short) rs.getInt("acc"));
equip.setAvoid((short) rs.getInt("avoid"));
equip.setDex((short) rs.getInt("dex"));
equip.setHands((short) rs.getInt("hands"));
equip.setHp((short) rs.getInt("hp"));
equip.setInt((short) rs.getInt("int"));
equip.setJump((short) rs.getInt("jump"));
equip.setVicious((short) rs.getInt("vicious"));
equip.setFlag((byte) rs.getInt("flag"));
equip.setLuk((short) rs.getInt("luk"));
equip.setMatk((short) rs.getInt("matk"));
equip.setMdef((short) rs.getInt("mdef"));
equip.setMp((short) rs.getInt("mp"));
equip.setSpeed((short) rs.getInt("speed"));
equip.setStr((short) rs.getInt("str"));
equip.setWatk((short) rs.getInt("watk"));
equip.setWdef((short) rs.getInt("wdef"));
equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
equip.setLevel((byte) rs.getInt("level"));
items.add(new MTSItemInfo((Item) equip, rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
}
}
rs.close();
ps.close();
ps = DatabaseConnection.getConnection().prepareStatement("SELECT COUNT(*) FROM mts_items");
rs = ps.executeQuery();
if (rs.next()) {
pages = (int) Math.ceil(rs.getInt(1) / 16);
}
rs.close();
ps.close();
} catch (SQLException e) {
}
c.announce(MaplePacketCreator.sendMTS(items, 1, 0, 0, pages));
c.announce(MaplePacketCreator.transferInventory(getTransfer(chr.getId())));
c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(chr.getId())));
}
private List<MTSItemInfo> getNotYetSold(int cid) {
List<MTSItemInfo> items = new ArrayList<>();
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM mts_items WHERE seller = ? AND transfer = 0 ORDER BY id DESC")) {
ps.setInt(1, cid);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
if (rs.getInt("type") != 1) {
Item i = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
i.setOwner(rs.getString("owner"));
items.add(new MTSItemInfo((Item) i, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
} else {
Equip equip = new Equip(rs.getInt("itemid"), (byte) rs.getInt("position"), -1);
equip.setOwner(rs.getString("owner"));
equip.setQuantity((short) 1);
equip.setAcc((short) rs.getInt("acc"));
equip.setAvoid((short) rs.getInt("avoid"));
equip.setDex((short) rs.getInt("dex"));
equip.setHands((short) rs.getInt("hands"));
equip.setHp((short) rs.getInt("hp"));
equip.setInt((short) rs.getInt("int"));
equip.setJump((short) rs.getInt("jump"));
equip.setVicious((short) rs.getInt("vicious"));
equip.setLuk((short) rs.getInt("luk"));
equip.setMatk((short) rs.getInt("matk"));
equip.setMdef((short) rs.getInt("mdef"));
equip.setMp((short) rs.getInt("mp"));
equip.setSpeed((short) rs.getInt("speed"));
equip.setStr((short) rs.getInt("str"));
equip.setWatk((short) rs.getInt("watk"));
equip.setWdef((short) rs.getInt("wdef"));
equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
equip.setLevel((byte) rs.getInt("level"));
equip.setFlag((byte) rs.getInt("flag"));
items.add(new MTSItemInfo((Item) equip, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
}
}
}
}
} catch (SQLException e) {
}
return items;
}
private List<MTSItemInfo> getTransfer(int cid) {
List<MTSItemInfo> items = new ArrayList<>();
try {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM mts_items WHERE transfer = 1 AND seller = ? ORDER BY id DESC")) {
ps.setInt(1, cid);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
if (rs.getInt("type") != 1) {
Item i = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
i.setOwner(rs.getString("owner"));
items.add(new MTSItemInfo((Item) i, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
} else {
Equip equip = new Equip(rs.getInt("itemid"), (byte) rs.getInt("position"), -1);
equip.setOwner(rs.getString("owner"));
equip.setQuantity((short) 1);
equip.setAcc((short) rs.getInt("acc"));
equip.setAvoid((short) rs.getInt("avoid"));
equip.setDex((short) rs.getInt("dex"));
equip.setHands((short) rs.getInt("hands"));
equip.setHp((short) rs.getInt("hp"));
equip.setInt((short) rs.getInt("int"));
equip.setJump((short) rs.getInt("jump"));
equip.setVicious((short) rs.getInt("vicious"));
equip.setLuk((short) rs.getInt("luk"));
equip.setMatk((short) rs.getInt("matk"));
equip.setMdef((short) rs.getInt("mdef"));
equip.setMp((short) rs.getInt("mp"));
equip.setSpeed((short) rs.getInt("speed"));
equip.setStr((short) rs.getInt("str"));
equip.setWatk((short) rs.getInt("watk"));
equip.setWdef((short) rs.getInt("wdef"));
equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
equip.setLevel((byte) rs.getInt("level"));
equip.setFlag((byte) rs.getInt("flag"));
items.add(new MTSItemInfo((Item) equip, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
}
}
}
}
} catch (SQLException e) {
}
return items;
}
}

View File

@@ -0,0 +1,41 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import server.MapleItemInformationProvider;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class FaceExpressionHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int emote = slea.readInt();
if (emote > 7) {
int emoteid = 5159992 + emote;
if (c.getPlayer().getInventory(MapleItemInformationProvider.getInstance().getInventoryType(emoteid)).findById(emoteid) == null) {
return;
}
}
c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.facialExpression(c.getPlayer(), emote), false);
}
}

View File

@@ -0,0 +1,52 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import constants.ServerConstants;
import client.MapleCharacter;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author Jay Estrella
*/
public final class FamilyAddHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!ServerConstants.USE_FAMILY_SYSTEM){
return;
}
System.out.println(slea.toString());
String toAdd = slea.readMapleAsciiString();
MapleCharacter addChr = c.getChannelServer().getPlayerStorage().getCharacterByName(toAdd);
if (addChr != null) {
addChr.getClient().announce(MaplePacketCreator.sendFamilyInvite(c.getPlayer().getId(), toAdd));
c.getPlayer().dropMessage("The invite has been sent.");
} else {
c.getPlayer().dropMessage("The player cannot be found!");
}
c.announce(MaplePacketCreator.enableActions());
}
}

View File

@@ -0,0 +1,102 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import constants.ServerConstants;
import client.MapleCharacter;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import net.SendOpcode;
import tools.data.input.SeekableLittleEndianAccessor;
import tools.data.output.MaplePacketLittleEndianWriter;
/**
*
* @author Moogra
*/
public final class FamilyUseHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!ServerConstants.USE_FAMILY_SYSTEM){
return;
}
int[] repCost = {3, 5, 7, 8, 10, 12, 15, 20, 25, 40, 50};
final int type = slea.readInt();
MapleCharacter victim;
if (type == 0 || type == 1) {
victim = c.getChannelServer().getPlayerStorage().getCharacterByName(slea.readMapleAsciiString());
if (victim != null) {
if (type == 0) {
c.getPlayer().changeMap(victim.getMap(), victim.getMap().getPortal(0));
} else {
victim.changeMap(c.getPlayer().getMap(), c.getPlayer().getMap().getPortal(0));
}
} else {
return;
}
} else {
int erate = type == 3 ? 150 : (type == 4 || type == 6 || type == 8 || type == 10 ? 200 : 100);
int drate = type == 2 ? 150 : (type == 4 || type == 5 || type == 7 || type == 9 ? 200 : 100);
if (type > 8) {
} else {
c.announce(useRep(drate == 100 ? 2 : (erate == 100 ? 3 : 4), type, erate, drate, ((type > 5 || type == 4) ? 2 : 1) * 15 * 60 * 1000));
}
}
c.getPlayer().getFamily().getMember(c.getPlayer().getId()).gainReputation(repCost[type]);
}
/**
* [65 00][02][08 00 00 00][C8 00 00 00][00 00 00 00][00][40 77 1B 00]
*/
private static byte[] useRep(int mode, int type, int erate, int drate, int time) {
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(0x60);//noty
mplew.write(mode);
mplew.writeInt(type);
if (mode < 4) {
mplew.writeInt(erate);
mplew.writeInt(drate);
}
mplew.write(0);
mplew.writeInt(time);
return mplew.getPacket();
}
//20 00
//00 00 00 00
//00 00 00 00 00 00 00 00
//80 01
//00 00 28 00
//8C 93 3E 00
//40 0D
//03 00 14 00
//8C 93 3E 00
//40 0D 03 00 00 00 00 00 02
private static byte[] giveBuff() {
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(SendOpcode.GIVE_BUFF.getValue());
mplew.writeInt(0);
mplew.writeLong(0);
return null;
}
}

View File

@@ -0,0 +1,122 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import client.inventory.Item;
import client.inventory.ItemFactory;
import client.inventory.MapleInventory;
import client.inventory.MapleInventoryType;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import net.AbstractMaplePacketHandler;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import tools.DatabaseConnection;
import tools.FilePrinter;
import tools.MaplePacketCreator;
import tools.Pair;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author kevintjuh93
*/
public class FredrickHandler extends AbstractMaplePacketHandler {
@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
byte operation = slea.readByte();
switch (operation) {
case 0x19: //Will never come...
//c.announce(MaplePacketCreator.getFredrick((byte) 0x24));
break;
case 0x1A:
List<Pair<Item, MapleInventoryType>> items;
try {
items = ItemFactory.MERCHANT.loadItems(chr.getId(), false);
if (!check(chr, items)) {
c.announce(MaplePacketCreator.fredrickMessage((byte) 0x21));
return;
}
chr.gainMeso(chr.getMerchantMeso(), false);
chr.setMerchantMeso(0);
if (deleteItems(chr)) {
if(chr.getHiredMerchant() != null)
chr.getHiredMerchant().clearItems();
for (int i = 0; i < items.size(); i++) {
Item item = items.get(i).getLeft();
MapleInventoryManipulator.addFromDrop(c, item, false);
String itemName = MapleItemInformationProvider.getInstance().getName(item.getItemId());
FilePrinter.printError(FilePrinter.FREDRICK + chr.getName() + ".txt", chr.getName() + " gained " + item.getQuantity() + " " + itemName + " (" + item.getItemId() + ")\r\n");
}
c.announce(MaplePacketCreator.fredrickMessage((byte) 0x1E));
} else {
chr.message("An unknown error has occured.");
}
break;
} catch (SQLException ex) {
ex.printStackTrace();
}
break;
case 0x1C: //Exit
break;
default:
}
}
private static boolean check(MapleCharacter chr, List<Pair<Item, MapleInventoryType>> items) {
if (chr.getMeso() + chr.getMerchantMeso() < 0) {
return false;
}
if (!MapleInventory.checkSpots(chr, items)) {
return false;
}
return true;
}
private static boolean deleteItems(MapleCharacter chr) {
try {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("DELETE FROM `inventoryitems` WHERE `type` = ? AND `characterid` = ?")) {
ps.setInt(1, ItemFactory.MERCHANT.getValue());
ps.setInt(2, chr.getId());
ps.execute();
}
return true;
} catch (SQLException e) {
return false;
}
}
}

View File

@@ -0,0 +1,78 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import tools.LogHelper;
import tools.FilePrinter;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleCharacter;
import client.MapleClient;
import client.autoban.AutobanFactory;
import client.command.Commands;
public final class GeneralChatHandler extends net.AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
String s = slea.readMapleAsciiString();
MapleCharacter chr = c.getPlayer();
if(chr.getAutobanManager().getLastSpam(7) + 200 > System.currentTimeMillis()) {
return;
}
if (s.length() > Byte.MAX_VALUE && !chr.isGM()) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit in General Chat.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to send text with length of " + s.length() + "\r\n");
c.disconnect(true, false);
return;
}
char heading = s.charAt(0);
if (heading == '/' || heading == '!' || heading == '@') {
String[] sp = s.split(" ");
sp[0] = sp[0].toLowerCase().substring(1);
if (!Commands.executePlayerCommand(c, sp, heading)) {
if (chr.isGM()) {
if (!Commands.executeGMCommand(c, sp, heading)) {
Commands.executeAdminCommand(c, sp, heading);
}
String command = "";
for (String used : sp) {
command += used + " ";
}
FilePrinter.printError("usedCommands.txt", c.getPlayer().getName() + " used: " + heading + command + "\r\n");
}
}
} else {
int show = slea.readByte();
if(chr.getMap().isMuted() && !chr.isGM()) {
chr.dropMessage(5, "The map you are in is currently muted. Please try again later.");
return;
}
if (!chr.isHidden()){
chr.getMap().broadcastMessage(MaplePacketCreator.getChatText(chr.getId(), s, chr.getWhiteChat(), show));
} else {
chr.getMap().broadcastGMMessage(MaplePacketCreator.getChatText(chr.getId(), s, chr.getWhiteChat(), show));
}
}
chr.getAutobanManager().spam(7);
}
}

View File

@@ -0,0 +1,63 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleCharacter.FameStatus;
import client.autoban.AutobanFactory;
import client.MapleClient;
import client.MapleStat;
import net.AbstractMaplePacketHandler;
import tools.FilePrinter;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class GiveFameHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter target = (MapleCharacter) c.getPlayer().getMap().getMapObject(slea.readInt());
int mode = slea.readByte();
int famechange = 2 * mode - 1;
MapleCharacter player = c.getPlayer();
if (target == null || target.getId() == player.getId() || player.getLevel() < 15) {
return;
} else if (famechange != 1 && famechange != -1) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit fame.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to fame hack with famechange " + famechange + "\r\n");
c.disconnect(true, false);
return;
}
FameStatus status = player.canGiveFame(target);
if (status == FameStatus.OK || player.isGM()){
if (Math.abs(target.getFame() + famechange) < 30001) {
target.addFame(famechange);
target.updateSingleStat(MapleStat.FAME, target.getFame());
}
if (!player.isGM()) {
player.hasGivenFame(target);
}
c.announce(MaplePacketCreator.giveFameResponse(mode, target.getName(), target.getFame()));
target.getClient().announce(MaplePacketCreator.receiveFame(mode, player.getName()));
} else {
c.announce(MaplePacketCreator.giveFameErrorResponse(status == FameStatus.NOT_TODAY ? 3 : 4));
}
}
}

View File

@@ -0,0 +1,266 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import net.server.guild.MapleGuildResponse;
import net.server.guild.MapleGuild;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import tools.data.input.SeekableLittleEndianAccessor;
import java.util.Iterator;
import tools.MaplePacketCreator;
import client.MapleCharacter;
import net.server.Server;
public final class GuildOperationHandler extends AbstractMaplePacketHandler {
private boolean isGuildNameAcceptable(String name) {
if (name.length() < 3 || name.length() > 12) {
return false;
}
for (int i = 0; i < name.length(); i++) {
if (!Character.isLowerCase(name.charAt(i)) && !Character.isUpperCase(name.charAt(i))) {
return false;
}
}
return true;
}
private void respawnPlayer(MapleCharacter mc) {
mc.getMap().broadcastMessage(mc, MaplePacketCreator.removePlayerFromMap(mc.getId()), false);
mc.getMap().broadcastMessage(mc, MaplePacketCreator.spawnPlayerMapobject(mc), false);
}
private class Invited {
public String name;
public int gid;
public long expiration;
public Invited(String n, int id) {
name = n.toLowerCase();
gid = id;
expiration = System.currentTimeMillis() + 60 * 60 * 1000;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof Invited)) {
return false;
}
Invited oth = (Invited) other;
return (gid == oth.gid && name.equals(oth));
}
@Override
public int hashCode() {
int hash = 3;
hash = 83 * hash + (this.name != null ? this.name.hashCode() : 0);
hash = 83 * hash + this.gid;
return hash;
}
}
private java.util.List<Invited> invited = new java.util.LinkedList<Invited>();
private long nextPruneTime = System.currentTimeMillis() + 20 * 60 * 1000;
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (System.currentTimeMillis() >= nextPruneTime) {
Iterator<Invited> itr = invited.iterator();
Invited inv;
while (itr.hasNext()) {
inv = itr.next();
if (System.currentTimeMillis() >= inv.expiration) {
itr.remove();
}
}
nextPruneTime = System.currentTimeMillis() + 20 * 60 * 1000;
}
MapleCharacter mc = c.getPlayer();
byte type = slea.readByte();
switch (type) {
case 0x00:
//c.announce(MaplePacketCreator.showGuildInfo(mc));
break;
case 0x02:
if (mc.getGuildId() > 0 || mc.getMapId() != 200000301) {
c.getPlayer().dropMessage(1, "You cannot create a new Guild while in one.");
return;
}
if (mc.getMeso() < MapleGuild.CREATE_GUILD_COST) {
c.getPlayer().dropMessage(1, "You do not have enough mesos to create a Guild.");
return;
}
String guildName = slea.readMapleAsciiString();
if (!isGuildNameAcceptable(guildName)) {
c.getPlayer().dropMessage(1, "The Guild name you have chosen is not accepted.");
return;
}
int gid;
gid = Server.getInstance().createGuild(mc.getId(), guildName);
if (gid == 0) {
c.announce(MaplePacketCreator.genericGuildMessage((byte) 0x1c));
return;
}
mc.gainMeso(-MapleGuild.CREATE_GUILD_COST, true, false, true);
mc.setGuildId(gid);
mc.setGuildRank(1);
mc.saveGuildStatus();
c.announce(MaplePacketCreator.showGuildInfo(mc));
c.getPlayer().dropMessage(1, "You have successfully created a Guild.");
respawnPlayer(mc);
break;
case 0x05:
if (mc.getGuildId() <= 0 || mc.getGuildRank() > 2) {
return;
}
String name = slea.readMapleAsciiString();
MapleGuildResponse mgr = MapleGuild.sendInvite(c, name);
if (mgr != null) {
c.announce(mgr.getPacket());
} else {
Invited inv = new Invited(name, mc.getGuildId());
if (!invited.contains(inv)) {
invited.add(inv);
}
}
break;
case 0x06:
if (mc.getGuildId() > 0) {
System.out.println("[hax] " + mc.getName() + " attempted to join a guild when s/he is already in one.");
return;
}
gid = slea.readInt();
int cid = slea.readInt();
if (cid != mc.getId()) {
System.out.println("[hax] " + mc.getName() + " attempted to join a guild with a different character id.");
return;
}
name = mc.getName().toLowerCase();
Iterator<Invited> itr = invited.iterator();
boolean bOnList = false;
while (itr.hasNext()) {
Invited inv = itr.next();
if (gid == inv.gid && name.equals(inv.name)) {
bOnList = true;
itr.remove();
break;
}
}
if (!bOnList) {
System.out.println("[hax] " + mc.getName() + " is trying to join a guild that never invited him/her (or that the invitation has expired)");
return;
}
mc.setGuildId(gid); // joins the guild
mc.setGuildRank(5); // start at lowest rank
int s;
s = Server.getInstance().addGuildMember(mc.getMGC());
if (s == 0) {
c.getPlayer().dropMessage(1, "The Guild you are trying to join is already full.");
mc.setGuildId(0);
return;
}
c.announce(MaplePacketCreator.showGuildInfo(mc));
mc.saveGuildStatus(); // update database
respawnPlayer(mc);
break;
case 0x07:
cid = slea.readInt();
name = slea.readMapleAsciiString();
if (cid != mc.getId() || !name.equals(mc.getName()) || mc.getGuildId() <= 0) {
System.out.println("[hax] " + mc.getName() + " tried to quit guild under the name \"" + name + "\" and current guild id of " + mc.getGuildId() + ".");
return;
}
c.announce(MaplePacketCreator.updateGP(mc.getGuildId(), 0));
Server.getInstance().leaveGuild(mc.getMGC());
c.announce(MaplePacketCreator.showGuildInfo(null));
mc.setGuildId(0);
mc.saveGuildStatus();
respawnPlayer(mc);
break;
case 0x08:
cid = slea.readInt();
name = slea.readMapleAsciiString();
if (mc.getGuildRank() > 2 || mc.getGuildId() <= 0) {
System.out.println("[hax] " + mc.getName() + " is trying to expel without rank 1 or 2.");
return;
}
Server.getInstance().expelMember(mc.getMGC(), name, cid);
break;
case 0x0d:
if (mc.getGuildId() <= 0 || mc.getGuildRank() != 1) {
System.out.println("[hax] " + mc.getName() + " tried to change guild rank titles when s/he does not have permission.");
return;
}
String ranks[] = new String[5];
for (int i = 0; i < 5; i++) {
ranks[i] = slea.readMapleAsciiString();
}
Server.getInstance().changeRankTitle(mc.getGuildId(), ranks);
break;
case 0x0e:
cid = slea.readInt();
byte newRank = slea.readByte();
if (mc.getGuildRank() > 2 || (newRank <= 2 && mc.getGuildRank() != 1) || mc.getGuildId() <= 0) {
System.out.println("[hax] " + mc.getName() + " is trying to change rank outside of his/her permissions.");
return;
}
if (newRank <= 1 || newRank > 5) {
return;
}
Server.getInstance().changeRank(mc.getGuildId(), cid, newRank);
break;
case 0x0f:
if (mc.getGuildId() <= 0 || mc.getGuildRank() != 1 || mc.getMapId() != 200000301) {
System.out.println("[hax] " + mc.getName() + " tried to change guild emblem without being the guild leader.");
return;
}
if (mc.getMeso() < MapleGuild.CHANGE_EMBLEM_COST) {
c.announce(MaplePacketCreator.serverNotice(1, "You do not have enough mesos to create a Guild."));
return;
}
short bg = slea.readShort();
byte bgcolor = slea.readByte();
short logo = slea.readShort();
byte logocolor = slea.readByte();
Server.getInstance().setGuildEmblem(mc.getGuildId(), bg, bgcolor, logo, logocolor);
mc.gainMeso(-MapleGuild.CHANGE_EMBLEM_COST, true, false, true);
respawnPlayer(mc);
break;
case 0x10:
if (mc.getGuildId() <= 0 || mc.getGuildRank() > 2) {
System.out.println("[hax] " + mc.getName() + " tried to change guild notice while not in a guild.");
return;
}
String notice = slea.readMapleAsciiString();
if (notice.length() > 100) {
return;
}
Server.getInstance().setGuildNotice(mc.getGuildId(), notice);
break;
default:
System.out.println("Unhandled GUILD_OPERATION packet: \n" + slea.toString());
}
}
}

View File

@@ -0,0 +1,63 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import client.autoban.AutobanFactory;
import client.autoban.AutobanManager;
import net.AbstractMaplePacketHandler;
import tools.data.input.SeekableLittleEndianAccessor;
import tools.MaplePacketCreator;
public final class HealOvertimeHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
AutobanManager abm = chr.getAutobanManager();
int timestamp = slea.readInt();
abm.setTimestamp(0, timestamp, 3);
slea.skip(4);
short healHP = slea.readShort();
if (healHP != 0) {
if ((abm.getLastSpam(0) + 1500) > timestamp) AutobanFactory.FAST_HP_HEALING.addPoint(abm, "Fast hp healing");
int abHeal = 140;
if(chr.getMapId() == 105040401 || chr.getMapId() == 105040402 || chr.getMapId() == 809000101 || chr.getMapId() == 809000201) abHeal += 40; // Sleepywood sauna and showa spa...
if (healHP > abHeal) {
AutobanFactory.HIGH_HP_HEALING.autoban(chr, "Healing: " + healHP + "; Max is " + abHeal + ".");
return;
}
chr.addHP(healHP);
chr.getMap().broadcastMessage(chr, MaplePacketCreator.showHpHealed(chr.getId(), healHP), false);
chr.checkBerserk();
abm.spam(0, timestamp);
}
short healMP = slea.readShort();
if (healMP != 0 && healMP < 1000) {
if ((abm.getLastSpam(1) + 1500) > timestamp) AutobanFactory.FAST_MP_HEALING.addPoint(abm, "Fast mp healing");
chr.addMP(healMP);
abm.spam(1, timestamp);
}
}
}

View File

@@ -0,0 +1,58 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.inventory.ItemFactory;
import client.MapleCharacter;
import java.sql.SQLException;
import java.util.Arrays;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import server.maps.MapleMapObjectType;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author XoticStory
*/
public final class HiredMerchantRequest extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
if (chr.getMap().getMapObjectsInRange(chr.getPosition(), 23000, Arrays.asList(MapleMapObjectType.HIRED_MERCHANT)).isEmpty() && chr.getMapId() > 910000000 && chr.getMapId() < 910000023) {
if (!chr.hasMerchant()) {
try {
if (ItemFactory.MERCHANT.loadItems(chr.getId(), false).isEmpty() && chr.getMerchantMeso() == 0) {
c.announce(MaplePacketCreator.hiredMerchantBox());
} else {
chr.announce(MaplePacketCreator.retrieveFirstMessage());
}
} catch (SQLException ex) {
}
} else {
chr.dropMessage(1, "You already have a store open.");
}
} else {
chr.dropMessage(1, "You cannot open your hired merchant here.");
}
}
}

View File

@@ -0,0 +1,35 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author BubblesDev
*/
public final class InnerPortalHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
}
}

View File

@@ -0,0 +1,90 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import constants.ServerConstants;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleCharacter;
import client.MapleClient;
import client.inventory.Item;
import client.inventory.MapleInventory;
import client.inventory.MapleInventoryType;
import client.inventory.ModifyInventory;
/**
*
* @author BubblesDev
*/
public final class ItemIdSortHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
chr.getAutobanManager().setTimestamp(4, slea.readInt(), 3);
byte inventoryType = slea.readByte();
if(!chr.isGM() || !ServerConstants.USE_ITEM_SORT) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (inventoryType < 1 || inventoryType > 5) {
c.disconnect(false, false);
return;
}
MapleInventory inventory = chr.getInventory(MapleInventoryType.getByType(inventoryType));
ArrayList<Item> itemarray = new ArrayList<>();
List<ModifyInventory> mods = new ArrayList<>();
for (short i = 1; i <= inventory.getSlotLimit(); i++) {
Item item = inventory.getItem(i);
if (item != null) {
itemarray.add((Item) item.copy());
}
}
Collections.sort(itemarray);
for (Item item : itemarray) {
inventory.removeItem(item.getPosition());
}
for (Item item : itemarray) {
//short position = item.getPosition();
inventory.addItem(item);
if (inventory.getType().equals(MapleInventoryType.EQUIP)) {
mods.add(new ModifyInventory(3, item));
mods.add(new ModifyInventory(0, item.copy()));//to prevent crashes
//mods.add(new ModifyInventory(2, item.copy(), position));
}
}
itemarray.clear();
c.announce(MaplePacketCreator.modifyInventory(true, mods));
c.announce(MaplePacketCreator.finishedSort2(inventoryType));
c.announce(MaplePacketCreator.enableActions());
}
}

View File

@@ -0,0 +1,57 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import client.inventory.MapleInventoryType;
import net.AbstractMaplePacketHandler;
import server.MapleInventoryManipulator;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author Matze
*/
public final class ItemMoveHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
slea.skip(4);
if(c.getPlayer().getAutobanManager().getLastSpam(6) + 300 > System.currentTimeMillis()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
MapleInventoryType type = MapleInventoryType.getByType(slea.readByte());
byte src = (byte) slea.readShort();
byte action = (byte) slea.readShort();
short quantity = slea.readShort();
if (src < 0 && action > 0) {
MapleInventoryManipulator.unequip(c, src, action);
} else if (action < 0) {
MapleInventoryManipulator.equip(c, src, action);
} else if (action == 0) {
MapleInventoryManipulator.drop(c, type, src, quantity);
} else {
MapleInventoryManipulator.move(c, type, src, action);
}
c.getPlayer().getAutobanManager().spam(6);
}
}

View File

@@ -0,0 +1,177 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import net.AbstractMaplePacketHandler;
import net.server.world.MaplePartyCharacter;
import scripting.item.ItemScriptManager;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import server.MapleItemInformationProvider.scriptedItem;
import server.maps.MapleMapItem;
import server.maps.MapleMapObject;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleCharacter;
import client.MapleClient;
/**
*
* @author Matze
*/
public final class ItemPickupHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(final SeekableLittleEndianAccessor slea, final MapleClient c) {
slea.readInt(); //Timestamp
slea.readByte();
slea.readPos(); //cpos
int oid = slea.readInt();
MapleCharacter chr = c.getPlayer();
MapleMapObject ob = chr.getMap().getMapObject(oid);
if (ob == null) {
return;
}
if (ob instanceof MapleMapItem) {
MapleMapItem mapitem = (MapleMapItem) ob;
if(System.currentTimeMillis() - mapitem.getDropTime() < 900) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (mapitem.getItemId() == 4031865 || mapitem.getItemId() == 4031866 || mapitem.getMeso() > 0 || MapleItemInformationProvider.getInstance().isConsumeOnPickup(mapitem.getItemId()) || MapleInventoryManipulator.checkSpace(c, mapitem.getItemId(), mapitem.getItem().getQuantity(), mapitem.getItem().getOwner())) {
if ((chr.getMapId() > 209000000 && chr.getMapId() < 209000016) || (chr.getMapId() >= 990000500 && chr.getMapId() <= 990000502)) {//happyville trees and guild PQ
if (!mapitem.isPlayerDrop() || mapitem.getDropper().getObjectId() == c.getPlayer().getObjectId()) {
if(mapitem.getMeso() > 0) {
chr.gainMeso(mapitem.getMeso(), true, true, false);
chr.getMap().broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 2, chr.getId()), mapitem.getPosition());
chr.getMap().removeMapObject(ob);
mapitem.setPickedUp(true);
} else if (MapleInventoryManipulator.addFromDrop(c, mapitem.getItem(), false)) {
chr.getMap().broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 2, chr.getId()), mapitem.getPosition());
chr.getMap().removeMapObject(ob);
mapitem.setPickedUp(true);
} else {
c.announce(MaplePacketCreator.enableActions());
return;
}
} else {
c.announce(MaplePacketCreator.getInventoryFull());
c.announce(MaplePacketCreator.getShowInventoryFull());
return;
}
c.announce(MaplePacketCreator.enableActions());
return;
}
synchronized (mapitem) {
if (mapitem.getQuest() > 0 && !chr.needQuestItem(mapitem.getQuest(), mapitem.getItemId())) {
c.announce(MaplePacketCreator.showItemUnavailable());
c.announce(MaplePacketCreator.enableActions());
return;
}
if (mapitem.isPickedUp()) {
c.announce(MaplePacketCreator.getInventoryFull());
c.announce(MaplePacketCreator.getShowInventoryFull());
return;
}
if (mapitem.getMeso() > 0) {
if (chr.getParty() != null) {
int mesosamm = mapitem.getMeso();
if (mesosamm > 50000 * chr.getMesoRate()) {
return;
}
int partynum = 0;
for (MaplePartyCharacter partymem : chr.getParty().getMembers()) {
if (partymem.isOnline() && partymem.getMapId() == chr.getMap().getId() && partymem.getChannel() == c.getChannel()) {
partynum++;
}
}
for (MaplePartyCharacter partymem : chr.getParty().getMembers()) {
if (partymem.isOnline() && partymem.getMapId() == chr.getMap().getId()) {
MapleCharacter somecharacter = c.getChannelServer().getPlayerStorage().getCharacterById(partymem.getId());
if (somecharacter != null) {
somecharacter.gainMeso(mesosamm / partynum, true, true, false);
}
}
}
} else {
chr.gainMeso(mapitem.getMeso(), true, true, false);
}
} else if (mapitem.getItem().getItemId() / 10000 == 243) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
scriptedItem info = ii.getScriptedItemInfo(mapitem.getItem().getItemId());
if (info.runOnPickup()) {
ItemScriptManager ism = ItemScriptManager.getInstance();
String scriptName = info.getScript();
if (ism.scriptExists(scriptName)) {
ism.getItemScript(c, scriptName);
}
} else {
if (!MapleInventoryManipulator.addFromDrop(c, mapitem.getItem(), true)) {
c.announce(MaplePacketCreator.enableActions());
return;
}
}
} else if(mapitem.getItemId() == 4031865 || mapitem.getItemId() == 4031866) {
// Add NX to account, show effect and make item disapear
chr.getCashShop().gainCash(1, mapitem.getItemId() == 4031865 ? 100 : 250);
} else if (useItem(c, mapitem.getItem().getItemId())) {
if (mapitem.getItem().getItemId() / 10000 == 238) {
chr.getMonsterBook().addCard(c, mapitem.getItem().getItemId());
}
} else if (MapleInventoryManipulator.addFromDrop(c, mapitem.getItem(), true)) {
} else if (mapitem.getItem().getItemId() == 4031868) {
chr.getMap().broadcastMessage(MaplePacketCreator.updateAriantPQRanking(chr.getName(), chr.getItemQuantity(4031868, false), false));
} else {
c.announce(MaplePacketCreator.enableActions());
return;
}
mapitem.setPickedUp(true);
chr.getMap().broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 2, chr.getId()), mapitem.getPosition());
chr.getMap().removeMapObject(ob);
}
}
}
c.announce(MaplePacketCreator.enableActions());
}
static boolean useItem(final MapleClient c, final int id) {
if (id / 1000000 == 2) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
if (ii.isConsumeOnPickup(id)) {
if (id > 2022430 && id < 2022434) {
for (MapleCharacter mc : c.getPlayer().getMap().getCharacters()) {
if (mc.getParty() == c.getPlayer().getParty()) {
ii.getItemEffect(id).applyTo(mc);
}
}
} else {
ii.getItemEffect(id).applyTo(c.getPlayer());
}
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,77 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import client.inventory.Item;
import client.inventory.MapleInventoryType;
import constants.ItemConstants;
import java.util.List;
import net.AbstractMaplePacketHandler;
import net.server.Server;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import server.MapleItemInformationProvider.RewardItem;
import tools.MaplePacketCreator;
import tools.Pair;
import tools.Randomizer;
import tools.data.input.SeekableLittleEndianAccessor;
/**
* @author Jay Estrella/ Modified by kevintjuh93
*/
public final class ItemRewardHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
byte slot = (byte) slea.readShort();
int itemId = slea.readInt(); // will load from xml I don't care.
if (c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot).getItemId() != itemId || c.getPlayer().getInventory(MapleInventoryType.USE).countById(itemId) < 1) return;
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
Pair<Integer, List<RewardItem>> rewards = ii.getItemReward(itemId);
for (RewardItem reward : rewards.getRight()) {
if (!MapleInventoryManipulator.checkSpace(c, reward.itemid, reward.quantity, "")) {
c.announce(MaplePacketCreator.getShowInventoryFull());
break;
}
if (Randomizer.nextInt(rewards.getLeft()) < reward.prob) {//Is it even possible to get an item with prob 1?
if (ItemConstants.getInventoryType(reward.itemid) == MapleInventoryType.EQUIP) {
final Item item = ii.getEquipById(reward.itemid);
if (reward.period != -1) {
item.setExpiration(System.currentTimeMillis() + (reward.period * 60 * 60 * 10));
}
MapleInventoryManipulator.addFromDrop(c, item, false);
} else {
MapleInventoryManipulator.addById(c, reward.itemid, reward.quantity);
}
MapleInventoryManipulator.removeById(c, MapleInventoryType.USE, itemId, 1, false, false);
if (reward.worldmsg != null) {
String msg = reward.worldmsg;
msg.replaceAll("/name", c.getPlayer().getName());
msg.replaceAll("/item", ii.getName(reward.itemid));
Server.getInstance().broadcastMessage(MaplePacketCreator.serverNotice(6, msg));
}
break;
}
}
c.announce(MaplePacketCreator.enableActions());
}
}

View File

@@ -0,0 +1,75 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import constants.ServerConstants;
import net.AbstractMaplePacketHandler;
import server.MapleInventoryManipulator;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleCharacter;
import client.MapleClient;
import client.inventory.MapleInventory;
import client.inventory.MapleInventoryType;
public final class ItemSortHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
chr.getAutobanManager().setTimestamp(2, slea.readInt(), 3);
MapleInventoryType inventoryType = MapleInventoryType.getByType(slea.readByte());
if (inventoryType.equals(MapleInventoryType.UNDEFINED) || c.getPlayer().getInventory(inventoryType).isFull()) {
c.getSession().write(MaplePacketCreator.enableActions());
return;
}
if(ServerConstants.USE_ITEM_SORT == false) {
c.announce(MaplePacketCreator.enableActions());
return;
}
MapleInventory inventory = c.getPlayer().getInventory(inventoryType);
boolean sorted = false;
while (!sorted) {
short freeSlot = inventory.getNextFreeSlot();
if (freeSlot != -1) {
short itemSlot = -1;
for (short i = (short) (freeSlot + 1); i <= inventory.getSlotLimit(); i = (short) (i + 1)) {
if (inventory.getItem(i) != null) {
itemSlot = i;
break;
}
}
if (itemSlot > 0) {
MapleInventoryManipulator.move(c, inventoryType, itemSlot, freeSlot);
} else {
sorted = true;
}
} else {
sorted = true;
}
}
c.getSession().write(MaplePacketCreator.finishedSort(inventoryType.getType()));
c.getSession().write(MaplePacketCreator.enableActions());
}
}

View File

@@ -0,0 +1,79 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import constants.GameConstants;
import client.MapleClient;
import client.MapleKeyBinding;
import client.Skill;
import client.SkillFactory;
import client.autoban.AutobanFactory;
import client.inventory.MapleInventoryType;
import net.AbstractMaplePacketHandler;
import tools.FilePrinter;
import tools.data.input.SeekableLittleEndianAccessor;
public final class KeymapChangeHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (slea.available() >= 8) {
int mode = slea.readInt();
if(mode == 0) {
int numChanges = slea.readInt();
for (int i = 0; i < numChanges; i++) {
int key = slea.readInt();
int type = slea.readByte();
int action = slea.readInt();
Skill skill = SkillFactory.getSkill(action);
boolean isBanndedSkill = false;
if (skill != null) {
isBanndedSkill = GameConstants.bannedBindSkills(skill.getId());
if (isBanndedSkill || (!c.getPlayer().isGM() && GameConstants.isGMSkills(skill.getId())) || (!GameConstants.isInJobTree(skill.getId(), c.getPlayer().getJob().getId()) && !c.getPlayer().isGM())) { //for those skills are are "technically" in the beginner tab, like bamboo rain in Dojo or skills you find in PYPQ
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit keymapping.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to use skill " + skill.getId() + "\r\n");
c.disconnect(true, false);
return;
}
if (c.getPlayer().getSkillLevel(skill) < 1) {
continue;
}
}
c.getPlayer().changeKeybinding(key, new MapleKeyBinding(type, action));
}
} else if(mode == 1) { // Auto HP Potion
int itemID = slea.readInt();
if(itemID != 0 && c.getPlayer().getInventory(MapleInventoryType.USE).findById(itemID) == null) {
c.disconnect(false, false); // Don't let them send a packet with a use item they dont have.
return;
}
c.getPlayer().changeKeybinding(91, new MapleKeyBinding(7, itemID));
} else if(mode == 2) { // Auto MP Potion
int itemID = slea.readInt();
if(itemID != 0 && c.getPlayer().getInventory(MapleInventoryType.USE).findById(itemID) == null) {
c.disconnect(false, false); // Don't let them send a packet with a use item they dont have.
return;
}
c.getPlayer().changeKeybinding(92, new MapleKeyBinding(7, itemID));
}
}
}
}

View File

@@ -0,0 +1,39 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author kevintjuh93
*/
public class LeftKnockbackHandler extends AbstractMaplePacketHandler {
public void handlePacket(SeekableLittleEndianAccessor slea, final MapleClient c) {
c.announce(MaplePacketCreator.leftKnockBack());
c.announce(MaplePacketCreator.enableActions());
}
}

View File

@@ -0,0 +1,834 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import net.AbstractMaplePacketHandler;
import net.server.Server;
import net.server.channel.Channel;
import server.MTSItemInfo;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import tools.DatabaseConnection;
import tools.MaplePacketCreator;
import tools.Pair;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleCharacter;
import client.MapleClient;
import client.inventory.Equip;
import client.inventory.Item;
import client.inventory.MapleInventoryType;
public final class MTSHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!c.getPlayer().getCashShop().isOpened()) {
return;
}
if (slea.available() > 0) {
byte op = slea.readByte();
if (op == 2) { //put item up for sale
byte itemtype = slea.readByte();
int itemid = slea.readInt();
slea.readShort();
slea.skip(7);
short stars = 1;
if (itemtype == 1) {
slea.skip(32);
} else {
stars = slea.readShort();
}
slea.readMapleAsciiString(); //another useless thing (owner)
if (itemtype == 1) {
slea.skip(32);
} else {
slea.readShort();
}
short slot;
short quantity;
if (itemtype != 1) {
if (itemid / 10000 == 207 || itemid / 10000 == 233) {
slea.skip(8);
}
slot = (short) slea.readInt();
} else {
slot = (short) slea.readInt();
}
if (itemtype != 1) {
if (itemid / 10000 == 207 || itemid / 10000 == 233) {
quantity = stars;
slea.skip(4);
} else {
quantity = (short) slea.readInt();
}
} else {
quantity = (byte) slea.readInt();
}
int price = slea.readInt();
if (itemtype == 1) {
quantity = 1;
}
if (quantity < 0 || price < 110 || c.getPlayer().getItemQuantity(itemid, false) < quantity) {
return;
}
MapleInventoryType type = MapleItemInformationProvider.getInstance().getInventoryType(itemid);
Item i = c.getPlayer().getInventory(type).getItem(slot).copy();
if (i != null && c.getPlayer().getMeso() >= 5000) {
Connection con = DatabaseConnection.getConnection();
try {
PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM mts_items WHERE seller = ?");
ps.setInt(1, c.getPlayer().getId());
ResultSet rs = ps.executeQuery();
if (rs.next()) {
if (rs.getInt(1) > 10) { //They have more than 10 items up for sale already!
c.getPlayer().dropMessage(1, "You already have 10 items up for auction!");
c.announce(getMTS(1, 0, 0));
c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
rs.close();
ps.close();
return;
}
}
rs.close();
ps.close();
Calendar calendar = Calendar.getInstance();
int year;
int month;
int day;
int oldmax = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
int oldday = calendar.get(Calendar.DAY_OF_MONTH) + 7;
if (oldmax < oldday) {
if (calendar.get(Calendar.MONTH) + 2 > 12) {
year = calendar.get(Calendar.YEAR) + 1;
month = 1;
calendar.set(year, month, 1);
day = oldday - oldmax;
} else {
month = calendar.get(Calendar.MONTH) + 2;
year = calendar.get(Calendar.YEAR);
calendar.set(year, month, 1);
day = oldday - oldmax;
}
} else {
day = calendar.get(Calendar.DAY_OF_MONTH) + 7;
month = calendar.get(Calendar.MONTH);
year = calendar.get(Calendar.YEAR);
}
String date = year + "-";
if (month < 10) {
date += "0" + month + "-";
} else {
date += month + "-";
}
if (day < 10) {
date += "0" + day;
} else {
date += day + "";
}
if (i.getType() == 2) {
Item item = (Item) i;
ps = con.prepareStatement("INSERT INTO mts_items (tab, type, itemid, quantity, seller, price, owner, sellername, sell_ends) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
ps.setInt(1, 1);
ps.setInt(2, (int) type.getType());
ps.setInt(3, item.getItemId());
ps.setInt(4, quantity);
ps.setInt(5, c.getPlayer().getId());
ps.setInt(6, price);
ps.setString(7, item.getOwner());
ps.setString(8, c.getPlayer().getName());
ps.setString(9, date);
} else {
Equip equip = (Equip) i;
ps = con.prepareStatement("INSERT INTO mts_items (tab, type, itemid, quantity, seller, price, upgradeslots, level, str, dex, `int`, luk, hp, mp, watk, matk, wdef, mdef, acc, avoid, hands, speed, jump, locked, owner, sellername, sell_ends, vicious, flag) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
ps.setInt(1, 1);
ps.setInt(2, (int) type.getType());
ps.setInt(3, equip.getItemId());
ps.setInt(4, quantity);
ps.setInt(5, c.getPlayer().getId());
ps.setInt(6, price);
ps.setInt(7, equip.getUpgradeSlots());
ps.setInt(8, equip.getLevel());
ps.setInt(9, equip.getStr());
ps.setInt(10, equip.getDex());
ps.setInt(11, equip.getInt());
ps.setInt(12, equip.getLuk());
ps.setInt(13, equip.getHp());
ps.setInt(14, equip.getMp());
ps.setInt(15, equip.getWatk());
ps.setInt(16, equip.getMatk());
ps.setInt(17, equip.getWdef());
ps.setInt(18, equip.getMdef());
ps.setInt(19, equip.getAcc());
ps.setInt(20, equip.getAvoid());
ps.setInt(21, equip.getHands());
ps.setInt(22, equip.getSpeed());
ps.setInt(23, equip.getJump());
ps.setInt(24, 0);
ps.setString(25, equip.getOwner());
ps.setString(26, c.getPlayer().getName());
ps.setString(27, date);
ps.setInt(28, equip.getVicious());
ps.setInt(29, equip.getFlag());
}
ps.executeUpdate();
ps.close();
MapleInventoryManipulator.removeFromSlot(c, type, slot, quantity, false);
} catch (SQLException e) {
}
c.getPlayer().gainMeso(-5000, false);
c.announce(MaplePacketCreator.MTSConfirmSell());
c.announce(getMTS(1, 0, 0));
c.announce(MaplePacketCreator.enableCSUse());
c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
}
} else if (op == 3) { //send offer for wanted item
} else if (op == 4) { //list wanted item
slea.readInt();
slea.readInt();
slea.readInt();
slea.readShort();
slea.readMapleAsciiString();
} else if (op == 5) { //change page
int tab = slea.readInt();
int type = slea.readInt();
int page = slea.readInt();
c.getPlayer().changePage(page);
if (tab == 4 && type == 0) {
c.announce(getCart(c.getPlayer().getId()));
} else if (tab == c.getPlayer().getCurrentTab() && type == c.getPlayer().getCurrentType() && c.getPlayer().getSearch() != null) {
c.announce(getMTSSearch(tab, type, c.getPlayer().getCurrentCI(), c.getPlayer().getSearch(), page));
} else {
c.getPlayer().setSearch(null);
c.announce(getMTS(tab, type, page));
}
c.getPlayer().changeTab(tab);
c.getPlayer().changeType(type);
c.announce(MaplePacketCreator.enableCSUse());
c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
} else if (op == 6) { //search
int tab = slea.readInt();
int type = slea.readInt();
slea.readInt();
int ci = slea.readInt();
String search = slea.readMapleAsciiString();
c.getPlayer().setSearch(search);
c.getPlayer().changeTab(tab);
c.getPlayer().changeType(type);
c.getPlayer().changeCI(ci);
c.announce(MaplePacketCreator.enableCSUse());
c.announce(MaplePacketCreator.enableActions());
c.announce(getMTSSearch(tab, type, ci, search, c.getPlayer().getCurrentPage()));
c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
} else if (op == 7) { //cancel sale
int id = slea.readInt(); //id of the item
Connection con = DatabaseConnection.getConnection();
try {
PreparedStatement ps = con.prepareStatement("UPDATE mts_items SET transfer = 1 WHERE id = ? AND seller = ?");
ps.setInt(1, id);
ps.setInt(2, c.getPlayer().getId());
ps.executeUpdate();
ps.close();
ps = con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ?");
ps.setInt(1, id);
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
c.announce(MaplePacketCreator.enableCSUse());
c.announce(getMTS(c.getPlayer().getCurrentTab(), c.getPlayer().getCurrentType(), c.getPlayer().getCurrentPage()));
c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
} else if (op == 8) { //transfer item from transfer inv.
int id = slea.readInt(); //id of the item
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps;
ResultSet rs;
try {
ps = con.prepareStatement("SELECT * FROM mts_items WHERE seller = ? AND transfer = 1 AND id= ? ORDER BY id DESC");
ps.setInt(1, c.getPlayer().getId());
ps.setInt(2, id);
rs = ps.executeQuery();
if (rs.next()) {
Item i;
if (rs.getInt("type") != 1) {
Item ii = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
ii.setOwner(rs.getString("owner"));
ii.setPosition(c.getPlayer().getInventory(MapleItemInformationProvider.getInstance().getInventoryType(rs.getInt("itemid"))).getNextFreeSlot());
i = ii.copy();
} else {
Equip equip = new Equip(rs.getInt("itemid"), (byte) rs.getInt("position"), -1);
equip.setOwner(rs.getString("owner"));
equip.setQuantity((short) 1);
equip.setAcc((short) rs.getInt("acc"));
equip.setAvoid((short) rs.getInt("avoid"));
equip.setDex((short) rs.getInt("dex"));
equip.setHands((short) rs.getInt("hands"));
equip.setHp((short) rs.getInt("hp"));
equip.setInt((short) rs.getInt("int"));
equip.setJump((short) rs.getInt("jump"));
equip.setLuk((short) rs.getInt("luk"));
equip.setMatk((short) rs.getInt("matk"));
equip.setMdef((short) rs.getInt("mdef"));
equip.setMp((short) rs.getInt("mp"));
equip.setSpeed((short) rs.getInt("speed"));
equip.setStr((short) rs.getInt("str"));
equip.setWatk((short) rs.getInt("watk"));
equip.setWdef((short) rs.getInt("wdef"));
equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
equip.setLevel((byte) rs.getInt("level"));
equip.setVicious((byte) rs.getInt("vicious"));
equip.setFlag((byte) rs.getInt("flag"));
equip.setPosition(c.getPlayer().getInventory(MapleItemInformationProvider.getInstance().getInventoryType(rs.getInt("itemid"))).getNextFreeSlot());
i = equip.copy();
}
try (PreparedStatement pse = con.prepareStatement("DELETE FROM mts_items WHERE id = ? AND seller = ? AND transfer = 1")) {
pse.setInt(1, id);
pse.setInt(2, c.getPlayer().getId());
pse.executeUpdate();
}
MapleInventoryManipulator.addFromDrop(c, i, false);
c.announce(MaplePacketCreator.enableCSUse());
c.announce(getCart(c.getPlayer().getId()));
c.announce(getMTS(c.getPlayer().getCurrentTab(), c.getPlayer().getCurrentType(), c.getPlayer().getCurrentPage()));
c.announce(MaplePacketCreator.MTSConfirmTransfer(i.getQuantity(), i.getPosition()));
c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
}
rs.close();
ps.close();
} catch (SQLException e) {
System.out.println("MTS Transfer error: " + e);
}
} else if (op == 9) { //add to cart
int id = slea.readInt(); //id of the item
Connection con = DatabaseConnection.getConnection();
try {
try (PreparedStatement ps1 = con.prepareStatement("SELECT * FROM mts_items WHERE id = ? AND seller <> ?")) {
ps1.setInt(1, id);//Previene que agregues al cart tus propios items
ps1.setInt(2, c.getPlayer().getId());
try (ResultSet rs1 = ps1.executeQuery()) {
if (rs1.next()) {
PreparedStatement ps = con.prepareStatement("SELECT * FROM mts_cart WHERE cid = ? AND itemid = ?");
ps.setInt(1, c.getPlayer().getId());
ps.setInt(2, id);
try (ResultSet rs = ps.executeQuery()) {
if (!rs.next()) {
try (PreparedStatement pse = con.prepareStatement("INSERT INTO mts_cart (cid, itemid) VALUES (?, ?)")) {
pse.setInt(1, c.getPlayer().getId());
pse.setInt(2, id);
pse.executeUpdate();
}
}
}
}
}
}
} catch (SQLException e) {
e.printStackTrace();
}
c.announce(getMTS(c.getPlayer().getCurrentTab(), c.getPlayer().getCurrentType(), c.getPlayer().getCurrentPage()));
c.announce(MaplePacketCreator.enableCSUse());
c.announce(MaplePacketCreator.enableActions());
c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
} else if (op == 10) { //delete from cart
int id = slea.readInt(); //id of the item
Connection con = DatabaseConnection.getConnection();
try {
try (PreparedStatement ps = con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ? AND cid = ?")) {
ps.setInt(1, id);
ps.setInt(2, c.getPlayer().getId());
ps.executeUpdate();
}
} catch (SQLException e) {
e.printStackTrace();
}
c.announce(getCart(c.getPlayer().getId()));
c.announce(MaplePacketCreator.enableCSUse());
c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
} else if (op == 12) { //put item up for auction
} else if (op == 13) { //cancel wanted cart thing
} else if (op == 14) { //buy auction item now
} else if (op == 16) { //buy
int id = slea.readInt(); //id of the item
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps;
ResultSet rs;
try {
ps = con.prepareStatement("SELECT * FROM mts_items WHERE id = ? ORDER BY id DESC");
ps.setInt(1, id);
rs = ps.executeQuery();
if (rs.next()) {
int price = rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1); //taxes
if (c.getPlayer().getCashShop().getCash(4) >= price) { //FIX
boolean alwaysnull = true;
for (Channel cserv : Server.getInstance().getAllChannels()) {
MapleCharacter victim = cserv.getPlayerStorage().getCharacterById(rs.getInt("seller"));
if (victim != null) {
victim.getCashShop().gainCash(4, rs.getInt("price"));
alwaysnull = false;
}
}
if (alwaysnull) {
ResultSet rse;
try (PreparedStatement pse = con.prepareStatement("SELECT accountid FROM characters WHERE id = ?")) {
pse.setInt(1, rs.getInt("seller"));
rse = pse.executeQuery();
if (rse.next()) {
try (PreparedStatement psee = con.prepareStatement("UPDATE accounts SET nxPrepaid = nxPrepaid + ? WHERE id = ?")) {
psee.setInt(1, rs.getInt("price"));
psee.setInt(2, rse.getInt("accountid"));
psee.executeUpdate();
}
}
}
rse.close();
}
PreparedStatement pse = con.prepareStatement("UPDATE mts_items SET seller = ?, transfer = 1 WHERE id = ?");
pse.setInt(1, c.getPlayer().getId());
pse.setInt(2, id);
pse.executeUpdate();
pse.close();
pse = con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ?");
pse.setInt(1, id);
pse.executeUpdate();
pse.close();
c.getPlayer().getCashShop().gainCash(4, -price);
c.announce(MaplePacketCreator.enableCSUse());
c.announce(getMTS(c.getPlayer().getCurrentTab(), c.getPlayer().getCurrentType(), c.getPlayer().getCurrentPage()));
c.announce(MaplePacketCreator.MTSConfirmBuy());
c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
c.announce(MaplePacketCreator.enableActions());
} else {
c.announce(MaplePacketCreator.MTSFailBuy());
}
}
rs.close();
ps.close();
} catch (SQLException e) {
c.announce(MaplePacketCreator.MTSFailBuy());
}
} else if (op == 17) { //buy from cart
int id = slea.readInt(); //id of the item
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps;
ResultSet rs;
try {
ps = con.prepareStatement("SELECT * FROM mts_items WHERE id = ? ORDER BY id DESC");
ps.setInt(1, id);
rs = ps.executeQuery();
if (rs.next()) {
int price = rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1);
if (c.getPlayer().getCashShop().getCash(4) >= price) {
for (Channel cserv : Server.getInstance().getAllChannels()) {
MapleCharacter victim = cserv.getPlayerStorage().getCharacterById(rs.getInt("seller"));
if (victim != null) {
victim.getCashShop().gainCash(4, rs.getInt("price"));
} else {
ResultSet rse;
try (PreparedStatement pse = con.prepareStatement("SELECT accountid FROM characters WHERE id = ?")) {
pse.setInt(1, rs.getInt("seller"));
rse = pse.executeQuery();
if (rse.next()) {
try (PreparedStatement psee = con.prepareStatement("UPDATE accounts SET nxPrepaid = nxPrepaid + ? WHERE id = ?")) {
psee.setInt(1, rs.getInt("price"));
psee.setInt(2, rse.getInt("accountid"));
psee.executeUpdate();
}
}
}
rse.close();
}
}
PreparedStatement pse = con.prepareStatement("UPDATE mts_items SET seller = ?, transfer = 1 WHERE id = ?");
pse.setInt(1, c.getPlayer().getId());
pse.setInt(2, id);
pse.executeUpdate();
pse.close();
pse = con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ?");
pse.setInt(1, id);
pse.executeUpdate();
pse.close();
c.getPlayer().getCashShop().gainCash(4, -price);
c.announce(getCart(c.getPlayer().getId()));
c.announce(MaplePacketCreator.enableCSUse());
c.announce(MaplePacketCreator.MTSConfirmBuy());
c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
} else {
c.announce(MaplePacketCreator.MTSFailBuy());
}
}
rs.close();
ps.close();
} catch (SQLException e) {
c.announce(MaplePacketCreator.MTSFailBuy());
}
} else {
System.out.println("Unhandled OP(MTS): " + op + " Packet: " + slea.toString());
}
} else {
c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
}
}
public List<MTSItemInfo> getNotYetSold(int cid) {
List<MTSItemInfo> items = new ArrayList<>();
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps;
ResultSet rs;
try {
ps = con.prepareStatement("SELECT * FROM mts_items WHERE seller = ? AND transfer = 0 ORDER BY id DESC");
ps.setInt(1, cid);
rs = ps.executeQuery();
while (rs.next()) {
if (rs.getInt("type") != 1) {
Item i = new Item(rs.getInt("itemid"), (byte) 0, (short) rs.getInt("quantity"));
i.setOwner(rs.getString("owner"));
items.add(new MTSItemInfo((Item) i, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
} else {
Equip equip = new Equip(rs.getInt("itemid"), (byte) rs.getInt("position"), -1);
equip.setOwner(rs.getString("owner"));
equip.setQuantity((short) 1);
equip.setAcc((short) rs.getInt("acc"));
equip.setAvoid((short) rs.getInt("avoid"));
equip.setDex((short) rs.getInt("dex"));
equip.setHands((short) rs.getInt("hands"));
equip.setHp((short) rs.getInt("hp"));
equip.setInt((short) rs.getInt("int"));
equip.setJump((short) rs.getInt("jump"));
equip.setVicious((short) rs.getInt("vicious"));
equip.setLuk((short) rs.getInt("luk"));
equip.setMatk((short) rs.getInt("matk"));
equip.setMdef((short) rs.getInt("mdef"));
equip.setMp((short) rs.getInt("mp"));
equip.setSpeed((short) rs.getInt("speed"));
equip.setStr((short) rs.getInt("str"));
equip.setWatk((short) rs.getInt("watk"));
equip.setWdef((short) rs.getInt("wdef"));
equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
equip.setLevel((byte) rs.getInt("level"));
equip.setFlag((byte) rs.getInt("flag"));
items.add(new MTSItemInfo((Item) equip, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
}
}
rs.close();
ps.close();
} catch (SQLException e) {
}
return items;
}
public byte[] getCart(int cid) {
List<MTSItemInfo> items = new ArrayList<>();
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps;
ResultSet rs;
int pages = 0;
try {
ps = con.prepareStatement("SELECT * FROM mts_cart WHERE cid = ? ORDER BY id DESC");
ps.setInt(1, cid);
rs = ps.executeQuery();
while (rs.next()) {
try (PreparedStatement pse = con.prepareStatement("SELECT * FROM mts_items WHERE id = ?")) {
pse.setInt(1, rs.getInt("itemid"));
ResultSet rse = pse.executeQuery();
if (rse.next()) {
if (rse.getInt("type") != 1) {
Item i = new Item(rse.getInt("itemid"), (short) 0, (short) rse.getInt("quantity"));
i.setOwner(rse.getString("owner"));
items.add(new MTSItemInfo((Item) i, rse.getInt("price"), rse.getInt("id"), rse.getInt("seller"), rse.getString("sellername"), rse.getString("sell_ends")));
} else {
Equip equip = new Equip(rse.getInt("itemid"), (byte) rse.getInt("position"), -1);
equip.setOwner(rse.getString("owner"));
equip.setQuantity((short) 1);
equip.setAcc((short) rse.getInt("acc"));
equip.setAvoid((short) rse.getInt("avoid"));
equip.setDex((short) rse.getInt("dex"));
equip.setHands((short) rse.getInt("hands"));
equip.setHp((short) rse.getInt("hp"));
equip.setInt((short) rse.getInt("int"));
equip.setJump((short) rse.getInt("jump"));
equip.setVicious((short) rse.getInt("vicious"));
equip.setLuk((short) rse.getInt("luk"));
equip.setMatk((short) rse.getInt("matk"));
equip.setMdef((short) rse.getInt("mdef"));
equip.setMp((short) rse.getInt("mp"));
equip.setSpeed((short) rse.getInt("speed"));
equip.setStr((short) rse.getInt("str"));
equip.setWatk((short) rse.getInt("watk"));
equip.setWdef((short) rse.getInt("wdef"));
equip.setUpgradeSlots((byte) rse.getInt("upgradeslots"));
equip.setLevel((byte) rse.getInt("level"));
equip.setFlag((byte) rs.getInt("flag"));
items.add(new MTSItemInfo((Item) equip, rse.getInt("price"), rse.getInt("id"), rse.getInt("seller"), rse.getString("sellername"), rse.getString("sell_ends")));
}
}
}
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT COUNT(*) FROM mts_cart WHERE cid = ?");
ps.setInt(1, cid);
rs = ps.executeQuery();
if (rs.next()) {
pages = rs.getInt(1) / 16;
if (rs.getInt(1) % 16 > 0) {
pages += 1;
}
}
rs.close();
ps.close();
} catch (SQLException e) {
}
return MaplePacketCreator.sendMTS(items, 4, 0, 0, pages);
}
public List<MTSItemInfo> getTransfer(int cid) {
List<MTSItemInfo> items = new ArrayList<>();
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps;
ResultSet rs;
try {
ps = con.prepareStatement("SELECT * FROM mts_items WHERE transfer = 1 AND seller = ? ORDER BY id DESC");
ps.setInt(1, cid);
rs = ps.executeQuery();
while (rs.next()) {
if (rs.getInt("type") != 1) {
Item i = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
i.setOwner(rs.getString("owner"));
items.add(new MTSItemInfo((Item) i, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
} else {
Equip equip = new Equip(rs.getInt("itemid"), (byte) rs.getInt("position"), -1);
equip.setOwner(rs.getString("owner"));
equip.setQuantity((short) 1);
equip.setAcc((short) rs.getInt("acc"));
equip.setAvoid((short) rs.getInt("avoid"));
equip.setDex((short) rs.getInt("dex"));
equip.setHands((short) rs.getInt("hands"));
equip.setHp((short) rs.getInt("hp"));
equip.setInt((short) rs.getInt("int"));
equip.setJump((short) rs.getInt("jump"));
equip.setVicious((short) rs.getInt("vicious"));
equip.setLuk((short) rs.getInt("luk"));
equip.setMatk((short) rs.getInt("matk"));
equip.setMdef((short) rs.getInt("mdef"));
equip.setMp((short) rs.getInt("mp"));
equip.setSpeed((short) rs.getInt("speed"));
equip.setStr((short) rs.getInt("str"));
equip.setWatk((short) rs.getInt("watk"));
equip.setWdef((short) rs.getInt("wdef"));
equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
equip.setLevel((byte) rs.getInt("level"));
equip.setFlag((byte) rs.getInt("flag"));
items.add(new MTSItemInfo((Item) equip, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
}
}
rs.close();
ps.close();
} catch (SQLException e) {
}
return items;
}
private static byte[] getMTS(int tab, int type, int page) {
List<MTSItemInfo> items = new ArrayList<>();
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps;
ResultSet rs;
int pages = 0;
try {
if (type != 0) {
ps = con.prepareStatement("SELECT * FROM mts_items WHERE tab = ? AND type = ? AND transfer = 0 ORDER BY id DESC LIMIT ?, 16");
} else {
ps = con.prepareStatement("SELECT * FROM mts_items WHERE tab = ? AND transfer = 0 ORDER BY id DESC LIMIT ?, 16");
}
ps.setInt(1, tab);
if (type != 0) {
ps.setInt(2, type);
ps.setInt(3, page * 16);
} else {
ps.setInt(2, page * 16);
}
rs = ps.executeQuery();
while (rs.next()) {
if (rs.getInt("type") != 1) {
Item i = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
i.setOwner(rs.getString("owner"));
items.add(new MTSItemInfo((Item) i, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
} else {
Equip equip = new Equip(rs.getInt("itemid"), (byte) rs.getInt("position"), -1);
equip.setOwner(rs.getString("owner"));
equip.setQuantity((short) 1);
equip.setAcc((short) rs.getInt("acc"));
equip.setAvoid((short) rs.getInt("avoid"));
equip.setDex((short) rs.getInt("dex"));
equip.setHands((short) rs.getInt("hands"));
equip.setHp((short) rs.getInt("hp"));
equip.setInt((short) rs.getInt("int"));
equip.setJump((short) rs.getInt("jump"));
equip.setVicious((short) rs.getInt("vicious"));
equip.setLuk((short) rs.getInt("luk"));
equip.setMatk((short) rs.getInt("matk"));
equip.setMdef((short) rs.getInt("mdef"));
equip.setMp((short) rs.getInt("mp"));
equip.setSpeed((short) rs.getInt("speed"));
equip.setStr((short) rs.getInt("str"));
equip.setWatk((short) rs.getInt("watk"));
equip.setWdef((short) rs.getInt("wdef"));
equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
equip.setLevel((byte) rs.getInt("level"));
equip.setFlag((byte) rs.getInt("flag"));
items.add(new MTSItemInfo((Item) equip, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
}
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT COUNT(*) FROM mts_items WHERE tab = ? " + (type != 0 ? "AND type = ?" : "") + "AND transfer = 0");
ps.setInt(1, tab);
if (type != 0) {
ps.setInt(2, type);
}
rs = ps.executeQuery();
if (rs.next()) {
pages = rs.getInt(1) / 16;
if (rs.getInt(1) % 16 > 0) {
pages++;
}
}
rs.close();
ps.close();
} catch (SQLException e) {
}
return MaplePacketCreator.sendMTS(items, tab, type, page, pages); // resniff
}
public byte[] getMTSSearch(int tab, int type, int cOi, String search, int page) {
List<MTSItemInfo> items = new ArrayList<>();
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
String listaitems = "";
if (cOi != 0) {
List<String> retItems = new ArrayList<>();
for (Pair<Integer, String> itemPair : ii.getAllItems()) {
if (itemPair.getRight().toLowerCase().contains(search.toLowerCase())) {
retItems.add(" itemid=" + itemPair.getLeft() + " OR ");
}
}
listaitems += " AND (";
if (retItems != null && retItems.size() > 0) {
for (String singleRetItem : retItems) {
listaitems += singleRetItem;
}
listaitems += " itemid=0 )";
}
} else {
listaitems = " AND sellername LIKE CONCAT('%','" + search + "', '%')";
}
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps;
ResultSet rs;
int pages = 0;
try {
if (type != 0) {
ps = con.prepareStatement("SELECT * FROM mts_items WHERE tab = ? " + listaitems + " AND type = ? AND transfer = 0 ORDER BY id DESC LIMIT ?, 16");
} else {
ps = con.prepareStatement("SELECT * FROM mts_items WHERE tab = ? " + listaitems + " AND transfer = 0 ORDER BY id DESC LIMIT ?, 16");
}
ps.setInt(1, tab);
if (type != 0) {
ps.setInt(2, type);
ps.setInt(3, page * 16);
} else {
ps.setInt(2, page * 16);
}
rs = ps.executeQuery();
while (rs.next()) {
if (rs.getInt("type") != 1) {
Item i = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
i.setOwner(rs.getString("owner"));
items.add(new MTSItemInfo((Item) i, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
} else {
Equip equip = new Equip(rs.getInt("itemid"), (byte) rs.getInt("position"), -1);
equip.setOwner(rs.getString("owner"));
equip.setQuantity((short) 1);
equip.setAcc((short) rs.getInt("acc"));
equip.setAvoid((short) rs.getInt("avoid"));
equip.setDex((short) rs.getInt("dex"));
equip.setHands((short) rs.getInt("hands"));
equip.setHp((short) rs.getInt("hp"));
equip.setInt((short) rs.getInt("int"));
equip.setJump((short) rs.getInt("jump"));
equip.setVicious((short) rs.getInt("vicious"));
equip.setLuk((short) rs.getInt("luk"));
equip.setMatk((short) rs.getInt("matk"));
equip.setMdef((short) rs.getInt("mdef"));
equip.setMp((short) rs.getInt("mp"));
equip.setSpeed((short) rs.getInt("speed"));
equip.setStr((short) rs.getInt("str"));
equip.setWatk((short) rs.getInt("watk"));
equip.setWdef((short) rs.getInt("wdef"));
equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
equip.setLevel((byte) rs.getInt("level"));
equip.setFlag((byte) rs.getInt("flag"));
items.add(new MTSItemInfo((Item) equip, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
}
}
rs.close();
ps.close();
if (type == 0) {
ps = con.prepareStatement("SELECT COUNT(*) FROM mts_items WHERE tab = ? " + listaitems + " AND transfer = 0");
ps.setInt(1, tab);
if (type != 0) {
ps.setInt(2, type);
}
rs = ps.executeQuery();
if (rs.next()) {
pages = rs.getInt(1) / 16;
if (rs.getInt(1) % 16 > 0) {
pages++;
}
}
rs.close();
ps.close();
}
} catch (SQLException e) {
}
return MaplePacketCreator.sendMTS(items, tab, type, page, pages);
}
}

View File

@@ -0,0 +1,86 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import server.MapleStatEffect;
import server.TimerManager;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleBuffStat;
import client.MapleCharacter;
import client.MapleCharacter.CancelCooldownAction;
import client.MapleClient;
import client.Skill;
import client.SkillFactory;
import constants.skills.Bishop;
import constants.skills.Evan;
import constants.skills.FPArchMage;
import constants.skills.ILArchMage;
public final class MagicDamageHandler extends AbstractDealDamageHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter player = c.getPlayer();
player.setPetLootCd(System.currentTimeMillis());
/*long timeElapsed = System.currentTimeMillis() - player.getAutobanManager().getLastSpam(8);
if(timeElapsed < 300) {
AutobanFactory.FAST_ATTACK.alert(player, "Time: " + timeElapsed);
}
player.getAutobanManager().spam(8);*/
AttackInfo attack = parseDamage(slea, player, false, true);
if (player.getBuffEffect(MapleBuffStat.MORPH) != null) {
if(player.getBuffEffect(MapleBuffStat.MORPH).isMorphWithoutAttack()) {
// How are they attacking when the client won't let them?
player.getClient().disconnect(false, false);
return;
}
}
byte[] packet = MaplePacketCreator.magicAttack(player, attack.skill, attack.skilllevel, attack.stance, attack.numAttackedAndDamage, attack.allDamage, -1, attack.speed, attack.direction, attack.display);
if (attack.skill == Evan.FIRE_BREATH || attack.skill == Evan.ICE_BREATH || attack.skill == FPArchMage.BIG_BANG || attack.skill == ILArchMage.BIG_BANG || attack.skill == Bishop.BIG_BANG) {
packet = MaplePacketCreator.magicAttack(player, attack.skill, attack.skilllevel, attack.stance, attack.numAttackedAndDamage, attack.allDamage, attack.charge, attack.speed, attack.direction, attack.display);
}
player.getMap().broadcastMessage(player, packet, false, true);
MapleStatEffect effect = attack.getAttackEffect(player, null);
Skill skill = SkillFactory.getSkill(attack.skill);
MapleStatEffect effect_ = skill.getEffect(player.getSkillLevel(skill));
if (effect_.getCooldown() > 0) {
if (player.skillisCooling(attack.skill)) {
return;
} else {
c.announce(MaplePacketCreator.skillCooldown(attack.skill, effect_.getCooldown()));
player.addCooldown(attack.skill, System.currentTimeMillis(), effect_.getCooldown() * 1000, TimerManager.getInstance().schedule(new CancelCooldownAction(player, attack.skill), effect_.getCooldown() * 1000));
}
}
applyAttack(attack, player, effect.getAttackCount());
Skill eaterSkill = SkillFactory.getSkill((player.getJob().getId() - (player.getJob().getId() % 10)) * 10000);// MP Eater, works with right job
int eaterLevel = player.getSkillLevel(eaterSkill);
if (eaterLevel > 0) {
for (Integer singleDamage : attack.allDamage.keySet()) {
eaterSkill.getEffect(eaterLevel).applyPassive(player, player.getMap().getMapObject(singleDamage), 0);
}
}
}
}

View File

@@ -0,0 +1,66 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import server.MakerItemFactory;
import server.MakerItemFactory.MakerItemCreateEntry;
import tools.Pair;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author Jay Estrella
*/
public final class MakerSkillHandler extends AbstractMaplePacketHandler {
private MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
slea.readInt();
int toCreate = slea.readInt();
MakerItemCreateEntry recipe = MakerItemFactory.getItemCreateEntry(toCreate);
if (canCreate(c, recipe) && !c.getPlayer().getInventory(ii.getInventoryType(toCreate)).isFull()) {
for (Pair<Integer, Integer> p : recipe.getReqItems()) {
int toRemove = p.getLeft();
MapleInventoryManipulator.removeById(c, ii.getInventoryType(toRemove), toRemove, p.getRight(), false, false);
}
MapleInventoryManipulator.addById(c, toCreate, (short) recipe.getRewardAmount());
}
}
private boolean canCreate(MapleClient c, MakerItemCreateEntry recipe) {
return hasItems(c, recipe) && c.getPlayer().getMeso() >= recipe.getCost() && c.getPlayer().getLevel() >= recipe.getReqLevel() && c.getPlayer().getSkillLevel(c.getPlayer().getJob().getId() / 1000 * 1000 + 1007) >= recipe.getReqSkillLevel();
}
private boolean hasItems(MapleClient c, MakerItemCreateEntry recipe) {
for (Pair<Integer, Integer> p : recipe.getReqItems()) {
int itemId = p.getLeft();
if (c.getPlayer().getInventory(ii.getInventoryType(itemId)).countById(itemId) < p.getRight()) {
return false;
}
}
return true;
}
}

View File

@@ -0,0 +1,52 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleCharacter;
import client.MapleClient;
/**
*
* @author Matze
*/
public final class MesoDropHandler extends AbstractMaplePacketHandler {//FIX
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter player = c.getPlayer();
if (!player.isAlive()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (!player.canDropMeso()){
player.announce(MaplePacketCreator.serverNotice(5, "Fast meso drop has been patched, cut that out. ;)"));
return;
}
slea.skip(4);
int meso = slea.readInt();
if (meso <= player.getMeso() && meso > 9 && meso < 50001) {
player.gainMeso(-meso, false, true, false);
player.getMap().spawnMesoDrop(meso, player.getPosition(), player, player, true, (byte) 2);
}
}
}

View File

@@ -0,0 +1,111 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import net.server.world.MapleMessenger;
import net.server.world.MapleMessengerCharacter;
import net.server.world.World;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class MessengerHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
String input;
byte mode = slea.readByte();
MapleCharacter player = c.getPlayer();
World world = c.getWorldServer();
MapleMessenger messenger = player.getMessenger();
switch (mode) {
case 0x00:
if (messenger == null) {
int messengerid = slea.readInt();
if (messengerid == 0) {
MapleMessengerCharacter messengerplayer = new MapleMessengerCharacter(player, 0);
messenger = world.createMessenger(messengerplayer);
player.setMessenger(messenger);
player.setMessengerPosition(0);
} else {
messenger = world.getMessenger(messengerid);
int position = messenger.getLowestPosition();
MapleMessengerCharacter messengerplayer = new MapleMessengerCharacter(player, position);
if (messenger.getMembers().size() < 3) {
player.setMessenger(messenger);
player.setMessengerPosition(position);
world.joinMessenger(messenger.getId(), messengerplayer, player.getName(), messengerplayer.getChannel());
}
}
}
break;
case 0x02:
if (messenger != null) {
MapleMessengerCharacter messengerplayer = new MapleMessengerCharacter(player, player.getMessengerPosition());
world.leaveMessenger(messenger.getId(), messengerplayer);
player.setMessenger(null);
player.setMessengerPosition(4);
}
break;
case 0x03:
if (messenger.getMembers().size() < 3) {
input = slea.readMapleAsciiString();
MapleCharacter target = c.getChannelServer().getPlayerStorage().getCharacterByName(input);
if (target != null) {
if (target.getMessenger() == null) {
target.getClient().announce(MaplePacketCreator.messengerInvite(c.getPlayer().getName(), messenger.getId()));
c.announce(MaplePacketCreator.messengerNote(input, 4, 1));
} else {
c.announce(MaplePacketCreator.messengerChat(player.getName() + " : " + input + " is already using Maple Messenger"));
}
} else {
if (world.find(input) > -1) {
world.messengerInvite(c.getPlayer().getName(), messenger.getId(), input, c.getChannel());
} else {
c.announce(MaplePacketCreator.messengerNote(input, 4, 0));
}
}
} else {
c.announce(MaplePacketCreator.messengerChat(player.getName() + " : You cannot have more than 3 people in the Maple Messenger"));
}
break;
case 0x05:
String targeted = slea.readMapleAsciiString();
MapleCharacter target = c.getChannelServer().getPlayerStorage().getCharacterByName(targeted);
if (target != null) {
if (target.getMessenger() != null) {
target.getClient().announce(MaplePacketCreator.messengerNote(player.getName(), 5, 0));
}
} else {
world.declineChat(targeted, player.getName());
}
break;
case 0x06:
if (messenger != null) {
MapleMessengerCharacter messengerplayer = new MapleMessengerCharacter(player, player.getMessengerPosition());
input = slea.readMapleAsciiString();
world.messengerChat(messenger, input, messengerplayer.getName());
}
break;
}
}
}

View File

@@ -0,0 +1,63 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import net.AbstractMaplePacketHandler;
import server.life.MapleMonster;
import server.maps.MapleMap;
import tools.MaplePacketCreator;
import tools.Randomizer;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleClient;
/**
*
* @author Xotic & BubblesDev
*/
public final class MobDamageMobFriendlyHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int attacker = slea.readInt();
slea.readInt();
int damaged = slea.readInt();
MapleMonster monster = c.getPlayer().getMap().getMonsterByOid(damaged);
if (monster == null || c.getPlayer().getMap().getMonsterByOid(attacker) == null) {
return;
}
int damage = Randomizer.nextInt(((monster.getMaxHp() / 13 + monster.getPADamage() * 10)) * 2 + 500) / 10; //Beng's formula.
// int damage = monster.getStats().getPADamage() + monster.getStats().getPDDamage() - 1;
if (monster.getId() == 9300061) {
if (monster.getHp() - damage < 1) {
monster.getMap().broadcastMessage(MaplePacketCreator.serverNotice(6, "The Moon Bunny went home because he was sick."));
c.getPlayer().getEventInstance().getMapInstance(monster.getMap().getId()).killFriendlies(monster);
}
MapleMap map = c.getPlayer().getEventInstance().getMapInstance(monster.getMap().getId());
map.addBunnyHit();
}
c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.MobDamageMobFriendly(monster, damage), monster.getPosition());
c.announce(MaplePacketCreator.enableActions());
}
}

View File

@@ -0,0 +1,45 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import server.maps.MapleMap;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author Jay Estrella
*/
public final class MobDamageMobHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int from = slea.readInt();
slea.readInt();
int to = slea.readInt();
slea.readByte();
int dmg = slea.readInt();
MapleMap map = c.getPlayer().getMap();
if (map.getMonsterByOid(from) != null && map.getMonsterByOid(to) != null) {
map.damageMonster(c.getPlayer(), map.getMonsterByOid(to), dmg);
}
}
}

View File

@@ -0,0 +1,42 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import server.life.MapleMonster;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class MonsterBombHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int oid = slea.readInt();
MapleMonster monster = c.getPlayer().getMap().getMonsterByOid(oid);
if (!c.getPlayer().isAlive() || monster == null) {
return;
}
if (monster.getId() == 8500003 || monster.getId() == 8500004) {
monster.getMap().broadcastMessage(MaplePacketCreator.killMonster(monster.getObjectId(), 4));
c.getPlayer().getMap().removeMapObject(oid);
}
}
}

View File

@@ -0,0 +1,37 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import tools.data.input.SeekableLittleEndianAccessor;
import tools.MaplePacketCreator;
public final class MonsterBookCoverHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int id = slea.readInt();
if (id == 0 || id / 10000 == 238) {
c.getPlayer().setMonsterBookCover(id);
c.announce(MaplePacketCreator.changeCover(id));
}
}
}

View File

@@ -0,0 +1,223 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import java.awt.Point;
import net.AbstractMaplePacketHandler;
import server.partyquest.MonsterCarnival;
import server.life.MapleLifeFactory;
import server.maps.MapleReactor;
import server.maps.MapleReactorFactory;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author kevintjuh93
*/
public final class MonsterCarnivalHandler extends AbstractMaplePacketHandler{
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
MonsterCarnival carnival = chr.getCarnival();
int tab = slea.readByte();
int number = slea.readShort();
if (carnival != null) {
if (chr.getCarnivalParty() != carnival.getPartyRed() || chr.getCarnivalParty() != carnival.getPartyBlue()) {
chr.getMap().broadcastMessage(MaplePacketCreator.leaveCPQ(chr));
chr.changeMap(980000010);
}
if (chr.getCP() > getPrice(tab, number)) {
if (tab == 0) { //SPAWNING
if (chr.getCarnivalParty().canSummon()) {
chr.getMap().spawnCPQMonster(MapleLifeFactory.getMonster(getMonster(number)), new Point(1, 1), carnival.oppositeTeam(chr.getCarnivalParty()).getTeam());
chr.getCarnivalParty().summon();
} else
chr.announce(MaplePacketCreator.CPQMessage((byte) 2));
} else if (tab == 1) {
} else if (tab == 2) {
int rid = 9980000 + chr.getTeam();
MapleReactor reactor = new MapleReactor(MapleReactorFactory.getReactor(rid), rid);
/*switch (number) {
case 0:
reactor.setMonsterStatus(tab, MonsterStatus.WEAPON_ATTACK_UP, MobSkillFactory.getMobSkill(150, 1));
break;
case 1:
reactor.setMonsterStatus(tab, MonsterStatus.WEAPON_DEFENSE_UP, MobSkillFactory.getMobSkill(151, 1));
break;
case 2:
reactor.setMonsterStatus(tab, MonsterStatus.MAGIC_ATTACK_UP, MobSkillFactory.getMobSkill(152, 1));
break;
case 3:
reactor.setMonsterStatus(tab, MonsterStatus.MAGIC_DEFENSE_UP, MobSkillFactory.getMobSkill(153, 1));
break;
case 4:
reactor.setMonsterStatus(tab, MonsterStatus.ACC, MobSkillFactory.getMobSkill(154, 1));
break;
case 5:
reactor.setMonsterStatus(tab, MonsterStatus.AVOID, MobSkillFactory.getMobSkill(155, 1));
break;
case 6:
reactor.setMonsterStatus(tab, MonsterStatus.SPEED, MobSkillFactory.getMobSkill(156, 1));
break;
case 7:
reactor.setMonsterStatus(tab, MonsterStatus.WEAPON_IMMUNITY, MobSkillFactory.getMobSkill(140, 1));
break;
case 8:
reactor.setMonsterStatus(tab, MonsterStatus.MAGIC_IMMUNITY, MobSkillFactory.getMobSkill(141, 1));
break;
} */
chr.getMap().spawnReactor(reactor);
}
} else {
chr.getMap().broadcastMessage(MaplePacketCreator.CPQMessage((byte) 1));
}
} else {
chr.announce(MaplePacketCreator.CPQMessage((byte) 5));
}
chr.announce(MaplePacketCreator.enableActions());
}
public int getMonster(int num) {
int mid = 0;
num++;
switch (num) {
case 1:
mid = 9300127;
break;
case 2:
mid = 9300128;
break;
case 3:
mid = 9300129;
break;
case 4:
mid = 9300130;
break;
case 5:
mid = 9300131;
break;
case 6:
mid = 9300132;
break;
case 7:
mid = 9300133;
break;
case 8:
mid = 9300134;
break;
case 9:
mid = 9300135;
break;
case 10:
mid = 9300136;
break;
}
return mid;
}
public int getPrice(int num, int tab) {
int price = 0;
num++;
if (tab == 0) {
switch (num) {
case 1:
case 2:
price = 7;
break;
case 3:
case 4:
price = 8;
break;
case 5:
case 6:
price = 9;
break;
case 7:
price = 10;
break;
case 8:
price = 11;
break;
case 9:
price = 12;
break;
case 10:
price = 30;
break;
}
} else if (tab == 1) {
switch (num) {
case 1:
price = 17;
break;
case 2:
case 4:
price = 19;
break;
case 3:
price = 12;
break;
case 5:
price = 16;
break;
case 6:
price = 14;
break;
case 7:
price = 22;
break;
case 8:
price = 18;
break;
}
} else {
switch (num) {
case 1:
case 3:
price = 17;
break;
case 2:
case 4:
case 6:
price = 16;
break;
case 5:
price = 13;
break;
case 7:
price = 12;
break;
case 8:
case 9:
price = 35;
break;
}
}
return price;
}
}

View File

@@ -0,0 +1,51 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import java.awt.Point;
import java.util.List;
import server.maps.MapleDragon;
import server.movement.LifeMovementFragment;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public class MoveDragonHandler extends AbstractMovementPacketHandler {
@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
final MapleCharacter chr = c.getPlayer();
final Point startPos = new Point(slea.readShort(), slea.readShort());
List<LifeMovementFragment> res = parseMovement(slea);
final MapleDragon dragon = chr.getDragon();
if (dragon != null && res != null && res.size() > 0) {
updatePosition(res, dragon, 0);
if (chr.isHidden()) {
chr.getMap().broadcastGMMessage(chr, MaplePacketCreator.moveDragon(dragon, startPos, res));
} else {
chr.getMap().broadcastMessage(chr, MaplePacketCreator.moveDragon(dragon, startPos, res), dragon.getPosition());
}
}
}
}

View File

@@ -0,0 +1,103 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import java.awt.Point;
import java.util.List;
import server.life.MapleMonster;
import server.life.MobSkill;
import server.life.MobSkillFactory;
import server.maps.MapleMapObject;
import server.maps.MapleMapObjectType;
import server.movement.LifeMovementFragment;
import tools.MaplePacketCreator;
import tools.Pair;
import tools.Randomizer;
import tools.data.input.SeekableLittleEndianAccessor;
public final class MoveLifeHandler extends AbstractMovementPacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int objectid = slea.readInt();
short moveid = slea.readShort();
MapleMapObject mmo = c.getPlayer().getMap().getMapObject(objectid);
if (mmo == null || mmo.getType() != MapleMapObjectType.MONSTER) {
return;
}
MapleMonster monster = (MapleMonster) mmo;
List<LifeMovementFragment> res;
byte skillByte = slea.readByte();
byte skill = slea.readByte();
int skill_1 = slea.readByte() & 0xFF;
byte skill_2 = slea.readByte();
byte skill_3 = slea.readByte();
byte skill_4 = slea.readByte();
slea.read(8);
MobSkill toUse = null;
if (skillByte == 1 && monster.getNoSkills() > 0) {
int random = Randomizer.nextInt(monster.getNoSkills());
Pair<Integer, Integer> skillToUse = monster.getSkills().get(random);
toUse = MobSkillFactory.getMobSkill(skillToUse.getLeft(), skillToUse.getRight());
int percHpLeft = (monster.getHp() / monster.getMaxHp()) * 100;
if (toUse.getHP() < percHpLeft || !monster.canUseSkill(toUse)) {
toUse = null;
}
}
if ((skill_1 >= 100 && skill_1 <= 200) && monster.hasSkill(skill_1, skill_2)) {
MobSkill skillData = MobSkillFactory.getMobSkill(skill_1, skill_2);
if (skillData != null && monster.canUseSkill(skillData)) {
skillData.applyEffect(c.getPlayer(), monster, true);
}
}
slea.readByte();
slea.readInt(); // whatever
short start_x = slea.readShort(); // hmm.. startpos?
short start_y = slea.readShort(); // hmm...
Point startPos = new Point(start_x, start_y);
res = parseMovement(slea);
if (monster.getController() != c.getPlayer()) {
if (monster.isAttackedBy(c.getPlayer())) {// aggro and controller change
monster.switchController(c.getPlayer(), true);
} else {
return;
}
} else if (skill == -1 && monster.isControllerKnowsAboutAggro() && !monster.isMobile() && !monster.isFirstAttack()) {
monster.setControllerHasAggro(false);
monster.setControllerKnowsAboutAggro(false);
}
boolean aggro = monster.isControllerHasAggro();
if (toUse != null) {
c.announce(MaplePacketCreator.moveMonsterResponse(objectid, moveid, monster.getMp(), aggro, toUse.getSkillId(), toUse.getSkillLevel()));
} else {
c.announce(MaplePacketCreator.moveMonsterResponse(objectid, moveid, monster.getMp(), aggro));
}
if (aggro) {
monster.setControllerKnowsAboutAggro(true);
}
if (res != null) {
c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.moveMonster(skillByte, skill, skill_1, skill_2, skill_3, skill_4, objectid, startPos, res), monster.getPosition());
updatePosition(res, monster, -1);
c.getPlayer().getMap().moveMonster(monster, monster.getPosition());
}
}
}

View File

@@ -0,0 +1,49 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import net.server.channel.handlers.AbstractMovementPacketHandler;
import java.util.List;
import client.MapleCharacter;
import client.MapleClient;
import server.movement.LifeMovementFragment;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class MovePetHandler extends AbstractMovementPacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int petId = slea.readInt();
slea.readLong();
// Point startPos = StreamUtil.readShortPoint(slea);
List<LifeMovementFragment> res = parseMovement(slea);
if (res.isEmpty()) {
return;
}
MapleCharacter player = c.getPlayer();
byte slot = player.getPetIndex(petId);
if (slot == -1) {
return;
}
player.getPet(slot).updatePosition(res);
player.getMap().broadcastMessage(player, MaplePacketCreator.movePet(player.getId(), petId, slot, res), false);
}
}

View File

@@ -0,0 +1,45 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import java.util.List;
import net.server.channel.handlers.AbstractMovementPacketHandler;
import server.movement.LifeMovementFragment;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class MovePlayerHandler extends AbstractMovementPacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
slea.skip(9);
final List<LifeMovementFragment> res = parseMovement(slea);
if (res != null) {
updatePosition(res, c.getPlayer(), 0);
c.getPlayer().getMap().movePlayer(c.getPlayer(), c.getPlayer().getPosition());
if (c.getPlayer().isHidden()) {
c.getPlayer().getMap().broadcastGMMessage(c.getPlayer(), MaplePacketCreator.movePlayer(c.getPlayer().getId(), res), false);
} else {
c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.movePlayer(c.getPlayer().getId(), res), false);
}
}
}
}

View File

@@ -0,0 +1,54 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import net.server.channel.handlers.AbstractMovementPacketHandler;
import java.awt.Point;
import java.util.Collection;
import java.util.List;
import client.MapleCharacter;
import client.MapleClient;
import server.maps.MapleSummon;
import server.movement.LifeMovementFragment;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class MoveSummonHandler extends AbstractMovementPacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int oid = slea.readInt();
Point startPos = new Point(slea.readShort(), slea.readShort());
List<LifeMovementFragment> res = parseMovement(slea);
MapleCharacter player = c.getPlayer();
Collection<MapleSummon> summons = player.getSummons().values();
MapleSummon summon = null;
for (MapleSummon sum : summons) {
if (sum.getObjectId() == oid) {
summon = sum;
break;
}
}
if (summon != null) {
updatePosition(res, summon, 0);
player.getMap().broadcastMessage(player, MaplePacketCreator.moveSummon(player.getId(), oid, startPos, res), summon.getPosition());
}
}
}

View File

@@ -0,0 +1,46 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import net.SendOpcode;
import tools.data.input.SeekableLittleEndianAccessor;
import tools.data.output.MaplePacketLittleEndianWriter;
public final class NPCAnimation extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
int length = (int) slea.available();
if (length == 6) { // NPC Talk
mplew.writeShort(SendOpcode.NPC_ACTION.getValue());
mplew.writeInt(slea.readInt());
mplew.writeShort(slea.readShort());
c.announce(mplew.getPacket());
} else if (length > 6) { // NPC Move
byte[] bytes = slea.read(length - 9);
mplew.writeShort(SendOpcode.NPC_ACTION.getValue());
mplew.write(bytes);
c.announce(mplew.getPacket());
}
}
}

View File

@@ -0,0 +1,75 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import scripting.npc.NPCScriptManager;
import scripting.quest.QuestScriptManager;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author Matze
*/
public final class NPCMoreTalkHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
byte lastMsg = slea.readByte(); // 00 (last msg type I think)
byte action = slea.readByte(); // 00 = end chat, 01 == follow
if (lastMsg == 2) {
if (action != 0) {
String returnText = slea.readMapleAsciiString();
if (c.getQM() != null) {
c.getQM().setGetText(returnText);
if (c.getQM().isStart()) {
QuestScriptManager.getInstance().start(c, action, lastMsg, -1);
} else {
QuestScriptManager.getInstance().end(c, action, lastMsg, -1);
}
} else {
c.getCM().setGetText(returnText);
NPCScriptManager.getInstance().action(c, action, lastMsg, -1);
}
} else if (c.getQM() != null) {
c.getQM().dispose();
} else {
c.getCM().dispose();
}
} else {
int selection = -1;
if (slea.available() >= 4) {
selection = slea.readInt();
} else if (slea.available() > 0) {
selection = slea.readByte();
}
if (c.getQM() != null) {
if (c.getQM().isStart()) {
QuestScriptManager.getInstance().start(c, action, lastMsg, selection);
} else {
QuestScriptManager.getInstance().end(c, action, lastMsg, selection);
}
} else if (c.getCM() != null) {
NPCScriptManager.getInstance().action(c, action, lastMsg, selection);
}
}
}
}

View File

@@ -0,0 +1,61 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import client.autoban.AutobanFactory;
import net.AbstractMaplePacketHandler;
import server.MapleItemInformationProvider;
import tools.FilePrinter;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author Matze
*/
public final class NPCShopHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
byte bmode = slea.readByte();
if (bmode == 0) { // mode 0 = buy :)
short slot = slea.readShort();// slot
int itemId = slea.readInt();
short quantity = slea.readShort();
if (quantity < 1) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit a npc shop.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to buy quantity " + quantity + " of item id " + itemId + "\r\n");
c.disconnect(true, false);
return;
}
c.getPlayer().getShop().buy(c, slot, itemId, quantity);
} else if (bmode == 1) { // sell ;)
short slot = slea.readShort();
int itemId = slea.readInt();
short quantity = slea.readShort();
c.getPlayer().getShop().sell(c, MapleItemInformationProvider.getInstance().getInventoryType(itemId), slot, quantity);
} else if (bmode == 2) { // recharge ;)
byte slot = (byte) slea.readShort();
c.getPlayer().getShop().recharge(c, slot);
} else if (bmode == 3) { // leaving :(
c.getPlayer().setShop(null);
}
}
}

View File

@@ -0,0 +1,72 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import net.server.channel.handlers.DueyHandler;
import client.MapleClient;
import constants.ServerConstants;
import net.AbstractMaplePacketHandler;
import scripting.npc.NPCScriptManager;
import server.life.MapleNPC;
import server.maps.MapleMapObject;
import server.maps.PlayerNPCs;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class NPCTalkHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!c.getPlayer().isAlive()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
int oid = slea.readInt();
MapleMapObject obj = c.getPlayer().getMap().getMapObject(oid);
if (obj instanceof MapleNPC) {
MapleNPC npc = (MapleNPC) obj;
if (npc.getId() == 9010009) { //is duey
if(System.currentTimeMillis() - c.getPlayer().getDuey() < ServerConstants.BLOCK_DUEY_RACE_COND)
return;
c.getPlayer().setDuey(System.currentTimeMillis());
c.announce(MaplePacketCreator.sendDuey((byte) 8, DueyHandler.loadItems(c.getPlayer())));
} else if (npc.hasShop()) {
if (c.getPlayer().getShop() != null) {
return;
}
npc.sendShop(c);
} else {
if (c.getCM() != null || c.getQM() != null) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if(npc.getId() >= 9100100 && npc.getId() <= 9100200) {
// Custom handling for gachapon scripts to reduce the amount of scripts needed.
NPCScriptManager.getInstance().start(c, npc.getId(), "gachapon", null);
} else {
NPCScriptManager.getInstance().start(c, npc.getId(), null);
}
}
} else if (obj instanceof PlayerNPCs) {
NPCScriptManager.getInstance().start(c, ((PlayerNPCs) obj).getId(), null);
}
}
}

View File

@@ -0,0 +1,80 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import net.AbstractMaplePacketHandler;
import tools.DatabaseConnection;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleClient;
public final class NoteActionHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int action = slea.readByte();
if (action == 0 && c.getPlayer().getCashShop().getAvailableNotes() > 0) {
String charname = slea.readMapleAsciiString();
String message = slea.readMapleAsciiString();
try {
if (c.getPlayer().getCashShop().isOpened())
c.announce(MaplePacketCreator.showCashInventory(c));
c.getPlayer().sendNote(charname, message, (byte) 1);
c.getPlayer().getCashShop().decreaseNotes();
} catch (SQLException e) {
e.printStackTrace();
}
} else if (action == 1) {
int num = slea.readByte();
slea.readByte();
slea.readByte();
int fame = 0;
for (int i = 0; i < num; i++) {
int id = slea.readInt();
slea.readByte(); //Fame, but we read it from the database :)
PreparedStatement ps;
try {
ps = DatabaseConnection.getConnection().prepareStatement("SELECT `fame` FROM notes WHERE id=? AND deleted=0");
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
if (rs.next())
fame += rs.getInt("fame");
rs.close();
ps = DatabaseConnection.getConnection().prepareStatement("UPDATE notes SET `deleted` = 1 WHERE id = ?");
ps.setInt(1, id);
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (fame > 0) {
c.getPlayer().gainFame(fame);
c.announce(MaplePacketCreator.getShowFameGain(fame));
}
}
}
}

View File

@@ -0,0 +1,68 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import client.autoban.AutobanFactory;
import net.AbstractMaplePacketHandler;
import net.server.Server;
import net.server.world.World;
import tools.FilePrinter;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class PartyChatHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter player = c.getPlayer();
if(player.getAutobanManager().getLastSpam(7) + 200 > System.currentTimeMillis()) {
return;
}
int type = slea.readByte(); // 0 for buddys, 1 for partys
int numRecipients = slea.readByte();
int recipients[] = new int[numRecipients];
for (int i = 0; i < numRecipients; i++) {
recipients[i] = slea.readInt();
}
String chattext = slea.readMapleAsciiString();
if (chattext.length() > Byte.MAX_VALUE && !player.isGM()) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit chats.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to send text with length of " + chattext.length() + "\r\n");
c.disconnect(true, false);
return;
}
World world = c.getWorldServer();
if (type == 0) {
world.buddyChat(recipients, player.getId(), player.getName(), chattext);
} else if (type == 1 && player.getParty() != null) {
world.partyChat(player.getParty(), chattext, player.getName());
} else if (type == 2 && player.getGuildId() > 0) {
Server.getInstance().guildChat(player.getGuildId(), player.getName(), player.getId(), chattext);
} else if (type == 3 && player.getGuild() != null) {
int allianceId = player.getGuild().getAllianceId();
if (allianceId > 0) {
Server.getInstance().allianceMessage(allianceId, MaplePacketCreator.multiChat(player.getName(), chattext, 3), player.getId(), -1);
}
}
player.getAutobanManager().spam(7);
}
}

View File

@@ -0,0 +1,151 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import net.AbstractMaplePacketHandler;
import net.server.world.MapleParty;
import net.server.world.MaplePartyCharacter;
import net.server.world.PartyOperation;
import net.server.world.World;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleCharacter;
import client.MapleClient;
public final class PartyOperationHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int operation = slea.readByte();
MapleCharacter player = c.getPlayer();
World world = c.getWorldServer();
MapleParty party = player.getParty();
MaplePartyCharacter partyplayer = player.getMPC();
switch (operation) {
case 1: { // create
if(player.getLevel() < 10) {
c.announce(MaplePacketCreator.partyStatusMessage(10));
return;
}
if (player.getParty() == null) {
partyplayer = new MaplePartyCharacter(player);
party = world.createParty(partyplayer);
player.setParty(party);
player.setMPC(partyplayer);
player.silentPartyUpdate();
c.announce(MaplePacketCreator.partyCreated(partyplayer));
} else {
c.announce(MaplePacketCreator.serverNotice(5, "You can't create a party as you are already in one."));
}
break;
}
case 2: {
if (party != null && partyplayer != null) {
if (partyplayer.equals(party.getLeader())) {
world.updateParty(party.getId(), PartyOperation.DISBAND, partyplayer);
if (player.getEventInstance() != null) {
player.getEventInstance().disbandParty();
}
} else {
world.updateParty(party.getId(), PartyOperation.LEAVE, partyplayer);
if (player.getEventInstance() != null) {
player.getEventInstance().leftParty(player);
}
}
player.setParty(null);
}
break;
}
case 3: {//join
int partyid = slea.readInt();
if (c.getPlayer().getParty() == null) {
party = world.getParty(partyid);
if (party != null) {
if (party.getMembers().size() < 6) {
partyplayer = new MaplePartyCharacter(player);
world.updateParty(party.getId(), PartyOperation.JOIN, partyplayer);
player.receivePartyMemberHP();
player.updatePartyMemberHP();
} else {
c.announce(MaplePacketCreator.partyStatusMessage(17));
}
} else {
c.announce(MaplePacketCreator.serverNotice(5, "The person you have invited to the party is already in one."));
}
} else {
c.announce(MaplePacketCreator.serverNotice(5, "You can't join the party as you are already in one."));
}
break;
}
case 4: {//invite
String name = slea.readMapleAsciiString();
MapleCharacter invited = world.getPlayerStorage().getCharacterByName(name);
if (invited != null) {
if(invited.getLevel() < 10) { //min requirement is level 10
c.announce(MaplePacketCreator.serverNotice(5, "The player you have invited does not meet the requirements."));
return;
}
if (invited.getParty() == null) {
if (player.getParty() == null) {
partyplayer = new MaplePartyCharacter(player);
party = world.createParty(partyplayer);
player.setParty(party);
player.setMPC(partyplayer);
c.announce(MaplePacketCreator.partyCreated(partyplayer));
}
if (party.getMembers().size() < 6) {
invited.getClient().announce(MaplePacketCreator.partyInvite(player));
} else {
c.announce(MaplePacketCreator.partyStatusMessage(17));
}
} else {
c.announce(MaplePacketCreator.partyStatusMessage(16));
}
} else {
c.announce(MaplePacketCreator.partyStatusMessage(19));
}
break;
}
case 5: { // expel
int cid = slea.readInt();
if (partyplayer.equals(party.getLeader())) {
MaplePartyCharacter expelled = party.getMemberById(cid);
if (expelled != null) {
world.updateParty(party.getId(), PartyOperation.EXPEL, expelled);
if (player.getEventInstance() != null) {
if (expelled.isOnline()) {
player.getEventInstance().disbandParty();
}
}
}
}
break;
}
case 6: {
int newLeader = slea.readInt();
MaplePartyCharacter newLeadr = party.getMemberById(newLeader);
party.setLeader(newLeadr);
world.updateParty(party.getId(), PartyOperation.CHANGE_LEADER, newLeadr);
break;
}
}
}
}

View File

@@ -0,0 +1,42 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import net.AbstractMaplePacketHandler;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleClient;
/**
*
* @author Quasar
*/
public class PartySearchRegisterHandler extends AbstractMaplePacketHandler {
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
return; //Disabling this for now.
/* MapleCharacter chr = c.getPlayer();
int min = slea.readInt();
int max = slea.readInt();
if (chr.getLevel() < min || chr.getLevel() > max || (max - min) > 30 || min > max) { // Client editing
return;
}*/
}
}

View File

@@ -0,0 +1,124 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import java.util.Collection;
import net.AbstractMaplePacketHandler;
import net.server.world.MapleParty;
import server.maps.MapleMap;
import server.maps.MapleMapObject;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleCharacter;
import client.MapleClient;
import client.MapleJob;
import constants.ServerConstants;
/**
*
* @author XoticStory
* @author BubblesDev
*/
public class PartySearchStartHandler extends AbstractMaplePacketHandler {
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if(!ServerConstants.USE_PARTY_SEARCH){
return;
}
int min = slea.readInt();
int max = slea.readInt();
slea.readInt(); // members
int jobs = slea.readInt();
MapleCharacter chr = c.getPlayer();
MapleMap map = chr.getMap();
Collection<MapleMapObject> mapobjs = map.getAllPlayer();
for (MapleMapObject mapobj : mapobjs) {
if (chr.getParty().getMembers().size() > 5) {
break;
}
if (mapobj instanceof MapleCharacter) {
MapleCharacter tchar = (MapleCharacter) mapobj;
int charlvl = tchar.getLevel();
if (charlvl >= min && charlvl <= max && isValidJob(tchar.getJob(), jobs)) {
if (c.getPlayer().getParty() == null) {
//WorldChannelInterface wci = c.getChannelServer().getWorldInterface();
MapleParty party = c.getPlayer().getParty();
//int partyid = party.getId();
//party = null;//.getParty(partyid);
if (party != null) {
if (party.getMembers().size() < 6) {
//MaplePartyCharacter partyplayer = tchar.getMPC();
//wci.updateParty(party.getId(), PartyOperation.JOIN, partyplayer);
c.getPlayer().receivePartyMemberHP();
c.getPlayer().updatePartyMemberHP();
} else {
c.announce(MaplePacketCreator.partyStatusMessage(17));
}
}
}
}
}
}
}
private static boolean isValidJob(MapleJob thejob, int jobs) {
int jobid = thejob.getId();
if (jobid == 0) {
return ((jobs & 2) > 0);
} else if (jobid == 100) {
return ((jobs & 4) > 0);
} else if (jobid > 100 && jobid < 113) {
return ((jobs & 8) > 0);
} else if (jobid > 110 && jobid < 123) {
return ((jobs & 16) > 0);
} else if (jobid > 120 && jobid < 133) {
return ((jobs & 32) > 0);
} else if (jobid == 200) {
return ((jobs & 64) > 0);
} else if (jobid > 209 && jobid < 213) {
return ((jobs & 128) > 0);
} else if (jobid > 219 && jobid < 223) {
return ((jobs & 256) > 0);
} else if (jobid > 229 && jobid < 233) {
return ((jobs & 512) > 0);
} else if (jobid == 500) {
return ((jobs & 1024) > 0);
} else if (jobid > 509 && jobid < 513) {
return ((jobs & 2048) > 0);
} else if (jobid > 519 && jobid < 523) {
return ((jobs & 4096) > 0);
} else if (jobid == 400) {
return ((jobs & 8192) > 0);
} else if (jobid > 400 && jobid < 413) {
return ((jobs & 16384) > 0);
} else if (jobid > 419 && jobid < 423) {
return ((jobs & 32768) > 0);
} else if (jobid == 300) {
return ((jobs & 65536) > 0);
} else if (jobid > 300 && jobid < 313) {
return ((jobs & 131072) > 0);
} else if (jobid > 319 && jobid < 323) {
return ((jobs & 262144) > 0);
}
return false;
}
}

View File

@@ -0,0 +1,66 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import client.inventory.Item;
import client.inventory.MapleInventoryType;
import net.AbstractMaplePacketHandler;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import server.MapleStatEffect;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class PetAutoPotHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!c.getPlayer().isAlive()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
slea.readByte();
slea.readLong();
slea.readInt();
short slot = slea.readShort();
int itemId = slea.readInt();
float Ratio = 0.85f;
Item toUse = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot);
if(toUse != null) {
MapleStatEffect stat = MapleItemInformationProvider.getInstance().getItemEffect(toUse.getItemId());
if (toUse.getQuantity() <= 0) return;
do {
if (toUse.getItemId() != itemId) {
c.announce(MaplePacketCreator.enableActions());
return;
}
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, (short) 1, false);
//stat = MapleItemInformationProvider.getInstance().getItemEffect(toUse.getItemId());
stat.applyTo(c.getPlayer());
} while(((stat.getHp() > 0 && c.getPlayer().getHp() < Ratio * c.getPlayer().getMaxHp()) || (stat.getMp() > 0 && c.getPlayer().getMp() < Ratio * c.getPlayer().getMaxMp())) && toUse.getQuantity() > 0);
}
}
}

View File

@@ -0,0 +1,50 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import client.autoban.AutobanFactory;
import net.AbstractMaplePacketHandler;
import tools.FilePrinter;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class PetChatHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int petId = slea.readInt();
slea.readInt();
slea.readByte();
int act = slea.readByte();
byte pet = c.getPlayer().getPetIndex(petId);
if ((pet < 0 || pet > 3) || (act < 0 || act > 9)) {
return;
}
String text = slea.readMapleAsciiString();
if (text.length() > Byte.MAX_VALUE) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with pets.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to send text with length of " + text.length() + "\r\n");
c.disconnect(true, false);
return;
}
c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.petChat(c.getPlayer().getId(), pet, act, text), true);
}
}

View File

@@ -0,0 +1,78 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import client.inventory.PetCommand;
import client.inventory.PetDataFactory;
import client.inventory.Item;
import client.inventory.MapleInventoryType;
import client.inventory.MaplePet;
import constants.ExpTable;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.Randomizer;
import tools.data.input.SeekableLittleEndianAccessor;
public final class PetCommandHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
int petId = slea.readInt();
byte petIndex = chr.getPetIndex(petId);
MaplePet pet;
if (petIndex == -1) {
return;
} else {
pet = chr.getPet(petIndex);
}
slea.readInt();
slea.readByte();
byte command = slea.readByte();
PetCommand petCommand = PetDataFactory.getPetCommand(pet.getItemId(), (int) command);
if (petCommand == null) {
return;
}
boolean success = false;
if (Randomizer.nextInt(101) <= petCommand.getProbability()) {
success = true;
if (pet.getCloseness() < 30000) {
int newCloseness = pet.getCloseness() + petCommand.getIncrease();
if (newCloseness > 30000) {
newCloseness = 30000;
}
pet.setCloseness(newCloseness);
if (newCloseness >= ExpTable.getClosenessNeededForLevel(pet.getLevel())) {
pet.setLevel((byte) (pet.getLevel() + 1));
c.announce(MaplePacketCreator.showOwnPetLevelUp(chr.getPetIndex(pet)));
chr.getMap().broadcastMessage(MaplePacketCreator.showPetLevelUp(c.getPlayer(), chr.getPetIndex(pet)));
}
pet.saveToDb();
Item petz = chr.getInventory(MapleInventoryType.CASH).getItem(pet.getPosition());
chr.forceUpdateItem(petz);
}
}
chr.getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.commandResponse(chr.getId(), petIndex, command, success), true);
}
}

View File

@@ -0,0 +1,39 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import tools.data.input.SeekableLittleEndianAccessor;
/**
* @author BubblesDev
*/
public final class PetExcludeItemsHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
slea.readLong();
byte amount = slea.readByte();
for (int i = 0; i < amount; i++) {
c.getPlayer().addExcluded(slea.readInt());
}
}
}

View File

@@ -0,0 +1,118 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import constants.ExpTable;
import client.MapleClient;
import client.inventory.MapleInventoryType;
import client.inventory.MaplePet;
import client.autoban.AutobanManager;
import client.inventory.Item;
import tools.Randomizer;
import net.AbstractMaplePacketHandler;
import server.MapleInventoryManipulator;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class PetFoodHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
AutobanManager abm = chr.getAutobanManager();
if (abm.getLastSpam(2) + 500 > System.currentTimeMillis()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
abm.spam(2);
abm.setTimestamp(1, slea.readInt(), 3);
if (chr.getNoPets() == 0) {
c.announce(MaplePacketCreator.enableActions());
return;
}
int previousFullness = 100;
byte slot = 0;
MaplePet[] pets = chr.getPets();
for (byte i = 0; i < 3; i++) {
if (pets[i] != null) {
if (pets[i].getFullness() < previousFullness) {
slot = i;
previousFullness = pets[i].getFullness();
}
}
}
MaplePet pet = chr.getPet(slot);
short pos = slea.readShort();
int itemId = slea.readInt();
Item use = chr.getInventory(MapleInventoryType.USE).getItem(pos);
if (use == null || (itemId / 10000) != 212 || use.getItemId() != itemId) {
return;
}
boolean gainCloseness = false;
if (Randomizer.nextInt(101) > 50) {
gainCloseness = true;
}
if (pet.getFullness() < 100) {
int newFullness = pet.getFullness() + 30;
if (newFullness > 100) {
newFullness = 100;
}
pet.setFullness(newFullness);
if (gainCloseness && pet.getCloseness() < 30000) {
int newCloseness = pet.getCloseness() + 1;
if (newCloseness > 30000) {
newCloseness = 30000;
}
pet.setCloseness(newCloseness);
if (newCloseness >= ExpTable.getClosenessNeededForLevel(pet.getLevel())) {
pet.setLevel((byte) (pet.getLevel() + 1));
c.announce(MaplePacketCreator.showOwnPetLevelUp(chr.getPetIndex(pet)));
chr.getMap().broadcastMessage(MaplePacketCreator.showPetLevelUp(c.getPlayer(), chr.getPetIndex(pet)));
}
}
chr.getMap().broadcastMessage(MaplePacketCreator.commandResponse(chr.getId(), slot, 0, true));
} else {
if (gainCloseness) {
int newCloseness = pet.getCloseness() - 1;
if (newCloseness < 0) {
newCloseness = 0;
}
pet.setCloseness(newCloseness);
if (pet.getLevel() > 1 && newCloseness < ExpTable.getClosenessNeededForLevel(pet.getLevel())) {
pet.setLevel((byte) (pet.getLevel() - 1));
}
}
chr.getMap().broadcastMessage(MaplePacketCreator.commandResponse(chr.getId(), slot, 0, false));
}
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, pos, (short) 1, false);
pet.saveToDb();
Item petz = chr.getInventory(MapleInventoryType.CASH).getItem(pet.getPosition());
if (petz == null){ //Not a real fix but fuck it you know?
return;
}
chr.forceUpdateItem(petz);
}
}

View File

@@ -0,0 +1,157 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import client.inventory.MaplePet;
import net.AbstractMaplePacketHandler;
import server.MapleInventoryManipulator;
import server.maps.MapleMapItem;
import server.maps.MapleMapObject;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import client.inventory.MapleInventoryType;
import net.server.world.MaplePartyCharacter;
import scripting.item.ItemScriptManager;
import server.MapleItemInformationProvider;
import server.MapleItemInformationProvider.scriptedItem;
import constants.ServerConstants;
/**
* @author TheRamon
*/
public final class PetLootHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
if(System.currentTimeMillis() - chr.getPetLootCd() < ServerConstants.PET_LOOT_UPON_ATTACK)
return;
MaplePet pet = chr.getPet(chr.getPetIndex(slea.readInt()));//why would it be an int...?
if (pet == null || !pet.isSummoned()) {
return;
}
slea.skip(13);
int oid = slea.readInt();
MapleMapObject ob = chr.getMap().getMapObject(oid);
if (ob == null) {
c.announce(MaplePacketCreator.getInventoryFull());
return;
}
if (ob instanceof MapleMapItem) {
MapleMapItem mapitem = (MapleMapItem) ob;
synchronized (mapitem) {
if (!chr.needQuestItem(mapitem.getQuest(), mapitem.getItemId())) {
c.announce(MaplePacketCreator.showItemUnavailable());
c.announce(MaplePacketCreator.enableActions());
return;
}
if(System.currentTimeMillis() - mapitem.getDropTime() < 900) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (mapitem.isPickedUp()) {
c.announce(MaplePacketCreator.getInventoryFull());
return;
}
if (mapitem.getDropper() == c.getPlayer()) {
return;
}
if (mapitem.getMeso() > 0) {
if (chr.getParty() != null) {
int mesosamm = mapitem.getMeso();
if (mesosamm > 50000 * chr.getMesoRate()) return;
int partynum = 0;
for (MaplePartyCharacter partymem : chr.getParty().getMembers()) {
if (partymem.isOnline() && partymem.getMapId() == chr.getMap().getId() && partymem.getChannel() == c.getChannel()) {
partynum++;
}
}
for (MaplePartyCharacter partymem : chr.getParty().getMembers()) {
if (partymem.isOnline() && partymem.getMapId() == chr.getMap().getId()) {
MapleCharacter somecharacter = c.getChannelServer().getPlayerStorage().getCharacterById(partymem.getId());
if (somecharacter != null) somecharacter.gainMeso(mesosamm / partynum, true, true, false);
}
}
chr.getMap().broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 5, chr.getId(), true, chr.getPetIndex(pet)), mapitem.getPosition());
chr.getMap().removeMapObject(ob);
} else if (chr.getInventory(MapleInventoryType.EQUIPPED).findById(1812000) != null) {
chr.gainMeso(mapitem.getMeso(), true, true, false);
chr.getMap().broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 5, chr.getId(), true, chr.getPetIndex(pet)), mapitem.getPosition());
chr.getMap().removeMapObject(ob);
} else {
mapitem.setPickedUp(false);
c.announce(MaplePacketCreator.enableActions());
return;
}
} else if (ItemPickupHandler.useItem(c, mapitem.getItem().getItemId())) {
if (mapitem.getItem().getItemId() / 10000 == 238) {
chr.getMonsterBook().addCard(c, mapitem.getItem().getItemId());
}
mapitem.setPickedUp(true);
chr.getMap().broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 5, chr.getId(), true, chr.getPetIndex(pet)), mapitem.getPosition());
chr.getMap().removeMapObject(ob);
} else if (mapitem.getItem().getItemId() / 100 == 50000) {
if (chr.getInventory(MapleInventoryType.EQUIPPED).findById(1812007) != null) {
for (int i : chr.getExcluded()) {
if (mapitem.getItem().getItemId() == i) {
return;
}
}
} else if (MapleInventoryManipulator.addById(c, mapitem.getItem().getItemId(), mapitem.getItem().getQuantity(), null, -1, mapitem.getItem().getExpiration())) {
chr.getMap().broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 5, chr.getId(), true, chr.getPetIndex(pet)), mapitem.getPosition());
chr.getMap().removeMapObject(ob);
} else {
return;
}
} else if (mapitem.getItem().getItemId() / 10000 == 243) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
scriptedItem info = ii.getScriptedItemInfo(mapitem.getItem().getItemId());
if (info.runOnPickup()) {
ItemScriptManager ism = ItemScriptManager.getInstance();
String scriptName = info.getScript();
if (ism.scriptExists(scriptName))
ism.getItemScript(c, scriptName);
} else {
MapleInventoryManipulator.addFromDrop(c, mapitem.getItem(), true);
}
chr.getMap().broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 5, chr.getId(), true, chr.getPetIndex(pet)), mapitem.getPosition());
chr.getMap().removeMapObject(ob);
} else if(mapitem.getItemId() == 4031865 || mapitem.getItemId() == 4031866) {
// Add NX to account, show effect and make item disapear
chr.getCashShop().gainCash(1, mapitem.getItemId() == 4031865 ? 100 : 250);
chr.getMap().broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 5, chr.getId(), true, chr.getPetIndex(pet)), mapitem.getPosition());
chr.getMap().removeMapObject(ob);
} else if (MapleInventoryManipulator.addFromDrop(c, mapitem.getItem(), true)) {
chr.getMap().broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 5, chr.getId(), true, chr.getPetIndex(pet)), mapitem.getPosition());
chr.getMap().removeMapObject(ob);
} else {
return;
}
mapitem.setPickedUp(true);
}
}
//c.announce(MaplePacketCreator.enableActions());
}
}

View File

@@ -0,0 +1,596 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import client.autoban.AutobanFactory;
import client.inventory.Item;
import client.inventory.MapleInventory;
import client.inventory.MapleInventoryType;
import constants.ItemConstants;
import java.util.Arrays;
import net.AbstractMaplePacketHandler;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import server.MapleMiniGame;
import server.MaplePlayerShop;
import server.MaplePlayerShopItem;
import server.MapleTrade;
import server.maps.FieldLimit;
import server.maps.HiredMerchant;
import server.maps.MapleMapObject;
import server.maps.MapleMapObjectType;
import tools.FilePrinter;
import tools.MaplePacketCreator;
import tools.Pair;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author Matze
*/
public final class PlayerInteractionHandler extends AbstractMaplePacketHandler {
public enum Action {
CREATE(0),
INVITE(2),
DECLINE(3),
VISIT(4),
ROOM(5),
CHAT(6),
CHAT_THING(8),
EXIT(0xA),
OPEN(0xB),
TRADE_BIRTHDAY(0x0E),
SET_ITEMS(0xF),
SET_MESO(0x10),
CONFIRM(0x11),
TRANSACTION(0x14),
ADD_ITEM(0x16),
BUY(0x17),
UPDATE_MERCHANT(0x19),
REMOVE_ITEM(0x1B),
BAN_PLAYER(0x1C),
MERCHANT_THING(0x1D),
OPEN_STORE(0x1E),
PUT_ITEM(0x21),
MERCHANT_BUY(0x22),
TAKE_ITEM_BACK(0x26),
MAINTENANCE_OFF(0x27),
MERCHANT_ORGANIZE(0x28),
CLOSE_MERCHANT(0x29),
REAL_CLOSE_MERCHANT(0x2A),
MERCHANT_MESO(0x2B),
SOMETHING(0x2D),
VIEW_VISITORS(0x2E),
BLACKLIST(0x2F),
REQUEST_TIE(0x32),
ANSWER_TIE(0x33),
GIVE_UP(0x34),
EXIT_AFTER_GAME(0x38),
CANCEL_EXIT(0x39),
READY(0x3A),
UN_READY(0x3B),
START(0x3D),
GET_RESULT(0x3E),
SKIP(0x3F),
MOVE_OMOK(0x40),
SELECT_CARD(0x44);
final byte code;
private Action(int code) {
this.code = (byte) code;
}
public byte getCode() {
return code;
}
}
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
byte mode = slea.readByte();
MapleCharacter chr = c.getPlayer();
if (mode == Action.CREATE.getCode()) {
byte createType = slea.readByte();
if (createType == 3) {// trade
MapleTrade.startTrade(chr);
} else if (createType == 1) { // omok mini game
if (chr.getChalkboard() != null || FieldLimit.CANNOTMINIGAME.check(chr.getMap().getFieldLimit())) {
return;
}
String desc = slea.readMapleAsciiString();
slea.readByte(); // 20 6E 4E
int type = slea.readByte(); // 20 6E 4E
MapleMiniGame game = new MapleMiniGame(chr, desc);
chr.setMiniGame(game);
game.setPieceType(type);
game.setGameType("omok");
chr.getMap().addMapObject(game);
chr.getMap().broadcastMessage(MaplePacketCreator.addOmokBox(chr, 1, 0));
game.sendOmok(c, type);
} else if (createType == 2) { // matchcard
if (chr.getChalkboard() != null) {
return;
}
String desc = slea.readMapleAsciiString();
slea.readByte(); // 20 6E 4E
int type = slea.readByte(); // 20 6E 4E
MapleMiniGame game = new MapleMiniGame(chr, desc);
game.setPieceType(type);
if (type == 0) {
game.setMatchesToWin(6);
} else if (type == 1) {
game.setMatchesToWin(10);
} else if (type == 2) {
game.setMatchesToWin(15);
}
game.setGameType("matchcard");
chr.setMiniGame(game);
chr.getMap().addMapObject(game);
chr.getMap().broadcastMessage(MaplePacketCreator.addMatchCardBox(chr, 1, 0));
game.sendMatchCard(c, type);
} else if (createType == 4 || createType == 5) { // shop
if (!chr.getMap().getMapObjectsInRange(chr.getPosition(), 23000, Arrays.asList(MapleMapObjectType.SHOP, MapleMapObjectType.HIRED_MERCHANT)).isEmpty()) {
return;
}
String desc = slea.readMapleAsciiString();
slea.skip(3);
int itemId = slea.readInt();
if (chr.getInventory(MapleInventoryType.CASH).countById(itemId) < 1) {
return;
}
if (chr.getMapId() > 910000000 && chr.getMapId() < 910000023 || itemId > 5030000 && itemId < 5030012 || itemId > 5140000 && itemId < 5140006) {
if (createType == 4) {
MaplePlayerShop shop = new MaplePlayerShop(c.getPlayer(), desc);
chr.setPlayerShop(shop);
chr.getMap().addMapObject(shop);
shop.sendShop(c);
c.announce(MaplePacketCreator.getPlayerShopRemoveVisitor(1));
} else {
HiredMerchant merchant = new HiredMerchant(chr, itemId, desc);
chr.setHiredMerchant(merchant);
chr.getClient().getChannelServer().addHiredMerchant(chr.getId(), merchant);
chr.announce(MaplePacketCreator.getHiredMerchant(chr, merchant, true));
}
}
}
} else if (mode == Action.INVITE.getCode()) {
int otherPlayer = slea.readInt();
if (chr.getId() == chr.getMap().getCharacterById(otherPlayer).getId()) {
return;
}
MapleTrade.inviteTrade(chr, chr.getMap().getCharacterById(otherPlayer));
} else if (mode == Action.DECLINE.getCode()) {
MapleTrade.declineTrade(chr);
} else if (mode == Action.VISIT.getCode()) {
if (chr.getTrade() != null && chr.getTrade().getPartner() != null) {
if (!chr.getTrade().isFullTrade() && !chr.getTrade().getPartner().isFullTrade()) {
MapleTrade.visitTrade(chr, chr.getTrade().getPartner().getChr());
} else {
c.announce(MaplePacketCreator.enableActions()); //Ill be nice and not dc u
return;
}
} else {
int oid = slea.readInt();
MapleMapObject ob = chr.getMap().getMapObject(oid);
if (ob instanceof MaplePlayerShop) {
MaplePlayerShop shop = (MaplePlayerShop) ob;
if (shop.isBanned(chr.getName())) {
chr.dropMessage(1, "You have been banned from this store.");
return;
}
if (shop.hasFreeSlot() && !shop.isVisitor(c.getPlayer())) {
shop.addVisitor(c.getPlayer());
chr.setPlayerShop(shop);
shop.sendShop(c);
}
} else if (ob instanceof MapleMiniGame) {
MapleMiniGame game = (MapleMiniGame) ob;
if (game.hasFreeSlot() && !game.isVisitor(c.getPlayer())) {
game.addVisitor(c.getPlayer());
chr.setMiniGame(game);
switch (game.getGameType()) {
case "omok":
game.sendOmok(c, game.getPieceType());
break;
case "matchcard":
game.sendMatchCard(c, game.getPieceType());
break;
}
} else {
chr.getClient().announce(MaplePacketCreator.getMiniGameFull());
}
} else if (ob instanceof HiredMerchant && chr.getHiredMerchant() == null) {
HiredMerchant merchant = (HiredMerchant) ob;
if (merchant.isOwner(c.getPlayer())) {
merchant.setOpen(false);
merchant.removeAllVisitors("");
c.announce(MaplePacketCreator.getHiredMerchant(chr, merchant, false));
} else if (!merchant.isOpen()) {
chr.dropMessage(1, "This shop is in maintenance, please come by later.");
return;
} else if (merchant.getFreeSlot() == -1) {
chr.dropMessage(1, "This shop has reached it's maximum capacity, please come by later.");
return;
} else {
merchant.addVisitor(c.getPlayer());
c.announce(MaplePacketCreator.getHiredMerchant(c.getPlayer(), merchant, false));
}
chr.setHiredMerchant(merchant);
}
}
} else if (mode == Action.CHAT.getCode()) { // chat lol
HiredMerchant merchant = chr.getHiredMerchant();
if (chr.getTrade() != null) {
chr.getTrade().chat(slea.readMapleAsciiString());
} else if (chr.getPlayerShop() != null) { //mini game
MaplePlayerShop shop = chr.getPlayerShop();
if (shop != null) {
shop.chat(c, slea.readMapleAsciiString());
}
} else if (chr.getMiniGame() != null) {
MapleMiniGame game = chr.getMiniGame();
if (game != null) {
game.chat(c, slea.readMapleAsciiString());
}
} else if (merchant != null) {
String message = chr.getName() + " : " + slea.readMapleAsciiString();
byte slot = (byte) (merchant.getVisitorSlot(c.getPlayer()) + 1);
merchant.getMessages().add(new Pair<>(message, slot));
merchant.broadcastToVisitors(MaplePacketCreator.hiredMerchantChat(message, slot));
}
} else if (mode == Action.EXIT.getCode()) {
if (chr.getTrade() != null) {
MapleTrade.cancelTrade(c.getPlayer());
} else {
MaplePlayerShop shop = chr.getPlayerShop();
MapleMiniGame game = chr.getMiniGame();
HiredMerchant merchant = chr.getHiredMerchant();
if (shop != null) {
if (shop.isOwner(c.getPlayer())) {
for (MaplePlayerShopItem mpsi : shop.getItems()) {
if (mpsi.getBundles() > 2) {
Item iItem = mpsi.getItem().copy();
iItem.setQuantity((short) (mpsi.getBundles() * iItem.getQuantity()));
MapleInventoryManipulator.addFromDrop(c, iItem, false);
} else if (mpsi.isExist()) {
MapleInventoryManipulator.addFromDrop(c, mpsi.getItem(), true);
}
}
chr.getMap().broadcastMessage(MaplePacketCreator.removeCharBox(c.getPlayer()));
shop.removeVisitors();
} else {
shop.removeVisitor(c.getPlayer());
}
chr.setPlayerShop(null);
} else if (game != null) {
chr.setMiniGame(null);
if (game.isOwner(c.getPlayer())) {
chr.getMap().broadcastMessage(MaplePacketCreator.removeCharBox(c.getPlayer()));
game.broadcastToVisitor(MaplePacketCreator.getMiniGameClose());
} else {
game.removeVisitor(c.getPlayer());
}
} else if (merchant != null) {
merchant.removeVisitor(c.getPlayer());
chr.setHiredMerchant(null);
}
}
} else if (mode == Action.OPEN.getCode()) {
MaplePlayerShop shop = chr.getPlayerShop();
HiredMerchant merchant = chr.getHiredMerchant();
if (shop != null && shop.isOwner(c.getPlayer())) {
slea.readByte();//01
chr.getMap().broadcastMessage(MaplePacketCreator.addCharBox(c.getPlayer(), 4));
} else if (merchant != null && merchant.isOwner(c.getPlayer())) {
chr.setHasMerchant(true);
merchant.setOpen(true);
chr.getMap().addMapObject(merchant);
chr.setHiredMerchant(null);
chr.getMap().broadcastMessage(MaplePacketCreator.spawnHiredMerchant(merchant));
slea.readByte();
}
} else if (mode == Action.READY.getCode()) {
MapleMiniGame game = chr.getMiniGame();
game.broadcast(MaplePacketCreator.getMiniGameReady(game));
} else if (mode == Action.UN_READY.getCode()) {
MapleMiniGame game = chr.getMiniGame();
game.broadcast(MaplePacketCreator.getMiniGameUnReady(game));
} else if (mode == Action.START.getCode()) {
MapleMiniGame game = chr.getMiniGame();
if (game.getGameType().equals("omok")) {
game.broadcast(MaplePacketCreator.getMiniGameStart(game, game.getLoser()));
chr.getMap().broadcastMessage(MaplePacketCreator.addOmokBox(game.getOwner(), 2, 1));
}
if (game.getGameType().equals("matchcard")) {
game.shuffleList();
game.broadcast(MaplePacketCreator.getMatchCardStart(game, game.getLoser()));
chr.getMap().broadcastMessage(MaplePacketCreator.addMatchCardBox(game.getOwner(), 2, 1));
}
} else if (mode == Action.GIVE_UP.getCode()) {
MapleMiniGame game = chr.getMiniGame();
if (game.getGameType().equals("omok")) {
if (game.isOwner(c.getPlayer())) {
game.broadcast(MaplePacketCreator.getMiniGameOwnerForfeit(game));
} else {
game.broadcast(MaplePacketCreator.getMiniGameVisitorForfeit(game));
}
}
if (game.getGameType().equals("matchcard")) {
if (game.isOwner(c.getPlayer())) {
game.broadcast(MaplePacketCreator.getMatchCardVisitorWin(game));
} else {
game.broadcast(MaplePacketCreator.getMatchCardOwnerWin(game));
}
}
} else if (mode == Action.REQUEST_TIE.getCode()) {
MapleMiniGame game = chr.getMiniGame();
if (game.isOwner(c.getPlayer())) {
game.broadcastToVisitor(MaplePacketCreator.getMiniGameRequestTie(game));
} else {
game.getOwner().getClient().announce(MaplePacketCreator.getMiniGameRequestTie(game));
}
} else if (mode == Action.ANSWER_TIE.getCode()) {
MapleMiniGame game = chr.getMiniGame();
slea.readByte();
if (game.getGameType().equals("omok")) {
game.broadcast(MaplePacketCreator.getMiniGameTie(game));
}
if (game.getGameType().equals("matchcard")) {
game.broadcast(MaplePacketCreator.getMatchCardTie(game));
}
} else if (mode == Action.SKIP.getCode()) {
MapleMiniGame game = chr.getMiniGame();
if (game.isOwner(c.getPlayer())) {
game.broadcast(MaplePacketCreator.getMiniGameSkipOwner(game));
} else {
game.broadcast(MaplePacketCreator.getMiniGameSkipVisitor(game));
}
} else if (mode == Action.MOVE_OMOK.getCode()) {
int x = slea.readInt(); // x point
int y = slea.readInt(); // y point
int type = slea.readByte(); // piece ( 1 or 2; Owner has one piece, visitor has another, it switches every game.)
chr.getMiniGame().setPiece(x, y, type, c.getPlayer());
} else if (mode == Action.SELECT_CARD.getCode()) {
int turn = slea.readByte(); // 1st turn = 1; 2nd turn = 0
int slot = slea.readByte(); // slot
MapleMiniGame game = chr.getMiniGame();
int firstslot = game.getFirstSlot();
if (turn == 1) {
game.setFirstSlot(slot);
if (game.isOwner(c.getPlayer())) {
game.broadcastToVisitor(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, turn));
} else {
game.getOwner().getClient().announce(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, turn));
}
} else if ((game.getCardId(firstslot + 1)) == (game.getCardId(slot + 1))) {
if (game.isOwner(c.getPlayer())) {
game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 2));
game.setOwnerPoints();
} else {
game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 3));
game.setVisitorPoints();
}
} else if (game.isOwner(c.getPlayer())) {
game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 0));
} else {
game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 1));
}
} else if (mode == Action.SET_MESO.getCode()) {
chr.getTrade().setMeso(slea.readInt());
} else if (mode == Action.SET_ITEMS.getCode()) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
MapleInventoryType ivType = MapleInventoryType.getByType(slea.readByte());
Item item = chr.getInventory(ivType).getItem(slea.readShort());
short quantity = slea.readShort();
byte targetSlot = slea.readByte();
if (quantity < 1 || quantity > item.getQuantity()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (chr.getTrade() != null) {
if ((quantity <= item.getQuantity() && quantity >= 0) || ItemConstants.isRechargable(item.getItemId())) {
if (ii.isDropRestricted(item.getItemId())) { // ensure that undroppable items do not make it to the trade window
if (!((item.getFlag() & ItemConstants.KARMA) == ItemConstants.KARMA || (item.getFlag() & ItemConstants.SPIKES) == ItemConstants.SPIKES)) {
c.announce(MaplePacketCreator.enableActions());
return;
}
}
Item tradeItem = item.copy();
if (ItemConstants.isRechargable(item.getItemId())) {
tradeItem.setQuantity(item.getQuantity());
MapleInventoryManipulator.removeFromSlot(c, ivType, item.getPosition(), item.getQuantity(), true);
} else {
tradeItem.setQuantity(quantity);
MapleInventoryManipulator.removeFromSlot(c, ivType, item.getPosition(), quantity, true);
}
tradeItem.setPosition(targetSlot);
chr.getTrade().addItem(tradeItem);
}
}
} else if (mode == Action.CONFIRM.getCode()) {
MapleTrade.completeTrade(c.getPlayer());
} else if (mode == Action.ADD_ITEM.getCode() || mode == Action.PUT_ITEM.getCode()) {
MapleInventoryType type = MapleInventoryType.getByType(slea.readByte());
short slot = slea.readShort();
short bundles = slea.readShort();
if (chr.getInventory(type).getItem(slot) == null || chr.getItemQuantity(chr.getInventory(type).getItem(slot).getItemId(), false) < bundles || chr.getInventory(type).getItem(slot).getFlag() == ItemConstants.UNTRADEABLE) {
return;
}
short perBundle = slea.readShort();
int price = slea.readInt();
if (perBundle <= 0 || perBundle * bundles > 2000 || bundles <= 0 || price <= 0 || price > Integer.MAX_VALUE) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with hired merchants.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " might of possibly packet edited Hired Merchants\nperBundle: " + perBundle + "\nperBundle * bundles (This multiplied cannot be greater than 2000): " + perBundle * bundles + "\nbundles: " + bundles + "\nprice: " + price);
return;
}
Item ivItem = chr.getInventory(type).getItem(slot);
Item sellItem = ivItem.copy();
if (chr.getItemQuantity(ivItem.getItemId(), false) < perBundle * bundles) {
return;
}
sellItem.setQuantity(perBundle);
MaplePlayerShopItem item = new MaplePlayerShopItem(sellItem, bundles, price);
MaplePlayerShop shop = chr.getPlayerShop();
HiredMerchant merchant = chr.getHiredMerchant();
if (shop != null && shop.isOwner(c.getPlayer())) {
if (ivItem != null && ivItem.getQuantity() >= bundles * perBundle) {
shop.addItem(item);
c.announce(MaplePacketCreator.getPlayerShopItemUpdate(shop));
}
} else if (merchant != null && merchant.isOwner(c.getPlayer())) {
merchant.addItem(item);
c.announce(MaplePacketCreator.updateHiredMerchant(merchant, c.getPlayer()));
}
if (ItemConstants.isRechargable(ivItem.getItemId())) {
MapleInventoryManipulator.removeFromSlot(c, type, slot, ivItem.getQuantity(), true);
} else {
MapleInventoryManipulator.removeFromSlot(c, type, slot, (short) (bundles * perBundle), true);
}
} else if (mode == Action.REMOVE_ITEM.getCode()) {
MaplePlayerShop shop = chr.getPlayerShop();
if (shop != null && shop.isOwner(c.getPlayer())) {
int slot = slea.readShort();
if (slot >= shop.getItems().size() || slot < 0) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with a player shop.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to remove item at slot " + slot + "\r\n");
c.disconnect(true, false);
return;
}
MaplePlayerShopItem item = shop.getItems().get(slot);
Item ivItem = item.getItem().copy();
shop.removeItem(slot);
ivItem.setQuantity(item.getBundles());
MapleInventoryManipulator.addFromDrop(c, ivItem, false);
c.announce(MaplePacketCreator.getPlayerShopItemUpdate(shop));
}
} else if (mode == Action.MERCHANT_MESO.getCode()) {//Hmmmm
/*if (!chr.getHiredMerchant().isOwner(chr) || chr.getMerchantMeso() < 1) return;
int possible = Integer.MAX_VALUE - chr.getMerchantMeso();
if (possible > 0) {
if (possible < chr.getMerchantMeso()) {
chr.gainMeso(possible, false);
chr.setMerchantMeso(chr.getMerchantMeso() - possible);
} else {
chr.gainMeso(chr.getMerchantMeso(), false);
chr.setMerchantMeso(0);
}
c.announce(MaplePacketCreator.updateHiredMerchant(chr.getHiredMerchant(), chr));
}*/
} else if (mode == Action.MERCHANT_ORGANIZE.getCode()) {
HiredMerchant merchant = chr.getHiredMerchant();
if (!merchant.isOwner(chr)) return;
if (chr.getMerchantMeso() > 0) {
int possible = Integer.MAX_VALUE - chr.getMerchantMeso();
if (possible > 0) {
if (possible < chr.getMerchantMeso()) {
chr.gainMeso(possible, false);
chr.setMerchantMeso(chr.getMerchantMeso() - possible);
} else {
chr.gainMeso(chr.getMerchantMeso(), false);
chr.setMerchantMeso(0);
}
}
}
for (int i = 0; i < merchant.getItems().size(); i++) {
if (!merchant.getItems().get(i).isExist()) merchant.removeFromSlot(i);
}
if (merchant.getItems().isEmpty()) {
c.announce(MaplePacketCreator.hiredMerchantOwnerLeave());
c.announce(MaplePacketCreator.leaveHiredMerchant(0x00, 0x03));
merchant.closeShop(c, false);
chr.setHasMerchant(false);
return;
}
c.announce(MaplePacketCreator.updateHiredMerchant(merchant, chr));
} else if (mode == Action.BUY.getCode() || mode == Action.MERCHANT_BUY.getCode()) {
int item = slea.readByte();
short quantity = slea.readShort();
if (quantity < 1) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with a hired merchant and or player shop.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to buy item " + item + " with quantity " + quantity + "\r\n");
c.disconnect(true, false);
return;
}
MaplePlayerShop shop = chr.getPlayerShop();
HiredMerchant merchant = chr.getHiredMerchant();
if (merchant != null && merchant.getOwner().equals(chr.getName())) {
return;
}
if (shop != null && shop.isVisitor(c.getPlayer())) {
shop.buy(c, item, quantity);
shop.broadcast(MaplePacketCreator.getPlayerShopItemUpdate(shop));
} else if (merchant != null) {
merchant.buy(c, item, quantity);
merchant.broadcastToVisitors(MaplePacketCreator.updateHiredMerchant(merchant, c.getPlayer()));
}
} else if (mode == Action.TAKE_ITEM_BACK.getCode()) {
HiredMerchant merchant = chr.getHiredMerchant();
if (merchant != null && merchant.isOwner(c.getPlayer())) {
int slot = slea.readShort();
MaplePlayerShopItem item = merchant.getItems().get(slot);
if (!MapleInventory.checkSpot(chr, item.getItem())) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (item.getBundles() > 0) {
Item iitem = item.getItem();
iitem.setQuantity((short) (item.getItem().getQuantity() * item.getBundles()));
MapleInventoryManipulator.addFromDrop(c, iitem, true);
}
merchant.removeFromSlot(slot);
c.announce(MaplePacketCreator.updateHiredMerchant(merchant, c.getPlayer()));
}
} else if (mode == Action.CLOSE_MERCHANT.getCode()) {
HiredMerchant merchant = chr.getHiredMerchant();
if (merchant != null && merchant.isOwner(c.getPlayer())) {
c.announce(MaplePacketCreator.hiredMerchantOwnerLeave());
c.announce(MaplePacketCreator.leaveHiredMerchant(0x00, 0x03));
merchant.closeShop(c, false);
chr.setHasMerchant(false);
}
} else if (mode == Action.MAINTENANCE_OFF.getCode()) {
HiredMerchant merchant = chr.getHiredMerchant();
if (merchant.getItems().isEmpty() && merchant.isOwner(c.getPlayer())) {
merchant.closeShop(c, false);
chr.setHasMerchant(false);
}
if (merchant != null && merchant.isOwner(c.getPlayer())) {
merchant.getMessages().clear();
merchant.setOpen(true);
}
chr.setHiredMerchant(null);
c.announce(MaplePacketCreator.enableActions());
} else if (mode == Action.BAN_PLAYER.getCode()) {
if (chr.getPlayerShop() != null && chr.getPlayerShop().isOwner(c.getPlayer())) {
chr.getPlayerShop().banPlayer(slea.readMapleAsciiString());
}
}
}
}

View File

@@ -0,0 +1,261 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import net.AbstractMaplePacketHandler;
import net.server.PlayerBuffValueHolder;
import net.server.Server;
import net.server.channel.Channel;
import net.server.channel.CharacterIdChannelPair;
import net.server.guild.MapleAlliance;
import net.server.guild.MapleGuild;
import net.server.world.MaplePartyCharacter;
import net.server.world.PartyOperation;
import net.server.world.World;
import tools.DatabaseConnection;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import client.BuddylistEntry;
import client.CharacterNameAndId;
import client.MapleCharacter;
import client.MapleClient;
import client.MapleFamily;
import client.SkillFactory;
import client.inventory.MapleInventoryType;
import client.inventory.MaplePet;
import client.inventory.PetDataFactory;
import constants.GameConstants;
import server.TimerManager;
public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
@Override
public final boolean validateState(MapleClient c) {
return !c.isLoggedIn();
}
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
final int cid = slea.readInt();
final Server server = Server.getInstance();
MapleCharacter player = c.getWorldServer().getPlayerStorage().getCharacterById(cid);
boolean newcomer = false;
if (player == null) {
try {
player = MapleCharacter.loadCharFromDB(cid, c, true);
newcomer = true;
} catch (SQLException e) {
e.printStackTrace();
}
} else {
player.newClient(c);
}
if (player == null) { //If you are still getting null here then please just uninstall the game >.>, we dont need you fucking with the logs
c.disconnect(true, false);
return;
}
c.setPlayer(player);
c.setAccID(player.getAccountID());
int state = c.getLoginState();
boolean allowLogin = true;
Channel cserv = c.getChannelServer();
if (state == MapleClient.LOGIN_SERVER_TRANSITION || state == MapleClient.LOGIN_NOTLOGGEDIN) {
for (String charName : c.loadCharacterNames(c.getWorld())) {
for (Channel ch : c.getWorldServer().getChannels()) {
if (ch.isConnected(charName)) {
allowLogin = false;
}
}
break;
}
}
if (state != MapleClient.LOGIN_SERVER_TRANSITION || !allowLogin) {
c.setPlayer(null);
c.announce(MaplePacketCreator.getAfterLoginError(7));
return;
}
c.updateLoginState(MapleClient.LOGIN_LOGGEDIN);
cserv.addPlayer(player);
List<PlayerBuffValueHolder> buffs = server.getPlayerBuffStorage().getBuffsFromStorage(cid);
if (buffs != null) {
player.silentGiveBuffs(buffs);
}
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = null;
PreparedStatement pss = null;
ResultSet rs = null;
try {
ps = con.prepareStatement("SELECT Mesos FROM dueypackages WHERE RecieverId = ? and Checked = 1");
ps.setInt(1, player.getId());
rs = ps.executeQuery();
if (rs.next()) {
try {
pss = DatabaseConnection.getConnection().prepareStatement("UPDATE dueypackages SET Checked = 0 where RecieverId = ?");
pss.setInt(1, player.getId());
pss.executeUpdate();
pss.close();
} catch (SQLException e) {
}
c.announce(MaplePacketCreator.sendDueyMSG((byte) 0x1B));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
}
if (pss != null) {
pss.close();
}
if (ps != null) {
ps.close();
}
} catch (SQLException ex) {
//ignore
ex.printStackTrace();
}
}
c.announce(MaplePacketCreator.getCharInfo(player));
if (!player.isHidden()) {
player.toggleHide(true);
}
player.sendKeymap();
player.sendMacros();
if(player.getKeymap().get(91) != null)
player.announce(MaplePacketCreator.sendAutoHpPot(player.getKeymap().get(91).getAction()));
if(player.getKeymap().get(92) != null)
player.announce(MaplePacketCreator.sendAutoMpPot(player.getKeymap().get(92).getAction()));
player.getMap().addPlayer(player);
World world = server.getWorld(c.getWorld());
world.getPlayerStorage().addPlayer(player);
int buddyIds[] = player.getBuddylist().getBuddyIds();
world.loggedOn(player.getName(), player.getId(), c.getChannel(), buddyIds);
for (CharacterIdChannelPair onlineBuddy : server.getWorld(c.getWorld()).multiBuddyFind(player.getId(), buddyIds)) {
BuddylistEntry ble = player.getBuddylist().get(onlineBuddy.getCharacterId());
ble.setChannel(onlineBuddy.getChannel());
player.getBuddylist().put(ble);
}
c.announce(MaplePacketCreator.updateBuddylist(player.getBuddylist().getBuddies()));
c.announce(MaplePacketCreator.loadFamily(player));
if (player.getFamilyId() > 0) {
MapleFamily f = world.getFamily(player.getFamilyId());
if (f == null) {
f = new MapleFamily(player.getId());
world.addFamily(player.getFamilyId(), f);
}
player.setFamily(f);
c.announce(MaplePacketCreator.getFamilyInfo(f.getMember(player.getId())));
}
if (player.getGuildId() > 0) {
MapleGuild playerGuild = server.getGuild(player.getGuildId(), player.getWorld(), player.getMGC());
if (playerGuild == null) {
player.deleteGuild(player.getGuildId());
player.resetMGC();
player.setGuildId(0);
} else {
server.setGuildMemberOnline(player.getMGC(), true, c.getChannel());
c.announce(MaplePacketCreator.showGuildInfo(player));
int allianceId = player.getGuild().getAllianceId();
if (allianceId > 0) {
MapleAlliance newAlliance = server.getAlliance(allianceId);
if (newAlliance == null) {
newAlliance = MapleAlliance.loadAlliance(allianceId);
if (newAlliance != null) {
server.addAlliance(allianceId, newAlliance);
} else {
player.getGuild().setAllianceId(0);
}
}
if (newAlliance != null) {
c.announce(MaplePacketCreator.getAllianceInfo(newAlliance));
c.announce(MaplePacketCreator.getGuildAlliances(newAlliance, c));
server.allianceMessage(allianceId, MaplePacketCreator.allianceMemberOnline(player, true), player.getId(), -1);
}
}
}
}
player.showNote();
if (player.getParty() != null) {
MaplePartyCharacter pchar = player.getMPC();
pchar.setChannel(c.getChannel());
pchar.setMapId(player.getMapId());
pchar.setOnline(true);
world.updateParty(player.getParty().getId(), PartyOperation.LOG_ONOFF, pchar);
}
player.updatePartyMemberHP();
if (player.getInventory(MapleInventoryType.EQUIPPED).findById(1122017) != null) {
player.equipPendantOfSpirit();
}
c.announce(MaplePacketCreator.updateBuddylist(player.getBuddylist().getBuddies()));
CharacterNameAndId pendingBuddyRequest = c.getPlayer().getBuddylist().pollPendingRequest();
if (pendingBuddyRequest != null) {
c.announce(MaplePacketCreator.requestBuddylistAdd(pendingBuddyRequest.getId(), c.getPlayer().getId(), pendingBuddyRequest.getName()));
}
if(newcomer) {
for(MaplePet pet : player.getPets()) {
if(pet != null)
player.startFullnessSchedule(PetDataFactory.getHunger(pet.getItemId()), pet, player.getPetIndex(pet));
}
}
c.announce(MaplePacketCreator.updateGender(player));
player.checkMessenger();
c.announce(MaplePacketCreator.enableReport());
player.changeSkillLevel(SkillFactory.getSkill(10000000 * player.getJobType() + 12), (byte) (player.getLinkedLevel() / 10), 20, -1);
player.checkBerserk();
player.expirationTask();
//player.setRates();
if (GameConstants.hasSPTable(player.getJob()) && player.getJob().getId() != 2001) {
player.createDragon();
}
if (newcomer){
/*
if (!c.hasVotedAlready()){
player.announce(MaplePacketCreator.earnTitleMessage("You can vote now! Vote and earn a vote point!"));
}
*/
if (player.isGM()){
Server.getInstance().broadcastGMMessage(MaplePacketCreator.earnTitleMessage("GM " + player.getName() + " has logged in"));
}
if (player.getMap().getHPDec() > 0) {
player.doHurtHp();
}
}
}
}

View File

@@ -0,0 +1,73 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import scripting.quest.QuestScriptManager;
import server.quest.MapleQuest;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author Matze
*/
public final class QuestActionHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
byte action = slea.readByte();
short questid = slea.readShort();
MapleCharacter player = c.getPlayer();
MapleQuest quest = MapleQuest.getInstance(questid);
if (action == 1) { //Start Quest
int npc = slea.readInt();
if (slea.available() >= 4) {
slea.readInt();
}
quest.start(player, npc);
} else if (action == 2) { // Complete Quest
int npc = slea.readInt();
slea.readInt();
if (slea.available() >= 2) {
int selection = slea.readShort();
quest.complete(player, npc, selection);
} else {
quest.complete(player, npc);
}
} else if (action == 3) {// forfeit quest
quest.forfeit(player);
} else if (action == 4) { // scripted start quest
int npc = slea.readInt();
slea.readInt();
if(quest.canStart(player, npc)) {
QuestScriptManager.getInstance().start(c, questid, npc);
}
} else if (action == 5) { // scripted end quests
//System.out.println(slea.toString());
int npc = slea.readInt();
slea.readInt();
if(quest.canComplete(player, npc)) {
QuestScriptManager.getInstance().end(c, questid, npc);
}
}
}
}

View File

@@ -0,0 +1,217 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import server.MapleStatEffect;
import server.TimerManager;
import tools.MaplePacketCreator;
import tools.Randomizer;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleBuffStat;
import client.MapleCharacter;
import client.MapleCharacter.CancelCooldownAction;
import client.MapleClient;
import client.Skill;
import client.SkillFactory;
import client.inventory.Item;
import client.inventory.MapleInventory;
import client.inventory.MapleInventoryType;
import client.inventory.MapleWeaponType;
import constants.ItemConstants;
import constants.skills.Aran;
import constants.skills.Buccaneer;
import constants.skills.NightLord;
import constants.skills.NightWalker;
import constants.skills.Shadower;
import constants.skills.ThunderBreaker;
import constants.skills.WindArcher;
public final class RangedAttackHandler extends AbstractDealDamageHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter player = c.getPlayer();
player.setPetLootCd(System.currentTimeMillis());
/*long timeElapsed = System.currentTimeMillis() - player.getAutobanManager().getLastSpam(8);
if(timeElapsed < 300) {
AutobanFactory.FAST_ATTACK.alert(player, "Time: " + timeElapsed);
}
player.getAutobanManager().spam(8);*/
AttackInfo attack = parseDamage(slea, player, true, false);
if (player.getBuffEffect(MapleBuffStat.MORPH) != null) {
if(player.getBuffEffect(MapleBuffStat.MORPH).isMorphWithoutAttack()) {
// How are they attacking when the client won't let them?
player.getClient().disconnect(false, false);
return;
}
}
if (attack.skill == Buccaneer.ENERGY_ORB || attack.skill == ThunderBreaker.SPARK || attack.skill == Shadower.TAUNT || attack.skill == NightLord.TAUNT) {
player.getMap().broadcastMessage(player, MaplePacketCreator.rangedAttack(player, attack.skill, attack.skilllevel, attack.stance, attack.numAttackedAndDamage, 0, attack.allDamage, attack.speed, attack.direction, attack.display), false);
applyAttack(attack, player, 1);
} else if (attack.skill == Aran.COMBO_SMASH || attack.skill == Aran.COMBO_PENRIL || attack.skill == Aran.COMBO_TEMPEST) {
player.getMap().broadcastMessage(player, MaplePacketCreator.rangedAttack(player, attack.skill, attack.skilllevel, attack.stance, attack.numAttackedAndDamage, 0, attack.allDamage, attack.speed, attack.direction, attack.display), false);
if (attack.skill == Aran.COMBO_SMASH && player.getCombo() >= 30) {
player.setCombo((short) 0);
applyAttack(attack, player, 1);
} else if (attack.skill == Aran.COMBO_PENRIL && player.getCombo() >= 100) {
player.setCombo((short) 0);
applyAttack(attack, player, 2);
} else if (attack.skill == Aran.COMBO_TEMPEST && player.getCombo() >= 200) {
player.setCombo((short) 0);
applyAttack(attack, player, 4);
}
} else {
Item weapon = player.getInventory(MapleInventoryType.EQUIPPED).getItem((short) -11);
MapleWeaponType type = MapleItemInformationProvider.getInstance().getWeaponType(weapon.getItemId());
if (type == MapleWeaponType.NOT_A_WEAPON) {
return;
}
short slot = -1;
int projectile = 0;
byte bulletCount = 1;
MapleStatEffect effect = null;
if (attack.skill != 0) {
effect = attack.getAttackEffect(player, null);
bulletCount = effect.getBulletCount();
if (effect.getCooldown() > 0) {
c.announce(MaplePacketCreator.skillCooldown(attack.skill, effect.getCooldown()));
}
}
boolean hasShadowPartner = player.getBuffedValue(MapleBuffStat.SHADOWPARTNER) != null;
if (hasShadowPartner) {
bulletCount *= 2;
}
MapleInventory inv = player.getInventory(MapleInventoryType.USE);
for (short i = 1; i <= inv.getSlotLimit(); i++) {
Item item = inv.getItem(i);
if (item != null) {
int id = item.getItemId();
slot = item.getPosition();
boolean bow = ItemConstants.isArrowForBow(id);
boolean cbow = ItemConstants.isArrowForCrossBow(id);
if (item.getQuantity() >= bulletCount) { //Fixes the bug where you can't use your last arrow.
if (type == MapleWeaponType.CLAW && ItemConstants.isThrowingStar(id) && weapon.getItemId() != 1472063) {
if (((id == 2070007 || id == 2070018) && player.getLevel() < 70) || (id == 2070016 && player.getLevel() < 50)) {
} else {
projectile = id;
break;
}
} else if ((type == MapleWeaponType.GUN && ItemConstants.isBullet(id))) {
if (id == 2331000 && id == 2332000) {
if (player.getLevel() > 69) {
projectile = id;
break;
}
} else if (player.getLevel() > (id % 10) * 20 + 9) {
projectile = id;
break;
}
} else if ((type == MapleWeaponType.BOW && bow) || (type == MapleWeaponType.CROSSBOW && cbow) || (weapon.getItemId() == 1472063 && (bow || cbow))) {
projectile = id;
break;
}
}
}
}
boolean soulArrow = player.getBuffedValue(MapleBuffStat.SOULARROW) != null;
boolean shadowClaw = player.getBuffedValue(MapleBuffStat.SHADOW_CLAW) != null;
if (projectile != 0) {
if (!soulArrow && !shadowClaw && attack.skill != 11101004 && attack.skill != 15111007 && attack.skill != 14101006) {
byte bulletConsume = bulletCount;
if (effect != null && effect.getBulletConsume() != 0) {
bulletConsume = (byte) (effect.getBulletConsume() * (hasShadowPartner ? 2 : 1));
}
if(slot < 0) System.out.println("<ERROR> Projectile to use was unable to be found.");
else MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, bulletConsume, false, true);
}
}
if (projectile != 0 || soulArrow || attack.skill == 11101004 || attack.skill == 15111007 || attack.skill == 14101006) {
int visProjectile = projectile; //visible projectile sent to players
if (ItemConstants.isThrowingStar(projectile)) {
MapleInventory cash = player.getInventory(MapleInventoryType.CASH);
for (int i = 1; i <= cash.getSlotLimit(); i++) { // impose order...
Item item = cash.getItem((short) i);
if (item != null) {
if (item.getItemId() / 1000 == 5021) {
visProjectile = item.getItemId();
break;
}
}
}
} else //bow, crossbow
if (soulArrow || attack.skill == 3111004 || attack.skill == 3211004 || attack.skill == 11101004 || attack.skill == 15111007 || attack.skill == 14101006) {
visProjectile = 0;
}
byte[] packet;
switch (attack.skill) {
case 3121004: // Hurricane
case 3221001: // Pierce
case 5221004: // Rapid Fire
case 13111002: // KoC Hurricane
packet = MaplePacketCreator.rangedAttack(player, attack.skill, attack.skilllevel, attack.rangedirection, attack.numAttackedAndDamage, visProjectile, attack.allDamage, attack.speed, attack.direction, attack.display);
break;
default:
packet = MaplePacketCreator.rangedAttack(player, attack.skill, attack.skilllevel, attack.stance, attack.numAttackedAndDamage, visProjectile, attack.allDamage, attack.speed, attack.direction, attack.display);
break;
}
player.getMap().broadcastMessage(player, packet, false, true);
if (effect != null) {
int money = effect.getMoneyCon();
if (money != 0) {
int moneyMod = money / 2;
money += Randomizer.nextInt(moneyMod);
if (money > player.getMeso()) {
money = player.getMeso();
}
player.gainMeso(-money, false);
}
}
if (attack.skill != 0) {
Skill skill = SkillFactory.getSkill(attack.skill);
MapleStatEffect effect_ = skill.getEffect(player.getSkillLevel(skill));
if (effect_.getCooldown() > 0) {
if (player.skillisCooling(attack.skill)) {
return;
} else {
c.announce(MaplePacketCreator.skillCooldown(attack.skill, effect_.getCooldown()));
player.addCooldown(attack.skill, System.currentTimeMillis(), effect_.getCooldown() * 1000, TimerManager.getInstance().schedule(new CancelCooldownAction(player, attack.skill), effect_.getCooldown() * 1000));
}
}
}
if ((player.getSkillLevel(SkillFactory.getSkill(NightWalker.VANISH)) > 0 || player.getSkillLevel(SkillFactory.getSkill(WindArcher.WIND_WALK)) > 0) && player.getBuffedValue(MapleBuffStat.DARKSIGHT) != null && attack.numAttacked > 0 && player.getBuffSource(MapleBuffStat.DARKSIGHT) != 9101004) {
player.cancelEffectFromBuffStat(MapleBuffStat.DARKSIGHT);
player.cancelBuffStats(MapleBuffStat.DARKSIGHT);
}
applyAttack(attack, player, bulletCount);
}
}
}
}

View File

@@ -0,0 +1,47 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import server.maps.MapleReactor;
import tools.data.input.SeekableLittleEndianAccessor;
/**
* @author Lerk
*/
public final class ReactorHitHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
//System.out.println(slea); //To see if there are any differences with packets
//CD 00 6B 00 00 00 01 00 00 00 03 00 00 00 20 03 F7 03 00 00
//[CD 00] [66 00 00 00] [00 00 00 00] [02 00] [00 00 19 01] [00 00 00 00]
int oid = slea.readInt();
int charPos = slea.readInt();
short stance = slea.readShort();
slea.skip(4);
int skillid = slea.readInt();
MapleReactor reactor = c.getPlayer().getMap().getReactorByOid(oid);
if (reactor != null && reactor.isAlive()) {
reactor.hitReactor(charPos, stance, skillid,c);
}
}
}

View File

@@ -0,0 +1,60 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import client.autoban.AutobanFactory;
import net.AbstractMaplePacketHandler;
import scripting.npc.NPCScriptManager;
import server.MapleItemInformationProvider;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author Generic
*/
public final class RemoteGachaponHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int ticket = slea.readInt();
int gacha = slea.readInt();
if (ticket != 5451000){
AutobanFactory.GENERAL.alert(c.getPlayer(), " Tried to use RemoteGachaponHandler with item id: " + ticket);
c.disconnect(false, false);
return;
} else if(gacha < 0 || gacha > 11) {
AutobanFactory.GENERAL.alert(c.getPlayer(), " Tried to use RemoteGachaponHandler with mode: " + gacha);
c.disconnect(false, false);
return;
} else if (c.getPlayer().getInventory(MapleItemInformationProvider.getInstance().getInventoryType(ticket)).countById(ticket) < 1) {
AutobanFactory.GENERAL.alert(c.getPlayer(), " Tried to use RemoteGachaponHandler without a ticket.");
c.disconnect(false, false);
return;
}
int npcId = 9100100;
if (gacha != 8 && gacha != 9) {
npcId += gacha;
} else {
npcId = gacha == 8 ? 9100109 : 9100117;
}
NPCScriptManager.getInstance().start(c, npcId, "gachaponRemote", null);
}
}

View File

@@ -0,0 +1,68 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleCharacter;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import net.server.channel.Channel;
import net.server.Server;
import server.maps.HiredMerchant;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
/**
*
* @author kevintjuh93 :3
*/
public class RemoteStoreHandler extends AbstractMaplePacketHandler {
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
HiredMerchant hm = getMerchant(c);
if (chr.hasMerchant() && hm != null) {
if (hm.getChannel() == chr.getClient().getChannel()) {
hm.setOpen(false);
hm.removeAllVisitors("");
chr.setHiredMerchant(hm);
chr.announce(MaplePacketCreator.getHiredMerchant(chr, hm, false));
} else {
c.announce(MaplePacketCreator.remoteChannelChange((byte) (hm.getChannel() - 1)));
}
return;
} else {
chr.dropMessage(1, "You don't have a Merchant open");
}
c.announce(MaplePacketCreator.enableActions());
}
public HiredMerchant getMerchant(MapleClient c) {
if (c.getPlayer().hasMerchant()) {
for (Channel cserv : Server.getInstance().getChannelsFromWorld(c.getWorld())) {
if (cserv.getHiredMerchants().get(c.getPlayer().getId()) != null) {
return cserv.getHiredMerchants().get(c.getPlayer().getId());
}
}
}
return null;
}
}

Some files were not shown because too many files have changed in this diff Show More