Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Block people from using megaphones!

Junior Spellweaver
Joined
Feb 23, 2008
Messages
111
Reaction score
1
Got lots of megaphone spammers on your server? This is the solution.

You can type !smegaoff [name] and it makes it so they cannot use megaphones.

You can type !smegaon [name] to let people use them again. Also, it resets once they relog, so it's not permanent.

The one limitation is that you have to be on the same channel as the person you are using the command on.

Here's the code:

--------------------------------------------------------------------------

In MapleCharacter.java, add this:
Code:
private boolean canSmega;

under this:
Code:
private int jobRankMove;


AND


Add this:
Code:
canSmega = true;

after this line:
Code:
private MapleCharacter() {


AND


Add this:
Code:
public boolean getCanSmega()
    {
        return canSmega;
    }
    
    public void setCanSmega(boolean setTo)
    {
        canSmega = setTo;
    }

after this code:
Code:
public void setLevel(int level) {
            this.level = level-1;
    }

--------------------------------------------------------------------------

In CommandProcessor.java, make sure you have this import at the top:
Code:
import net.sf.odinms.client.messages.ServernoticeMapleClientMessageCallback;


AND


Add all this code:
Code:
else if (splitted[0].equals("!smegaoff"))
            {
                MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                victim.setCanSmega(false);
                mc.dropMessage("You have disabled " + victim.getName() + "'s megaphone privilages");
                
                ServernoticeMapleClientMessageCallback cm = new ServernoticeMapleClientMessageCallback(victim.getClient());
                
                if(!(c.getPlayer().getName().equals(victim.getName())))
                {
                    cm.dropMessage("Your megaphone privilages have been disabled by a GM.");
                }
            }
            
            else if (splitted[0].equals("!smegaon"))
            {
                MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                victim.setCanSmega(true);
                mc.dropMessage("You have enabled " + victim.getName() + "'s megaphone privilages");
                
                ServernoticeMapleClientMessageCallback cm = new ServernoticeMapleClientMessageCallback(victim.getClient());
                
                if(!(c.getPlayer().getName().equals(victim.getName())))
                {
                    cm.dropMessage("Your megaphone privilages have been enabled by a GM.");
                }
            }

under this (or wherever you want if you know what you're doing):
Code:
else if (splitted[0].equals("!fakerelog")) {
                c.getSession().write(MaplePacketCreator.getCharInfo(player));
                player.getMap().removePlayer(player);
                player.getMap().addPlayer(player);
            }


--------------------------------------------------------------------------


And finally, find your net.sf.odinms.net.channel.handler.UseCashItemHandler.java, and replace it with the file I have attached to this post.



That should do it.
 

Attachments

You must be registered for see attachments list
Visit my hompage
Loyal Member
Joined
May 2, 2008
Messages
1,017
Reaction score
2
Re: [Release] Block people from using megaphones!

good job!
 
Experienced Elementalist
Joined
Apr 13, 2008
Messages
298
Reaction score
1
Re: [Release] Block people from using megaphones!

Awesome! It shouldn't be hard to make it so that if they relog it doesn't reset. Just use an SQL column
 
Junior Spellweaver
Joined
Feb 23, 2008
Messages
111
Reaction score
1
Re: [Release] Block people from using megaphones!

Awesome! It shouldn't be hard to make it so that if they relog it doesn't reset. Just use an SQL column

Yes, but then you could block them and forget, and they'd be screwed.
 
Experienced Elementalist
Joined
Apr 13, 2008
Messages
298
Reaction score
1
Re: [Release] Block people from using megaphones!

They could just let you know I guess, but you have a point.

What about using a timer?
 
Junior Spellweaver
Joined
Feb 23, 2008
Messages
111
Reaction score
1
Re: [Release] Block people from using megaphones!

If you messed around with Threads, you could get it to set to a timer.
 
Mythic Archon
Loyal Member
Joined
May 11, 2008
Messages
722
Reaction score
50
Re: [Release] Block people from using megaphones!

im getting 26 errors is anyone else getting them?
 
Junior Spellweaver
Joined
Feb 23, 2008
Messages
111
Reaction score
1
Re: [Release] Block people from using megaphones!

im getting 26 errors is anyone else getting them?

Post them here as well as uploading the code that the errors are in.
 
Mythic Archon
Loyal Member
Joined
May 11, 2008
Messages
722
Reaction score
50
Re: [Release] Block people from using megaphones!

i only get 3 now...
Code:
init:
deps-jar:
Compiling 282 source files to C:\Documents and Settings\Administrator\My Documents\NetBeansProjects\Odinms\build\classes
C:\Documents and Settings\Administrator\Desktop\UnownMS\net.sf.odinms\src\net\sf\odinms\provider\xmlwz\FileStoredPngMapleCanvas.java:14: warning: com.sun.imageio.plugins.png.PNGImageReaderSpi is Sun proprietary API and may be removed in a future release
import com.sun.imageio.plugins.png.PNGImageReaderSpi;
C:\Documents and Settings\Administrator\Desktop\UnownMS\net.sf.odinms\src\net\sf\odinms\client\MapleCharacter.java:189: cannot find symbol
symbol  : variable canSmega
location: class net.sf.odinms.client.MapleCharacter
            canSmega = true;
C:\Documents and Settings\Administrator\Desktop\UnownMS\net.sf.odinms\src\net\sf\odinms\client\MapleCharacter.java:2618: cannot find symbol
symbol  : variable canSmega
location: class net.sf.odinms.client.MapleCharacter
        return canSmega;
C:\Documents and Settings\Administrator\Desktop\UnownMS\net.sf.odinms\src\net\sf\odinms\client\MapleCharacter.java:2623: cannot find symbol
symbol  : variable canSmega
location: class net.sf.odinms.client.MapleCharacter
        canSmega = setTo;
C:\Documents and Settings\Administrator\Desktop\UnownMS\net.sf.odinms\src\net\sf\odinms\provider\xmlwz\FileStoredPngMapleCanvas.java:47: warning: com.sun.imageio.plugins.png.PNGImageReaderSpi is Sun proprietary API and may be removed in a future release
                        ImageReaderSpi readerSpi = iioRegistry.getServiceProviderByClass(PNGImageReaderSpi.class);
                                                                                         ^
Note: C:\Documents and Settings\Administrator\Desktop\UnownMS\net.sf.odinms\src\net\sf\odinms\client\messages\CommandProcessor.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors
2 warnings
BUILD FAILED (total time: 1 second)
Heres my MapleCharacter.Java
Code:
/*
	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.sf.odinms.client;

import java.awt.Point;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.text.NumberFormat;
import java.text.DecimalFormat;

import net.sf.odinms.client.anticheat.CheatTracker;
import net.sf.odinms.database.DatabaseConnection;
import net.sf.odinms.database.DatabaseException;
import net.sf.odinms.net.MaplePacket;
import net.sf.odinms.net.PacketProcessor;
import net.sf.odinms.net.channel.ChannelServer;
import net.sf.odinms.net.world.MapleMessenger;
import net.sf.odinms.net.world.MapleMessengerCharacter;
import net.sf.odinms.net.world.MapleParty;
import net.sf.odinms.net.world.MaplePartyCharacter;
import net.sf.odinms.net.world.PartyOperation;
import net.sf.odinms.scripting.event.EventInstanceManager;
import net.sf.odinms.server.MapleItemInformationProvider;
import net.sf.odinms.server.MaplePlayerShop;
import net.sf.odinms.server.MaplePortal;
import net.sf.odinms.server.MapleShop;
import net.sf.odinms.server.MapleStatEffect;
import net.sf.odinms.server.MapleStorage;
import net.sf.odinms.server.MapleTrade;
import net.sf.odinms.server.TimerManager;
import net.sf.odinms.server.life.MapleMonster;
import net.sf.odinms.server.maps.AbstractAnimatedMapleMapObject;
import net.sf.odinms.server.maps.MapleDoor;
import net.sf.odinms.server.maps.MapleMap;
import net.sf.odinms.server.maps.MapleMapFactory;
import net.sf.odinms.server.maps.MapleMapObject;
import net.sf.odinms.server.maps.MapleMapObjectType;
import net.sf.odinms.server.maps.MapleSummon;
import net.sf.odinms.server.maps.SavedLocationType;
import net.sf.odinms.server.quest.MapleCustomQuest;
import net.sf.odinms.server.quest.MapleQuest;
import net.sf.odinms.net.world.remote.WorldChannelInterface;
import net.sf.odinms.tools.MaplePacketCreator;
import net.sf.odinms.tools.Pair;
import net.sf.odinms.net.world.guild.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MapleCharacter extends AbstractAnimatedMapleMapObject implements InventoryContainer {
	private static Logger log = LoggerFactory.getLogger(PacketProcessor.class);
	public static final double MAX_VIEW_RANGE_SQ = 850 * 850;
	
	private int world;
	private int accountid;
	
	private int rank;
	private int rankMove;
	private int jobRank;
	private int jobRankMove;
	private boolean cansmega;
	private String name;
	private int level;
        //pvp
        private int pvpkills;
        private int pvpdeaths;
	private int str, dex, luk, int_;
	private AtomicInteger exp = new AtomicInteger();
	private int hp, maxhp;
	private int mp, maxmp;
	private int mpApUsed, hpApUsed;
	private int hair, face;
	private AtomicInteger meso = new AtomicInteger();
	private int remainingAp, remainingSp;
	
	private int savedLocations[];

	private int fame;
	private long lastfametime;
	private List<Integer> lastmonthfameids;

	// local stats represent current stats of the player to avoid expensive operations
	private transient int localmaxhp, localmaxmp;
	private transient int localstr, localdex, localluk, localint_;
	private transient int magic, watk;
	private transient double speedMod, jumpMod;
	private transient int localmaxbasedamage;

	private int id;
	private MapleClient client;
	private MapleMap map;
	private int initialSpawnPoint;
	// mapid is only used when calling getMapId() with map == null, it is not updated when running in channelserver mode
	private int mapid;
	private MapleShop shop = null;
	private MaplePlayerShop playerShop = null;
	private MapleStorage storage = null;
	private MaplePet pet = null;
	private MapleTrade trade = null;

	private MapleSkinColor skinColor = MapleSkinColor.NORMAL;
	private MapleJob job = MapleJob.BEGINNER;
	private int gender;
	private boolean gm;
	private boolean hidden;
	private boolean canDoor = true;
	
	private int chair;
	private int itemEffect;
	
        Calendar cal = Calendar.getInstance();
	private long lastJQ = cal.getTimeInMillis();;
	private long time;
	
	private MapleParty party;
	private EventInstanceManager eventInstance = null;

	private MapleInventory[] inventory;
	private Map<MapleQuest, MapleQuestStatus> quests;
	private Set<MapleMonster> controlled = new LinkedHashSet<MapleMonster>();
	private Set<MapleMapObject> visibleMapObjects = new LinkedHashSet<MapleMapObject>();
	private Map<ISkill, SkillEntry> skills = new LinkedHashMap<ISkill, SkillEntry>();
	private Map<MapleBuffStat, MapleBuffStatValueHolder> effects = new LinkedHashMap<MapleBuffStat, MapleBuffStatValueHolder>();
	private Map<Integer, MapleKeyBinding> keymap = new LinkedHashMap<Integer, MapleKeyBinding>();
	private List<MapleDoor> doors = new ArrayList<MapleDoor>();
	private Map<Integer, MapleSummon> summons = new LinkedHashMap<Integer, MapleSummon>();
	private BuddyList buddylist;
        private ScheduledFuture<?> beholderHealingSchedule;
        private ScheduledFuture<?> beholderBuffSchedule;
	
	// anticheat related information
	private CheatTracker anticheat;
	private ScheduledFuture<?> dragonBloodSchedule;

	//guild related information
	private int guildid;
	private int guildrank;
	private MapleGuildCharacter mgc = null;

	private MapleMessenger messenger = null;
        int messengerposition = 4;

	// cash shop related information
	private int nxcash;
	private int maplepoints;
	private int gifttokens;
	private boolean incs;
	
	
	private MapleCharacter() {
            canSmega = true;
		setStance(0);
		// pet = new MaplePet(5000005, (byte) 10);
		// pet.setName("Hase");
		inventory = new MapleInventory[MapleInventoryType.values().length];
		for (MapleInventoryType type : MapleInventoryType.values()) {
			inventory[type.ordinal()] = new MapleInventory(type, (byte) 100);
		}
		
		savedLocations = new int[SavedLocationType.values().length];
		for (int i = 0; i < SavedLocationType.values().length; i++) {
			savedLocations[i] = -1;
		}
		
		quests = new LinkedHashMap<MapleQuest, MapleQuestStatus>();
		anticheat = new CheatTracker(this);
		setPosition(new Point(0, 0));
	}

	public static MapleCharacter loadCharFromDB(int charid, MapleClient client, boolean channelserver)
																										throws SQLException {
		MapleCharacter ret = new MapleCharacter();
		ret.client = client;
		ret.id = charid;

		Connection con = DatabaseConnection.getConnection();
		PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE id = ?");
		ps.setInt(1, charid);
		ResultSet rs = ps.executeQuery();
		if (!rs.next()) {
			throw new RuntimeException("Loading the Char Failed (char not found)");
		}
		ret.name = rs.getString("name");
                //pvp
                ret.pvpdeaths = rs.getInt("pvpdeaths");
                ret.pvpkills = rs.getInt("pvpkills");
		ret.level = rs.getInt("level");
		ret.fame = rs.getInt("fame");
		ret.str = rs.getInt("str");
		ret.dex = rs.getInt("dex");
		ret.int_ = rs.getInt("int");
		ret.luk = rs.getInt("luk");
		ret.exp.set(rs.getInt("exp"));

		ret.hp = rs.getInt("hp");
		ret.maxhp = rs.getInt("maxhp");
		ret.mp = rs.getInt("mp");
		ret.maxmp = rs.getInt("maxmp");

		ret.remainingSp = rs.getInt("sp");
		ret.remainingAp = rs.getInt("ap");

		ret.meso.set(rs.getInt("meso"));

		ret.gm = rs.getInt("gm") == 0 ? false : true;

		ret.skinColor = MapleSkinColor.getById(rs.getInt("skincolor"));
		ret.gender = rs.getInt("gender");
		ret.job = MapleJob.getById(rs.getInt("job"));

		ret.hair = rs.getInt("hair");
		ret.face = rs.getInt("face");

		ret.accountid = rs.getInt("accountid");
                
		ret.mapid = rs.getInt("map");
		ret.initialSpawnPoint = rs.getInt("spawnpoint");
		ret.world = rs.getInt("world");
		
                ret.rank = rs.getInt("rank");
                ret.rankMove = rs.getInt("rankMove");
                ret.jobRank = rs.getInt("jobRank");
                ret.jobRankMove = rs.getInt("jobRankMove");

	        ret.guildid = rs.getInt("guildid");
	        ret.guildrank = rs.getInt("guildrank");
		if (ret.guildid > 0)
			ret.mgc = new MapleGuildCharacter(ret);
                   
		int buddyCapacity = rs.getInt("buddyCapacity");
		ret.buddylist = new BuddyList(buddyCapacity);
		if (channelserver) {
			MapleMapFactory mapFactory = ChannelServer.getInstance(client.getChannel()).getMapFactory();
			ret.map = mapFactory.getMap(ret.mapid);
			if (ret.map == null) { //char is on a map that doesn't exist warp it to henesys
				ret.map = mapFactory.getMap(100000000);
			}
			MaplePortal portal = ret.map.getPortal(ret.initialSpawnPoint);
			if (portal == null) {
				portal = ret.map.getPortal(0); // char is on a spawnpoint that doesn't exist - select the first spawnpoint instead
				ret.initialSpawnPoint = 0;
			}
			ret.setPosition(portal.getPosition());
			
			int partyid = rs.getInt("party");
			if (partyid >= 0) {
				try {
					MapleParty party = client.getChannelServer().getWorldInterface().getParty(partyid);
					if (party != null && party.getMemberById(ret.id) != null) {
						ret.party = party;
					}
				} catch (RemoteException e) {
					client.getChannelServer().reconnectWorld();
				}
			}
                       
                        int messengerid = rs.getInt("messengerid");
                        int position = rs.getInt("messengerposition");
                        if (messengerid > 0 && position < 4 && position > -1) {
				try {
                                        WorldChannelInterface wci = ChannelServer.getInstance(client.getChannel()).getWorldInterface();
					MapleMessenger messenger = wci.getMessenger(messengerid);
					if (messenger != null) {
						ret.messenger = messenger;
                                                ret.messengerposition = position;
					}
				} catch (RemoteException e) {
					client.getChannelServer().reconnectWorld();
				}
			}
		}

		rs.close();
		ps.close();
		
		ps = con.prepareStatement("SELECT * FROM accounts WHERE id = ?");
		ps.setInt(1, ret.accountid);
		rs = ps.executeQuery();
		while (rs.next()) {
			ret.getClient().setAccountName(rs.getString("name"));
			ret.nxcash = rs.getInt("nxCash");
			ret.maplepoints = rs.getInt("mPoints");
			ret.gifttokens = rs.getInt("gTokens");
		}
		rs.close();
		ps.close();

		String sql = "SELECT * FROM inventoryitems " + "LEFT JOIN inventoryequipment USING (inventoryitemid) "
			+ "WHERE characterid = ?";
		if (!channelserver)
			sql += " AND inventorytype = " + MapleInventoryType.EQUIPPED.getType();
		ps = con.prepareStatement(sql);
		ps.setInt(1, charid);
		// PreparedStatement itemLog = con.prepareStatement("SELECT msg FROM inventorylog WHERE inventoryitemid = ?");
		rs = ps.executeQuery();
		while (rs.next()) {
			MapleInventoryType type = MapleInventoryType.getByType((byte) rs.getInt("inventorytype"));
			// itemLog.setInt(1, rs.getInt("inventoryitemid"));
			// ResultSet rsItemLog = itemLog.executeQuery();
			// IItem logItem;
			if (type.equals(MapleInventoryType.EQUIP) || type.equals(MapleInventoryType.EQUIPPED)) {
				int itemid = rs.getInt("itemid");
				Equip equip = new Equip(itemid, (byte) rs.getInt("position"));
				equip.setOwner(rs.getString("owner"));
				equip.setQuantity((short) rs.getInt("quantity"));
				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"));
				ret.getInventory(type).addFromDB(equip);
				// logItem = equip;
			} else {
				Item item = new Item(rs.getInt("itemid"), (byte) rs.getInt("position"), (short) rs.getInt("quantity"));
				item.setOwner(rs.getString("owner"));
				ret.getInventory(type).addFromDB(item);
				// logItem = item;
			}
			// while (rsItemLog.next()) {
			// logItem.log(rsItemLog.getString("msg"), true);
			// }
			// rsItemLog.close();
		}
		rs.close();
		ps.close();
		// itemLog.close();

		if (channelserver) {
			ps = con.prepareStatement("SELECT * FROM queststatus WHERE characterid = ?");
			ps.setInt(1, charid);
			rs = ps.executeQuery();
			PreparedStatement pse = con.prepareStatement("SELECT * FROM queststatusmobs WHERE queststatusid = ?");
			while (rs.next()) {
				MapleQuest q = MapleQuest.getInstance(rs.getInt("quest"));
				MapleQuestStatus status = new MapleQuestStatus(q, MapleQuestStatus.Status.getById(rs.getInt("status")));
				long cTime = rs.getLong("time");
				if (cTime > -1)
					status.setCompletionTime(cTime * 1000);
				status.setForfeited(rs.getInt("forfeited"));
				ret.quests.put(q, status);
				pse.setInt(1, rs.getInt("queststatusid"));
				ResultSet rsMobs = pse.executeQuery();
				while (rsMobs.next()) {
					status.setMobKills(rsMobs.getInt("mob"), rsMobs.getInt("count"));
				}
				rsMobs.close();
			}
			rs.close();
			ps.close();
			pse.close();

			ps = con.prepareStatement("SELECT skillid,skilllevel,masterlevel FROM skills WHERE characterid = ?");
			ps.setInt(1, charid);
			rs = ps.executeQuery();
			while (rs.next()) {
				ret.skills.put(SkillFactory.getSkill(rs.getInt("skillid")), new SkillEntry(rs.getInt("skilllevel"), rs.getInt("masterlevel")));
			}
			rs.close();
			ps.close();

			ps = con.prepareStatement("SELECT `key`,`type`,`action` FROM keymap WHERE characterid = ?");
			ps.setInt(1, charid);
			rs = ps.executeQuery();
			while (rs.next()) {
				int key = rs.getInt("key");
				int type = rs.getInt("type");
				int action = rs.getInt("action");
				ret.keymap.put(Integer.valueOf(key), new MapleKeyBinding(type, action));
			}
			rs.close();
			ps.close();
			
			ps = con.prepareStatement("SELECT `locationtype`,`map` FROM savedlocations WHERE characterid = ?");
			ps.setInt(1, charid);
			rs = ps.executeQuery();
			while (rs.next()) {
				String locationType = rs.getString("locationtype");
				int mapid = rs.getInt("map");
				ret.savedLocations[SavedLocationType.valueOf(locationType).ordinal()] = mapid;
			}
			rs.close();
			ps.close();
			
			ps = con.prepareStatement("SELECT `characterid_to`,`when` FROM famelog WHERE characterid = ? AND DATEDIFF(NOW(),`when`) < 30");
			ps.setInt(1, charid);
			rs = ps.executeQuery();
			ret.lastfametime = 0;
			ret.lastmonthfameids = new ArrayList<Integer>(31);
			while (rs.next()) {
				ret.lastfametime = Math.max(ret.lastfametime, rs.getTimestamp("when").getTime());
				ret.lastmonthfameids.add(Integer.valueOf(rs.getInt("characterid_to")));
			}
			rs.close();
			ps.close();
			
			ret.buddylist.loadFromDb(charid);
			ret.storage = MapleStorage.loadOrCreateFromDB(ret.accountid);
		}

		// if (charid == 30000) {
		// ret.playerShop = new MaplePlayerShop(ret, "For the lulztest");
		// ret.playerShop.addItem(new MaplePlayerShopItem(ret.playerShop, new Item(4000000, (byte) 0, (short) 1),
		// (short) 80, 400));
		// }

		ret.recalcLocalStats();
		ret.silentEnforceMaxHpMp();
		return ret;
	}
	
	public static MapleCharacter getDefault (MapleClient client, int chrid) {
		MapleCharacter ret = getDefault(client);
		ret.id = chrid;
		return ret;
	}

	public static MapleCharacter getDefault(MapleClient client) {
		MapleCharacter ret = new MapleCharacter();
		ret.client = client;
		ret.hp = 50;
		ret.maxhp = 50;
		ret.mp = 50;
		ret.maxmp = 50;
		ret.map = null;
		// ret.map = ChannelServer.getInstance(client.getChannel()).getMapFactory().getMap(0);
		ret.exp.set(0);
		ret.gm = false;
		ret.job = MapleJob.BEGINNER;
		ret.meso.set(0);
		ret.level = 1;
                ret.pvpdeaths = 0;
                ret.pvpkills = 0;
		ret.accountid = client.getAccID();
		ret.buddylist = new BuddyList(25);
		ret.nxcash = 0;
		ret.maplepoints = 0;
		ret.gifttokens = 0;
		ret.incs = false;

		ret.keymap.put(Integer.valueOf(18), new MapleKeyBinding(4, 0));
		ret.keymap.put(Integer.valueOf(65), new MapleKeyBinding(6, 106));
		ret.keymap.put(Integer.valueOf(2), new MapleKeyBinding(4, 10));
		ret.keymap.put(Integer.valueOf(23), new MapleKeyBinding(4, 1));
		ret.keymap.put(Integer.valueOf(3), new MapleKeyBinding(4, 12));
		ret.keymap.put(Integer.valueOf(4), new MapleKeyBinding(4, 13));
		ret.keymap.put(Integer.valueOf(5), new MapleKeyBinding(4, 18));
		ret.keymap.put(Integer.valueOf(6), new MapleKeyBinding(4, 21));
		ret.keymap.put(Integer.valueOf(16), new MapleKeyBinding(4, 8));
		ret.keymap.put(Integer.valueOf(17), new MapleKeyBinding(4, 5));
		ret.keymap.put(Integer.valueOf(19), new MapleKeyBinding(4, 4));
		ret.keymap.put(Integer.valueOf(25), new MapleKeyBinding(4, 19));
		ret.keymap.put(Integer.valueOf(26), new MapleKeyBinding(4, 14));
		ret.keymap.put(Integer.valueOf(27), new MapleKeyBinding(4, 15));
		ret.keymap.put(Integer.valueOf(29), new MapleKeyBinding(5, 52));
		ret.keymap.put(Integer.valueOf(31), new MapleKeyBinding(4, 2));
		ret.keymap.put(Integer.valueOf(34), new MapleKeyBinding(4, 17));
		ret.keymap.put(Integer.valueOf(35), new MapleKeyBinding(4, 11));
		ret.keymap.put(Integer.valueOf(37), new MapleKeyBinding(4, 3));
		ret.keymap.put(Integer.valueOf(38), new MapleKeyBinding(4, 20));
		ret.keymap.put(Integer.valueOf(40), new MapleKeyBinding(4, 16));
		ret.keymap.put(Integer.valueOf(43), new MapleKeyBinding(4, 9));
		ret.keymap.put(Integer.valueOf(44), new MapleKeyBinding(5, 50));
		ret.keymap.put(Integer.valueOf(45), new MapleKeyBinding(5, 51));
		ret.keymap.put(Integer.valueOf(46), new MapleKeyBinding(4, 6));
		ret.keymap.put(Integer.valueOf(50), new MapleKeyBinding(4, 7));
		ret.keymap.put(Integer.valueOf(56), new MapleKeyBinding(5, 53));
		ret.keymap.put(Integer.valueOf(59), new MapleKeyBinding(6, 100));
		ret.keymap.put(Integer.valueOf(60), new MapleKeyBinding(6, 101));
		ret.keymap.put(Integer.valueOf(61), new MapleKeyBinding(6, 102));
		ret.keymap.put(Integer.valueOf(62), new MapleKeyBinding(6, 103));
		ret.keymap.put(Integer.valueOf(63), new MapleKeyBinding(6, 104));
		ret.keymap.put(Integer.valueOf(64), new MapleKeyBinding(6, 105));

		ret.recalcLocalStats();
		
		return ret;
	}

	public void saveToDB(boolean update) {
		Connection con = DatabaseConnection.getConnection();
		try {
			// clients should not be able to log back before their old state is saved (see MapleClient#getLoginState) so we are save to switch to a very low isolation level here
			con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
			// connections are thread local now, no need to
			// synchronize anymore =)
			con.setAutoCommit(false);
			PreparedStatement ps;
			if (update) {
				ps = con.prepareStatement("UPDATE characters "
					+ "SET level = ?, fame = ?, str = ?, dex = ?, luk = ?, `int` = ?, "
					+ "exp = ?, hp = ?, mp = ?, maxhp = ?, maxmp = ?, sp = ?, ap = ?, "
					+ "gm = ?, skincolor = ?, gender = ?, job = ?, hair = ?, face = ?, map = ?, "
					+ "meso = ?, hpApUsed = ?, mpApUsed = ?, spawnpoint = ?, party = ?, buddyCapacity = ?, messengerid = ?, messengerposition = ?, pvpkills = ?, pvpdeaths = ? WHERE id = ?");
			} else {
                            //31 inserts
				ps = con
					.prepareStatement("INSERT INTO characters ("
						+ "level, fame, str, dex, luk, `int`, exp, hp, mp, "
						+ "maxhp, maxmp, sp, ap, gm, skincolor, gender, job, hair, face, map, meso, hpApUsed, mpApUsed, spawnpoint, party, buddyCapacity, messengerid, messengerposition, pvpkills, pvpdeaths, accountid, name, world"
						+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
			}

			ps.setInt(1, level);
			ps.setInt(2, fame);
			ps.setInt(3, str);
			ps.setInt(4, dex);
			ps.setInt(5, luk);
			ps.setInt(6, int_);
			ps.setInt(7, exp.get());
			ps.setInt(8, hp);
			ps.setInt(9, mp);
			ps.setInt(10, maxhp);
			ps.setInt(11, maxmp);
			ps.setInt(12, remainingSp);
			ps.setInt(13, remainingAp);
			ps.setInt(14, (gm ? 1 : 0));
			ps.setInt(15, skinColor.getId());
			ps.setInt(16, gender);
			ps.setInt(17, job.getId());
			ps.setInt(18, hair);
			ps.setInt(19, face);
			if (map == null) {
				ps.setInt(20, 0);
			} else {
				ps.setInt(20, map.getId());
			}
			ps.setInt(21, meso.get());
			ps.setInt(22, hpApUsed);
			ps.setInt(23, mpApUsed);
			if (map == null) {
				ps.setInt(24, 0);
			} else {
				MaplePortal closest = map.findClosestSpawnpoint(getPosition());
				if (closest != null) {
					ps.setInt(24, closest.getId());
				} else {
					ps.setInt(24, 0);
				}
			}
			if (party != null) {
				ps.setInt(25, party.getId());
			} else {
				ps.setInt(25, -1);
			}
			ps.setInt(26, buddylist.getCapacity());
                        
                        if (messenger != null) {
                                ps.setInt(27, messenger.getId());
                                ps.setInt(28, messengerposition);
                        }
                        else {
				ps.setInt(27, 0);
                                ps.setInt(28, 4);                                
                        }
                        
			ps.setInt(29, pvpkills);
                        ps.setInt(30, pvpdeaths);

			if (update) {
				ps.setInt(31, id);
			} else {
				ps.setInt(31, accountid);
                                ps.setString(32, name);
				ps.setInt(33, world); // TODO store world somewhere ;)
			}
			int updateRows = ps.executeUpdate();
			if (!update) {
				ResultSet rs = ps.getGeneratedKeys();
				if (rs.next()) {
					this.id = rs.getInt(1);
				} else {
					throw new DatabaseException("Inserting char failed.");
				}
			} else if (updateRows < 1) {
				throw new DatabaseException("Character not in database (" + id + ")");
			}
			ps.close();

			ps = con.prepareStatement("DELETE FROM inventoryitems WHERE characterid = ?");
			ps.setInt(1, id);
			ps.executeUpdate();
			ps.close();
			ps = con.prepareStatement("INSERT INTO inventoryitems"
				+ "(characterid, itemid, inventorytype, position, quantity, owner) " + "VALUES (?, ?, ?, ?, ?, ?)");
			PreparedStatement pse = con.prepareStatement("INSERT INTO inventoryequipment "
				+ "VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
			// PreparedStatement psl = con.prepareStatement("INSERT INTO inventorylog " +
			// "VALUES (DEFAULT, ?, ?)");
			for (MapleInventory iv : inventory) {
				ps.setInt(3, iv.getType().getType());
				for (IItem item : iv.list()) {
					// ps.setInt(1, item.getId());
					ps.setInt(1, id);
					ps.setInt(2, item.getItemId());
					ps.setInt(4, item.getPosition());
					ps.setInt(5, item.getQuantity());
					ps.setString(6, item.getOwner());
					ps.executeUpdate();
					ResultSet rs = ps.getGeneratedKeys();
					int itemid;
					if (rs.next()) {
						itemid = rs.getInt(1);
					} else {
						throw new DatabaseException("Inserting char failed.");
					}
					// for (String msg : item.getLog()) {
					// psl.setInt(1, itemid);
					// psl.setString(2, msg);
					// psl.executeUpdate();
					// }

					if (iv.getType().equals(MapleInventoryType.EQUIP) ||
						iv.getType().equals(MapleInventoryType.EQUIPPED)) {
						pse.setInt(1, itemid);
						IEquip equip = (IEquip) item;
						pse.setInt(2, equip.getUpgradeSlots());
						pse.setInt(3, equip.getLevel());
						pse.setInt(4, equip.getStr());
						pse.setInt(5, equip.getDex());
						pse.setInt(6, equip.getInt());
						pse.setInt(7, equip.getLuk());
						pse.setInt(8, equip.getHp());
						pse.setInt(9, equip.getMp());
						pse.setInt(10, equip.getWatk());
						pse.setInt(11, equip.getMatk());
						pse.setInt(12, equip.getWdef());
						pse.setInt(13, equip.getMdef());
						pse.setInt(14, equip.getAcc());
						pse.setInt(15, equip.getAvoid());
						pse.setInt(16, equip.getHands());
						pse.setInt(17, equip.getSpeed());
						pse.setInt(18, equip.getJump());
						pse.executeUpdate();
					}
				}
			}
			ps.close();
			pse.close();
			// psl.close();

			deleteWhereCharacterId(con, "DELETE FROM queststatus WHERE characterid = ?");
			ps = con.prepareStatement("INSERT INTO queststatus (`queststatusid`, `characterid`, `quest`, `status`, `time`, `forfeited`) " +
				" VALUES (DEFAULT, ?, ?, ?, ?, ?)",
				Statement.RETURN_GENERATED_KEYS);
			pse = con.prepareStatement("INSERT INTO queststatusmobs VALUES (DEFAULT, ?, ?, ?)");
			ps.setInt(1, id);
			for (MapleQuestStatus q : quests.values()) {
				ps.setInt(2, q.getQuest().getId());
				ps.setInt(3, q.getStatus().getId());
				ps.setInt(4, (int) (q.getCompletionTime() / 1000));
				ps.setInt(5, q.getForfeited());
				ps.executeUpdate();
				ResultSet rs = ps.getGeneratedKeys();
				rs.next();
				for (int mob : q.getMobKills().keySet()) {
					pse.setInt(1, rs.getInt(1));
					pse.setInt(2, mob);
					pse.setInt(3, q.getMobKills(mob));
					pse.executeUpdate();
				}
				rs.close();
			}
			ps.close();
			pse.close();


			deleteWhereCharacterId(con, "DELETE FROM skills WHERE characterid = ?");
			ps = con.prepareStatement("INSERT INTO skills (characterid, skillid, skilllevel, masterlevel) VALUES (?, ?, ?, ?)");
			ps.setInt(1, id);
			for (Entry<ISkill, SkillEntry> skill : skills.entrySet()) {
				ps.setInt(2, skill.getKey().getId());
				ps.setInt(3, skill.getValue().skillevel);
                                ps.setInt(4, skill.getValue().masterlevel);
				ps.executeUpdate();
			}
			ps.close();

			deleteWhereCharacterId(con, "DELETE FROM keymap WHERE characterid = ?");
			ps = con.prepareStatement("INSERT INTO keymap (characterid, `key`, `type`, `action`) VALUES (?, ?, ?, ?)");
			ps.setInt(1, id);
			for (Entry<Integer, MapleKeyBinding> keybinding : keymap.entrySet()) {
				ps.setInt(2, keybinding.getKey().intValue());
				ps.setInt(3, keybinding.getValue().getType());
				ps.setInt(4, keybinding.getValue().getAction());
				ps.executeUpdate();
			}
			ps.close();
			
			deleteWhereCharacterId(con, "DELETE FROM savedlocations WHERE characterid = ?");
			ps = con.prepareStatement("INSERT INTO savedlocations (characterid, `locationtype`, `map`) VALUES (?, ?, ?)");
			ps.setInt(1, id);
			for (SavedLocationType savedLocationType : SavedLocationType.values()) {
				if (savedLocations[savedLocationType.ordinal()] != -1) {
					ps.setString(2, savedLocationType.name());
					ps.setInt(3, savedLocations[savedLocationType.ordinal()]);
					ps.executeUpdate();
				}
			}
			ps.close();
			
			deleteWhereCharacterId(con, "DELETE FROM buddies WHERE characterid = ? AND pending = 0");
			ps = con.prepareStatement("INSERT INTO buddies (characterid, `buddyid`, `pending`) VALUES (?, ?, 0)");
			ps.setInt(1, id);
			for (BuddylistEntry entry : buddylist.getBuddies()) {
				if (entry.isVisible()) {
					ps.setInt(2, entry.getCharacterId());
					ps.executeUpdate();
				}
			}
			ps.close();
			
			ps = con.prepareStatement("UPDATE accounts SET `nxCash` = ?, `mPoints` = ?, `gTokens` = ? WHERE id = ?");
			ps.setInt(1, nxcash);
			ps.setInt(2, maplepoints);
			ps.setInt(3, gifttokens);
			ps.setInt(4, client.getAccID());
			ps.executeUpdate();
			ps.close();

			if (storage != null) {
				storage.saveToDB();
			} else {
				MapleStorage.create(client.getAccID());
			}

			con.commit();
		} catch (Exception e) {
			log.error(MapleClient.getLogMessage(this, "[charsave] Error saving character data"), e);
			try {
				con.rollback();
			} catch (SQLException e1) {
				log.error(MapleClient.getLogMessage(this, "[charsave] Error Rolling Back"), e);
			}
		} finally {
			try {
				con.setAutoCommit(true);
				con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
			} catch (SQLException e) {
				log.error(MapleClient.getLogMessage(this, "[charsave] Error going back to autocommit mode"), e);
			}
		}
	}

	private void deleteWhereCharacterId(Connection con, String sql) throws SQLException {
		 PreparedStatement ps = con.prepareStatement(sql);
		ps.setInt(1, id);
		ps.executeUpdate();
		ps.close();
	}

	public MapleQuestStatus getQuest(MapleQuest quest) {
		if (!quests.containsKey(quest))
			return new MapleQuestStatus(quest, MapleQuestStatus.Status.NOT_STARTED);
		return quests.get(quest);
	}

	public void updateQuest(MapleQuestStatus quest) {
		quests.put(quest.getQuest(), quest);
		if (!(quest.getQuest() instanceof MapleCustomQuest)) {
			if (quest.getStatus().equals(MapleQuestStatus.Status.STARTED)) {
				client.getSession().write(MaplePacketCreator.startQuest(this, (short) quest.getQuest().getId()));
				client.getSession().write(MaplePacketCreator.updateQuestInfo(this, (short) quest.getQuest().getId(), quest.getNpc(), (byte) 6));
			} else if (quest.getStatus().equals(MapleQuestStatus.Status.COMPLETED)) {
				client.getSession().write(MaplePacketCreator.completeQuest(this, (short) quest.getQuest().getId()));
			} else if (quest.getStatus().equals(MapleQuestStatus.Status.NOT_STARTED)) {
				client.getSession().write(MaplePacketCreator.forfeitQuest(this, (short) quest.getQuest().getId()));
			}
		}
	}

	public static int getIdByName(String name, int world) {
		Connection con = DatabaseConnection.getConnection();
		PreparedStatement ps;
		try {
			ps = con.prepareStatement("SELECT id FROM characters WHERE name = ? AND world = ?");
			ps.setString(1, name);
			ps.setInt(2, world);
			ResultSet rs = ps.executeQuery();
			if (!rs.next()) {
				ps.close();
				return -1;
			}
			int id = rs.getInt("id");
			ps.close();
			return id;
		} catch (SQLException e) {
			log.error("ERROR", e);
		}
		return -1;
	}

	public Integer getBuffedValue(MapleBuffStat effect) {
		MapleBuffStatValueHolder mbsvh = effects.get(effect);
		if (mbsvh == null) {
			return null;
		}
		return Integer.valueOf(mbsvh.value);
	}
	
	public boolean isBuffFrom (MapleBuffStat stat, ISkill skill) {
		MapleBuffStatValueHolder mbsvh = effects.get(stat);
		if (mbsvh == null) {
			return false;
		}
		return mbsvh.effect.isSkill() && mbsvh.effect.getSourceId() == skill.getId();
	}
	
	public int getBuffSource (MapleBuffStat stat) {
		MapleBuffStatValueHolder mbsvh = effects.get(stat);
		if (mbsvh == null) {
			return -1;
		}
		return mbsvh.effect.getSourceId();
	}
	
	public void setBuffedValue(MapleBuffStat effect, int value) {
		MapleBuffStatValueHolder mbsvh = effects.get(effect);
		if (mbsvh == null) {
			return;
		}
		mbsvh.value = value;
	}

	public Long getBuffedStarttime(MapleBuffStat effect) {
		MapleBuffStatValueHolder mbsvh = effects.get(effect);
		if (mbsvh == null) {
			return null;
		}
		return Long.valueOf(mbsvh.startTime);
	}

	public MapleStatEffect getStatForBuff(MapleBuffStat effect) {
		MapleBuffStatValueHolder mbsvh = effects.get(effect);
		if (mbsvh == null) {
			return null;
		}
		return mbsvh.effect;
	}
	
	private void prepareDragonBlood(final MapleStatEffect bloodEffect) {
		if (dragonBloodSchedule != null) {
			dragonBloodSchedule.cancel(false);
		}
		dragonBloodSchedule = TimerManager.getInstance().register(new Runnable() {
			@Override
			public void run() {
				addHP(-bloodEffect.getX());
				getClient().getSession().write(MaplePacketCreator.showOwnBuffEffect(bloodEffect.getSourceId(), 5));
				getMap().broadcastMessage(MapleCharacter.this, MaplePacketCreator.showBuffeffect(getId(), bloodEffect.getSourceId(), 5), false);
			}
		}, 4000, 4000);
	}
	
	public void registerEffect(MapleStatEffect effect, long starttime, ScheduledFuture<?> schedule) {
		if (effect.isHide()) {
			this.hidden = true;
			getMap().broadcastMessage(this, MaplePacketCreator.removePlayerFromMap(getId()), false);
		} else if (effect.isDragonBlood()) {
			prepareDragonBlood(effect);
		}
		else if (effect.isBeholder()) {
                        prepareBeholderEffect();
                }
		for (Pair<MapleBuffStat, Integer> statup : effect.getStatups()) {
			effects.put(statup.getLeft(), new MapleBuffStatValueHolder(effect, starttime, schedule, statup.getRight().intValue()));
		}
		
		recalcLocalStats();
	}

	private List<MapleBuffStat> getBuffStats(MapleStatEffect effect, long startTime) {
		List<MapleBuffStat> stats = new ArrayList<MapleBuffStat>();
		for (Entry<MapleBuffStat, MapleBuffStatValueHolder> stateffect : effects.entrySet()) {
			MapleBuffStatValueHolder mbsvh = stateffect.getValue();
			if (mbsvh.effect.sameSource(effect) && (startTime == -1 || startTime == mbsvh.startTime)) {
				stats.add(stateffect.getKey());
			}
		}
		return stats;
	}

	private void deregisterBuffStats(List<MapleBuffStat> stats) {
		List<MapleBuffStatValueHolder> effectsToCancel = new ArrayList<MapleBuffStatValueHolder>(stats.size());
		for (MapleBuffStat stat : stats) {
			MapleBuffStatValueHolder mbsvh = effects.get(stat);
			if (mbsvh != null) {
				effects.remove(stat);
				boolean addMbsvh = true;
				for (MapleBuffStatValueHolder contained : effectsToCancel) {
					if (mbsvh.startTime == contained.startTime && contained.effect == mbsvh.effect) {
						addMbsvh = false;
					}
				}
				if (addMbsvh) {
					effectsToCancel.add(mbsvh);
				}
				if (stat == MapleBuffStat.SUMMON || stat == MapleBuffStat.PUPPET) {
					int summonId = mbsvh.effect.getSourceId();
					MapleSummon summon = summons.get(summonId);
					if(summon != null) {
					    getMap().broadcastMessage(MaplePacketCreator.removeSpecialMapObject(this, summonId, true), summon.getPosition());
					    getMap().removeMapObject(summon);
					    removeVisibleMapObject(summon);
					    summons.remove(summonId);
					}
					if (summon.getSkill() == 1321007){
                                            if (beholderHealingSchedule != null) {
                                                beholderHealingSchedule.cancel(false);
                                                beholderHealingSchedule = null;
                                            }
                                            if (beholderBuffSchedule != null) {
                                                beholderBuffSchedule.cancel(false);
                                                beholderBuffSchedule = null;
                                            }
                                        }
				} else if (stat == MapleBuffStat.DRAGONBLOOD) {
					dragonBloodSchedule.cancel(false);
					dragonBloodSchedule = null;
				}
			}
		}
		for (MapleBuffStatValueHolder cancelEffectCancelTasks : effectsToCancel) {
			if (getBuffStats(cancelEffectCancelTasks.effect, cancelEffectCancelTasks.startTime).size() == 0) {
				cancelEffectCancelTasks.schedule.cancel(false);
			}
		}
	}

	/**
	 * @param effect
	 * @param overwrite when overwrite is set no data is sent and all the Buffstats in the StatEffect are deregistered
	 * @param startTime
	 */
	public void cancelEffect(MapleStatEffect effect, boolean overwrite, long startTime) {
		List<MapleBuffStat> buffstats;
		if (!overwrite) {
			buffstats = getBuffStats(effect, startTime);
		} else {
			List<Pair<MapleBuffStat, Integer>> statups = effect.getStatups();
			buffstats = new ArrayList<MapleBuffStat>(statups.size());
			for (Pair<MapleBuffStat, Integer> statup : statups) {
				buffstats.add(statup.getLeft());
			}
		}
		deregisterBuffStats(buffstats);
		if (effect.isMagicDoor()) {
			// remove for all on maps
			if (!getDoors().isEmpty()) {
				MapleDoor door = getDoors().iterator().next();
				for (MapleCharacter chr : door.getTarget().getCharacters()) {
					door.sendDestroyData(chr.getClient());
				}
				for (MapleCharacter chr : door.getTown().getCharacters()) {
					door.sendDestroyData(chr.getClient());
				}
				for (MapleDoor destroyDoor : getDoors()) {
					door.getTarget().removeMapObject(destroyDoor);
					door.getTown().removeMapObject(destroyDoor);
				}
				clearDoors();
				silentPartyUpdate();
			}
		}
		
		// check if we are still logged in �.o
		if (!overwrite) {
			cancelPlayerBuffs(buffstats);
			if (effect.isHide() && (MapleCharacter) getMap().getMapObject(getObjectId()) != null) {
				this.hidden = false;
				getMap().broadcastMessage(this, MaplePacketCreator.spawnPlayerMapobject(this), false);
			}
		}
	}
	
	public void cancelBuffStats(MapleBuffStat ... stat) {
		List<MapleBuffStat> buffStatList = Arrays.asList(stat);
		deregisterBuffStats(buffStatList);
		cancelPlayerBuffs(buffStatList);
	}
	
	public void cancelEffectFromBuffStat(MapleBuffStat stat) {
		cancelEffect(effects.get(stat).effect, false, -1);
	}

	private void cancelPlayerBuffs(List<MapleBuffStat> buffstats) {
		if (getClient().getChannelServer().getPlayerStorage().getCharacterById(getId()) != null) { // are we still connected ?
			recalcLocalStats();
			enforceMaxHpMp();
			getClient().getSession().write(MaplePacketCreator.cancelBuff(buffstats));
			getMap().broadcastMessage(this, MaplePacketCreator.cancelForeignBuff(getId(), buffstats), false);
		}
	}
	
	public void cancelAllBuffs() {
		LinkedList<MapleBuffStatValueHolder> allBuffs = new LinkedList<MapleBuffStatValueHolder>(effects.values());
		for (MapleBuffStatValueHolder mbsvh : allBuffs) {
			cancelEffect(mbsvh.effect, false, mbsvh.startTime);
		}
	}
	
	public void cancelMagicDoor() {
		LinkedList<MapleBuffStatValueHolder> allBuffs = new LinkedList<MapleBuffStatValueHolder>(effects.values());
		for (MapleBuffStatValueHolder mbsvh : allBuffs) {
			if (mbsvh.effect.isMagicDoor()) {
				cancelEffect(mbsvh.effect, false, mbsvh.startTime);
			}
		}		
	}
	
	public void handleOrbgain() {
	    int orbcount = getBuffedValue(MapleBuffStat.COMBO);
		ISkill combo = SkillFactory.getSkill(1111002);
		ISkill advcombo = SkillFactory.getSkill(1120003);

		MapleStatEffect ceffect = null;
		int advComboSkillLevel = getSkillLevel(advcombo);
		if (advComboSkillLevel > 0) {
			ceffect = advcombo.getEffect(advComboSkillLevel);
		} else {
			ceffect = combo.getEffect(getSkillLevel(combo));
		}
		
		if (orbcount < ceffect.getX() + 1) {
			int neworbcount = orbcount + 1;
			if (advComboSkillLevel > 0 && ceffect.makeChanceResult()) {
				if (neworbcount < ceffect.getX() + 1)
					neworbcount++;
			}

			List<Pair<MapleBuffStat, Integer>> stat = Collections.singletonList(new Pair<MapleBuffStat, Integer>(MapleBuffStat.COMBO, neworbcount));
			setBuffedValue(MapleBuffStat.COMBO, neworbcount);
			int duration = ceffect.getDuration();
			duration += (int) ((getBuffedStarttime(MapleBuffStat.COMBO) - System.currentTimeMillis()));

			getClient().getSession().write(MaplePacketCreator.giveBuff(1111002, duration, stat, false));
			getMap().broadcastMessage(this, MaplePacketCreator.giveForeignBuff(getId(), stat), false);
		}
	}
	
	public void handleOrbconsume() {
	    ISkill combo = SkillFactory.getSkill(1111002);
	    MapleStatEffect ceffect = combo.getEffect(getSkillLevel(combo));
	    List<Pair<MapleBuffStat, Integer>> stat = Collections.singletonList(new Pair<MapleBuffStat, Integer>(MapleBuffStat.COMBO, 1));
	    setBuffedValue(MapleBuffStat.COMBO, 1);
	    int duration = ceffect.getDuration();
	    duration += (int)((getBuffedStarttime(MapleBuffStat.COMBO) - System.currentTimeMillis()));

	    getClient().getSession().write(MaplePacketCreator.giveBuff(1111002, duration, stat, false));
	    getMap().broadcastMessage(this, MaplePacketCreator.giveForeignBuff(getId(), stat), false);
	}
	
	private void silentEnforceMaxHpMp() {
		setMp(getMp());
		setHp(getHp(), true);
	}

	private void enforceMaxHpMp() {
		List<Pair<MapleStat, Integer>> stats = new ArrayList<Pair<MapleStat, Integer>>(2);
		if (getMp() > getCurrentMaxMp()) {
			setMp(getMp());
			stats.add(new Pair<MapleStat, Integer>(MapleStat.MP, Integer.valueOf(getMp())));
		}
		if (getHp() > getCurrentMaxHp()) {
			setHp(getHp());
			stats.add(new Pair<MapleStat, Integer>(MapleStat.HP, Integer.valueOf(getHp())));
		}
		if (stats.size() > 0) {
			getClient().getSession().write(MaplePacketCreator.updatePlayerStats(stats));
		}
	}

	public MapleMap getMap() {
		return map;
	}
	
	/**
	 * only for tests
	 * 
	 * @param newmap
	 */
	public void setMap(MapleMap newmap) {
		this.map = newmap;
	}

	public int getMapId() {
		if (map != null) {
			return map.getId();
		}
		return mapid;
	}

	public int getInitialSpawnpoint() {
		return initialSpawnPoint;
	}

	public int getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public int getLevel() {
		return level;
	}
        
        public int getRank() {
                return rank;
        }
        
        public int getRankMove() {
                return rankMove;
        }
        
        public int getJobRank() {
            return jobRank;
        }
        
        public int getJobRankMove() {
            return jobRankMove;
        }
        
	public int getFame() {
		return fame;
	}

	public int getStr() {
		return str;
	}

	public int getDex() {
		return dex;
	}

	public int getLuk() {
		return luk;
	}

	public int getInt() {
		return int_;
	}

	public MapleClient getClient() {
		return client;
	}

	public int getExp() {
		return exp.get();
	}

 	public int getPvpKills() {
                return pvpkills;
        }
        
        public int getPvpDeaths() {
                return pvpdeaths;
        }

	public int getHp() {
		return hp;
	}

	public int getMaxHp() {
		return maxhp;
	}

	public int getMp() {
		return mp;
	}

	public int getMaxMp() {
		return maxmp;
	}

	public int getRemainingAp() {
		return remainingAp;
	}

	public int getRemainingSp() {
		return remainingSp;
	}

	public int getMpApUsed() {
		return mpApUsed;
	}

	public void setMpApUsed(int mpApUsed) {
		this.mpApUsed = mpApUsed;
	}

	public int getHpApUsed() {
		return hpApUsed;
	}

	public boolean isHidden() {
		return hidden;
	}

	public void setHpApUsed(int hpApUsed) {
		this.hpApUsed = hpApUsed;
	}

	public MapleSkinColor getSkinColor() {
		return skinColor;
	}

	public MapleJob getJob() {
		return job;
	}

	public int getGender() {
		return gender;
	}

	public int getHair() {
		return hair;
	}

	public int getFace() {
		return face;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setStr(int str) {
		this.str = str;
		recalcLocalStats();
	}

	public void setDex(int dex) {
		this.dex = dex;
		recalcLocalStats();
	}

	public void setLuk(int luk) {
		this.luk = luk;
		recalcLocalStats();
	}

	public void setInt(int int_) {
		this.int_ = int_;
		recalcLocalStats();
	}
         
         public void setMaxHP(int maxhp){
             this.maxhp = maxhp;
             recalcLocalStats();
         }
         
         public void setMaxMP(int maxmp){
             this.maxmp = maxmp;
             recalcLocalStats();
         }
 
	public void setHair(int hair) {
		this.hair = hair;
	}

	public void setFace(int face) {
		this.face = face;
	}

	public void setRemainingAp(int remainingAp) {
		this.remainingAp = remainingAp;
	}

	public void setRemainingSp(int remainingSp) {
		this.remainingSp = remainingSp;
	}

	public void setPvpDeaths(int amount) {
                this.pvpdeaths = amount;
        }

        public void setPvpKills(int amount) {
                this.pvpkills = amount;
        }
        public void gainPvpDeath() {
                this.pvpdeaths += 1;
        }

        public void gainPvpKill() {
                this.pvpkills += 1;
        }

	public void setSkinColor(MapleSkinColor skinColor) {
		this.skinColor = skinColor;
	}

	public void setGender(int gender) {
		this.gender = gender;
	}
	
	public CheatTracker getCheatTracker() {
		return anticheat;
	}
	
	public BuddyList getBuddylist() {
		return buddylist;
	}
	
	public void addFame(int famechange) {
		this.fame += famechange;
	}
	
	public void changeMap(final MapleMap to, final Point pos) {
		/*getClient().getSession().write(MaplePacketCreator.spawnPortal(map.getId(), to.getId(), pos));
		if (getParty() != null) {
			getClient().getSession().write(MaplePacketCreator.partyPortal(map.getId(), to.getId(), pos));
		}*/
		MaplePacket warpPacket = MaplePacketCreator.getWarpToMap(to, 0x80, this);
		changeMapInternal(to, pos, warpPacket);
	}

	public void changeMap(final MapleMap to, final MaplePortal pto) {
		MaplePacket warpPacket = MaplePacketCreator.getWarpToMap(to, pto.getId(), this);
		changeMapInternal(to, pto.getPosition(), warpPacket);
	}
	
	private void changeMapInternal(final MapleMap to, final Point pos, MaplePacket warpPacket) {
		warpPacket.setOnSend(new Runnable() {
			@Override
			public void run() {
				map.removePlayer(MapleCharacter.this);
				if (getClient().getChannelServer().getPlayerStorage().getCharacterById(getId()) != null) {
					map = to;
					setPosition(pos);
					to.addPlayer(MapleCharacter.this);
					if (party != null) {
					silentPartyUpdate();
						getClient().getSession().write(MaplePacketCreator.updateParty(getClient().getChannel(), party, PartyOperation.SILENT_UPDATE, null));
						updatePartyMemberHP();
					}
				}
			}
		});
		getClient().getSession().write(warpPacket);
	}
	
	public void leaveMap() {
		controlled.clear();
		visibleMapObjects.clear();
		if(chair != 0) {
			chair = 0;
		}
	}

	public void changeJob(MapleJob newJob) {
		this.job = newJob;
		this.remainingSp++;
		updateSingleStat(MapleStat.AVAILABLESP, this.remainingSp);
		updateSingleStat(MapleStat.JOB, newJob.getId());
		getMap().broadcastMessage(this, MaplePacketCreator.showJobChange(getId()), false);
		silentPartyUpdate();
		guildUpdate();
	}
	
	public void gainAp(int ap) {
		this.remainingAp += ap;
		updateSingleStat(MapleStat.AVAILABLEAP, this.remainingAp);
	}

        private void prepareBeholderEffect() {
                if (beholderHealingSchedule != null) {
                    beholderHealingSchedule.cancel(false);
                }
                if (beholderBuffSchedule != null) {
                    beholderBuffSchedule.cancel(false);
                }
                ISkill bHealing = SkillFactory.getSkill(1320008);
                int bHealingLvl = getSkillLevel(bHealing);
                if (bHealingLvl > 0) {
                    final MapleStatEffect healEffect = bHealing.getEffect(bHealingLvl);
                    int healInterval = healEffect.getX() * 1000;
                    beholderHealingSchedule = TimerManager.getInstance().register(new Runnable() {
			@Override
			public void run() {
				addHP(healEffect.getHp());
                                //Show Client
                                //The beholder
                                MaplePacket beholder = MaplePacketCreator.summonSkill(getId(), 1321007, 5);
                                MaplePacket forClient = MaplePacketCreator.showOwnBuffEffect(1321007, 2);
                                MaplePacket forOthers = MaplePacketCreator.showBuffeffect(getId(), 1321007, 2);
                                getClient().getSession().write(forClient);
                                getMap().broadcastMessage(MapleCharacter.this, beholder, true);
                                getMap().broadcastMessage(MapleCharacter.this, forOthers, false);
			}
                    }, healInterval, healInterval);
                }
                ISkill bBuff = SkillFactory.getSkill(1320009);
                int bBuffLvl = getSkillLevel(bBuff);
                if (bBuffLvl > 0) {
                    final MapleStatEffect buffEffect = bBuff.getEffect(bBuffLvl);
                    int buffInterval = buffEffect.getX() * 1000;
                    beholderBuffSchedule = TimerManager.getInstance().register(new Runnable() {
			@Override
			public void run() {
                                buffEffect.applyTo(MapleCharacter.this);
                                MaplePacket beholder = MaplePacketCreator.summonSkill(getId(), 1321007, (int)(Math.random() * 3) + 6);
                                MaplePacket forClient = MaplePacketCreator.showOwnBuffEffect(1321007, 2);
                                MaplePacket forOthers = MaplePacketCreator.showBuffeffect(getId(), 1321007, 2);
                                getClient().getSession().write(forClient);
                                getMap().broadcastMessage(MapleCharacter.this, beholder, true);
                                getMap().broadcastMessage(MapleCharacter.this, forOthers, false);
			}
                    }, buffInterval, buffInterval);
                }
        }

	public void changeSkillLevel(ISkill skill, int newLevel, int newMasterlevel) {
		skills.put(skill, new SkillEntry(newLevel, newMasterlevel));
		this.getClient().getSession().write(MaplePacketCreator.updateSkill(skill.getId(), newLevel, newMasterlevel));
	}

	public void setHp(int newhp) {
		setHp(newhp, false);
	}
	
	private void setHp(int newhp, boolean silent) {
		int oldHp = hp;
		int thp = newhp;
		if (thp < 0) {
			thp = 0;
		}
		if (thp > localmaxhp) {
			thp = localmaxhp;
		}
		this.hp = thp;
		
		if (!silent) {
			updatePartyMemberHP();
		}
		if (oldHp > hp && !isAlive()) {
			playerDead();
		}
	}

	private void playerDead() {
		if (getEventInstance() != null) {
			getEventInstance().playerKilled(this);
		}
		cancelAllBuffs();
		getClient().getSession().write(MaplePacketCreator.enableActions());
	}

	public void updatePartyMemberHP() {
		if (party != null) {
			int channel = client.getChannel();
			for (MaplePartyCharacter partychar : party.getMembers()) {
				if (partychar.getMapid() == getMapId() && partychar.getChannel() == channel) {
					MapleCharacter other = ChannelServer.getInstance(channel).getPlayerStorage().getCharacterByName(partychar.getName());
					if (other != null) {
						other.getClient().getSession().write(
							MaplePacketCreator.updatePartyMemberHP(getId(), this.hp, localmaxhp));
					}
				}
			}
		}
	}

	public void receivePartyMemberHP() {
		if (party != null) {
			int channel = client.getChannel();
			for (MaplePartyCharacter partychar : party.getMembers()) {
				if (partychar.getMapid() == getMapId() && partychar.getChannel() == channel) {
					MapleCharacter other = ChannelServer.getInstance(channel).getPlayerStorage().getCharacterByName(partychar.getName());
					if (other != null) {
						getClient().getSession().write(
							MaplePacketCreator.updatePartyMemberHP(other.getId(), other.getHp(), other.getCurrentMaxHp()));
					}
				}
			}
		}
	}

	public void setMp(int newmp) {
		int tmp = newmp;
		if (tmp < 0) {
			tmp = 0;
		}
		if (tmp > localmaxmp) {
			tmp = localmaxmp;
		}
		this.mp = tmp;
	}

	/**
	 * Convenience function which adds the supplied parameter to the current hp then directly does a updateSingleStat.
	 * 
	 * @see MapleCharacter#setHp(int)
	 * @param delta
	 */
	public void addHP(int delta) {
		setHp(hp + delta);
		updateSingleStat(MapleStat.HP, hp);
	}

	/**
	 * Convenience function which adds the supplied parameter to the current mp then directly does a updateSingleStat.
	 * 
	 * @see MapleCharacter#setMp(int)
	 * @param delta
	 */
	public void addMP(int delta) {
		setMp(mp + delta);
		updateSingleStat(MapleStat.MP, mp);
	}

	/**
	 * Updates a single stat of this MapleCharacter for the client. This method only creates and sends an update packet,
	 * it does not update the stat stored in this MapleCharacter instance.
	 * 
	 * @param stat
	 * @param newval
	 * @param itemReaction
	 */
	public void updateSingleStat(MapleStat stat, int newval, boolean itemReaction) {
		Pair<MapleStat, Integer> statpair = new Pair<MapleStat, Integer>(stat, Integer.valueOf(newval));
		MaplePacket updatePacket = MaplePacketCreator.updatePlayerStats(Collections.singletonList(statpair),
			itemReaction);
		client.getSession().write(updatePacket);
	}

	public void updateSingleStat(MapleStat stat, int newval) {
		updateSingleStat(stat, newval, false);
	}
	
	public void gainExp(int gain, boolean show, boolean inChat, boolean white) {
		if (getLevel() < 200) { // lv200 is max and has 0 exp required to level
			int newexp = this.exp.addAndGet(gain);
			updateSingleStat(MapleStat.EXP, newexp);
		}
		if (show) { // still show the expgain even if it's not there
			client.getSession().write(MaplePacketCreator.getShowExpGain(gain, inChat, white));
		}
		while (level < 200 && exp.get() >= ExpTable.getExpNeededForLevel(level + 1)) {
			levelUp();
		}
	}
	
	public void silentPartyUpdate() {
		if (party != null) {
			try {
				getClient().getChannelServer().getWorldInterface().updateParty(party.getId(),
					PartyOperation.SILENT_UPDATE, new MaplePartyCharacter(MapleCharacter.this));
			} catch (RemoteException e) {
				log.error("REMOTE THROW", e);
				getClient().getChannelServer().reconnectWorld();
			}
		}
	}

	public void gainExp(int gain, boolean show, boolean inChat) {
		gainExp(gain, show, inChat, true);
	}

	public boolean isGM() {
		return gm;
	}

	public MapleInventory getInventory(MapleInventoryType type) {
		return inventory[type.ordinal()];
	}

	public MapleShop getShop() {
		return shop;
	}

	public void setShop(MapleShop shop) {
		this.shop = shop;
	}

	public int getMeso() {
		return meso.get();
	}

        public int getNX() { 
                return nxcash; 
        }
	public int getSavedLocation(SavedLocationType type) {
		return savedLocations[type.ordinal()];
	}

	public void saveLocation(SavedLocationType type) {
		savedLocations[type.ordinal()] = getMapId();
	}
	
	public void clearSavedLocation(SavedLocationType type) {
		savedLocations[type.ordinal()] = -1;
	}

	public void gainMeso(int gain, boolean show) {
		gainMeso(gain, show, false, false);
	}

	public void gainMeso(int gain, boolean show, boolean enableActions) {
		gainMeso(gain, show, enableActions, false);
	}

	public void gainMeso(int gain, boolean show, boolean enableActions, boolean inChat) {
		if (meso.get() + gain < 0) {
			client.getSession().write(MaplePacketCreator.enableActions());
			return;
		}
		int newVal = meso.addAndGet(gain);
		updateSingleStat(MapleStat.MESO, newVal, enableActions);
		if (show) {
			client.getSession().write(MaplePacketCreator.getShowMesoGain(gain, inChat));
		}
	}

	/**
	 * Adds this monster to the controlled list. The monster must exist on the Map.
	 * 
	 * @param monster
	 */
	public void controlMonster(MapleMonster monster, boolean aggro) {
		monster.setController(this);
		controlled.add(monster);
		client.getSession().write(MaplePacketCreator.controlMonster(monster, false, aggro));
	}

	public void stopControllingMonster(MapleMonster monster) {
		controlled.remove(monster);
	}

	public Collection<MapleMonster> getControlledMonsters() {
		return Collections.unmodifiableCollection(controlled);
	}

	public int getNumControlledMonsters() {
		return controlled.size();
	}

	@Override
	public String toString() {
		return "Character: " + this.name;
	}

	public int getAccountID() {
		return accountid;
	}

	public void mobKilled(int id) {
		for (MapleQuestStatus q : quests.values()) {
			if (q.getStatus() == MapleQuestStatus.Status.COMPLETED || q.getQuest().canComplete(this, null))
				continue;
			if (q.mobKilled(id) && !(q.getQuest() instanceof MapleCustomQuest)) {
				client.getSession().write(MaplePacketCreator.updateQuestMobKills(q));
				if (q.getQuest().canComplete(this, null)) {
					client.getSession().write(MaplePacketCreator.getShowQuestCompletion(q.getQuest().getId()));
				}
			}
		}
	}

	public final List<MapleQuestStatus> getStartedQuests() {
		List<MapleQuestStatus> ret = new LinkedList<MapleQuestStatus>();
		for (MapleQuestStatus q : quests.values()) {
			if (q.getStatus().equals(MapleQuestStatus.Status.STARTED) && !(q.getQuest() instanceof MapleCustomQuest))
				ret.add(q);
		}
		return Collections.unmodifiableList(ret);
	}

	public final List<MapleQuestStatus> getCompletedQuests() {
		List<MapleQuestStatus> ret = new LinkedList<MapleQuestStatus>();
		for (MapleQuestStatus q : quests.values()) {
			if (q.getStatus().equals(MapleQuestStatus.Status.COMPLETED) && !(q.getQuest() instanceof MapleCustomQuest))
				ret.add(q);
		}
		return Collections.unmodifiableList(ret);
	}

	public MaplePlayerShop getPlayerShop() {
		return playerShop;
	}

	public void setPlayerShop(MaplePlayerShop playerShop) {
		this.playerShop = playerShop;
	}

	public Map<ISkill, SkillEntry> getSkills() {
		return Collections.unmodifiableMap(skills);
	}

	public int getSkillLevel(ISkill skill) {
		SkillEntry ret = skills.get(skill);
		if (ret == null) {
			return 0;
		}
		return ret.skillevel;
	}
	
	public int getMasterLevel(ISkill skill) {
		SkillEntry ret = skills.get(skill);
		if (ret == null) {
			return 0;
		}
		return ret.masterlevel;
	}

	// the equipped inventory only contains equip... I hope
	public int getTotalDex() {
		return localdex;
	}

	public int getTotalInt() {
		return localint_;
	}

	public int getTotalStr() {
		return localstr;
	}

	public int getTotalLuk() {
		return localluk;
	}

	public int getTotalMagic() {
		return magic;
	}
	
	public double getSpeedMod() {
		return speedMod;
	}
	
	public double getJumpMod() {
		return jumpMod;
	}
	
	public int getTotalWatk() {
		return watk;
	}

	private static int rand(int lbound, int ubound) {
		return (int) ((Math.random() * (ubound - lbound + 1)) + lbound);
	}

	public void levelUp() {
		ISkill improvingMaxHP = SkillFactory.getSkill(1000001);
		ISkill improvingMaxMP = SkillFactory.getSkill(2000001);

		int improvingMaxHPLevel = getSkillLevel(improvingMaxHP);
		int improvingMaxMPLevel = getSkillLevel(improvingMaxMP);
		remainingAp += 5;
		if (job == MapleJob.BEGINNER) {
			// info from the odin what's working thread, thanks
			maxhp += rand(14, 16);
			maxmp += rand(10, 12);
		} else if (job.isA(MapleJob.BOWMAN) || job.isA(MapleJob.THIEF) || job.isA(MapleJob.GM)) {
			// info from bowman forum at sleepywood, thanks guys
			maxhp += rand(20, 24);
			maxmp += rand(14, 16);
		} else if (job.isA(MapleJob.MAGICIAN)) {
			// made up
			maxhp += rand(10, 14);
			maxmp += rand(20, 24);
		} else if (job.isA(MapleJob.WARRIOR)) {
			// made up
			maxhp += rand(22, 26);
			maxmp += rand(4, 7);
		}

		if (improvingMaxHPLevel > 0) {
			maxhp += improvingMaxHP.getEffect(improvingMaxHPLevel).getX();
		}
		if (improvingMaxMPLevel > 0) {
			maxmp += improvingMaxMP.getEffect(improvingMaxMPLevel).getX();
		}
		maxmp += getTotalInt() / 10;
		exp.addAndGet(-ExpTable.getExpNeededForLevel(level + 1));
		if (level == 200) {
			exp.set(0);

			if(exp.get() > 0)
                              exp.set(0);
		}

		maxhp = Math.min(30000, maxhp);
		maxmp = Math.min(30000, maxmp);

		level += 1;
		List<Pair<MapleStat, Integer>> statup = new ArrayList<Pair<MapleStat, Integer>>(8);
		statup.add(new Pair<MapleStat, Integer>(MapleStat.AVAILABLEAP, Integer.valueOf(remainingAp)));
		statup.add(new Pair<MapleStat, Integer>(MapleStat.MAXHP, Integer.valueOf(maxhp)));
		statup.add(new Pair<MapleStat, Integer>(MapleStat.MAXMP, Integer.valueOf(maxmp)));
		statup.add(new Pair<MapleStat, Integer>(MapleStat.HP, Integer.valueOf(maxhp)));
		statup.add(new Pair<MapleStat, Integer>(MapleStat.MP, Integer.valueOf(maxmp)));
		statup.add(new Pair<MapleStat, Integer>(MapleStat.EXP, Integer.valueOf(exp.get())));
		statup.add(new Pair<MapleStat, Integer>(MapleStat.LEVEL, Integer.valueOf(level)));

		if (job != MapleJob.BEGINNER) {
			remainingSp += 3;
			statup.add(new Pair<MapleStat, Integer>(MapleStat.AVAILABLESP, Integer.valueOf(remainingSp)));
		}

		setHp(maxhp);
		setMp(maxmp);
		getClient().getSession().write(MaplePacketCreator.updatePlayerStats(statup));
		getMap().broadcastMessage(this, MaplePacketCreator.showLevelup(getId()), false);
		recalcLocalStats();
		silentPartyUpdate();
		guildUpdate();
	}

	public void changeKeybinding(int key, MapleKeyBinding keybinding) {
		if (keybinding.getType() != 0) {
			keymap.put(Integer.valueOf(key), keybinding);
		} else {
			keymap.remove(Integer.valueOf(key));
		}
	}

	public void sendKeymap() {
		getClient().getSession().write(MaplePacketCreator.getKeymap(keymap));
	}

	public void tempban(String reason, Calendar duration, int greason) {
		if (lastmonthfameids == null) {
			throw new RuntimeException("Trying to ban a non-loaded character (testhack)");
		}
		tempban(reason, duration, greason, client.getAccID());
		client.getSession().close();
	}
	
	public static boolean tempban(String reason, Calendar duration, int greason, int accountid) {
		try {
			Connection con = DatabaseConnection.getConnection();
			PreparedStatement ps = con.prepareStatement("UPDATE accounts SET tempban = ?, banreason = ?, greason = ? WHERE id = ?");
			Timestamp TS = new Timestamp(duration.getTimeInMillis());
			ps.setTimestamp(1, TS);
			ps.setString(2, reason);
			ps.setInt(3, greason);
			ps.setInt(4, accountid);
			ps.executeUpdate();
			ps.close();
			return true;
		} catch (SQLException ex) {
			log.error("Error while tempbanning", ex);
		}
		return false;
	}

	public void ban(String reason) {
		if (lastmonthfameids == null) {
			throw new RuntimeException("Trying to ban a non-loaded character (testhack)");
		}
		try {
			getClient().banMacs();
			Connection con = DatabaseConnection.getConnection();
			PreparedStatement ps = con.prepareStatement("UPDATE accounts SET banned = ?, banreason = ? WHERE id = ?");
			ps.setInt(1, 1);
			ps.setString(2, reason);
			ps.setInt(3, accountid);
			ps.executeUpdate();
			ps.close();
			ps = con.prepareStatement("INSERT INTO ipbans VALUES (DEFAULT, ?)");
			String[] ipSplit = client.getSession().getRemoteAddress().toString().split(":");
			ps.setString(1, ipSplit[0]);
			ps.executeUpdate();
			ps.close();
		} catch (SQLException ex) {
			log.error("Error while banning", ex);
		}
		client.getSession().close();
	}

	public static boolean ban(String id, String reason, boolean accountId) {
		try {
			Connection con = DatabaseConnection.getConnection();
			PreparedStatement ps;
			if (id.matches("/[0-9]{1,3}\\..*")) {
				ps = con.prepareStatement("INSERT INTO ipbans VALUES (DEFAULT, ?)");
				ps.setString(1, id);
				ps.executeUpdate();
				ps.close();
				return true;
			}
			if (accountId) {
				ps = con.prepareStatement("SELECT id FROM accounts WHERE name = ?");
			} else {
				ps = con.prepareStatement("SELECT accountid FROM characters WHERE name = ?");
			}
			boolean ret = false;
			ps.setString(1, id);
			ResultSet rs = ps.executeQuery();
			if (rs.next()) {
				PreparedStatement psb = con.prepareStatement("UPDATE accounts SET banned = 1, banreason = ? WHERE id = ?");
				psb.setString(1, reason);
				psb.setInt(2, rs.getInt(1));
				psb.executeUpdate();
				psb.close();
				ret = true;
			}
			rs.close();
			ps.close();
			return ret;
		} catch (SQLException ex) {
			log.error("Error while banning", ex);
		}
		return false;
	}

	/**
	 * Oid of players is always = the cid
	 */
	@Override
	public int getObjectId() {
		return getId();
	}

	/**
	 * Throws unsupported operation exception, oid of players is read only
	 */
	@Override
	public void setObjectId(int id) {
		throw new UnsupportedOperationException();
	}

	public MapleStorage getStorage() {
		return storage;
	}

	public int getCurrentMaxHp() {
		return localmaxhp;
	}

	public int getCurrentMaxMp() {
		return localmaxmp;
	}
	
	public int getCurrentMaxBaseDamage() {
		return localmaxbasedamage;
	}
	
	public int calculateMaxBaseDamage (int watk) {
		int maxbasedamage;
		if (watk == 0) {
			maxbasedamage = 1;
		} else {
			IItem weapon_item = getInventory(MapleInventoryType.EQUIPPED).getItem((byte) -11);
			if (weapon_item != null) {
				MapleWeaponType weapon = MapleItemInformationProvider.getInstance().getWeaponType(weapon_item.getItemId());
				int mainstat;
				int secondarystat;
				if (weapon == MapleWeaponType.BOW || weapon == MapleWeaponType.CROSSBOW) {
					mainstat = localdex;
					secondarystat = localstr;
				} else if (getJob().isA(MapleJob.THIEF) && (weapon == MapleWeaponType.CLAW || weapon == MapleWeaponType.DAGGER)) {
					mainstat = localluk;
					secondarystat = localdex + localstr;
				} else {
					mainstat = localstr;
					secondarystat = localdex;
				}
				maxbasedamage = (int) (((weapon.getMaxDamageMultiplier() * mainstat + secondarystat) / 100.0) * watk);
				 //just some saveguard against rounding errors, we want to a/b for this
				maxbasedamage += 10;
			} else {
				maxbasedamage = 0;
			}
		}
		return maxbasedamage;
	}
	
	public void addVisibleMapObject (MapleMapObject mo) {
		visibleMapObjects.add(mo);
	}
	
	public void removeVisibleMapObject (MapleMapObject mo) {
		visibleMapObjects.remove(mo);
	}
	
	public boolean isMapObjectVisible (MapleMapObject mo) {
		return visibleMapObjects.contains(mo);
	}
	
	public Collection<MapleMapObject> getVisibleMapObjects () {
		return Collections.unmodifiableCollection(visibleMapObjects);
	}
	
	public boolean isAlive() {
		return this.hp > 0;
	}
	
	@Override
	public void sendDestroyData(MapleClient client) {
		client.getSession().write(MaplePacketCreator.removePlayerFromMap(this.getObjectId()));
	}

	@Override
	public void sendSpawnData(MapleClient client) {
		if (!this.isHidden()) {
			client.getSession().write(MaplePacketCreator.spawnPlayerMapobject(this));
		}
	}
	
	private void recalcLocalStats() {
		int oldmaxhp = localmaxhp;
		localmaxhp = getMaxHp();
		localmaxmp = getMaxMp();
		localdex = getDex();
		localint_ = getInt();
		localstr = getStr();
		localluk = getLuk();
		int speed = 100;
		int jump = 100;
		magic = localint_;
		watk = 0;
		for (IItem item : getInventory(MapleInventoryType.EQUIPPED)) {
			IEquip equip = (IEquip) item;
			localmaxhp += equip.getHp();
			localmaxmp += equip.getMp();
			localdex += equip.getDex();
			localint_ += equip.getInt();
			localstr += equip.getStr();
			localluk += equip.getLuk();
			magic += equip.getMatk() + equip.getInt();
			watk += equip.getWatk();
			speed += equip.getSpeed();
			jump += equip.getJump();
		}
		magic = Math.min(magic, 2000);
		Integer hbhp = getBuffedValue(MapleBuffStat.HYPERBODYHP);
		if (hbhp != null) {
			localmaxhp += (hbhp.doubleValue() / 100) * localmaxhp;
		}
		Integer hbmp = getBuffedValue(MapleBuffStat.HYPERBODYMP);
		if (hbmp != null) {
			localmaxmp += (hbmp.doubleValue() / 100) * localmaxmp;
		}
		localmaxhp = Math.min(30000, localmaxhp);
		localmaxmp = Math.min(30000, localmaxmp);
		Integer watkbuff = getBuffedValue(MapleBuffStat.WATK);
		if (watkbuff != null) {
			watk += watkbuff.intValue();
		}
		if (job.isA(MapleJob.BOWMAN)) {
			ISkill expert = null;
			if (job.isA(MapleJob.CROSSBOWMASTER)) {
				expert = SkillFactory.getSkill(3220004);
			} else if (job.isA(MapleJob.BOWMASTER)) {
				expert = SkillFactory.getSkill(3120005);
			}
			if (expert != null) {
				int boostLevel = getSkillLevel(expert);
				if (boostLevel > 0) {
					watk += expert.getEffect(boostLevel).getX();
				}
			}
		}
		Integer matkbuff = getBuffedValue(MapleBuffStat.MATK);
		if (matkbuff != null) {
			magic += matkbuff.intValue();
		}
		Integer speedbuff = getBuffedValue(MapleBuffStat.SPEED);
		if (speedbuff != null) {
			speed += speedbuff.intValue();
		}
		Integer jumpbuff = getBuffedValue(MapleBuffStat.JUMP);
		if (jumpbuff != null) {
			jump += jumpbuff.intValue();
		}
		if (speed > 140) {
			speed = 140;
		}
		if (jump > 123) {
			jump = 123;
		}
		speedMod = speed / 100.0;
		jumpMod = jump / 100.0;
		Integer mount = getBuffedValue(MapleBuffStat.MONSTER_RIDING);
		if (mount != null) {
			jumpMod = 1.23;
			switch (mount.intValue()) {
				case 1:
					speedMod = 1.5;
					break;
				case 2:
					speedMod = 1.7;
					break;
				case 3:
					speedMod = 1.8;
					break;
				default:
					log.warn("Unhandeled monster riding level");
			}
		}
		localmaxbasedamage = calculateMaxBaseDamage(watk);
		if (oldmaxhp != 0 && oldmaxhp != localmaxhp) {
			updatePartyMemberHP();
		}
	}

	public void equipChanged() {
		getMap().broadcastMessage(this, MaplePacketCreator.updateCharLook(this), false);
		recalcLocalStats();
		enforceMaxHpMp();
                if (getClient().getPlayer().getMessenger() != null) {
                    WorldChannelInterface wci = ChannelServer.getInstance(getClient().getChannel()).getWorldInterface();
                    try {
			wci.updateMessenger(getClient().getPlayer().getMessenger().getId(), getClient().getPlayer().getName(), getClient().getChannel());
                    } 
                    catch (RemoteException e) {
			getClient().getChannelServer().reconnectWorld();
                    }
                }
	}

	public MaplePet getPet() {
		return pet;
	}

	public void setPet(MaplePet pet) {
		this.pet = pet;
	}
	
	public FameStatus canGiveFame(MapleCharacter from) {
		if (lastfametime >= System.currentTimeMillis() - 60*60*24*1000) {
			return FameStatus.NOT_TODAY;
		} else if (lastmonthfameids.contains(Integer.valueOf(from.getId()))) {
			return FameStatus.NOT_THIS_MONTH;
		} else {
			return FameStatus.OK;
		}
	}
	
	public void hasGivenFame(MapleCharacter to) {
		lastfametime = System.currentTimeMillis();
		lastmonthfameids.add(Integer.valueOf(to.getId()));
		Connection con = DatabaseConnection.getConnection();
		try {
			PreparedStatement ps = con
				.prepareStatement("INSERT INTO famelog (characterid, characterid_to) VALUES (?, ?)");
			ps.setInt(1, getId());
			ps.setInt(2, to.getId());
			ps.executeUpdate();
			ps.close();
		} catch (SQLException e) {
			log.error("ERROR writing famelog for char " + getName() + " to " + to.getName(), e);
		}
	}
	
	public MapleParty getParty() {
		return party;
	}

	public int getWorld() {
		return world;
	}

	public void setWorld(int world) {
		this.world = world;
	}

	public void setParty(MapleParty party) {
		this.party = party;
	}

	public MapleTrade getTrade() {
		return trade;
	}

	public void setTrade(MapleTrade trade) {
		this.trade = trade;
	}

	public EventInstanceManager getEventInstance() {
		return eventInstance;
	}

	public void setEventInstance(EventInstanceManager eventInstance) {
		this.eventInstance = eventInstance;
	}
	
	public void addDoor(MapleDoor door) {
		doors.add(door);
	}
	
	public void clearDoors() {
		doors.clear();
	}
	
	public List<MapleDoor> getDoors() {
		return new ArrayList<MapleDoor>(doors);
	}
	
	public boolean canDoor() {
		return canDoor;
	}
	
	public void disableDoor() {
		canDoor = false;
		TimerManager tMan = TimerManager.getInstance();
		tMan.schedule(new Runnable() {
			@Override
			public void run() {
				canDoor = true;
			}
		}, 5000);
	}
	
	public Map<Integer, MapleSummon> getSummons() {
		return summons;
	}
	
	public int getChair() {
		return chair;
	}

	public int getItemEffect() {
		return itemEffect;
	}

	public void setChair(int chair) {
		this.chair = chair;
	}

	public void setItemEffect(int itemEffect) {
		this.itemEffect = itemEffect;
	}
	
	@Override
	public Collection<MapleInventory> allInventories() {
		return Arrays.asList(inventory);
	}
	
	@Override
	public MapleMapObjectType getType() {
		return MapleMapObjectType.PLAYER;
	}

	private static class MapleBuffStatValueHolder {
		public MapleStatEffect effect;
		public long startTime;
		public int value;
		public ScheduledFuture<?> schedule;

		public MapleBuffStatValueHolder(MapleStatEffect effect, long startTime, ScheduledFuture<?> schedule, int value) {
			super();
			this.effect = effect;
			this.startTime = startTime;
			this.schedule = schedule;
			this.value = value;
		}
	}
	
	public static class SkillEntry {
		public int skillevel;
		public int masterlevel;
		
		public SkillEntry(int skillevel, int masterlevel) {
			this.skillevel = skillevel;
			this.masterlevel = masterlevel;
		}
		
		@Override
		public String toString() {
			return skillevel + ":" + masterlevel;
		}
	}
	
	public enum FameStatus {
		OK, NOT_TODAY, NOT_THIS_MONTH
	}
    
        public int getBuddyCapacity() {
                return buddylist.getCapacity();    
        }
         
       public void setBuddyCapacity(int capacity) {
                buddylist.setCapacity(capacity);
                client.getSession().write(MaplePacketCreator.updateBuddyCapacity(capacity));
        }

        public void gainNX(int nxchange) {  
                this.nxcash += nxchange;
	}
        
	public MapleMessenger getMessenger() {
		return messenger;
	}

	public void setMessenger(MapleMessenger messenger) {
		this.messenger = messenger;
	}
        
        public void checkMessenger() {
                if (messenger != null && messengerposition < 4 && messengerposition > -1 ) {
                    try {
                            WorldChannelInterface wci = ChannelServer.getInstance(client.getChannel()).getWorldInterface();
                            MapleMessengerCharacter messengerplayer = new MapleMessengerCharacter(client.getPlayer(), messengerposition);
                            wci.silentJoinMessenger(messenger.getId(), messengerplayer, messengerposition);
                            wci.updateMessenger(getClient().getPlayer().getMessenger().getId(), getClient().getPlayer().getName(), getClient().getChannel());
                    }
                    catch (RemoteException e) {
                            client.getChannelServer().reconnectWorld();
                    }
                }
        }
        
        public int getMessengerPosition() {
		return messengerposition;
	}

	public void setMessengerPosition(int position) {
		this.messengerposition = position;
	}

	public int hasEXPCard() {
		for ( int i=5210999; i<5211048; i++ ) {
			if (haveItem(i, 1, false, true)) {
				return 2;
			}
		}
		return 1;
	}
	
	public boolean getNXCodeValid(String code, boolean validcode) throws SQLException {
		
		Connection con = DatabaseConnection.getConnection();
		PreparedStatement ps = con.prepareStatement("SELECT `valid` FROM nxcode WHERE code = ?");
		ps.setString(1, code);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			validcode = rs.getInt("valid") == 0 ? false : true;
		}
		
		rs.close();
		ps.close();
		
		return validcode;
	}
	
	public int getNXCodeType(String code) throws SQLException {
		
		int type = -1;
		Connection con = DatabaseConnection.getConnection();
		PreparedStatement ps = con.prepareStatement("SELECT `type` FROM nxcode WHERE code = ?");
		ps.setString(1, code);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			type = rs.getInt("type");
		}
		
		rs.close();
		ps.close();
		
		return type;
	}
	
	public int getNXCodeItem(String code) throws SQLException {
		
		int item = -1;
		Connection con = DatabaseConnection.getConnection();
		PreparedStatement ps = con.prepareStatement("SELECT `item` FROM nxcode WHERE code = ?");
		ps.setString(1, code);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			item = rs.getInt("item");
		}
		
		rs.close();
		ps.close();
		
		return item;
	}
	
	public void setNXCodeUsed(String code) throws SQLException {
		Connection con = DatabaseConnection.getConnection();
		PreparedStatement ps = con.prepareStatement("UPDATE nxcode SET `valid` = 0 WHERE code = ?");
		ps.setString(1, code);
		ps.executeUpdate();
		ps = con.prepareStatement("UPDATE nxcode SET `user` = ? WHERE code = ?");
		ps.setString(1, this.getName());
		ps.setString(2, code);
		ps.executeUpdate();
		ps.close();
	}
	
	public void setInCS(boolean yesno) {
		this.incs = yesno;
	}
	
	public boolean inCS() {
		return this.incs;
	}

        public void updateJQ() {
            Calendar cal = Calendar.getInstance();
            this.lastJQ = cal.getTimeInMillis();
	}
		
	public boolean grabJQ() {
           Calendar cal = Calendar.getInstance();
           long time = cal.getTimeInMillis();
		if ((time - (1000 * 60 * 5)) >= this.lastJQ){
			return true;
		}
		else {
			return false;
		}			
	}
	
	public int getGuildId() {
		return guildid;
	}

	public int getGuildRank() {
		return guildrank;
	}

	public void setGuildId(int _id) {
		guildid = _id;
		if (guildid > 0) {
			if (mgc == null)
				mgc = new MapleGuildCharacter(this);
			else
				mgc.setGuildId(guildid);
		} else
			mgc = null;
	}

	public void setGuildRank(int _rank) {
		guildrank = _rank;
		if (mgc != null)
			mgc.setGuildRank(_rank);
	}

	public MapleGuildCharacter getMGC() {
		return mgc;
	}

	public void guildUpdate() {
		if (this.guildid <= 0)
			return;

		mgc.setLevel(this.level);
		mgc.setJobId(this.job.getId());

		try {
			this.client.getChannelServer().getWorldInterface().memberLevelJobUpdate(this.mgc);
		} catch (RemoteException re) {
			log.error("RemoteExcept while trying to update level/job in guild.", re);
		}
	}
	
	private NumberFormat nf = new DecimalFormat("#,###,###,###");

	public String guildCost() {
		return nf.format(MapleGuild.CREATE_GUILD_COST);
	}

	public String emblemCost() {
		return nf.format(MapleGuild.CHANGE_EMBLEM_COST);
	}

	public String capacityCost() {
		return nf.format(MapleGuild.INCREASE_CAPACITY_COST);
	}

	public void genericGuildMessage(int code) {
		this.client.getSession().write(MaplePacketCreator.genericGuildMessage((byte) code));
	}

	public void disbandGuild() {
		if (guildid <= 0 || guildrank != 1) {
			log.warn(this.name + " tried to disband and s/he is either not in a guild or not leader.");
			return;
		}

		try {
			client.getChannelServer().getWorldInterface().disbandGuild(this.guildid);
		} catch (Exception e) {
			log.error("Error while disbanding guild.", e);
		}
	}

	public void increaseGuildCapacity() {
		if (this.getMeso() < MapleGuild.INCREASE_CAPACITY_COST) {
			client.getSession().write(MaplePacketCreator.serverNotice(1, "You do not have enough mesos."));
			return;
		}

		if (this.guildid <= 0) {
			log.info(this.name + " is trying to increase guild capacity without being in the guild.");
			return;
		}

		try {
			client.getChannelServer().getWorldInterface().increaseGuildCapacity(this.guildid);
		} catch (Exception e) {
			log.error("Error while increasing capacity.", e);
			return;
		}

		this.gainMeso(-MapleGuild.INCREASE_CAPACITY_COST, true, false, true);
	}

	public void saveGuildStatus() {
		Connection con = DatabaseConnection.getConnection();
		try {
			PreparedStatement ps = con.prepareStatement("UPDATE characters SET guildid = ?, guildrank = ? WHERE id = ?");
			ps.setInt(1, this.guildid);
			ps.setInt(2, this.guildrank);
			ps.setInt(3, this.id);
			ps.execute();
			ps.close();
		} catch (SQLException se) {
			log.error("SQL error: " + se.getLocalizedMessage(), se);
		}
	}
	
	/**
	 * Allows you to change someone's NXCash, Maple Points, and Gift Tokens!
	 * 
	 * Created by Acrylic/Penguins
	 * 
	 * @param type: 0 = NX, 1 = MP, 2 = GT, quantity: how much to modify it by. Negatives subtract points, Positives add points. 
	 */
	public void modifyCSPoints(int type, int quantity) {
		if (type == 0) {
			this.nxcash += quantity;
		} else if (type == 1) {
			this.maplepoints += quantity;
		} else if (type == 2) {
			this.gifttokens += quantity;
		}
	}
	
	public int returnCSPoints(int type) {
		if (type == 0) {
			return this.nxcash;
		} else if (type == 1) {
			return this.maplepoints;
		} else if (type == 2) {
			return this.gifttokens;
		} else {
			return 0;
		}
	}
	
	public boolean haveItem(int itemid) {
		return haveItem(itemid, 1);
	}
	
	public boolean haveItem(int itemid, int quantity) {
		return haveItem(itemid, quantity, false, true);
	}

	public void setFame(int fame) {
            this.fame = fame; 
        }
        
        public void gainFame(int famechange) {  
            this.fame += famechange;
	}

        public void setLevel(int level) {
                this.level = level-1;
        }
        public boolean getCanSmega()
    {
        return canSmega;
    }
    
    public void setCanSmega(boolean setTo)
    {
        canSmega = setTo;
    }
	
	public boolean haveItem(int itemid, int quantity, boolean checkEquipped, boolean greaterOrEquals) {
		MapleInventoryType type = MapleItemInformationProvider.getInstance().getInventoryType(itemid);
		MapleInventory iv = inventory[type.ordinal()];
		int possesed = iv.countById(itemid);
		if (checkEquipped) {
			possesed += inventory[MapleInventoryType.EQUIPPED.ordinal()].countById(itemid);
		}
		if (greaterOrEquals) {
			return possesed >= quantity;
		} else {
			return possesed == quantity;
		}
	}

 }
Heres my CommandProcessor.java
Code:
/*
	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.sf.odinms.client.messages;

import java.awt.Point;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Calendar;

import javax.management.MBeanServer;
import javax.management.ObjectName;

import net.sf.odinms.client.IItem;
import net.sf.odinms.client.Item;
import net.sf.odinms.client.MapleCharacter;
import net.sf.odinms.client.MapleCharacterUtil;
import net.sf.odinms.client.MapleClient;
import net.sf.odinms.client.MapleInventoryType;
import net.sf.odinms.client.MapleJob;
import net.sf.odinms.client.MapleStat;
import net.sf.odinms.client.MapleInventory;
import net.sf.odinms.client.SkillFactory;
import net.sf.odinms.client.anticheat.CheatingOffense;
import net.sf.odinms.database.DatabaseConnection;
import net.sf.odinms.net.ExternalCodeTableGetter;
import net.sf.odinms.net.MaplePacket;
import net.sf.odinms.net.PacketProcessor;
import net.sf.odinms.scripting.event.EventInstanceManager;
import net.sf.odinms.net.RecvPacketOpcode;
import net.sf.odinms.net.SendPacketOpcode;
import net.sf.odinms.net.channel.ChannelServer;
import net.sf.odinms.net.channel.handler.GeneralchatHandler;
import net.sf.odinms.net.world.remote.CheaterData;
import net.sf.odinms.net.world.remote.WorldLocation;
import net.sf.odinms.scripting.portal.PortalScriptManager;
import net.sf.odinms.scripting.reactor.ReactorScriptManager;
import net.sf.odinms.server.MapleInventoryManipulator;
import net.sf.odinms.server.MapleItemInformationProvider;
import net.sf.odinms.server.MaplePortal;
import net.sf.odinms.server.MapleShop;
import net.sf.odinms.server.MapleShopFactory;
import net.sf.odinms.server.MapleTrade;
import net.sf.odinms.server.ShutdownServer;
import net.sf.odinms.server.TimerManager;
import net.sf.odinms.server.life.MapleLifeFactory;
import net.sf.odinms.server.life.MapleMonster;
import net.sf.odinms.server.life.MapleMonsterInformationProvider;
import net.sf.odinms.server.life.MapleMonsterStats;
import net.sf.odinms.server.life.MapleNPC;
import net.sf.odinms.server.maps.MapleDoor;
import net.sf.odinms.server.maps.MapleMap;
import net.sf.odinms.server.maps.MapleMapObject;
import net.sf.odinms.server.maps.MapleMapObjectType;
import net.sf.odinms.server.quest.MapleQuest;
import net.sf.odinms.tools.HexTool;
import net.sf.odinms.tools.MaplePacketCreator;
import net.sf.odinms.tools.MockIOSession;
import net.sf.odinms.tools.Pair;
import net.sf.odinms.tools.StringUtil;
import net.sf.odinms.tools.data.output.MaplePacketLittleEndianWriter;
import net.sf.odinms.server.life.SpawnPoint;
import net.sf.odinms.server.maps.MapleMapFactory;
import net.sf.odinms.server.maps.MapleMapItem;
import net.sf.odinms.server.maps.MapleReactor;
import net.sf.odinms.server.maps.MapleReactorFactory;
import net.sf.odinms.server.maps.MapleReactorStats;
import net.sf.odinms.client.messages.ServernoticeMapleClientMessageCallback;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URL;
import java.net.URLConnection;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.io.InputStreamReader;
import java.lang.String;

public class CommandProcessor implements CommandProcessorMBean {
	private static CommandProcessor instance = new CommandProcessor();
	private static final Logger log = LoggerFactory.getLogger(GeneralchatHandler.class);
	private static List<Pair<MapleCharacter,String>> gmlog = new LinkedList<Pair<MapleCharacter,String>>();
	private static Runnable persister;
	final private static String[] reasons = {"Hacking", "Botting", "Scamming", "Fake GM", "Harassment", "Advertising"};

	static {
		persister = new PersistingTask();
		TimerManager.getInstance().register(persister, 62000);
	}
	
	private CommandProcessor() {
		// hidden singleton so we can become managable
	}
	
	public static class PersistingTask implements Runnable {
		@Override
		public void run() {
			synchronized (gmlog) {
				Connection con = DatabaseConnection.getConnection();
				try {
					PreparedStatement ps = con.prepareStatement("INSERT INTO gmlog (cid, command) VALUES (?, ?)");
					for (Pair<MapleCharacter,String> logentry : gmlog) {
						ps.setInt(1, logentry.getLeft().getId());
						ps.setString(2, logentry.getRight());
						ps.executeUpdate();
					}
					ps.close();
				} catch (SQLException e) {
					log.error("error persisting cheatlog", e);
				}
				gmlog.clear();
			}
		}
	}
	
	public static void registerMBean() {
		MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
		try {
			mBeanServer.registerMBean(instance, new ObjectName("net.sf.odinms.client.messages:name=CommandProcessor"));
		} catch (Exception e) {
			log.error("Error registering CommandProcessor MBean");
		}
	}
	
	private static int getNoticeType(String typestring) {
		if (typestring.equals("n")) {
			return 0;
		} else if (typestring.equals("p")) {
			return 1;
		} else if (typestring.equals("l")) {
			return 2;
		} else if (typestring.equals("nv")) {
			return 5;
		} else if (typestring.equals("v")) {
			return 5;
		} else if (typestring.equals("b")) {
			return 6;
		}
		return -1;
	}

              	private static String joinAfterString(String splitted[], String str) {
		for (int i = 1; i < splitted.length; i++) {
			if (splitted[i].equalsIgnoreCase(str) && i + 1 < splitted.length) {
                            return StringUtil.joinStringFrom(splitted, i+1);
			}
		}
		return null;
	}
        
	private static int getOptionalIntArg(String splitted[], int position, int def) {
		if (splitted.length > position) {
			try {
				return Integer.parseInt(splitted[position]);
			} catch (NumberFormatException nfe) {
				return def;
			}
		}
		return def;
	}

	private static String getNamedArg(String splitted[], int startpos, String name) {
		for (int i = startpos; i < splitted.length; i++) {
			if (splitted[i].equalsIgnoreCase(name) && i + 1 < splitted.length) {
				return splitted[i + 1];
			}
		}
		return null;
	}

	private static Integer getNamedIntArg(String splitted[], int startpos, String name) {
		String arg = getNamedArg(splitted, startpos, name);
		if (arg != null) {
			try {
				return Integer.parseInt(arg);
			} catch (NumberFormatException nfe) {
				// swallow - we don't really care
			}
		}
		return null;
	}
	
	private static int getNamedIntArg(String splitted[], int startpos, String name, int def) {
		Integer ret = getNamedIntArg(splitted, startpos, name);
		if (ret == null) {
			return def;
		}
		return ret.intValue();
	}

	private static Double getNamedDoubleArg(String splitted[], int startpos, String name) {
		String arg = getNamedArg(splitted, startpos, name);
		if (arg != null) {
			try {
				return Double.parseDouble(arg);
			} catch (NumberFormatException nfe) {
				// swallow - we don't really care
			}
		}
		return null;
	}

	public static boolean processCommand(MapleClient c, String line) {
		return processCommandInternal(c, new ServernoticeMapleClientMessageCallback(c), c.getPlayer().isGM(), line);
	}
	
	/* (non-Javadoc)
	 * @see net.sf.odinms.client.messages.CommandProcessorMBean#processCommandJMX(int, int, java.lang.String)
	 */
	public String processCommandJMX(int cserver, int mapid, String command) {
		ChannelServer cserv = ChannelServer.getInstance(cserver);
		if (cserv == null) {
			return "The specified channel Server does not exist in this serverprocess";
		}
		MapleClient c = new MapleClient(null, null, new MockIOSession());
		MapleCharacter chr = MapleCharacter.getDefault(c, 26023);
		c.setPlayer(chr);
		chr.setName("/---------jmxuser-------------\\"); // (name longer than maxmimum length)
		MapleMap map = cserv.getMapFactory().getMap(mapid);
		if (map != null) {
			chr.setMap(map);
			SkillFactory.getSkill(5101004).getEffect(1).applyTo(chr);
			map.addPlayer(chr);
		}
		cserv.addPlayer(chr);
		MessageCallback mc = new StringMessageCallback();
		try {
			processCommandInternal(c, mc, true, command);
		} finally {
			if (map != null) {
				map.removePlayer(chr);
			}
			cserv.removePlayer(chr);
		}
		return mc.toString();
	}
	
	/* (non-Javadoc)
	 * @see net.sf.odinms.client.messages.CommandProcessorMBean#processCommandInstance(net.sf.odinms.client.MapleClient, java.lang.String)
	 */
	private static boolean processCommandInternal(MapleClient c, MessageCallback mc, boolean isGM, String line) {
		MapleCharacter player = c.getPlayer();
		ChannelServer cserv = c.getChannelServer();
		if (line.charAt(0) == '!' && isGM || line.charAt(0) =='@') {
			synchronized (gmlog) {
				gmlog.add(new Pair<MapleCharacter, String>(player, line));
			}
			log.warn("{} used a GM command: {}", c.getPlayer().getName(), line);
			String[] splitted = line.split(" ");
			if (splitted[0].equals("!map")) {
				int mapid = Integer.parseInt(splitted[1]);
				MapleMap target = cserv.getMapFactory().getMap(mapid);
				MaplePortal targetPortal = null;
				if (splitted.length > 2) {
					try {
						targetPortal = target.getPortal(Integer.parseInt(splitted[2]));
					} catch (IndexOutOfBoundsException ioobe) {
						// noop, assume the gm didn't know how many portals there are
					} catch (NumberFormatException nfe) {
						// noop, assume that the gm is drunk
					}
				}
				if (targetPortal == null) {
					targetPortal = target.getPortal(0);
				}
				player.changeMap(target, targetPortal);
			} else if (splitted[0].equals("!jail")) {
				MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
				int mapid = 200090300; // mulung ride
				if (splitted.length > 2 && splitted[1].equals("2")) {
					mapid = 980000404; // exit for CPQ; not used
					victim = cserv.getPlayerStorage().getCharacterByName(splitted[2]);
				}
				if (victim != null) {
					MapleMap target = cserv.getMapFactory().getMap(mapid);
					MaplePortal targetPortal = target.getPortal(0);
					victim.changeMap(target, targetPortal);
					mc.dropMessage(victim.getName() + " was jailed!");
				} else {
					mc.dropMessage(splitted[1] + " not found!");
				}
			} else if (splitted[0].equals("!lolcastle")) {
				if (splitted.length != 2) {
					mc.dropMessage("Syntax: !lolcastle level (level = 1-5)");
				}
				MapleMap target = c.getChannelServer().getEventSM().getEventManager("lolcastle").getInstance("lolcastle" + splitted[1]).getMapFactory().getMap(990000300, false, false);
				player.changeMap(target, target.getPortal(0));
			} else if (splitted[0].equals("!warp")) {
				MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
				if (victim != null) {
					if (splitted.length == 2) {
						MapleMap target = victim.getMap();
						c.getPlayer().changeMap(target, target.findClosestSpawnpoint(victim.getPosition()));
					} else {
						int mapid = Integer.parseInt(splitted[2]);
						MapleMap target = ChannelServer.getInstance(c.getChannel()).getMapFactory().getMap(mapid);
						victim.changeMap(target, target.getPortal(0));
					}
				} else {
					try {
						victim = c.getPlayer();
						WorldLocation loc = c.getChannelServer().getWorldInterface().getLocation(splitted[1]);
						if (loc != null) {
							mc.dropMessage("You will be cross-channel warped. This may take a few seconds.");
							//WorldLocation loc = new WorldLocation(40000, 2);
							MapleMap target = c.getChannelServer().getMapFactory().getMap(loc.map);
							c.getPlayer().cancelAllBuffs();
							String ip = c.getChannelServer().getIP(loc.channel);
							c.getPlayer().getMap().removePlayer(c.getPlayer());
							victim.setMap(target);
							String[] socket = ip.split(":");
							if (c.getPlayer().getTrade() != null) {
								MapleTrade.cancelTrade(c.getPlayer());
							}
							c.getPlayer().saveToDB(true);
							if (c.getPlayer().getCheatTracker() != null)
								c.getPlayer().getCheatTracker().dispose();
							ChannelServer.getInstance(c.getChannel()).removePlayer(c.getPlayer());
							c.updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION);
							try {
								MaplePacket packet = MaplePacketCreator.getChannelChange(
									InetAddress.getByName(socket[0]), Integer.parseInt(socket[1]));
								c.getSession().write(packet);
							} catch (Exception e) {
								throw new RuntimeException(e);
							}
						} else {
							int map = Integer.parseInt(splitted[1]);
							MapleMap target = cserv.getMapFactory().getMap(map);
							player.changeMap(target, target.getPortal(0));
						}
					} catch (/*Remote*/Exception e) {
						mc.dropMessage("Something went wrong " + e.getMessage());
					}
				}
			}  else if (splitted[0].equals("!toggleoffense")) {
				try {
					CheatingOffense co = CheatingOffense.valueOf(splitted[1]);
					co.setEnabled(!co.isEnabled());
				} catch (IllegalArgumentException iae) {
					mc.dropMessage("Offense " + splitted[1] + " not found");
				}
	
				} else if (splitted[0].equals("!warphere")) {
				MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
				victim.changeMap(c.getPlayer().getMap(), c.getPlayer().getMap().findClosestSpawnpoint(
					c.getPlayer().getPosition()));
			} else if (splitted[0].equals("!spawn")) {
				int mid = Integer.parseInt(splitted[1]);
				int num = Math.min(getOptionalIntArg(splitted, 2, 1), 500);

				if (mid == 9400203) {
					log.info(MapleClient.getLogMessage(player, "Trying to spawn a silver slime"));
					return true;
				}

				Integer hp = getNamedIntArg(splitted, 1, "hp");
				Integer exp = getNamedIntArg(splitted, 1, "exp");
				Double php = getNamedDoubleArg(splitted, 1, "php");
				Double pexp = getNamedDoubleArg(splitted, 1, "pexp");

				MapleMonster onemob = MapleLifeFactory.getMonster(mid);

				int newhp = 0;
				int newexp = 0;

				double oldExpRatio = ((double) onemob.getHp() / onemob.getExp());

				if (hp != null) {
					newhp = hp.intValue();
				} else if (php != null) {
					newhp = (int) (onemob.getMaxHp() * (php.doubleValue() / 100));
				} else {
					newhp = onemob.getMaxHp();
				}
				if (exp != null) {
					newexp = exp.intValue();
				} else if (pexp != null) {
					newexp = (int) (onemob.getExp() * (pexp.doubleValue() / 100));
				} else {
					newexp = onemob.getExp();
				}

				if (newhp < 1) {
					newhp = 1;
				}
				double newExpRatio = ((double) newhp / newexp);
				if (newExpRatio < oldExpRatio && newexp > 0) {
					mc.dropMessage("The new hp/exp ratio is better than the old one. (" + newExpRatio + " < " +
						oldExpRatio + ") Please don't do this");
					return true;
				}
				
				MapleMonsterStats overrideStats = new MapleMonsterStats();
				overrideStats.setHp(newhp);
				overrideStats.setExp(newexp);
				overrideStats.setMp(onemob.getMaxMp());
				
				for (int i = 0; i < num; i++) {
					MapleMonster mob = MapleLifeFactory.getMonster(mid);
					mob.setHp(newhp);
					mob.setOverrideStats(overrideStats);
					c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob, c.getPlayer().getPosition());
				}
			} else if (splitted[0].equals("!servermessage")) {
				ChannelServer.getInstance(c.getChannel()).setServerMessage(StringUtil.joinStringFrom(splitted, 1));
			} else if (splitted[0].equals("!array")) {
				mc.dropMessage("Array");
			} else if (splitted[0].equals("!notice")) {
				int joinmod = 1;

				int range = -1;
				if (splitted[1].equals("m")) {
					range = 0;
				} else if (splitted[1].equals("c")) {
					range = 1;
				} else if (splitted[1].equals("w")) {
					range = 2;
				}

				int tfrom = 2;
				if (range == -1) {
					range = 2;
					tfrom = 1;
				}
				int type = getNoticeType(splitted[tfrom]);
				if (type == -1) {
					type = 0;
					joinmod = 0;
				}
				String prefix = "";
				if (splitted[tfrom].equals("nv")) {
					prefix = "[Notice] ";
				}
				joinmod += tfrom;
				MaplePacket packet = MaplePacketCreator.serverNotice(type, prefix +
					StringUtil.joinStringFrom(splitted, joinmod));
				if (range == 0) {
					c.getPlayer().getMap().broadcastMessage(packet);
				} else if (range == 1) {
					ChannelServer.getInstance(c.getChannel()).broadcastPacket(packet);
				} else if (range == 2) {
					try {
						ChannelServer.getInstance(c.getChannel()).getWorldInterface().broadcastMessage(
							c.getPlayer().getName(), packet.getBytes());
					} catch (RemoteException e) {
						c.getChannelServer().reconnectWorld();
					}
				}
			} else if (splitted[0].equals("!say")) {
                            if (splitted.length > 1) { 
                                MaplePacket packet = MaplePacketCreator.serverNotice(6, "[" + c.getPlayer().getName() + "] " + StringUtil.joinStringFrom(splitted, 1));
                                try {
                                    ChannelServer.getInstance(c.getChannel()).getWorldInterface().broadcastMessage(
                                    c.getPlayer().getName(), packet.getBytes());
				} catch (RemoteException e) {
                                    c.getChannelServer().reconnectWorld();
				}
                            } else {
                                mc.dropMessage("Syntax: !say <message>");
                            }
			} else if (splitted[0].equals("!job")) {
				c.getPlayer().changeJob(MapleJob.getById(Integer.parseInt(splitted[1])));
			} else if (splitted[0].equals("!clock")) {
				player.getMap().broadcastMessage(MaplePacketCreator.getClock(getOptionalIntArg(splitted, 1, 60)));
			} else if (splitted[0].equals("!pill")) {
				MapleInventoryManipulator.addById(c, 2002009, (short) 5, c.getPlayer().getName() + " used !pill", player.getName());
			}  else if (splitted[0].equals("!pill")) {
				MapleInventoryManipulator.addById(c, 2002009, (short) 5, c.getPlayer().getName() + " used !pill", player.getName());
			}
                if (splitted[0].equals("!save")) {
                        player.saveToDB(true);
                }   else if (splitted[0].equals("!smegaoff"))
            {
                MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                victim.setCanSmega(false);
                mc.dropMessage("You have disabled " + victim.getName() + "'s megaphone privilages");
                
                ServernoticeMapleClientMessageCallback cm = new ServernoticeMapleClientMessageCallback(victim.getClient());
                
                if(!(c.getPlayer().getName().equals(victim.getName())))
                {
                    cm.dropMessage("Your megaphone privilages have been disabled by a GM.");
                }
            }
            
            else if (splitted[0].equals("!smegaon"))
            {
                MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                victim.setCanSmega(true);
                mc.dropMessage("You have enabled " + victim.getName() + "'s megaphone privilages");
                
                ServernoticeMapleClientMessageCallback cm = new ServernoticeMapleClientMessageCallback(victim.getClient());
                
                if(!(c.getPlayer().getName().equals(victim.getName())))
                {
                    cm.dropMessage("Your megaphone privilages have been enabled by a GM.");
                }
            
                } else if (splitted[0].equals("!jobperson")) {
                              MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);  
                             victim.changeJob(MapleJob.getById(getOptionalIntArg(splitted, 2, 2)));
	} else if (splitted[0].equals("!giftnx")) {
                             MapleCharacter victim1 = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                        int points = Integer.parseInt(splitted[2]);
                            	victim1.modifyCSPoints(0, points);
                                mc.dropMessage("Yah!");
				
                        } else if (splitted[0].equals("!unownms"))
            {
                if (splitted.length == 1)
                {
                    mc.dropMessage("Usage: !amega [name] [type] [message], where [type] is love, cloud, or diablo.");
                }
                
                MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                
                String type = splitted[2];
                int channel = victim.getClient().getChannel();
                String text = StringUtil.joinStringFrom(splitted, 3);
                
                int itemID = 0;
                
                if(type.equals("love"))
                    itemID = 5390002;
                
                else if(type.equals("cloud"))
                    itemID = 5390001;
                
                else if(type.equals("diablo"))
                    itemID = 5390000;
                
                else
                {
                    mc.dropMessage("Invalid type (use love, cloud, or diablo)");
                    return true;
                }
                
                String[] lines = {"", "", "", ""};
                
                if(text.length() > 30)
                {
                    lines[0] = text.substring(0, 10);
                    lines[1] = text.substring(10, 20);
                    lines[2] = text.substring(20, 30);
                    lines[3] = text.substring(30);
                }
                
                else if(text.length() > 20)
                {
                    lines[0] = text.substring(0, 10);
                    lines[1] = text.substring(10, 20);
                    lines[2] = text.substring(20);
                }
                
                else if(text.length() > 10)
                {
                    lines[0] = text.substring(0, 10);
                    lines[1] = text.substring(10);
                }
                
                else if(text.length() <= 10)
                {
                    lines[0] = text;
                }
                
                LinkedList list = new LinkedList();
                list.add(lines[0]);
                list.add(lines[1]);
                list.add(lines[2]);
                list.add(lines[3]);
                
                try
                {
                    MaplePacket mp = MaplePacketCreator.getAvatarMega(victim, channel, itemID, list);
                    victim.getClient().getChannelServer().getWorldInterface().broadcastMessage(null, mp.getBytes());
                }
                catch(Exception e)
                {}
            }  else if (splitted[0].equals("!dcall")) {
    
				int level = 0;
                               
				for (MapleCharacter mch : cserv.getPlayerStorage().getAllCharacters()){
				mch.getClient().getSession().close();
					mch.getClient().disconnect();
                                }
				
				}  else if (splitted[0].equals("!jobperson")) {
                              MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);  
                             victim.changeJob(MapleJob.getById(getOptionalIntArg(splitted, 2, 2)));
			}      else if (splitted[0].equals("@str")) {
                   int up;
                    up = Integer.parseInt(splitted[1]);
                    if ( player.getRemainingAp() < up ||  player.getRemainingAp() < 0) {
                        mc.dropMessage("InsufficientAP");
                    }  else if ( player.getRemainingAp() > 0) {
                          player.setStr(player.getStr() + up);
                          player.setRemainingAp(player.getRemainingAp() - up);
                          player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
                          player.updateSingleStat(MapleStat.STR, player.getStr());
                }
                 
                }else if (splitted[0].equals("@int")) {
                   int up;
                    up = Integer.parseInt(splitted[1]);
                    if ( player.getRemainingAp() < up ||  player.getRemainingAp() < 0) {
                        mc.dropMessage("InsufficientAP");
                    } else if ( player.getRemainingAp() > 0) {
                          player.setInt(player.getInt() + up);
                          player.setRemainingAp(player.getRemainingAp() - up);
                          player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
                          player.updateSingleStat(MapleStat.INT, player.getInt());
                }
                    //DEX
                }else if (splitted[0].equals("@dex")) {
                   int up;
                    up = Integer.parseInt(splitted[1]);
                    if ( player.getRemainingAp() < up ||  player.getRemainingAp() < 0) {
                        mc.dropMessage("InsufficientAP");
                    } else if ( player.getRemainingAp() > 0) {
                          player.setDex(player.getDex() + up);
                          player.setRemainingAp(player.getRemainingAp() - up);
                           player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
                          player.updateSingleStat(MapleStat.DEX, player.getDex());
                }
                    //LUCK
                }else if (splitted[0].equals("@luk")) {
                   int up;
                    up = Integer.parseInt(splitted[1]);
                    if ( player.getRemainingAp() < up ||  player.getRemainingAp() < 0) {
                        mc.dropMessage("InsufficientAP");
                    } else if ( player.getRemainingAp() > 0) {
                          player.setLuk(player.getLuk() + up);
                             player.setRemainingAp(player.getRemainingAp() - up);
                           player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
                          player.updateSingleStat(MapleStat.LUK, player.getLuk());
                }
                } else if (splitted[0].equals("@exp")) {
                             int expfix;
				expfix = c.getPlayer().getExp();
                               if (expfix < 0) {
                                      c.getPlayer().gainExp(-expfix, false, false);
				      player.updateSingleStat(MapleStat.EXP, player.getExp()); }
mc.dropMessage("You don't have negative exp.");

                } else if (splitted[0].equals("!item")) {
				short quantity = (short) getOptionalIntArg(splitted, 2, 1);
				MapleInventoryManipulator.addById(c, Integer.parseInt(splitted[1]), quantity, c.getPlayer().getName() +
					"used !item with quantity " + quantity, player.getName());
			} else if (splitted[0].equals("!drop")) {
				MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
				int itemId = Integer.parseInt(splitted[1]);
				short quantity = (short) (short) getOptionalIntArg(splitted, 2, 1);
				IItem toDrop;
				if (ii.getInventoryType(itemId) == MapleInventoryType.EQUIP)
					toDrop = ii.getEquipById(itemId);
				else
					toDrop = new Item(itemId, (byte) 0, (short) quantity);
				StringBuilder logMsg = new StringBuilder("Created by ");
				logMsg.append(c.getPlayer().getName());
				logMsg.append(" using !drop. Quantity: ");
				logMsg.append(quantity);
				toDrop.log(logMsg.toString(), false);
				toDrop.setOwner(player.getName());
				c.getPlayer().getMap().spawnItemDrop(c.getPlayer(), c.getPlayer(), toDrop, c.getPlayer().getPosition(), true,true);
			} else if (splitted[0].equals("!shop")) {
				MapleShopFactory sfact = MapleShopFactory.getInstance();
				MapleShop shop = sfact.getShop(1);
				shop.sendShop(c);
			} else if (splitted[0].equals("!equip")) {
				MapleShopFactory sfact = MapleShopFactory.getInstance();
				MapleShop shop = sfact.getShop(2);
				shop.sendShop(c);
			} else if (splitted[0].equals("!gmshop")) {
				MapleShopFactory sfact = MapleShopFactory.getInstance();
				MapleShop shop = sfact.getShop(1337);
				shop.sendShop(c);
                        } else if (splitted[0].equals("!cleardrops")){
                            MapleMap map = c.getPlayer().getMap();
                            double range = Double.POSITIVE_INFINITY;
                            List<MapleMapObject> items = map.getMapObjectsInRange(c.getPlayer().getPosition(), range, Arrays.asList(MapleMapObjectType.ITEM));
                            for (MapleMapObject itemmo : items) {
                            map.removeMapObject(itemmo);
                            map.broadcastMessage(MaplePacketCreator.removeItemFromMap(itemmo.getObjectId(), 0, c.getPlayer().getId()));
                                }
                            mc.dropMessage("You have destroyed " + items.size() + " items on the ground.");  
                        } else if (splitted[0].equals("!clearReactorDrops")) {
				ReactorScriptManager.getInstance().clearDrops();
			} else if (splitted[0].equals("!clearshops")) {
				MapleShopFactory.getInstance().clear(); 
} else if (splitted[0].equals("@rebirth")) {
                            int expfix;
                            if (player.getLevel() >= 200) {
                            player.setLevel(1);
                            c.getPlayer().changeJob(MapleJob.getById(0));
                            
                            expfix = c.getPlayer().getExp();
                                      c.getPlayer().gainExp(-expfix, false, false);
				      player.updateSingleStat(MapleStat.EXP, player.getExp()); 
				
                            } else {
                                mc.dropMessage("Rebirth is only available at level 200+");
                            }
                
                        }else if (splitted[0].equals("!kill")) {
                                MapleCharacter victim1 = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
    victim1.setHp(0);
    victim1.setMp(0);
    victim1.updateSingleStat(MapleStat.HP, 0);
    victim1.updateSingleStat(MapleStat.MP, 0);
                                MapleCharacter victim2 = cserv.getPlayerStorage().getCharacterByName(splitted[2]);
    victim2.setHp(0);
    victim2.setMp(0);
    victim2.updateSingleStat(MapleStat.HP, 0);
    victim2.updateSingleStat(MapleStat.MP, 0);
                                MapleCharacter victim3 = cserv.getPlayerStorage().getCharacterByName(splitted[3]);
    victim3.setHp(0);
    victim3.setMp(0);
    victim3.updateSingleStat(MapleStat.HP, 0);
    victim3.updateSingleStat(MapleStat.MP, 0);
                                MapleCharacter victim4 = cserv.getPlayerStorage().getCharacterByName(splitted[4]);
    victim4.setHp(0);
    victim4.setMp(0);
    victim4.updateSingleStat(MapleStat.HP, 0);
    victim4.updateSingleStat(MapleStat.MP, 0);
                                MapleCharacter victim5 = cserv.getPlayerStorage().getCharacterByName(splitted[5]);
    victim5.setHp(0);
    victim5.setMp(0);
    victim5.updateSingleStat(MapleStat.HP, 0);
    victim5.updateSingleStat(MapleStat.MP, 0);
                                MapleCharacter victim6 = cserv.getPlayerStorage().getCharacterByName(splitted[6]);
    victim6.setHp(0);
    victim6.setMp(0);
    victim6.updateSingleStat(MapleStat.HP, 0);
    victim6.updateSingleStat(MapleStat.MP, 0);
   }
     else if (splitted[0].equals("!levelperson")) {
    MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);  
                             victim.setLevel(getOptionalIntArg(splitted, 2, 2));
    victim.levelUp();
     int newexp = victim.getExp();
     if (newexp < 0) {
      victim.gainExp(-newexp, false, false);
	}
	} else if (splitted[0].equals("!listreports")) {
                            ResultSet rs = getReports();
                            try {
                                while(rs.next()){
                                    mc.dropMessage("id: " + rs.getInt("id") + " | time reported: " + rs.getTimestamp("reporttime").toString() + " | reason: " + reasons[rs.getByte("reason")]);
                                }
                            } catch(Exception ex) {}
                        } else if (splitted[0].equals("!getreport")) {
                            if(splitted.length != 2) return true;
                            int reportid = Integer.parseInt(splitted[1]);
                            ResultSet rs = getReport(reportid);
                            try {
                                while(rs.next()){
                                    mc.dropMessage("id: " + rs.getInt("id") + " | time reported: " + rs.getTimestamp("reporttime").toString() + " | reason: " + reasons[rs.getByte("reason")]);
                                    mc.dropMessage("reporter charid: " + rs.getInt("reporterid"));
                                    mc.dropMessage("victim charid: " + rs.getInt("victimid"));
                                    mc.dropMessage("chatlog: ");
                                    mc.dropMessage(rs.getString("chatlog"));
                                    mc.dropMessage("Status: " + rs.getString("status"));
                                    
                                }
                            } catch(Exception ex){}
                        } else if (splitted[0].equals("!delreport")) {   
                            if(splitted.length != 2) return true;
                            int reportid = Integer.parseInt(splitted[1]);
                            deleteReport(reportid);
                        } else if (splitted[0].equals("!setreportstatus")) {  
                             if(splitted.length < 3) return true;
                            int reportid = Integer.parseInt(splitted[1]);
                            String status = StringUtil.joinStringFrom(splitted, 2);
                            setReportStatus(reportid, status);
                        } else if (splitted[0].equals("!getnamebyid")) {
                            if(splitted.length != 2) return true;
                            int cid = Integer.parseInt(splitted[1]);
                            mc.dropMessage(getCharInfoById(cid));
                        } else if (splitted[0].equals("!getnamebyid")) {
                            if(splitted.length != 2) return true;
                            int cid = Integer.parseInt(splitted[1]);
                            mc.dropMessage(getCharInfoById(cid));
		 }else if (splitted[0].equals("!online")) { // testing
				MessageCallback callback = new ServernoticeMapleClientMessageCallback(c);
				StringBuilder builder = new StringBuilder("Characters online: ");
				for (MapleCharacter chr : cserv.getPlayerStorage().getAllCharacters()) {
					if (builder.length() > 150) { 
						builder.setLength(builder.length() - 2);
						callback.dropMessage(builder.toString());
						builder = new StringBuilder();
					}
					builder.append(MapleCharacterUtil.makeMapleReadable(chr.getName()));
					builder.append(", ");
				}
				builder.setLength(builder.length() - 2);
				c.getSession().write(MaplePacketCreator.serverNotice(6, builder.toString()));
} else if (splitted[0].equals("!clearevents")) {
				for (ChannelServer instance : ChannelServer.getAllInstances()) {
					instance.reloadEvents();
				}
                        }else if(splitted[0].equalsIgnoreCase("!showMonsterID"))
        {
            MapleMap map = player.getMap();
            double range = Double.POSITIVE_INFINITY;
            List<MapleMapObject> monsters = map.getMapObjectsInRange(player.getPosition(), range, Arrays
                .asList(MapleMapObjectType.MONSTER));
            for (MapleMapObject monstermo : monsters) {
                MapleMonster monster = (MapleMonster) monstermo;
                String alive="false";
                if(monster.isAlive())alive="true";
                mc.dropMessage("name="+monster.getName()+" ID="+monster.getId()+" isAlive="+alive);
            }
        }
	else if (splitted[0].equals("!showPortalName"))
        {
            final MaplePortal portal = player.getMap().findClosestSpawnpoint(player.getPosition());
            mc.dropMessage(portal.getName() + " id: " + portal.getId() + " script: " + portal.getScriptName()+" name: "+portal.getName());
        } else if (splitted[0].equals("!level")) {  //By PurpleMadness
                            c.getPlayer().setLevel(getOptionalIntArg(splitted, 1, 1));
				c.getPlayer().levelUp();
				int newexp = c.getPlayer().getExp();
				if (newexp < 0) {
					c.getPlayer().gainExp(-newexp, false, false);
                             	}
                        } else if (splitted[0].equals("!getnamebyid")) {
                            if(splitted.length != 2) return true;
                            int cid = Integer.parseInt(splitted[1]);
                            mc.dropMessage(getCharInfoById(cid));

				}else if (splitted[0].equals("!exprate")) { // by Redline/2azn4u
				if (splitted.length > 1) {
					int exp = Integer.parseInt(splitted[1]);
					cserv.setExpRate(exp);
					MaplePacket packet = MaplePacketCreator.serverNotice(6, "Exp Rate has been changed to " + exp + "x");
					ChannelServer.getInstance(c.getChannel()).broadcastPacket(packet);
				} else 
					mc.dropMessage("Syntax: !exprate <number>");
                                
                        } 
				else if (splitted[0].equals("!music")) {
                                if (splitted[1].equals("names") && splitted.length == 2) {
                                        mc.dropMessage("Names are case sensitive!");
                                        mc.dropMessage("Use !song names [Folder Name] to get list of songs.");
                                        mc.dropMessage("Folder Names:");
                                        mc.dropMessage("Bgm00 | Bgm01 | Bgm02 | Bgm03 | Bgm04");
                                        mc.dropMessage("Bgm05 | Bgm06 | Bgm07 | Bgm08 | Bgm09");
                                        mc.dropMessage("Bgm10 | Bgm11 | Bgm12 | Bgm13 | Bgm14");
                                        mc.dropMessage("    Bgm15 | BgmEvent | BgmGL | BgmJp");
                                } else if (splitted[1].equals("names") && splitted.length == 3) {
                                        if (splitted[2].equals("Bgm00")) {
                                            mc.dropMessage("Bgm00/SleepyWood");
                                            mc.dropMessage("Bgm00/FloralLife");
                                            mc.dropMessage("Bgm00/GoPicnic");
                                            mc.dropMessage("Bgm00/Nightmare");
                                            mc.dropMessage("Bgm00/RestNPeace");
                                        } else if (splitted[2].equals("Bgm01")) {
                                            mc.dropMessage("Bgm01/AncientMove");
                                            mc.dropMessage("Bgm01/MoonlightShadow");
                                            mc.dropMessage("Bgm01/WhereTheBarlogFrom");
                                            mc.dropMessage("Bgm01/CavaBien");
                                            mc.dropMessage("Bgm01/HighlandStar");
                                            mc.dropMessage("Bgm01/BadGuys");
                                        } else if (splitted[2].equals("Bgm02")) {
                                            mc.dropMessage("Bgm02/MissingYou");
                                            mc.dropMessage("Bgm02/WhenTheMorningComes");
                                            mc.dropMessage("Bgm02/EvilEyes");
                                            mc.dropMessage("Bgm02/JungleBook");
                                            mc.dropMessage("Bgm02/AboveTheTreetops");
                                        } else if (splitted[2].equals("Bgm03")) {
                                            mc.dropMessage("Bgm03/Subway");
                                            mc.dropMessage("Bgm03/Elfwood");
                                            mc.dropMessage("Bgm03/BlueSky");
                                            mc.dropMessage("Bgm03/Beachway");
                                            mc.dropMessage("Bgm03/SnowyVillage");
                                        } else if (splitted[2].equals("Bgm04")) {
                                            mc.dropMessage("Bgm04/PlayWithMe");
                                            mc.dropMessage("Bgm04/WhiteChristmas");
                                            mc.dropMessage("Bgm04/UponTheSky");
                                            mc.dropMessage("Bgm04/ArabPirate");
                                            mc.dropMessage("Bgm04/Shinin'Harbor");
                                            mc.dropMessage("Bgm04/WarmRegard");
                                        } else if (splitted[2].equals("Bgm05")) {
                                            mc.dropMessage("Bgm05/WolfWood");
                                            mc.dropMessage("Bgm05/DownToTheCave");
                                            mc.dropMessage("Bgm05/AbandonedMine");
                                            mc.dropMessage("Bgm05/MineQuest");
                                            mc.dropMessage("Bgm05/HellGate");
                                        } else if (splitted[2].equals("Bgm06")) {
                                            mc.dropMessage("Bgm06/FinalFight");
                                            mc.dropMessage("Bgm06/WelcomeToTheHell");
                                            mc.dropMessage("Bgm06/ComeWithMe");
                                            mc.dropMessage("Bgm06/FlyingInABlueDream");
                                            mc.dropMessage("Bgm06/FantasticThinking");
                                        } else if (splitted[2].equals("Bgm07")) {
                                            mc.dropMessage("Bgm07/WaltzForWork");
                                            mc.dropMessage("Bgm07/WhereverYouAre");
                                            mc.dropMessage("Bgm07/FunnyTimeMaker");
                                            mc.dropMessage("Bgm07/HighEnough");
                                            mc.dropMessage("Bgm07/Fantasia");
                                        } else if (splitted[2].equals("Bgm08")) {
                                            mc.dropMessage("Bgm08/LetsMarch");
                                            mc.dropMessage("Bgm08/ForTheGlory");
                                            mc.dropMessage("Bgm08/FindingForest");
                                            mc.dropMessage("Bgm08/LetsHuntAliens");
                                            mc.dropMessage("Bgm08/PlotOfPixie");
                                        } else if (splitted[2].equals("Bgm09")) {
                                            mc.dropMessage("Bgm09/DarkShadow");
                                            mc.dropMessage("Bgm09/TheyMenacingYou");
                                            mc.dropMessage("Bgm09/FairyTale");
                                            mc.dropMessage("Bgm09/FairyTalediffvers");
                                            mc.dropMessage("Bgm09/TimeAttack");
                                        } else if (splitted[2].equals("Bgm10")) {
                                            mc.dropMessage("Bgm10/Timeless");
                                            mc.dropMessage("Bgm10/TimelessB");
                                            mc.dropMessage("Bgm10/BizarreTales");
                                            mc.dropMessage("Bgm10/TheWayGrotesque");
                                            mc.dropMessage("Bgm10/Eregos");
                                        } else if (splitted[2].equals("Bgm11")) {
                                            mc.dropMessage("Bgm11/BlueWorld");
                                            mc.dropMessage("Bgm11/Aquarium");
                                            mc.dropMessage("Bgm11/ShiningSea");
                                            mc.dropMessage("Bgm11/DownTown");
                                            mc.dropMessage("Bgm11/DarkMountain");
                                        } else if (splitted[2].equals("Bgm12")) {
                                            mc.dropMessage("Bgm12/AquaCave");
                                            mc.dropMessage("Bgm12/DeepSee");
                                            mc.dropMessage("Bgm12/WaterWay");
                                            mc.dropMessage("Bgm12/AcientRemain");
                                            mc.dropMessage("Bgm12/RuinCastle");
                                            mc.dropMessage("Bgm12/Dispute");
                                        } else if (splitted[2].equals("Bgm13")) {
                                            mc.dropMessage("Bgm13/CokeTown");
                                            mc.dropMessage("Bgm13/Leafre");
                                            mc.dropMessage("Bgm13/Minar'sDream");
                                            mc.dropMessage("Bgm13/AcientForest");
                                            mc.dropMessage("Bgm13/TowerOfGoddess");
                                        } else if (splitted[2].equals("Bgm14")) {
                                            mc.dropMessage("Bgm14/DragonLoad");
                                            mc.dropMessage("Bgm14/HonTale");
                                            mc.dropMessage("Bgm14/CaveOfHontale");
                                            mc.dropMessage("Bgm14/DragonNest");
                                            mc.dropMessage("Bgm14/Ariant");
                                            mc.dropMessage("Bgm14/HotDesert");
                                        } else if (splitted[2].equals("Bgm15")) {
                                            mc.dropMessage("Bgm15/MureungHill");
                                            mc.dropMessage("Bgm15/MureungForest");
                                            mc.dropMessage("Bgm15/WhiteHerb");
                                            mc.dropMessage("Bgm15/Pirate");
                                            mc.dropMessage("Bgm15/SunsetDesert");
                                        } else if (splitted[2].equals("BgmEvent")) {
                                            mc.dropMessage("BgmEvent/FunnyRabbit");
                                            mc.dropMessage("BgmEvent/FunnyRabbitFaster");
                                        } else if (splitted[2].equals("BgmGL")) {
                                            mc.dropMessage("BgmGL/amoria");
                                            mc.dropMessage("BgmGL/chapel");
                                            mc.dropMessage("BgmGL/cathedral");
                                            mc.dropMessage("BgmGL/Amorianchallenge");
                                        } else if (splitted[2].equals("BgmJp")) {
                                            mc.dropMessage("BgmJp/Feeling");
                                            mc.dropMessage("BgmJp/BizarreForest");
                                            mc.dropMessage("BgmJp/Hana");
                                            mc.dropMessage("BgmJp/Yume");
                                            mc.dropMessage("BgmJp/Bathroom");
                                            mc.dropMessage("BgmJp/BattleField");
                                            mc.dropMessage("BgmJp/FirstStepMaster");
                                }
                                } else {
                                        String songName =  splitted[1];
                                        c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.musicChange(songName)); 
                                        
                                } 
                        } else if (splitted[0].equals("!mesorate")) { // by Redline/2azn4u
				if (splitted.length > 1) {
					int meso = Integer.parseInt(splitted[1]);
					cserv.setMesoRate(meso);
					MaplePacket packet = MaplePacketCreator.serverNotice(6, "Meso Rate has been changed to " + meso + "x");
					ChannelServer.getInstance(c.getChannel()).broadcastPacket(packet);
				} else 
					mc.dropMessage("Syntax: !mesorate <number>");
                        } else if (splitted[0].equals("!droprate")) { // by doncare aka voice123

                if (splitted.length > 1) {
                    int drop = Integer.parseInt(splitted[1]);
                    cserv.setDropRate(drop);
                    MaplePacket packet = MaplePacketCreator.serverNotice(6, "Drop Rate has been changed to " + drop + "x");
                    ChannelServer.getInstance(c.getChannel()).broadcastPacket(packet);
                } else 
                    mc.dropMessage("Syntax: !droprate <number>");
                
                        }        else if (splitted[0].equals("!bossdroprate")) { // by doncare aka voice123

                if (splitted.length > 1) {
                    int bossdrop = Integer.parseInt(splitted[1]);
                    cserv.setBossDropRate(bossdrop);
                    MaplePacket packet = MaplePacketCreator.serverNotice(6, "Boss Drop Rate has been changed to " + bossdrop + "x");
                    ChannelServer.getInstance(c.getChannel()).broadcastPacket(packet);
                } else 
                    mc.dropMessage("Syntax: !bossdroprate <number>");
 } 			else if (splitted[0].equals("!mesos")){
                            c.getPlayer().gainMeso(Integer.parseInt(splitted[1]), true);    
                   }	else if (splitted[0].equals("!warpallhere")) {
                	for (MapleCharacter mch : cserv.getPlayerStorage().getAllCharacters())
                    	if (mch.getMapId() != c.getPlayer().getMapId())
                        mch.changeMap(c.getPlayer().getMap(), c.getPlayer().getPosition()); 
			} else if (splitted[0].equalsIgnoreCase("!killmonster")) {
            if(splitted.length ==2)
            {
                MapleMap map = c.getPlayer().getMap();
                double range = Double.POSITIVE_INFINITY;
                int targetId=Integer.parseInt(splitted[1]);
        
                List<MapleMapObject> monsters = map.getMapObjectsInRange(c.getPlayer().getPosition(), range, Arrays
                    .asList(MapleMapObjectType.MONSTER));

                for (MapleMapObject monstermo : monsters) {
                    MapleMonster monster = (MapleMonster) monstermo;
                    if (monster.getId()==targetId) {
                        map.killMonster(monster, player, false);
                        break;
                    }
                }
            }

			} else if (splitted[0].equals("!resetquest")) {
				MapleQuest.getInstance(Integer.parseInt(splitted[1])).forfeit(c.getPlayer());
			} else if (splitted[0].equals("!gps")) {
				// c.getSession().write(MaplePacketCreator.getPlayerShop(c.getPlayer(), 0, null));
			} else if (splitted[0].equals("!nearestPortal")) {
				final MaplePortal portal = player.getMap().findClosestSpawnpoint(player.getPosition());
				mc.dropMessage(portal.getName() + " id: " + portal.getId() + " script: " + portal.getScriptName());
			} else if (splitted[0].equals("!sp")) {
				player.setRemainingSp(getOptionalIntArg(splitted, 1, 1));
				player.updateSingleStat(MapleStat.AVAILABLESP, player.getRemainingSp());
			} else if (splitted[0].equals("!fakerelog")) {
				c.getSession().write(MaplePacketCreator.getCharInfo(player));
				player.getMap().removePlayer(player);
				player.getMap().addPlayer(player);
			}
                 else if (splitted[0].equals("!test")) {
				// faeks id is 30000 (30 75 00 00)
				// MapleCharacter faek = ((MapleCharacter) c.getPlayer().getMap().getMapObject(30000));
				
				//List<BuddylistEntry> buddylist = Arrays.asList(new BuddylistEntry("derGuteBuddy", 30000, 1, true));
//				c.getSession().write(MaplePacketCreator.updateBuddylist(buddylist));
				// c.getSession().write(MaplePacketCreator.updateBuddyChannel(30000, 1));
				// c.getSession().write(MaplePacketCreator.updateBuddyChannel(30000, 0));
				//c.getSession().write(MaplePacketCreator.requestBuddylistAdd(30000, "FaekChar"));
				//c.getSession().write(MaplePacketCreator.requestBuddylistAdd(30001, "FaekChar2"));
				//c.getSession().write(MaplePacketCreator.multiChat("lulu", line, 0));
				// c.getSession().write(MaplePacketCreator.showOwnBuffEffect(1311008, 5));
				// c.getSession().write(MaplePacketCreator.showBuffeffect(30000, 1311008, 5));
				//c.getSession().write(MaplePacketCreator.getPacketFromHexString("2B 00 07 22 64 1F 23 00 57 69 6E 64 53 63 61 72 73 00 FF FF 2C 02 56 0A 35 B7 34 A9 17 00 78 4D 41 55 53 49 78 00 73 00 FF FF 2C 00 FF FF FF FF 6A 3A 0D 00 6F 31 56 69 45 54 78 47 69 52 4C 00 2C 02 56 0A 35 B7 7D 3C 05 00 69 74 7A 78 65 6D 69 6C 79 79 00 00 2C 02 56 0A 35 B7 00 ED 19 00 31 39 39 52 61 6E 64 6F 6D 67 75 79 00 02 56 0A 35 B7 69 7D 00 00 64 61 76 74 73 61 69 00 6D 67 75 79 00 02 56 0A 35 B7 46 85 17 00 44 72 61 6B 65 58 6B 69 6C 6C 65 72 00 00 FF FF FF FF AD 78 00 00 42 61 74 6F 73 69 61 00 6C 6C 65 72 00 02 56 0A 35 B7 A7 B1 02 00 53 65 63 6E 69 6E 00 00 6C 6C 65 72 00 00 FF FF FF FF 05 50 00 00 48 61 6E 64 4F 66 47 6F 64 00 65 72 00 02 56 0A 35 B7 29 21 41 00 53 61 65 61 00 66 47 6F 64 00 65 72 00 00 FF FF FF FF 79 00 01 00 62 75 74 74 77 61 78 00 64 00 65 72 00 02 56 0A 35 B7 B9 01 02 00 48 65 72 6F 53 6F 50 72 6F 00 65 72 00 02 56 0A 35 B7 63 0F 23 00 4D 53 43 42 00 6F 50 72 6F 00 65 72 00 02 56 0A 35 B7 63 40 0F 00 44 65 6D 30 6E 7A 61 62 75 7A 61 00 00 02 56 0A 35 B7 B2 C8 00 00 41 73 69 61 6E 4D 49 63 6B 65 79 00 00 00 FF FF FF FF E1 6D 13 00 54 52 44 52 6F 6C 6C 61 00 65 79 00 00 00 FF FF FF FF 0D 35 00 00 53 65 63 72 61 6E 6F 00 00 65 79 00 00 00 FF FF FF FF DF E3 01 00 62 69 7A 7A 00 6E 6F 00 00 65 79 00 00 00 FF FF FF FF 56 93 2F 00 54 65 72 70 65 00 6F 00 00 65 79 00 00 00 FF FF FF FF 69 EB 14 00 53 6B 79 64 72 65 61 6D 00 65 79 00 00 00 FF FF FF FF 1B 04 02 00 4E 61 67 6C 66 61 72 00 00 65 79 00 00 00 FF FF FF FF FA 6F 00 00 53 68 6D 75 66 66 00 67 6F 6E 00 00 00 00 FF FF FF FF 09 E2 00 00 44 65 70 74 69 63 00 67 6F 6E 00 00 00 00 FF FF FF FF 85 49 15 00 54 79 73 74 6F 00 00 67 6F 6E 00 00 00 02 56 0A 35 B7 F8 9A 17 00 46 6F 68 6E 7A 00 00 67 6F 6E 00 00 00 02 56 0A 35 B7 86 B2 0F 00 41 62 79 73 61 6C 43 6C 65 72 69 63 00 02 56 0A 35 B7 1A 88 1D 00 78 73 63 72 69 62 62 6C 65 73 7A 00 00 00 FF FF FF FF D5 5C 1E 00 46 6A 6F 65 72 67 79 6E 6E 00 7A 00 00 00 FF FF FF FF 4B CE 03 00 41 72 72 6F 77 68 65 61 64 31 33 35 00 02 56 0A 35 B7 8F 2F 20 00 4E 61 77 75 74 6F 00 61 64 31 33 35 00 00 FF FF FF FF D5 8E 1E 00 4C 61 72 69 6C 79 00 61 64 31 33 35 00 00 FF FF FF FF 9B 85 0F 00 53 68 65 65 70 68 65 72 64 00 33 35 00 00 FF FF FF FF 30 C0 23 00 46 6A 6F 65 72 00 6E 61 6C 20 66 61 69 00 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"));
				c.getSession().write(MaplePacketCreator.getPacketFromHexString("2B 00 14 30 C0 23 00 00 11 00 00 00"));
			} else if (splitted[0].equals("!dc")) {
				int level = 0;
				MapleCharacter victim;
				if (splitted[1].charAt(0) == '-') {
					level = StringUtil.countCharacters(splitted[1], 'f');
					victim = cserv.getPlayerStorage().getCharacterByName(splitted[2]);
				} else {
					victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
				}
				victim.getClient().getSession().close();
				if (level >= 1) {
					victim.getClient().disconnect();
				}
				if (level >= 2) {
					victim.saveToDB(true);
					cserv.removePlayer(victim);
				}
			} else if (splitted[0].equals("!coke")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9500144);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(9500151);
                            MapleMonster mob2 = MapleLifeFactory.getMonster(9500152);
                            MapleMonster mob3 = MapleLifeFactory.getMonster(9500153);
                            MapleMonster mob4 = MapleLifeFactory.getMonster(9500154);
                            MapleMonster mob5 = MapleLifeFactory.getMonster(9500143);
                            MapleMonster mob6 = MapleLifeFactory.getMonster(9500145);
                            MapleMonster mob7 = MapleLifeFactory.getMonster(9500149);
                            MapleMonster mob8 = MapleLifeFactory.getMonster(9500147);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob3, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob4, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob5, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob6, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob7, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob8, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!papu")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(8500001);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        } else if (splitted[0].equals("!zakum")){
			MapleMonster mob0 = MapleLifeFactory.getMonster(8800003);
			MapleMonster mob1 = MapleLifeFactory.getMonster(8800004);
			MapleMonster mob2 = MapleLifeFactory.getMonster(8800005);
			MapleMonster mob3 = MapleLifeFactory.getMonster(8800006);
			MapleMonster mob4 = MapleLifeFactory.getMonster(8800007);
			MapleMonster mob5 = MapleLifeFactory.getMonster(8800008);
			MapleMonster mob6 = MapleLifeFactory.getMonster(8800009);
			MapleMonster mob7 = MapleLifeFactory.getMonster(8800010);
			MapleMonster mob8 = MapleLifeFactory.getMonster(8800000);
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob3, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob4, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob5, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob6, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob7, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob8, c.getPlayer().getPosition());
			c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.serverNotice(0, "The almighty Zakum has awakened!"));
			}else if (splitted[0].equals("!horntail")){
			MapleMonster mob0 = MapleLifeFactory.getMonster(8810002);
			MapleMonster mob1 = MapleLifeFactory.getMonster(8810003);
			MapleMonster mob2 = MapleLifeFactory.getMonster(8810004);
			MapleMonster mob3 = MapleLifeFactory.getMonster(8810005);
			MapleMonster mob4 = MapleLifeFactory.getMonster(8810006);
			MapleMonster mob5 = MapleLifeFactory.getMonster(8810007);
			MapleMonster mob6 = MapleLifeFactory.getMonster(8810008);
			MapleMonster mob7 = MapleLifeFactory.getMonster(8810009);
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob3, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob4, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob5, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob6, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob7, c.getPlayer().getPosition());
			c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.serverNotice(0, "As the cave shakes and rattles, here comes Horntail.")); 
			}else if (splitted[0].equals("!ergoth")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9300028);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!ludimini")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(8160000);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(8170000);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!cornian")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(8150201);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(8150200);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!balrog")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(8130100);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(8150000);
                            MapleMonster mob2 = MapleLifeFactory.getMonster(9400536);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!mushmom")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(6130101);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(6300005);
                            MapleMonster mob2 = MapleLifeFactory.getMonster(9400205);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!wyvern")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(8150300);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(8150301);
                            MapleMonster mob2 = MapleLifeFactory.getMonster(8150302);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!pirate")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9300119);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(9300107);
                            MapleMonster mob2 = MapleLifeFactory.getMonster(9300105);
                            MapleMonster mob3 = MapleLifeFactory.getMonster(9300106);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob3, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!clone")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9001002);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(9001000);
                            MapleMonster mob2 = MapleLifeFactory.getMonster(9001003);
                            MapleMonster mob3 = MapleLifeFactory.getMonster(9001001);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob3, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!anego")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9400121);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!theboss")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9400300);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!snackbar")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9500179);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!papapixie")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9300039);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!horseman")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9400549);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!blackcrow")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9400014);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!leafreboss")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9400014);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(8180001);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!shark")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(8150101);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(8150100);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!franken")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9300139);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(9300140);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!bird")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9300090);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(9300089);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!pianus")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(8510000);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!centipede")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9500177);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        } else if (splitted[0].equals("!horntail")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(8810026);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.serverNotice(0, "As the cave shakes and rattles, here comes Horntail.")); 
                            MapleMap map = c.getPlayer().getMap();
				double range = Double.POSITIVE_INFINITY;				
				List<MapleMapObject> monsters = map.getMapObjectsInRange(c.getPlayer().getPosition(), range, Arrays
					.asList(MapleMapObjectType.MONSTER));
					for (MapleMapObject monstermo : monsters) {
					MapleMonster monster = (MapleMonster) monstermo;					
						map.killMonster(monster, c.getPlayer(), false);
									
				}
			} else if (splitted[0].equals("!goto")) {
                    //Map name array
                    int[] gotomapid = { 
                        180000000, //GmMap
                        60000, //Southperry
                        1010000, //Amherst
                        100000000, //henesys 
                        101000000, //ellinia 
                        102000000, //perion
                        103000000, //kerning
                        104000000, //lith
                        105040300, //sleepywood
                        110000000, //florina
                        200000000, //orbis
                        209000000, //happy
                        211000000, //elnath
                        220000000, //ludi
                        230000000, //aqua
                        240000000, //leafre
                        250000000, //mulung
                        251000000, //herb
                        221000000, //omega
                        222000000, //korean (Folk Town)
                        600000000, //nlc (New Leaf City)
                        990000000, //excavation (Sharenian/Excavation Site)
                        230040420, //Pianus cave
                        240060200, //Horned Tail's cave
                        100000005, //Mushmom
                        240020101, //Griffey
                        240020401, //Manon
                        682000001, //Headless Horseman
                        105090900, //Jr.Balrog
			280030000, //Zakum's Altar
			220080001, //Papulatus map
			801000000, //showa Town
			200000301, //Guild HeadQuarters
			800000000, //Shrine (Mushroom Shrine)
			910000000, //Free Market Entrance
			240040511, //Skelegon map (Leafre)
                    };
                    String[] gotomapname = { 
                        "gmmap",
                        "southperry",
                        "amherst",
                        "henesys", 
                        "ellinia", 
                        "perion", 
                        "kerning", 
                        "lith", 
                        "sleepywood", 
                        "florina",
                        "orbis", 
                        "happy", 
                        "elnath", 
                        "ludi", 
                        "aqua", 
                        "leafre", 
                        "mulung", 
                        "herb", 
                        "omega", 
                        "korean", 
                        "nlc",
                        "excavation",
                        "pianus",
                        "horntail",
                        "mushmom",
                        "griffey",
                        "manon",
                        "horseman",
                        "balrog",
			"zakum",
			"papu",
			"showa",
			"guild",
			"shrine",
			"fm",
			"skelegon",
                    };
                    //Function
                    if (splitted.length < 2) { //If no arguments, list options.
                        mc.dropMessage("Syntax: !goto <mapname> <optional_target>, where target is char name and mapname is one of:");
                        mc.dropMessage("gmmap, southperry, amherst, henesys, ellinia, perion, kerning, lith, sleepywood, florina,");
                        mc.dropMessage("orbis, happy, elnath, ludi, aqua, leafre, mulung, herb, omega, korean, nlc, excavation, pianus");
                        mc.dropMessage("horntail, mushmom, griffey, manon, horseman, balrog, zakum, papu, showa, guild, shrine, fm, skelegon");
                    } else {
                        for (int i = 0; gotomapid[i] != 0 && gotomapname[i] != null; ++i) { //for every array which isn't empty
  if (splitted[1].equals(gotomapname[i])) { //If argument equals name
    MapleMap target = cserv.getMapFactory().getMap(gotomapid[i]);
    MaplePortal targetPortal = target.getPortal(0);
    if (splitted.length < 3) { //If no target name, continue
      player.changeMap(target, targetPortal);
    } else if (splitted.length > 2) { //If target name, new target
      MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[2]);
      victim.changeMap(target, targetPortal);
                }
             }
        }
 }
                        }  else if (splitted[0].equals("!heal")) {
      			player.setHp(player.getMaxHp());
       			player.updateSingleStat(MapleStat.HP, player.getMaxHp());
       			player.setMp(player.getMaxMp());
       			player.updateSingleStat(MapleStat.MP, player.getMaxMp());
			} else if (splitted[0].equals("!cheaters")) {
				try {
					List<CheaterData> cheaters = c.getChannelServer().getWorldInterface().getCheaters();
					for (int x = cheaters.size() - 1; x >= 0; x--) {
						CheaterData cheater = cheaters.get(x);
						mc.dropMessage(cheater.getInfo());
					}
				} catch (RemoteException e) {
					c.getChannelServer().reconnectWorld();
				} 
			    } else if (splitted[0].equals("!charinfo")) {
    StringBuilder builder = new StringBuilder();
    MapleCharacter other = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
    builder.append(MapleClient.getLogMessage(other, ""));
    builder.append(" at X: ");
    builder.append(other.getPosition().x);
    builder.append("/ Y: ");
    builder.append(other.getPosition().y);
    builder.append("/ RX0: ");
    builder.append(other.getPosition().x + 50);
    builder.append("/ RX1: ");
    builder.append(other.getPosition().x - 50);
    builder.append("/ FH: ");
    builder.append(other.getMap().getFootholds().findBelow(c.getPlayer().getPosition()).getId());
    builder.append(" ");
    builder.append(other.getHp());
    builder.append("/");
    builder.append(other.getCurrentMaxHp());
    builder.append("hp ");
    builder.append(other.getMp());
    builder.append("/");
    builder.append(other.getCurrentMaxMp());
    builder.append("mp ");
    builder.append(other.getExp());
    builder.append("exp hasParty: ");
    builder.append(other.getParty() != null);
    builder.append(" hasTrade: ");
    builder.append(other.getTrade() != null);
    builder.append(" remoteAddress: ");
    builder.append(other.getClient().getSession().getRemoteAddress());
    mc.dropMessage(builder.toString());
    other.getClient().dropDebugMessage(mc);
			} else if (splitted[0].equals("!ban")) {
				if (splitted.length < 3) {
					new ServernoticeMapleClientMessageCallback(2, c).dropMessage("Syntaxhelper : Syntax: !ban charname reason");
					return true;
				}
				String originalReason = StringUtil.joinStringFrom(splitted, 2);
				String reason = c.getPlayer().getName() + " banned " + splitted[1] + ": " +
				originalReason;
				MapleCharacter target = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
				if (target != null) {
					String readableTargetName = MapleCharacterUtil.makeMapleReadable(target.getName());
					String ip = target.getClient().getSession().getRemoteAddress().toString().split(":")[0];
					reason += " (IP: " + ip + ")";
					target.ban(reason);
					mc.dropMessage("Banned " + readableTargetName + " ipban for " + ip + " reason: " + originalReason);
				} else {
					if (MapleCharacter.ban(splitted[1], reason, false)) {
						mc.dropMessage("Offline Banned " + splitted[1]);
					} else {
						mc.dropMessage("Failed to ban " + splitted[1]);
					}
                                }
			} else if (splitted[0].equals("!tempban")) {
				Calendar tempB = Calendar.getInstance();
				String originalReason = joinAfterString(splitted, ":");

				if (splitted.length < 4 || originalReason == null) {
					mc.dropMessage("Syntax helper: !tempban <name> [i / m / w / d / h] <amount> [r  [reason id] : Text Reason");
					return true;
				}

				int yChange = getNamedIntArg(splitted, 1, "y", 0);
				int mChange = getNamedIntArg(splitted, 1, "m", 0);
				int wChange = getNamedIntArg(splitted, 1, "w", 0);
				int dChange = getNamedIntArg(splitted, 1, "d", 0);
				int hChange = getNamedIntArg(splitted, 1, "h", 0);
				int iChange = getNamedIntArg(splitted, 1, "i", 0);
				int gReason = getNamedIntArg(splitted, 1, "r", 7);

				String reason = c.getPlayer().getName() + " tempbanned " + splitted[1] + ": " + originalReason;


				if (gReason > 14) {
					mc.dropMessage("You have entered an incorrect ban reason ID, please try again.");
					return true;
				}

				DateFormat df = DateFormat.getInstance();
				tempB.set(tempB.get(Calendar.YEAR) + yChange, tempB.get(Calendar.MONTH) + mChange, tempB.get(Calendar.DATE) +
					(wChange * 7) + dChange, tempB.get(Calendar.HOUR_OF_DAY) + hChange, tempB.get(Calendar.MINUTE) +
					iChange);

				MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);

				if (victim == null) {
					int accId = MapleClient.findAccIdForCharacterName(splitted[1]);
					if (accId >= 0 && MapleCharacter.tempban(reason, tempB, gReason, accId)) {
						mc.dropMessage("The character " + splitted[1] + " has been successfully offline-tempbanned till " + df.format(tempB.getTime()) + ".");
					} else {
						mc.dropMessage("There was a problem offline banning character " + splitted[1] + ".");
					}
				} else {
					victim.tempban(reason, tempB, gReason);
					mc.dropMessage("The character " + splitted[1] + " has been successfully tempbanned till " + df.format(tempB.getTime()));
				}
                        }
                else if (splitted[0].equals("!levelup")) {
				c.getPlayer().levelUp();
				int newexp = c.getPlayer().getExp();
				if (newexp < 0) {
					c.getPlayer().gainExp(-newexp, false, false);
				}
			} else if (splitted[0].equals("!whereami")) {
				new ServernoticeMapleClientMessageCallback(c).dropMessage("You are on map " +
					c.getPlayer().getMap().getId());
			} else if (splitted[0].equals("!version")) {
				new ServernoticeMapleClientMessageCallback(c)
					.dropMessage("ANUJAN PWNS!");
			} else if (splitted[0].equals("!credit")) {
				new ServernoticeMapleClientMessageCallback(c)
					.dropMessage("All people");
			} else if (splitted[0].equals("!connected")) {
				try {
					Map<Integer, Integer> connected = cserv.getWorldInterface().getConnected();
					StringBuilder conStr = new StringBuilder("Connected Clients: ");
					boolean first = true;
					for (int i : connected.keySet()) {
						if (!first) {
							conStr.append(", ");
						} else {
							first = false;
						}
						if (i == 0) {
							conStr.append("Total: ");
							conStr.append(connected.get(i));
						} else {
							conStr.append("Ch");
							conStr.append(i);
							conStr.append(": ");
							conStr.append(connected.get(i));
						}
					}
					new ServernoticeMapleClientMessageCallback(c).dropMessage(conStr.toString());
				} catch (RemoteException e) {
					c.getChannelServer().reconnectWorld();
				}
			} else if (splitted[0].equals("!whosthere")) {
				MessageCallback callback = new ServernoticeMapleClientMessageCallback(c);
				StringBuilder builder = new StringBuilder("Players on Map: ");
				for (MapleCharacter chr : c.getPlayer().getMap().getCharacters()) {
					if (builder.length() > 150) { // wild guess :o
						builder.setLength(builder.length() - 2);
						callback.dropMessage(builder.toString());
						builder = new StringBuilder();
					}
					builder.append(MapleCharacterUtil.makeMapleReadable(chr.getName()));
					builder.append(", ");
				}
				builder.setLength(builder.length() - 2);
				c.getSession().write(MaplePacketCreator.serverNotice(6, builder.toString()));
			} else if (splitted[0].equals("!shutdown")) {
				int time = 60000;
				if (splitted.length > 1) {
					time = Integer.parseInt(splitted[1]) * 60000;
				}
				persister.run();
				c.getChannelServer().shutdown(time);
			} else if (splitted[0].equals("!shutdownworld")) {
				int time = 60000;
				if (splitted.length > 1) {
					time = Integer.parseInt(splitted[1]) * 60000;
				}
				persister.run();
				c.getChannelServer().shutdownWorld(time);
				// shutdown
			} else if (splitted[0].equals("!shutdownnow")) {
				persister.run();
				new ShutdownServer(c.getChannel()).run();
			} else if (splitted[0].equals("!timerdebug")) {
				TimerManager.getInstance().dropDebugInfo(mc);
			} else if (splitted[0].equals("!threads")) {
				Thread[] threads = new Thread[Thread.activeCount()];
				Thread.enumerate(threads);
				String filter = "";
				if (splitted.length > 1) {
					filter = splitted[1];
				}
				for (int i = 0; i < threads.length; i++) {
					String tstring = threads[i].toString();
					if (tstring.toLowerCase().indexOf(filter.toLowerCase()) > -1) {
						mc.dropMessage(i + ": " + tstring);
					}
				}
			} else if (splitted[0].equals("!showtrace")) {
				if (splitted.length < 2) {
					return true;
				}
				Thread[] threads = new Thread[Thread.activeCount()];
				Thread.enumerate(threads);
				Thread t = threads[Integer.parseInt(splitted[1])];
				mc.dropMessage(t.toString() + ":");
				for (StackTraceElement elem : t.getStackTrace()) {
					mc.dropMessage(elem.toString());
				}
			} else if (splitted[0].equals("!dumpthreads")) {
				Map<Thread, StackTraceElement[]> traces = Thread.getAllStackTraces();
				try {
					PrintWriter pw = new PrintWriter(new File("threaddump.txt"));
					for (Entry<Thread, StackTraceElement[]> t : traces.entrySet()) {
						pw.println(t.getKey().toString());
						for (StackTraceElement elem : t.getValue()) {
							pw.println(elem.toString());
						}
						pw.println();
					}
					pw.close();
				} catch (FileNotFoundException e) {
					log.error("ERROR", e);
				}
			} else if (splitted[0].equals("!reloadops")) {
				try {
					ExternalCodeTableGetter.populateValues(SendPacketOpcode.getDefaultProperties(), SendPacketOpcode.values());
					ExternalCodeTableGetter.populateValues(RecvPacketOpcode.getDefaultProperties(), RecvPacketOpcode.values());
				} catch (Exception e) {
					log.error("Failed to reload props", e);
				}
				PacketProcessor.getProcessor(PacketProcessor.Mode.CHANNELSERVER).reset(PacketProcessor.Mode.CHANNELSERVER);
				PacketProcessor.getProcessor(PacketProcessor.Mode.CHANNELSERVER).reset(PacketProcessor.Mode.CHANNELSERVER);
			} else if (splitted[0].equals("!clearPortalScripts")) {
				PortalScriptManager.getInstance().clearScripts();
			} else if (splitted[0].equals("!killall") || splitted[0].equals("!monsterdebug")) {
				MapleMap map = c.getPlayer().getMap();
				double range = Double.POSITIVE_INFINITY;
				if (splitted.length > 1) {
					int irange = Integer.parseInt(splitted[1]);
					range = irange * irange;
				}
				List<MapleMapObject> monsters = map.getMapObjectsInRange(c.getPlayer().getPosition(), range, Arrays
					.asList(MapleMapObjectType.MONSTER));
				boolean kill = splitted[0].equals("!killall");
				for (MapleMapObject monstermo : monsters) {
					MapleMonster monster = (MapleMonster) monstermo;
					if (kill) {
						map.killMonster(monster, c.getPlayer(), false);
					} else {
						mc.dropMessage("Monster " + monster.toString());
					}
				}
				if (kill) {
					mc.dropMessage("You have killed " + monsters.size() + " monsters in your map");
				}
			} else if (splitted[0].equals("!skill")) {
				int skill = Integer.parseInt(splitted[1]);
				int level = getOptionalIntArg(splitted, 2, 1);
				int masterlevel = getOptionalIntArg(splitted, 3, 1);
				c.getPlayer().changeSkillLevel(SkillFactory.getSkill(skill), level, masterlevel);
			} else if (splitted[0].equals("!spawndebug")) {
				c.getPlayer().getMap().spawnDebug(mc);
			} else if (splitted[0].equals("!door")) {
				Point doorPos = new Point(player.getPosition());
				doorPos.y -= 270;
				MapleDoor door = new MapleDoor(c.getPlayer(), doorPos);
				door.getTarget().addMapObject(door);
				//c.getSession().write(MaplePacketCreator.spawnDoor(/*c.getPlayer().getId()*/ 0x1E47, door.getPosition(), false));
				/*c.getSession().write(MaplePacketCreator.saveSpawnPosition(door.getPosition()));*/
				MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
				mplew.write(HexTool.getByteArrayFromHexString("B9 00 00 47 1E 00 00 0A 04 76 FF"));
				c.getSession().write(mplew.getPacket());
				mplew = new MaplePacketLittleEndianWriter();
				mplew.write(HexTool.getByteArrayFromHexString("36 00 00 EF 1C 0D 4C 3E 1D 0D 0A 04 76 FF"));
				c.getSession().write(mplew.getPacket());
				c.getSession().write(MaplePacketCreator.enableActions());
				door = new MapleDoor(door);
				door.getTown().addMapObject(door);
			} else if (splitted[0].equals("!tdrops")) {
				player.getMap().toggleDrops();
			} else if (splitted[0].equals("!lowhp")) {
				player.setHp(1);
				player.setMp(500);
				player.updateSingleStat(MapleStat.HP, 1);
				player.updateSingleStat(MapleStat.MP, 500);
			}  else if (splitted[0].equals("!fullhp")) {
				player.setHp(player.getMaxHp());
				player.updateSingleStat(MapleStat.HP, player.getMaxHp());
                                }else if (splitted[0].equals("!search")) {
				try {

				    URL                url;
				    URLConnection      urlConn;
				    BufferedReader    dis;

				    url = new URL("http://www.mapletip.com/search_java.php?search_value=" + splitted[1] + "&check=true");

				    urlConn = url.openConnection();
				    urlConn.setDoInput(true);
				    urlConn.setUseCaches(false);

				    dis = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
				    String s;
				 
				    while ((s = dis.readLine()) != null) {
				    	mc.dropMessage(s);
				    }
				    dis.close();
				    }
				    catch (MalformedURLException mue) {}
				    catch (IOException ioe) {}
			} else if (splitted[0].equals("!cheaters")) {
				try {
					List<CheaterData> cheaters = c.getChannelServer().getWorldInterface().getCheaters();
					for (int x = cheaters.size() - 1; x >= 0; x--) {
						CheaterData cheater = cheaters.get(x);
						mc.dropMessage(cheater.getInfo());
					}
				} catch (RemoteException e) {
					c.getChannelServer().reconnectWorld();
				}
			} else if (splitted[0].equals("!clearguilds")) {
				try
				{
					mc.dropMessage("Attempting to reload all guilds... this may take a while...");
					cserv.getWorldInterface().clearGuilds();
					mc.dropMessage("Completed.");
				}
				catch (RemoteException re)
				{
					mc.dropMessage("RemoteException occurred while attempting to reload guilds.");
					log.error("RemoteException occurred while attempting to reload guilds.", re);
				}
			
			} else if (splitted[0].equals("!npc")) {
				int npcId = Integer.parseInt(splitted[1]);
				MapleNPC npc = MapleLifeFactory.getNPC(npcId);
				if (npc != null && !npc.getName().equals("MISSINGNO")) {
					npc.setPosition(c.getPlayer().getPosition());
					npc.setCy(c.getPlayer().getPosition().y);
					npc.setRx0(c.getPlayer().getPosition().x + 50);
					npc.setRx1(c.getPlayer().getPosition().x - 50);
					npc.setFh(c.getPlayer().getMap().getFootholds().findBelow(c.getPlayer().getPosition()).getId());
					npc.setCustom(true);
					c.getPlayer().getMap().addMapObject(npc);
					c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.spawnNPC(npc, false));
					// c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.spawnNPC(npc, true));
				} else {
					mc.dropMessage("You have entered an invalid Npc-Id");
				}
			}  else if (splitted[0].equals("!removenpcs")) {
				List<MapleMapObject> npcs = player.getMap().getMapObjectsInRange(c.getPlayer().getPosition(), Double.POSITIVE_INFINITY, Arrays
					.asList(MapleMapObjectType.NPC));
				for (MapleMapObject npcmo : npcs) {
					MapleNPC npc = (MapleNPC) npcmo;
					if (npc.isCustom()) {
						player.getMap().removeMapObject(npc.getObjectId());
					}
				}
			} else {
				mc.dropMessage("GM Command " + splitted[0] + " does not exist");
			}
			return true;
		}
		return false;
	}

	 private static ResultSet getReports(){
            try {
            Connection dcon = DatabaseConnection.getConnection();
            PreparedStatement ps = dcon.prepareStatement("SELECT * FROM reports");
            return ps.executeQuery();
            
            } catch(Exception ex) {}
            return null;
            
        }
        private static void deleteReport(int id){
            try {
            Connection dcon = DatabaseConnection.getConnection();
            PreparedStatement ps = dcon.prepareStatement("DELETE FROM reports WHERE id = ?");
            ps.setInt(1, id);
            ps.executeUpdate();
            ps.close();       
            
            
            } catch(Exception ex) {}
            
            
        }
        private static ResultSet getReport(int id){
            try {
            Connection dcon = DatabaseConnection.getConnection();
            PreparedStatement ps = dcon.prepareStatement("SELECT * FROM reports where id = ?");
            ps.setInt(1, id);
            return ps.executeQuery();
            
            } catch(Exception ex) {}
            return null;
        }
        private static void setReportStatus(int id, String status){
                        try {
            Connection dcon = DatabaseConnection.getConnection();
            PreparedStatement ps = dcon.prepareStatement("UPDATE reports SET status = ? WHERE id = ?");
            ps.setString(1, status);
            ps.setInt(2, id);
            ps.executeUpdate();
            ps.close();       
            
            
            } catch(Exception ex) {}
            
        }
        
        private static String getCharInfoById(int id){
                        try {
            Connection dcon = DatabaseConnection.getConnection();
            PreparedStatement ps = dcon.prepareStatement("SELECT * FROM characters where id = ?");
            ps.setInt(1, id);
            ResultSet rs = ps.executeQuery();
            if(rs.next())
            return rs.getString("name");
            
            } catch(Exception ex) {}
            return "error while trying to get name";
            
        }
       
        
}
 
Junior Spellweaver
Joined
Feb 23, 2008
Messages
111
Reaction score
1
Re: [Release] Block people from using megaphones!

Anujan, in MapleCharacter.java, change this:
Code:
private boolean cansmega;

to this:
Code:
private boolean canSmega;

(the S has to be capitalized)
 
Junior Spellweaver
Joined
Jun 25, 2008
Messages
166
Reaction score
0
Re: [Release] Block people from using megaphones!

So, how i add timer or fix the relog thing..?
 
Newbie Spellweaver
Joined
Jun 22, 2008
Messages
48
Reaction score
0
Re: [Release] Block people from using megaphones!

Instead of posting the UseItemHandler, would you mind to state out what to modify instead? Not everyone have the same 'base'...
 
Mythic Archon
Loyal Member
Joined
May 11, 2008
Messages
722
Reaction score
50
Re: [Release] Block people from using megaphones!

k thanks Sathon
 
Experienced Elementalist
Joined
Jun 22, 2008
Messages
264
Reaction score
0
Re: [Release] Block people from using megaphones!

what did you change in net.sf.odinms.net.channel.handler.UseCashItemHandler.java?
cus i dun wanna replace mine, since i edited a whole bunch of stuff @_@.

~dXm
 
Newbie Spellweaver
Joined
Jun 23, 2008
Messages
77
Reaction score
0
Re: [Release] Block people from using megaphones!

You got to remember. In Java, Capitalizing and etc. is VERY IMPORTANT!!!!
 
Joined
Jun 11, 2008
Messages
588
Reaction score
45
Re: [Release] Block people from using megaphones!

init:
deps-jar:
Compiling 1 source file to C:\Users\William\Server Pictures and Plans\ServerBuildFolder\build\classes
C:\Users\Matt\Pictures\Server Files\MapleWorldz V.2.1\src\net\sf\odinms\client\messages\CommandProcessor.java:1500: 'else' without 'if'
else if (splitted[0].equals("!smegaoff"))
1 error
BUILD FAILED (total time: 0 seconds)

CommandProcessor.java
PHP:
/*
	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.sf.odinms.client.messages;

import java.awt.Point;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Calendar;

import javax.management.MBeanServer;
import javax.management.ObjectName;

import net.sf.odinms.client.IItem;
import net.sf.odinms.client.Item;
import net.sf.odinms.client.MapleCharacter;
import net.sf.odinms.client.MapleCharacterUtil;
import net.sf.odinms.client.MapleClient;
import net.sf.odinms.client.MapleInventoryType;
import net.sf.odinms.client.MapleJob;
import net.sf.odinms.client.MapleStat;
import net.sf.odinms.client.MapleInventory;
import net.sf.odinms.client.SkillFactory;
import net.sf.odinms.client.anticheat.CheatingOffense;
import net.sf.odinms.database.DatabaseConnection;
import net.sf.odinms.net.ExternalCodeTableGetter;
import net.sf.odinms.net.MaplePacket;
import net.sf.odinms.net.PacketProcessor;
import net.sf.odinms.scripting.event.EventInstanceManager;
import net.sf.odinms.net.RecvPacketOpcode;
import net.sf.odinms.net.SendPacketOpcode;
import net.sf.odinms.net.channel.ChannelServer;
import net.sf.odinms.net.channel.handler.GeneralchatHandler;
import net.sf.odinms.net.world.remote.CheaterData;
import net.sf.odinms.net.world.remote.WorldLocation;
import net.sf.odinms.scripting.portal.PortalScriptManager;
import net.sf.odinms.scripting.reactor.ReactorScriptManager;
import net.sf.odinms.server.MapleInventoryManipulator;
import net.sf.odinms.server.MapleItemInformationProvider;
import net.sf.odinms.server.MaplePortal;
import net.sf.odinms.server.MapleShop;
import net.sf.odinms.server.MapleShopFactory;
import net.sf.odinms.server.MapleTrade;
import net.sf.odinms.server.ShutdownServer;
import net.sf.odinms.server.TimerManager;
import net.sf.odinms.server.life.MapleLifeFactory;
import net.sf.odinms.server.life.MapleMonster;
import net.sf.odinms.server.life.MapleMonsterInformationProvider;
import net.sf.odinms.server.life.MapleMonsterStats;
import net.sf.odinms.server.life.MapleNPC;
import net.sf.odinms.server.maps.MapleDoor;
import net.sf.odinms.server.maps.MapleMap;
import net.sf.odinms.server.maps.MapleMapObject;
import net.sf.odinms.server.maps.MapleMapObjectType;
import net.sf.odinms.server.quest.MapleQuest;
import net.sf.odinms.tools.HexTool;
import net.sf.odinms.tools.MaplePacketCreator;
import net.sf.odinms.tools.MockIOSession;
import net.sf.odinms.tools.Pair;
import net.sf.odinms.tools.StringUtil;
import net.sf.odinms.tools.data.output.MaplePacketLittleEndianWriter;
import net.sf.odinms.server.life.SpawnPoint;
import net.sf.odinms.server.maps.MapleMapFactory;
import net.sf.odinms.server.maps.MapleMapItem;
import net.sf.odinms.server.maps.MapleReactor;
import net.sf.odinms.server.maps.MapleReactorFactory;
import net.sf.odinms.server.maps.MapleReactorStats;
import net.sf.odinms.client.MapleSkinColor;
import net.sf.odinms.client.messages.ServernoticeMapleClientMessageCallback;
import net.sf.odinms.server.MapleStorage;
import net.sf.odinms.scripting.npc.NPCScriptManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URL;
import java.net.URLConnection;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.io.InputStreamReader;
import java.util.Collections;
import net.sf.odinms.tools.MaplePacketCreator;
import net.sf.odinms.tools.StringUtil;

public class CommandProcessor implements CommandProcessorMBean {
	private static CommandProcessor instance = new CommandProcessor();
	private static final Logger log = LoggerFactory.getLogger(GeneralchatHandler.class);
	private static List<Pair<MapleCharacter,String>> gmlog = new LinkedList<Pair<MapleCharacter,String>>();
	private static Runnable persister;
	final private static String[] reasons = {"Hacking", "Botting", "Scamming", "Fake GM", "Harassment", "Advertising"};

	static {
		persister = new PersistingTask();
		TimerManager.getInstance().register(persister, 62000);
	}
    private static int NPCID;

    public static Object getInstance() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
	
	private CommandProcessor() {
		// hidden singleton so we can become managable
	}
	
	public static class PersistingTask implements Runnable {
		@Override
		public void run() {
			synchronized (gmlog) {
				Connection con = DatabaseConnection.getConnection();
				try {
					PreparedStatement ps = con.prepareStatement("INSERT INTO gmlog (cid, command) VALUES (?, ?)");
					for (Pair<MapleCharacter,String> logentry : gmlog) {
						ps.setInt(1, logentry.getLeft().getId());
						ps.setString(2, logentry.getRight());
						ps.executeUpdate();
					}
					ps.close();
				} catch (SQLException e) {
					log.error("error persisting cheatlog", e);
				}
				gmlog.clear();
			}
		}
	}
	
	public static void registerMBean() {
		MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
		try {
			mBeanServer.registerMBean(instance, new ObjectName("net.sf.odinms.client.messages:name=CommandProcessor"));
		} catch (Exception e) {
			log.error("Error registering CommandProcessor MBean");
		}
	}
	
	private static int getNoticeType(String typestring) {
		if (typestring.equals("n")) {
			return 0;
		} else if (typestring.equals("p")) {
			return 1;
		} else if (typestring.equals("l")) {
			return 2;
		} else if (typestring.equals("nv")) {
			return 5;
		} else if (typestring.equals("v")) {
			return 5;
		} else if (typestring.equals("b")) {
			return 6;
		}
		return -1;
	}

              	private static String joinAfterString(String splitted[], String str) {
		for (int i = 1; i < splitted.length; i++) {
			if (splitted[i].equalsIgnoreCase(str) && i + 1 < splitted.length) {
                            return StringUtil.joinStringFrom(splitted, i+1);
			}
		}
		return null;
	}
        
	private static int getOptionalIntArg(String splitted[], int position, int def) {
		if (splitted.length > position) {
			try {
				return Integer.parseInt(splitted[position]);
			} catch (NumberFormatException nfe) {
				return def;
			}
		}
		return def;
	}

	private static String getNamedArg(String splitted[], int startpos, String name) {
		for (int i = startpos; i < splitted.length; i++) {
			if (splitted[i].equalsIgnoreCase(name) && i + 1 < splitted.length) {
				return splitted[i + 1];
			}
		}
		return null;
	}

	private static Integer getNamedIntArg(String splitted[], int startpos, String name) {
		String arg = getNamedArg(splitted, startpos, name);
		if (arg != null) {
			try {
				return Integer.parseInt(arg);
			} catch (NumberFormatException nfe) {
				// swallow - we don't really care
			}
		}
		return null;
	}
	
	private static int getNamedIntArg(String splitted[], int startpos, String name, int def) {
		Integer ret = getNamedIntArg(splitted, startpos, name);
		if (ret == null) {
			return def;
		}
		return ret.intValue();
	}

	private static Double getNamedDoubleArg(String splitted[], int startpos, String name) {
		String arg = getNamedArg(splitted, startpos, name);
		if (arg != null) {
			try {
				return Double.parseDouble(arg);
			} catch (NumberFormatException nfe) {
				// swallow - we don't really care
			}
		}
		return null;
	}

	public static boolean processCommand(MapleClient c, String line) {
		return processCommandInternal(c, new ServernoticeMapleClientMessageCallback(c), c.getPlayer().isGM(), line);
	}
	
	/* (non-Javadoc)
	 * @see net.sf.odinms.client.messages.CommandProcessorMBean#processCommandJMX(int, int, java.lang.String)
	 */
	public String processCommandJMX(int cserver, int mapid, String command) {
		ChannelServer cserv = ChannelServer.getInstance(cserver);
		if (cserv == null) {
			return "The specified channel Server does not exist in this serverprocess";
		}
		MapleClient c = new MapleClient(null, null, new MockIOSession());
		MapleCharacter chr = MapleCharacter.getDefault(c, 26023);
		c.setPlayer(chr);
		chr.setName("/---------jmxuser-------------\\"); // (name longer than maxmimum length)
		MapleMap map = cserv.getMapFactory().getMap(mapid);
		if (map != null) {
			chr.setMap(map);
			SkillFactory.getSkill(5101004).getEffect(1).applyTo(chr);
			map.addPlayer(chr);
		}
		cserv.addPlayer(chr);
		MessageCallback mc = new StringMessageCallback();
		try {
			processCommandInternal(c, mc, true, command);
		} finally {
			if (map != null) {
				map.removePlayer(chr);
			}
			cserv.removePlayer(chr);
		}
		return mc.toString();
	}
	
	/* (non-Javadoc)
	 * @see net.sf.odinms.client.messages.CommandProcessorMBean#processCommandInstance(net.sf.odinms.client.MapleClient, java.lang.String)
	 */
private static boolean processCommandInternal(MapleClient c, MessageCallback mc, boolean isGM, String line) {
		MapleCharacter player = c.getPlayer();
		ChannelServer cserv = c.getChannelServer();
		if (line.charAt(0) == '!' && isGM || line.charAt(0) == '@') {
			if(isGM){
                        synchronized (gmlog) {
				gmlog.add(new Pair<MapleCharacter, String>(player, line));
			}
			log.warn("{} used a GM command: {}", c.getPlayer().getName(), line);
                        }
			String[] splitted = line.split(" ");
			if (splitted[0].equals("!map")) {
				int mapid = Integer.parseInt(splitted[1]);
				MapleMap target = cserv.getMapFactory().getMap(mapid);
				MaplePortal targetPortal = null;
				if (splitted.length > 2) {
					try {
						targetPortal = target.getPortal(Integer.parseInt(splitted[2]));
					} catch (IndexOutOfBoundsException ioobe) {
						// noop, assume the gm didn't know how many portals there are
					} catch (NumberFormatException nfe) {
						// noop, assume that the gm is drunk
					}
				}
				if (targetPortal == null) {
					targetPortal = target.getPortal(0);
				}
				player.changeMap(target, targetPortal);
                        } else if (splitted[0].equals("!jail")) {
                MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                int mapid = 920011200;
                if (splitted.length > 2) {
                    int jailnum = Integer.parseInt(splitted[1]);
                    if (jailnum == 2) mapid = 920011200; //tower of goddes witch ~PCG~
                    else if (jailnum == 3) mapid = 980000404;
                    else if (jailnum == 4) mapid = 980000404;
                    else if (jailnum == 5) mapid = 980000404;
                    else if (jailnum == 6) mapid = 980000404;
                    else if (jailnum == 7) mapid = 980000404;
                    else if (jailnum == 8) mapid = 980000404;
                    else if (jailnum == 9) mapid = 980000000;
                    else if (jailnum == 10) mapid = 980000404;
                    else if (jailnum == 11) mapid = 980000404;
                }
                if (victim != null) {
                    MapleMap target = cserv.getMapFactory().getMap(mapid);
                    MaplePortal targetPortal = target.getPortal(0);
                    victim.changeMap(target, targetPortal);
                    mc.dropMessage(victim.getName() + " was jailed!");
                } else {
                    mc.dropMessage(splitted[1] + " not found!");
                }
				if (victim != null) {
					MapleMap target = cserv.getMapFactory().getMap(mapid);
					MaplePortal targetPortal = target.getPortal(0);
					victim.changeMap(target, targetPortal);
					mc.dropMessage(victim.getName() + " was jailed!");
				} else {
					mc.dropMessage(splitted[1] + " not found!");
				}
			} else if (splitted[0].equals("!sethp")) {
				int hp = Integer.parseInt(splitted[1]);
				if(hp > player.getMaxHp()) {
					player.setHp(player.getMaxHp());
					player.updateSingleStat(MapleStat.HP, player.getMaxHp());
				} else {
					player.setHp(hp);
					player.updateSingleStat(MapleStat.HP, hp);
				}
			} else if (splitted[0].equals("!setmp")) {
				int mp = Integer.parseInt(splitted[1]);
				if(mp > player.getMaxMp()) {
					player.setMp(player.getMaxMp());
					player.updateSingleStat(MapleStat.MP, player.getMaxMp());
				} else {
					player.setMp(mp);
					player.updateSingleStat(MapleStat.MP, mp);
				}
			} else if (splitted[0].equals("!healother")) {
MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
victim.setHp(victim.getMaxHp());
victim.updateSingleStat(MapleStat.HP, victim.getMaxHp());
victim.setMp(victim.getMaxMp());
victim.updateSingleStat(MapleStat.MP, victim.getMaxMp());
} else if (splitted[0].equals("!cheaters")) {
try {
List<CheaterData> cheaters = c.getChannelServer().getWorldInterface().getCheaters();
for (int x = cheaters.size() - 1; x >= 0; x--) {
CheaterData cheater = cheaters.get(x);
mc.dropMessage(cheater.getInfo());
}
} catch (RemoteException e) {
c.getChannelServer().reconnectWorld();
}
			} else if (splitted[0].equals("!lolcastle")) {
				if (splitted.length != 2) {
					mc.dropMessage("Syntax: !lolcastle level (level = 1-5)");
				}
				MapleMap target = c.getChannelServer().getEventSM().getEventManager("lolcastle").getInstance("lolcastle" + splitted[1]).getMapFactory().getMap(990000300, false, false);
				player.changeMap(target, target.getPortal(0));
		                } else if (splitted[0].equals("!gmchat")) {
                        if (player.getGmChatEnabled()) {
                                player.gmChatEnabled(false);
                                mc.dropMessage("Your GM chat has been disabled.");
                        } else {
                                player.gmChatEnabled(true);
                                mc.dropMessage("Your GM chat has been enabled");
                        }
                } else if (splitted[0].equals("!gmsg")) {
                        String gmMSG = StringUtil.joinStringFrom(splitted, 1);
                        for (ChannelServer cservs : ChannelServer.getAllInstances()){
                                for (MapleCharacter players : cservs.getPlayerStorage().getAllCharacters()) {
                                        if (players.isGM() && players.getGmChatEnabled()) {
                                                players.getClient().getSession().write(MaplePacketCreator.serverNotice(2, player.getName() + " : " + gmMSG));
                                        }
                                }
                        }
       
        
			} else if (splitted[0].equals("!warp")) {
				MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
				if (victim != null) {
					if (splitted.length == 2) {
						MapleMap target = victim.getMap();
						c.getPlayer().changeMap(target, target.findClosestSpawnpoint(victim.getPosition()));
					} else {
						int mapid = Integer.parseInt(splitted[2]);
						MapleMap target = ChannelServer.getInstance(c.getChannel()).getMapFactory().getMap(mapid);
						victim.changeMap(target, target.getPortal(0));
					}
				} else {
					try {
						victim = c.getPlayer();
						WorldLocation loc = c.getChannelServer().getWorldInterface().getLocation(splitted[1]);
						if (loc != null) {
							mc.dropMessage("You will be cross-channel warped. This may take a few seconds.");
							//WorldLocation loc = new WorldLocation(40000, 2);
							MapleMap target = c.getChannelServer().getMapFactory().getMap(loc.map);
							c.getPlayer().cancelAllBuffs();
							String ip = c.getChannelServer().getIP(loc.channel);
							c.getPlayer().getMap().removePlayer(c.getPlayer());
							victim.setMap(target);
							String[] socket = ip.split(":");
							if (c.getPlayer().getTrade() != null) {
								MapleTrade.cancelTrade(c.getPlayer());
							}
							c.getPlayer().saveToDB(true);
							if (c.getPlayer().getCheatTracker() != null)
								c.getPlayer().getCheatTracker().dispose();
							ChannelServer.getInstance(c.getChannel()).removePlayer(c.getPlayer());
							c.updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION);
							try {
								MaplePacket packet = MaplePacketCreator.getChannelChange(
									InetAddress.getByName(socket[0]), Integer.parseInt(socket[1]));
								c.getSession().write(packet);
							} catch (Exception e) {
								throw new RuntimeException(e);
							}
						} else {
							int map = Integer.parseInt(splitted[1]);
							MapleMap target = cserv.getMapFactory().getMap(map);
							player.changeMap(target, target.getPortal(0));
						}
					} catch (/*Remote*/Exception e) {
						mc.dropMessage("Something went wrong " + e.getMessage());
					}
				}
			}  else if (splitted[0].equals("!toggleoffense")) {
				try {
					CheatingOffense co = CheatingOffense.valueOf(splitted[1]);
					co.setEnabled(!co.isEnabled());
				} catch (IllegalArgumentException iae) {
					mc.dropMessage("Offense " + splitted[1] + " not found");
				}
	
				} else if (splitted[0].equals("!warphere")) {
				MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
				victim.changeMap(c.getPlayer().getMap(), c.getPlayer().getMap().findClosestSpawnpoint(
					c.getPlayer().getPosition()));
	} else if (splitted[0].equals("@helpwith")) {
if (splitted.length != 2) {
mc.dropMessage("Syntax: The following commands will help you:");
mc.dropMessage("@helpwith commands");
mc.dropMessage("@helpwith report");
mc.dropMessage("@helpwith job");
mc.dropMessage("@helpwith skills");
mc.dropMessage("@helpwith ap");
mc.dropMessage("@helpwith buying");
mc.dropMessage("@helpwith rebirth");
} else if (splitted[1].equals("commands")) {
mc.dropMessage("Commands:");
mc.dropMessage("@str,@luk,@int,@dex. They help you distribute sp faster example:(@str 500)");
mc.dropMessage("@expfix, self explanatory. It will fix your exp if it is in negative numbers"); 
} else if (splitted[1].equals("report")) { 
mc.dropMessage("How to report:");
mc.dropMessage("Right click the player you want to report");
mc.dropMessage("Then click the drop down menu and select why yo want to report the player"); 
mc.dropMessage("You may include a chat log for the Gm's to review just tick the box");
} else if (splitted[1].equals("job")) { 
mc.dropMessage("Changing jobs:");
mc.dropMessage("To change your job simply do it like in normal MapleStory");
mc.dropMessage("Now when you hit 30 and higher you may use cody located in henesys to change jobs");
mc.dropMessage("You may rebirth to another class but you may not use archer+shadow partner");
} else if (splitted[1].equals("skills")) {
mc.dropMessage("All About Skills:");
mc.dropMessage("Once you are level 30 you may use Mia to max all your skills");
mc.dropMessage("Their are a couple of skills that will not work due to them not being coded");
} else if (splitted[1].equals("ap")) {
mc.dropMessage("All About Ability(Ap):");
mc.dropMessage("To add ap faster use the @str etc.. commands(it is not free sp)");
mc.dropMessage("The maximum Ap you may have is 31,000");
mc.dropMessage("To get a stat reset simply go to thomas swift located on the far right side of henesys");
} else if (splitted[1].equals("buying")) {
mc.dropMessage("Where to buy stuff:");
mc.dropMessage("Go check out Nana in henesys!");
mc.dropMessage("Fredrick in fm sells megaphones!"); 
mc.dropMessage("Mad Bunny sells all chairs.");
} else if (splitted[1].equals("rebirth")) { 
mc.dropMessage("All about the rebirth Process:");
mc.dropMessage("You must be level 200");
mc.dropMessage("Use the @rebirth");
mc.dropMessage("Have fun!");
} else {
mc.dropMessage("Try another term");
}
	}	else if (splitted[0].equals("!search")) {
                try {

                    URL                url;
                    URLConnection      urlConn;
                    BufferedReader    dis;
                                    
                                    String replaced = "";
                                    
                                    if (splitted.length > 1) { 
                                      replaced = StringUtil.joinStringFrom(splitted, 1).replace(' ', '%');
                                    } else {
                                      mc.dropMessage("Syntax: !search item name/map name/monster name");
                                    }
                                    
                    url = new URL("http://www.mapletip.com/search_java.php?search_value=" + replaced + "&check=true");

                    urlConn = url.openConnection();
                    urlConn.setDoInput(true);
                    urlConn.setUseCaches(false);

                    dis = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
                    String s;
                 
                    while ((s = dis.readLine()) != null) {
                        mc.dropMessage(s);
                    }
                                    mc.dropMessage("Search for " + '"' + replaced.replace('%', ' ') + '"' + " was completed.");
                    dis.close();
                    }
                    catch (MalformedURLException mue) {}
                    catch (IOException ioe) {}
            
			} else if (splitted[0].equals("!spawn")) {
				int mid = Integer.parseInt(splitted[1]);
				int num = Math.min(getOptionalIntArg(splitted, 2, 1), 500);

				if (mid == 9400203) {
					log.info(MapleClient.getLogMessage(player, "Trying to spawn a silver slime"));
					return true;
				}

				Integer hp = getNamedIntArg(splitted, 1, "hp");
				Integer exp = getNamedIntArg(splitted, 1, "exp");
				Double php = getNamedDoubleArg(splitted, 1, "php");
				Double pexp = getNamedDoubleArg(splitted, 1, "pexp");

				MapleMonster onemob = MapleLifeFactory.getMonster(mid);

				int newhp = 0;
				int newexp = 0;

				double oldExpRatio = ((double) onemob.getHp() / onemob.getExp());

				if (hp != null) {
					newhp = hp.intValue();
				} else if (php != null) {
					newhp = (int) (onemob.getMaxHp() * (php.doubleValue() / 100));
				} else {
					newhp = onemob.getMaxHp();
				}
				if (exp != null) {
					newexp = exp.intValue();
				} else if (pexp != null) {
					newexp = (int) (onemob.getExp() * (pexp.doubleValue() / 100));
				} else {
					newexp = onemob.getExp();
				}

				if (newhp < 1) {
					newhp = 1;
				}
				double newExpRatio = ((double) newhp / newexp);
				if (newExpRatio < oldExpRatio && newexp > 0) {
					mc.dropMessage("The new hp/exp ratio is better than the old one. (" + newExpRatio + " < " +
						oldExpRatio + ") Please don't do this");
					return true;
				}
				
				MapleMonsterStats overrideStats = new MapleMonsterStats();
				overrideStats.setHp(newhp);
				overrideStats.setExp(newexp);
				overrideStats.setMp(onemob.getMaxMp());
				
				for (int i = 0; i < num; i++) {
					MapleMonster mob = MapleLifeFactory.getMonster(mid);
					mob.setHp(newhp);
					mob.setOverrideStats(overrideStats);
					c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob, c.getPlayer().getPosition());
				}
			} else if (splitted[0].equals("!servermessage")) {
				ChannelServer.getInstance(c.getChannel()).setServerMessage(StringUtil.joinStringFrom(splitted, 1));
			} else if (splitted[0].equals("!array")) {
				mc.dropMessage("Array");
			} else if (splitted[0].equals("!hurt")) {
                                MapleCharacter victim1 = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
    victim1.setHp(1);
    victim1.setMp(1);
    victim1.updateSingleStat(MapleStat.HP, 1);
    victim1.updateSingleStat(MapleStat.MP, 1);
			} else if (splitted[0].equals("!notice")) {
				int joinmod = 1;

				int range = -1;
				if (splitted[1].equals("m")) {
					range = 0;
				} else if (splitted[1].equals("c")) {
					range = 1;
				} else if (splitted[1].equals("w")) {
					range = 2;
				}

				int tfrom = 2;
				if (range == -1) {
					range = 2;
					tfrom = 1;
				}
				int type = getNoticeType(splitted[tfrom]);
				if (type == -1) {
					type = 0;
					joinmod = 0;
				}
				String prefix = "";
				if (splitted[tfrom].equals("nv")) {
					prefix = "[Notice] ";
				}
				joinmod += tfrom;
				MaplePacket packet = MaplePacketCreator.serverNotice(type, prefix +
					StringUtil.joinStringFrom(splitted, joinmod));
				if (range == 0) {
					c.getPlayer().getMap().broadcastMessage(packet);
				} else if (range == 1) {
					ChannelServer.getInstance(c.getChannel()).broadcastPacket(packet);
				} else if (range == 2) {
					try {
						ChannelServer.getInstance(c.getChannel()).getWorldInterface().broadcastMessage(
							c.getPlayer().getName(), packet.getBytes());
					} catch (RemoteException e) {
						c.getChannelServer().reconnectWorld();
					}
				}
	                        }  else if (splitted[0].equals("!sex"))
            {
                if (splitted.length == 1)
                {
                    mc.dropMessage("Usage: !amega [name] [type] [message], where [type] is love, cloud, or diablo.");
                }
                
                MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                
                String type = splitted[2];
                int channel = victim.getClient().getChannel();
                String text = StringUtil.joinStringFrom(splitted, 3);
                
                int itemID = 0;
                
                if(type.equals("love"))
                    itemID = 5390002;
                
                else if(type.equals("cloud"))
                    itemID = 5390001;
                
                else if(type.equals("diablo"))
                    itemID = 5390000;
                
                else
                {
                    mc.dropMessage("Invalid type (use love, cloud, or diablo)");
                    return true;
                }
                
                String[] lines = {"", "", "", ""};
                
                if(text.length() > 30)
                {
                    lines[0] = text.substring(0, 10);
                    lines[1] = text.substring(10, 20);
                    lines[2] = text.substring(20, 30);
                    lines[3] = text.substring(30);
                }
                
                else if(text.length() > 20)
                {
                    lines[0] = text.substring(0, 10);
                    lines[1] = text.substring(10, 20);
                    lines[2] = text.substring(20);
                }
                
                else if(text.length() > 10)
                {
                    lines[0] = text.substring(0, 10);
                    lines[1] = text.substring(10);
                }
                
                else if(text.length() <= 10)
                {
                    lines[0] = text;
                }
                
                LinkedList list = new LinkedList();
                list.add(lines[0]);
                list.add(lines[1]);
                list.add(lines[2]);
                list.add(lines[3]);
                
                try
                {
                    MaplePacket mp = MaplePacketCreator.getAvatarMega(victim, channel, itemID, list);
                    victim.getClient().getChannelServer().getWorldInterface().broadcastMessage(null, mp.getBytes());
                }
                catch(Exception e)
                {}    
	                        } else if (splitted[0].equals("!commands")) {
                                mc.dropMessage("The GM Commands are:");
                                mc.dropMessage("!map, !jail, !jail 2, !lolcastle, !warp, !toggleoffense, !warphere, !spawn, !servermessage, !notice,");
                                mc.dropMessage("!job, !clock, !pill, !item, !drop, !shop, !equip, !clearshops, !cleardrops, !clearevents,");
                                mc.dropMessage("!clearquest, !sp, !dc, !ban, !levelup, !whereami, !connected, !whosthere, !timerdebug, !reloadops,");
                                mc.dropMessage("!killall, !monsterdebug, !skill, !tdrops, !lowhp, !fullhp, !cheaters, !search, !unban, !giftnx, !healother, !hurt");
                                mc.dropMessage("!dcall, !spy, !hide, !mesoperson, !sex, !killmap, !face, !healmap, !fame, !speak,");
                                mc.dropMessage("!nearestPortal, !lolhaha, !setall, !nxslimes, !tip, !skin, !dropmesos, !gmset, !worldtrip, !gmchat, !slap, !slapeveryone");
                                mc.dropMessage("!gmsg, !sethp, !setmp, !coke, !papu, !zakum, !ergoth, !ludimini, !cornian, !balrog,");
                                mc.dropMessage("!mushmom, !wyvern, !pirate, !clone, !anego, !theboss, !snackbar, !papapixie, !horseman, !blackcrow,");
                                mc.dropMessage("!leafreboss, !shark, !franken, !bird, !pianus, !centipede, !horntail");
                        } else if (splitted[0].equals("@commands")) {
                                mc.dropMessage("The player Commands are:");
                                mc.dropMessage("@str, @int, @dex, @luk, @exp, @rebirth, @save, @pvp5, @version, @helpwith, @leavepvp");
	                      } else if (splitted[0].equals("!saveall")) { 
                            for (ChannelServer chan : cserv.getAllInstances()) { 
                                for (MapleCharacter chr : chan.getPlayerStorage().getAllCharacters()) { 
                                    chr.saveToDB(true); 
                                } 
                            } 
                            mc.dropMessage("save complete");

}	else if (splitted[0].equals("!dropmeso")) {
                                int hair = Integer.parseInt(splitted[2]);
                                  MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);  
                                if (victim != null) {
                                     victim.getMap().spawnMesoDrop(hair, hair, victim.getPosition(),victim,victim, false);
                                }else {
                                c.getPlayer().getMap().spawnMesoDrop(hair, hair, c.getPlayer().getPosition(), c.getPlayer(),c.getPlayer(), false);
                                }
                        
			} else if (splitted[0].equals("!say")) {
                            if (splitted.length > 1) { 
                                MaplePacket packet = MaplePacketCreator.serverNotice(6, "[" + c.getPlayer().getName() + "] " + StringUtil.joinStringFrom(splitted, 1));
                                try {
                                    ChannelServer.getInstance(c.getChannel()).getWorldInterface().broadcastMessage(
                                    c.getPlayer().getName(), packet.getBytes());
				} catch (RemoteException e) {
                                    c.getChannelServer().reconnectWorld();
				}
                            } else {
                                mc.dropMessage("Syntax: !say <message>");
                            }
			} else if (splitted[0].equals("!job")) {
				c.getPlayer().changeJob(MapleJob.getById(Integer.parseInt(splitted[1])));
} else if (splitted[0].equals("!slapeveryone")) { 
                               int loss = Integer.parseInt(splitted[2]); 
                               for (MapleCharacter victims : cserv.getPlayerStorage().getAllCharacters()) 
                                   if (victims != null) { 
                                       victims.setHp(victims.getHp()-loss);; 
                                       victims.setMp(victims.getMp()-loss); 
                                       victims.updateSingleStat(MapleStat.HP, victims.getHp()-loss); 
                                       victims.updateSingleStat(MapleStat.MP, victims.getMp()-loss); 
                                       mc.dropMessage("You slapped EVERYBODY! People you slapped include: " +victims.getName()+"."); 
                                         // remove line above if you have a GIANT server with houndreds of people in one town at a time 
    
                                   }          
                         
                         
} else if (splitted[0].equals("@str")) {
                   int up;
                    up = Integer.parseInt(splitted[1]);
                    if ( player.getRemainingAp() < up ||  player.getRemainingAp() < 0 || player.getStr() >= 31000 || up < 0) {
                        mc.dropMessage("Insufficient AP or above the 31000 limit.");
                    } else if ( player.getRemainingAp() > 0) {
                          player.setStr(player.getStr() + up);
                          player.setRemainingAp(player.getRemainingAp() - up);
                          player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
                          player.updateSingleStat(MapleStat.STR, player.getStr());
                }
                 
                }else if (splitted[0].equals("@int")) {
                   int up;
                    up = Integer.parseInt(splitted[1]);
                    if ( player.getRemainingAp() < up ||  player.getRemainingAp() < 0 || player.getInt() >= 31000 || up < 0) {
                        mc.dropMessage("Insufficient AP or above the 31000 limit");
                    } else if ( player.getRemainingAp() > 0) {
                          player.setInt(player.getInt() + up);
                          player.setRemainingAp(player.getRemainingAp() - up);
                          player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
                          player.updateSingleStat(MapleStat.INT, player.getInt());
                }
                    //DEX
                }else if (splitted[0].equals("@dex")) {
                   int up;
                    up = Integer.parseInt(splitted[1]);
                    if ( player.getRemainingAp() < up ||  player.getRemainingAp() < 0 || player.getDex() >= 31000 || up < 0) {
                        mc.dropMessage("Insufficient AP or above the 31000 limit");
                    } else if ( player.getRemainingAp() > 0) {
                          player.setDex(player.getDex() + up);
                          player.setRemainingAp(player.getRemainingAp() - up);
                           player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
                          player.updateSingleStat(MapleStat.DEX, player.getDex());
                }
                    //LUCK
                }else if (splitted[0].equals("@luk")) {
                   int up;
                    up = Integer.parseInt(splitted[1]);
                    if ( player.getRemainingAp() < up ||  player.getRemainingAp() < 0 || player.getLuk() >= 31000 || up < 0) {
                        mc.dropMessage("Insufficient AP or above the 31000 limit");
                    } else if ( player.getRemainingAp() > 0) {
                          player.setLuk(player.getLuk() + up);
                             player.setRemainingAp(player.getRemainingAp() - up);
                           player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
                          player.updateSingleStat(MapleStat.LUK, player.getLuk());
                }
                }
			 else if (splitted[0].equals("!clock")) {
				player.getMap().broadcastMessage(MaplePacketCreator.getClock(getOptionalIntArg(splitted, 1, 60)));

		}	else if (splitted[0].equals("@exp")) {
                             int expfix;
				expfix = c.getPlayer().getExp();
                               if (expfix < 0) {
                                      c.getPlayer().gainExp(-expfix, false, false);
				      player.updateSingleStat(MapleStat.EXP, player.getExp()); }
mc.dropMessage("You don't have negative exp.");

                
			} else if (splitted[0].equals("!pill")) {
				MapleInventoryManipulator.addById(c, 2002009, (short) 5, c.getPlayer().getName() + " used !pill", player.getName());
			} else if (splitted[0].equals("!item")) {
				short quantity = (short) getOptionalIntArg(splitted, 2, 1);
				MapleInventoryManipulator.addById(c, Integer.parseInt(splitted[1]), quantity, c.getPlayer().getName() +
					"used !item with quantity " + quantity, player.getName());
			} else if (splitted[0].equals("!drop")) {
				MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
				int itemId = Integer.parseInt(splitted[1]);
				short quantity = (short) (short) getOptionalIntArg(splitted, 2, 1);
				IItem toDrop;
				if (ii.getInventoryType(itemId) == MapleInventoryType.EQUIP)
					toDrop = ii.getEquipById(itemId);
				else
					toDrop = new Item(itemId, (byte) 0, (short) quantity);
				StringBuilder logMsg = new StringBuilder("Created by ");
				logMsg.append(c.getPlayer().getName());
				logMsg.append(" using !drop. Quantity: ");
				logMsg.append(quantity);
				toDrop.log(logMsg.toString(), false);
				toDrop.setOwner(player.getName());
				c.getPlayer().getMap().spawnItemDrop(c.getPlayer(), c.getPlayer(), toDrop, c.getPlayer().getPosition(), true,true);
			} else if (splitted[0].equals("!shop")) {
				MapleShopFactory sfact = MapleShopFactory.getInstance();
				MapleShop shop = sfact.getShop(1);
				shop.sendShop(c);
			} else if (splitted[0].equals("@save")) {
				c.getPlayer().saveToDB(true);
				 mc.dropMessage("Saved.");

			} else if (splitted[0].equals("!ap")) { 
                player.setRemainingAp(getOptionalIntArg(splitted, 1, 1)); 
                player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());			
} else if (splitted[0].equals("!equip")) {
				MapleShopFactory sfact = MapleShopFactory.getInstance();
				MapleShop shop = sfact.getShop(2);
				shop.sendShop(c);
			} else if (splitted[0].equals("!gmshop")) {
				MapleShopFactory sfact = MapleShopFactory.getInstance();
				MapleShop shop = sfact.getShop(1337);
				shop.sendShop(c);
                        } else if (splitted[0].equals("!cleardrops")){
                            MapleMap map = c.getPlayer().getMap();
                            double range = Double.POSITIVE_INFINITY;
                            List<MapleMapObject> items = map.getMapObjectsInRange(c.getPlayer().getPosition(), range, Arrays.asList(MapleMapObjectType.ITEM));
                            for (MapleMapObject itemmo : items) {
                            map.removeMapObject(itemmo);
                            map.broadcastMessage(MaplePacketCreator.removeItemFromMap(itemmo.getObjectId(), 0, c.getPlayer().getId()));
                                }
                            mc.dropMessage("You have destroyed " + items.size() + " items on the ground.");  
                        } else if (splitted[0].equals("!clearReactorDrops")) {
				ReactorScriptManager.getInstance().clearDrops();
			} else if (splitted[0].equals("!clearshops")) {
				MapleShopFactory.getInstance().clear(); 
                        } else if (splitted[0].equals("!storage")) {
                                c.getPlayer().getStorage().sendStorage(c, 2080005);

} else if (splitted[0].equals("!kill")) {
                                MapleCharacter victim1 = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
    victim1.setHp(0);
    victim1.setMp(0);
    victim1.updateSingleStat(MapleStat.HP, 0);
    victim1.updateSingleStat(MapleStat.MP, 0);
                                MapleCharacter victim2 = cserv.getPlayerStorage().getCharacterByName(splitted[2]);
    victim2.setHp(0);
    victim2.setMp(0);
    victim2.updateSingleStat(MapleStat.HP, 0);
    victim2.updateSingleStat(MapleStat.MP, 0);
                                MapleCharacter victim3 = cserv.getPlayerStorage().getCharacterByName(splitted[3]);
    victim3.setHp(0);
    victim3.setMp(0);
    victim3.updateSingleStat(MapleStat.HP, 0);
    victim3.updateSingleStat(MapleStat.MP, 0);
                                MapleCharacter victim4 = cserv.getPlayerStorage().getCharacterByName(splitted[4]);
    victim4.setHp(0);
    victim4.setMp(0);
    victim4.updateSingleStat(MapleStat.HP, 0);
    victim4.updateSingleStat(MapleStat.MP, 0);
                                MapleCharacter victim5 = cserv.getPlayerStorage().getCharacterByName(splitted[5]);
    victim5.setHp(0);
    victim5.setMp(0);
    victim5.updateSingleStat(MapleStat.HP, 0);
    victim5.updateSingleStat(MapleStat.MP, 0);
                                MapleCharacter victim6 = cserv.getPlayerStorage().getCharacterByName(splitted[6]);
    victim6.setHp(0);
    victim6.setMp(0);
    victim6.updateSingleStat(MapleStat.HP, 0);
    victim6.updateSingleStat(MapleStat.MP, 0);
   }
     else if (splitted[0].equals("!levelperson")) {
    MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);  
                             victim.setLevel(getOptionalIntArg(splitted, 2, 2));
    victim.levelUp();
     int newexp = victim.getExp();
     if (newexp < 0) {
      victim.gainExp(-newexp, false, false);
	}
	} else if (splitted[0].equals("!listreports")) {
                            ResultSet rs = getReports();
                            try {
                                while(rs.next()){
                                    mc.dropMessage("id: " + rs.getInt("id") + " | time reported: " + rs.getTimestamp("reporttime").toString() + " | reason: " + reasons[rs.getByte("reason")]);
                                }
                            } catch(Exception ex) {}
                        } else if (splitted[0].equals("!getreport")) {
                            if(splitted.length != 2) return true;
                            int reportid = Integer.parseInt(splitted[1]);
                            ResultSet rs = getReport(reportid);
                            try {
                                while(rs.next()){
                                    mc.dropMessage("id: " + rs.getInt("id") + " | time reported: " + rs.getTimestamp("reporttime").toString() + " | reason: " + reasons[rs.getByte("reason")]);
                                    mc.dropMessage("reporter charid: " + rs.getInt("reporterid"));
                                    mc.dropMessage("victim charid: " + rs.getInt("victimid"));
                                    mc.dropMessage("chatlog: ");
                                    mc.dropMessage(rs.getString("chatlog"));
                                    mc.dropMessage("Status: " + rs.getString("status"));
                                    
                                }
                            } catch(Exception ex){}
                        } else if (splitted[0].equals("!delreport")) {   
                            if(splitted.length != 2) return true;
                            int reportid = Integer.parseInt(splitted[1]);
                            deleteReport(reportid);
                        } else if (splitted[0].equals("!setreportstatus")) {  
                             if(splitted.length < 3) return true;
                            int reportid = Integer.parseInt(splitted[1]);
                            String status = StringUtil.joinStringFrom(splitted, 2);
                            setReportStatus(reportid, status);
                        } else if (splitted[0].equals("!getnamebyid")) {
                            if(splitted.length != 2) return true;
                            int cid = Integer.parseInt(splitted[1]);
                            mc.dropMessage(getCharInfoById(cid));
                        } else if (splitted[0].equals("!getnamebyid")) {
                            if(splitted.length != 2) return true;
                            int cid = Integer.parseInt(splitted[1]);
                            mc.dropMessage(getCharInfoById(cid));
		 }else if (splitted[0].equals("!online")) { // testing
				MessageCallback callback = new ServernoticeMapleClientMessageCallback(c);
				StringBuilder builder = new StringBuilder("Characters online: ");
				for (MapleCharacter chr : cserv.getPlayerStorage().getAllCharacters()) {
					if (builder.length() > 150) { 
						builder.setLength(builder.length() - 2);
						callback.dropMessage(builder.toString());
						builder = new StringBuilder();
					}
					builder.append(MapleCharacterUtil.makeMapleReadable(chr.getName()));
					builder.append(", ");
				}
				builder.setLength(builder.length() - 2);
				c.getSession().write(MaplePacketCreator.serverNotice(6, builder.toString()));
                        } else if (splitted[0].equals("@opennpc")) {
                                NPCScriptManager npc = NPCScriptManager.getInstance();
                                npc.start(c, NPCID);
} else if (splitted[0].equals("!leeton"))
            {
                MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                victim.setLeetness(true);
                mc.dropMessage("You have given " + victim.getName() + " the gift of 1337ness.");
                
                ServernoticeMapleClientMessageCallback cm = new ServernoticeMapleClientMessageCallback(victim.getClient());
        
                if(!(c.getPlayer().getName().equals(victim.getName())))
                {
                    cm.dropMessage("You have been given the gift of 1337ness by a GM.");
                }
                
            
            
           } else if (splitted[0].equals("!leetoff"))
            {
                MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                victim.setLeetness(false);
                mc.dropMessage("You have taken away " + victim.getName() + "'s 1337ness.");
                
                ServernoticeMapleClientMessageCallback cm = new ServernoticeMapleClientMessageCallback(victim.getClient());
        
                if(!(c.getPlayer().getName().equals(victim.getName())))
                {
                    cm.dropMessage("Your 1337ness has been taken away by a GM.");
                }
} else if (splitted[0].equals("!clearevents")) {
				for (ChannelServer instance : ChannelServer.getAllInstances()) {
					instance.reloadEvents();
				}
                        }else if(splitted[0].equalsIgnoreCase("!showMonsterID"))
        {
            MapleMap map = player.getMap();
            double range = Double.POSITIVE_INFINITY;
            List<MapleMapObject> monsters = map.getMapObjectsInRange(player.getPosition(), range, Arrays
                .asList(MapleMapObjectType.MONSTER));
            for (MapleMapObject monstermo : monsters) {
                MapleMonster monster = (MapleMonster) monstermo;
                String alive="false";
                if(monster.isAlive())alive="true";
                mc.dropMessage("name="+monster.getName()+" ID="+monster.getId()+" isAlive="+alive);
            }
        }
	else if (splitted[0].equals("!showPortalName"))
        {
            final MaplePortal portal = player.getMap().findClosestSpawnpoint(player.getPosition());
            mc.dropMessage(portal.getName() + " id: " + portal.getId() + " script: " + portal.getScriptName()+" name: "+portal.getName());
        } else if (splitted[0].equals("!level")) {  //By PurpleMadness
                            c.getPlayer().setLevel(getOptionalIntArg(splitted, 1, 1));
				c.getPlayer().levelUp();
				int newexp = c.getPlayer().getExp();
				if (newexp < 0) {
					c.getPlayer().gainExp(-newexp, false, false);
                             	}
                        } else if (splitted[0].equals("!getnamebyid")) {
                            if(splitted.length != 2) return true;
                            int cid = Integer.parseInt(splitted[1]);
                            mc.dropMessage(getCharInfoById(cid));

				}else if (splitted[0].equals("!exprate")) { // by Redline/2azn4u
				if (splitted.length > 1) {
					int exp = Integer.parseInt(splitted[1]);
					cserv.setExpRate(exp);
					MaplePacket packet = MaplePacketCreator.serverNotice(6, "Exp Rate has been changed to " + exp + "x");
					ChannelServer.getInstance(c.getChannel()).broadcastPacket(packet);
				} else 
					mc.dropMessage("Syntax: !exprate <number>");
                                
                        } 
				else if (splitted[0].equals("!music")) {
                                if (splitted[1].equals("names") && splitted.length == 2) {
                                        mc.dropMessage("Names are case sensitive!");
                                        mc.dropMessage("Use !song names [Folder Name] to get list of songs.");
                                        mc.dropMessage("Folder Names:");
                                        mc.dropMessage("Bgm00 | Bgm01 | Bgm02 | Bgm03 | Bgm04");
                                        mc.dropMessage("Bgm05 | Bgm06 | Bgm07 | Bgm08 | Bgm09");
                                        mc.dropMessage("Bgm10 | Bgm11 | Bgm12 | Bgm13 | Bgm14");
                                        mc.dropMessage("    Bgm15 | BgmEvent | BgmGL | BgmJp");
                                } else if (splitted[1].equals("names") && splitted.length == 3) {
                                        if (splitted[2].equals("Bgm00")) {
                                            mc.dropMessage("Bgm00/SleepyWood");
                                            mc.dropMessage("Bgm00/FloralLife");
                                            mc.dropMessage("Bgm00/GoPicnic");
                                            mc.dropMessage("Bgm00/Nightmare");
                                            mc.dropMessage("Bgm00/RestNPeace");
                                        } else if (splitted[2].equals("Bgm01")) {
                                            mc.dropMessage("Bgm01/AncientMove");
                                            mc.dropMessage("Bgm01/MoonlightShadow");
                                            mc.dropMessage("Bgm01/WhereTheBarlogFrom");
                                            mc.dropMessage("Bgm01/CavaBien");
                                            mc.dropMessage("Bgm01/HighlandStar");
                                            mc.dropMessage("Bgm01/BadGuys");
                                        } else if (splitted[2].equals("Bgm02")) {
                                            mc.dropMessage("Bgm02/MissingYou");
                                            mc.dropMessage("Bgm02/WhenTheMorningComes");
                                            mc.dropMessage("Bgm02/EvilEyes");
                                            mc.dropMessage("Bgm02/JungleBook");
                                            mc.dropMessage("Bgm02/AboveTheTreetops");
                                        } else if (splitted[2].equals("Bgm03")) {
                                            mc.dropMessage("Bgm03/Subway");
                                            mc.dropMessage("Bgm03/Elfwood");
                                            mc.dropMessage("Bgm03/BlueSky");
                                            mc.dropMessage("Bgm03/Beachway");
                                            mc.dropMessage("Bgm03/SnowyVillage");
                                        } else if (splitted[2].equals("Bgm04")) {
                                            mc.dropMessage("Bgm04/PlayWithMe");
                                            mc.dropMessage("Bgm04/WhiteChristmas");
                                            mc.dropMessage("Bgm04/UponTheSky");
                                            mc.dropMessage("Bgm04/ArabPirate");
                                            mc.dropMessage("Bgm04/Shinin'Harbor");
                                            mc.dropMessage("Bgm04/WarmRegard");
                                        } else if (splitted[2].equals("Bgm05")) {
                                            mc.dropMessage("Bgm05/WolfWood");
                                            mc.dropMessage("Bgm05/DownToTheCave");
                                            mc.dropMessage("Bgm05/AbandonedMine");
                                            mc.dropMessage("Bgm05/MineQuest");
                                            mc.dropMessage("Bgm05/HellGate");
                                        } else if (splitted[2].equals("Bgm06")) {
                                            mc.dropMessage("Bgm06/FinalFight");
                                            mc.dropMessage("Bgm06/WelcomeToTheHell");
                                            mc.dropMessage("Bgm06/ComeWithMe");
                                            mc.dropMessage("Bgm06/FlyingInABlueDream");
                                            mc.dropMessage("Bgm06/FantasticThinking");
                                        } else if (splitted[2].equals("Bgm07")) {
                                            mc.dropMessage("Bgm07/WaltzForWork");
                                            mc.dropMessage("Bgm07/WhereverYouAre");
                                            mc.dropMessage("Bgm07/FunnyTimeMaker");
                                            mc.dropMessage("Bgm07/HighEnough");
                                            mc.dropMessage("Bgm07/Fantasia");
                                        } else if (splitted[2].equals("Bgm08")) {
                                            mc.dropMessage("Bgm08/LetsMarch");
                                            mc.dropMessage("Bgm08/ForTheGlory");
                                            mc.dropMessage("Bgm08/FindingForest");
                                            mc.dropMessage("Bgm08/LetsHuntAliens");
                                            mc.dropMessage("Bgm08/PlotOfPixie");
                                        } else if (splitted[2].equals("Bgm09")) {
                                            mc.dropMessage("Bgm09/DarkShadow");
                                            mc.dropMessage("Bgm09/TheyMenacingYou");
                                            mc.dropMessage("Bgm09/FairyTale");
                                            mc.dropMessage("Bgm09/FairyTalediffvers");
                                            mc.dropMessage("Bgm09/TimeAttack");
                                        } else if (splitted[2].equals("Bgm10")) {
                                            mc.dropMessage("Bgm10/Timeless");
                                            mc.dropMessage("Bgm10/TimelessB");
                                            mc.dropMessage("Bgm10/BizarreTales");
                                            mc.dropMessage("Bgm10/TheWayGrotesque");
                                            mc.dropMessage("Bgm10/Eregos");
                                        } else if (splitted[2].equals("Bgm11")) {
                                            mc.dropMessage("Bgm11/BlueWorld");
                                            mc.dropMessage("Bgm11/Aquarium");
                                            mc.dropMessage("Bgm11/ShiningSea");
                                            mc.dropMessage("Bgm11/DownTown");
                                            mc.dropMessage("Bgm11/DarkMountain");
                                        } else if (splitted[2].equals("Bgm12")) {
                                            mc.dropMessage("Bgm12/AquaCave");
                                            mc.dropMessage("Bgm12/DeepSee");
                                            mc.dropMessage("Bgm12/WaterWay");
                                            mc.dropMessage("Bgm12/AcientRemain");
                                            mc.dropMessage("Bgm12/RuinCastle");
                                            mc.dropMessage("Bgm12/Dispute");
                                        } else if (splitted[2].equals("Bgm13")) {
                                            mc.dropMessage("Bgm13/CokeTown");
                                            mc.dropMessage("Bgm13/Leafre");
                                            mc.dropMessage("Bgm13/Minar'sDream");
                                            mc.dropMessage("Bgm13/AcientForest");
                                            mc.dropMessage("Bgm13/TowerOfGoddess");
                                        } else if (splitted[2].equals("Bgm14")) {
                                            mc.dropMessage("Bgm14/DragonLoad");
                                            mc.dropMessage("Bgm14/HonTale");
                                            mc.dropMessage("Bgm14/CaveOfHontale");
                                            mc.dropMessage("Bgm14/DragonNest");
                                            mc.dropMessage("Bgm14/Ariant");
                                            mc.dropMessage("Bgm14/HotDesert");
                                        } else if (splitted[2].equals("Bgm15")) {
                                            mc.dropMessage("Bgm15/MureungHill");
                                            mc.dropMessage("Bgm15/MureungForest");
                                            mc.dropMessage("Bgm15/WhiteHerb");
                                            mc.dropMessage("Bgm15/Pirate");
                                            mc.dropMessage("Bgm15/SunsetDesert");
                                        } else if (splitted[2].equals("BgmEvent")) {
                                            mc.dropMessage("BgmEvent/FunnyRabbit");
                                            mc.dropMessage("BgmEvent/FunnyRabbitFaster");
                                        } else if (splitted[2].equals("BgmGL")) {
                                            mc.dropMessage("BgmGL/amoria");
                                            mc.dropMessage("BgmGL/chapel");
                                            mc.dropMessage("BgmGL/cathedral");
                                            mc.dropMessage("BgmGL/Amorianchallenge");
                                        } else if (splitted[2].equals("BgmJp")) {
                                            mc.dropMessage("BgmJp/Feeling");
                                            mc.dropMessage("BgmJp/BizarreForest");
                                            mc.dropMessage("BgmJp/Hana");
                                            mc.dropMessage("BgmJp/Yume");
                                            mc.dropMessage("BgmJp/Bathroom");
                                            mc.dropMessage("BgmJp/BattleField");
                                            mc.dropMessage("BgmJp/FirstStepMaster");
                                }
                                } else {
                                        String songName =  splitted[1];
                                        c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.musicChange(songName)); 
                                        
                                } 
                        } else if (splitted[0].equals("!mesorate")) { // by Redline/2azn4u
				if (splitted.length > 1) {
					int meso = Integer.parseInt(splitted[1]);
					cserv.setMesoRate(meso);
					MaplePacket packet = MaplePacketCreator.serverNotice(6, "Meso Rate has been changed to " + meso + "x");
					ChannelServer.getInstance(c.getChannel()).broadcastPacket(packet);
				} else 
					mc.dropMessage("Syntax: !mesorate <number>");
                        } else if (splitted[0].equals("!droprate")) { // by doncare aka voice123

                if (splitted.length > 1) {
                    int drop = Integer.parseInt(splitted[1]);
                    cserv.setDropRate(drop);
                    MaplePacket packet = MaplePacketCreator.serverNotice(6, "Drop Rate has been changed to " + drop + "x");
                    ChannelServer.getInstance(c.getChannel()).broadcastPacket(packet);
                } else 
                    mc.dropMessage("Syntax: !droprate <number>");
                
                        }        else if (splitted[0].equals("!bossdroprate")) { // by doncare aka voice123

                if (splitted.length > 1) {
                    int bossdrop = Integer.parseInt(splitted[1]);
                    cserv.setBossDropRate(bossdrop);
                    MaplePacket packet = MaplePacketCreator.serverNotice(6, "Boss Drop Rate has been changed to " + bossdrop + "x");
                    ChannelServer.getInstance(c.getChannel()).broadcastPacket(packet);
                } else 
                    mc.dropMessage("Syntax: !bossdroprate <number>");


} else if (splitted[0].equals("!mesos")){
                            c.getPlayer().gainMeso(Integer.parseInt(splitted[1]), true);    
                   }	else if (splitted[0].equals("!warpallhere")) {
                	for (MapleCharacter mch : cserv.getPlayerStorage().getAllCharacters())
                    	if (mch.getMapId() != c.getPlayer().getMapId())
                        mch.changeMap(c.getPlayer().getMap(), c.getPlayer().getPosition()); 
			} else if (splitted[0].equalsIgnoreCase("!killmonster")) {
            if(splitted.length ==2)
            {
                MapleMap map = c.getPlayer().getMap();
                double range = Double.POSITIVE_INFINITY;
                int targetId=Integer.parseInt(splitted[1]);
        
                List<MapleMapObject> monsters = map.getMapObjectsInRange(c.getPlayer().getPosition(), range, Arrays
                    .asList(MapleMapObjectType.MONSTER));

                for (MapleMapObject monstermo : monsters) {
                    MapleMonster monster = (MapleMonster) monstermo;
                    if (monster.getId()==targetId) {
                        map.killMonster(monster, player, false);
                        break;
                    }
                }
            }

			} else if (splitted[0].equals("!resetquest")) {
				MapleQuest.getInstance(Integer.parseInt(splitted[1])).forfeit(c.getPlayer());
} else if (splitted[0].equals("!leetonch"))
            {
                               for (MapleCharacter dude : cserv.getPlayerStorage().getAllCharacters())
                                   if (dude != null) {
                dude.setLeetness(true);
                mc.dropMessage("You have given the channel the gift of 1337ness.");
                
                ServernoticeMapleClientMessageCallback cm = new ServernoticeMapleClientMessageCallback(dude.getClient());
        
                if(!(c.getPlayer().getName().equals(dude.getName())))
                {
                    cm.dropMessage("You have been given the gift of 1337ness by a GM.");
                }
                                   }   
                        
           } else if (splitted[0].equals("!leetoffch"))
            {
                               for (MapleCharacter boi : cserv.getPlayerStorage().getAllCharacters())
                                   if (boi != null) {
                boi.setLeetness(false);
                mc.dropMessage("You have taken away the channel's 1337ness.");
                
                ServernoticeMapleClientMessageCallback cm = new ServernoticeMapleClientMessageCallback(boi.getClient());
        
                if(!(c.getPlayer().getName().equals(boi.getName())))
                {
                    cm.dropMessage("Your 1337ness has been taken away by a GM.");
                }
                                   }
} else if (splitted[0].equals("!unban")) {
				if (MapleCharacter.unban(splitted[1], false)) {
					mc.dropMessage("Unbanned " + splitted[1]);
				} else {
					mc.dropMessage("Failed to unban " + splitted[1]);
				}
			
	}	else if (splitted[0].equals("!giftnx")) {
                             MapleCharacter victim1 = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                        int points = Integer.parseInt(splitted[2]);
                            	victim1.modifyCSPoints(0, points);
                                mc.dropMessage("Yah!");
				
                        
			} else if (splitted[0].equals("!jobperson")) {
                              MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);  
                             victim.changeJob(MapleJob.getById(getOptionalIntArg(splitted, 2, 2)));
}	else if (splitted[0].equals("!slap")) { 
                                        int loss = Integer.parseInt(splitted[2]); 
                                        MapleCharacter victim1 = cserv.getPlayerStorage().getCharacterByName(splitted[1]); 
                                        victim1.setHp(victim1.getHp()-loss); 
                                        victim1.setMp(victim1.getMp()-loss); 
                                        victim1.updateSingleStat(MapleStat.HP, victim1.getHp()-loss); 
                                        victim1.updateSingleStat(MapleStat.MP, victim1.getMp()-loss); 
                                        mc.dropMessage("You slapped " +victim1.getName()+"."); 
                                        MapleCharacter victim2 = cserv.getPlayerStorage().getCharacterByName(splitted[2]); 
                                        victim2.setHp(victim2.getHp()-loss); 
                                        victim2.setMp(victim2.getMp()-loss); 
                                        victim2.updateSingleStat(MapleStat.HP, victim2.getHp()-loss); 
                                        victim2.updateSingleStat(MapleStat.MP, victim2.getMp()-loss); 
                                        mc.dropMessage("You slapped " +victim2.getName()+"."); 
                                        MapleCharacter victim3 = cserv.getPlayerStorage().getCharacterByName(splitted[3]); 
                                        victim3.setHp(victim3.getHp()-loss); 
                                        victim3.setMp(victim3.getMp()-loss); 
                                        victim3.updateSingleStat(MapleStat.HP, victim3.getHp()-loss); 
                                        victim3.updateSingleStat(MapleStat.MP, victim3.getMp()-loss); 
                                        mc.dropMessage("You slapped " +victim3.getName()+"."); 
                                        MapleCharacter victim4 = cserv.getPlayerStorage().getCharacterByName(splitted[4]); 
                                        victim4.setHp(victim4.getHp()-loss); 
                                        victim4.setMp(victim4.getMp()-loss); 
                                        victim4.updateSingleStat(MapleStat.HP, victim4.getHp()-loss); 
                                        victim4.updateSingleStat(MapleStat.MP, victim4.getMp()-loss); 
                                        mc.dropMessage("You slapped " +victim4.getName()+"."); 
                                        MapleCharacter victim5 = cserv.getPlayerStorage().getCharacterByName(splitted[5]); 
                                        victim5.setHp(victim5.getHp()-loss); 
                                        victim5.setMp(victim5.getMp()-loss); 
                                        victim5.updateSingleStat(MapleStat.HP, victim5.getHp()-loss); 
                                        victim5.updateSingleStat(MapleStat.MP, victim5.getMp()-loss); 
                                        mc.dropMessage("You slapped " +victim5.getName()+"."); 
                                        MapleCharacter victim6 = cserv.getPlayerStorage().getCharacterByName(splitted[6]); 
                                        victim6.setHp(victim6.getHp()-loss); 
                                        victim6.setMp(victim6.getMp()-loss); 
                                        victim6.updateSingleStat(MapleStat.HP, victim6.getHp()-loss); 
                                        victim6.updateSingleStat(MapleStat.MP, victim6.getMp()-loss); 
                                        mc.dropMessage("You slapped " +victim6.getName()+"."); 
                                        MapleCharacter victim7 = cserv.getPlayerStorage().getCharacterByName(splitted[6]); 
                                        victim7.setHp(victim7.getHp()-loss); 
                                        victim7.setMp(victim7.getMp()-loss); 
                                        victim7.updateSingleStat(MapleStat.HP, victim7.getHp()-loss); 
                                        victim7.updateSingleStat(MapleStat.MP, victim7.getMp()-loss); 
                                        mc.dropMessage("You slapped " +victim7.getName()+"."); 
                                        MapleCharacter victim8 = cserv.getPlayerStorage().getCharacterByName(splitted[6]); 
                                        victim8.setHp(victim8.getHp()-loss); 
                                        victim8.setMp(victim8.getMp()-loss); 
                                        victim8.updateSingleStat(MapleStat.HP, victim8.getHp()-loss); 
                                        victim8.updateSingleStat(MapleStat.MP, victim8.getMp()-loss); 
                                        mc.dropMessage("You slapped " +victim8.getName()+"."); 
                                        MapleCharacter victim9 = cserv.getPlayerStorage().getCharacterByName(splitted[6]); 
                                        victim9.setHp(victim9.getHp()-loss); 
                                        victim9.setMp(victim9.getMp()-loss); 
                                        victim9.updateSingleStat(MapleStat.HP, victim9.getHp()-loss); 
                                        victim9.updateSingleStat(MapleStat.MP, victim9.getMp()-loss); 
                                        mc.dropMessage("You slapped " +victim9.getName()+"."); 
                                        MapleCharacter victim10 = cserv.getPlayerStorage().getCharacterByName(splitted[6]); 
                                        victim10.setHp(victim10.getHp()-loss); 
                                        victim10.setMp(victim10.getMp()-loss); 
                                        victim10.updateSingleStat(MapleStat.HP, victim10.getHp()-loss); 
                                        victim10.updateSingleStat(MapleStat.MP, victim10.getMp()-loss); 
                                        mc.dropMessage("You slapped " +victim10.getName()+"."); 
                                        MapleCharacter victim11 = cserv.getPlayerStorage().getCharacterByName(splitted[6]); 
                                        victim11.setHp(victim11.getHp()-loss); 
                                        victim11.setMp(victim11.getMp()-loss); 
                                        victim11.updateSingleStat(MapleStat.HP, victim11.getHp()-loss); 
                                        victim11.updateSingleStat(MapleStat.MP, victim11.getMp()-loss); 
                                        mc.dropMessage("You slapped " +victim11.getName()+"."); 
                                         MapleCharacter victim12 = cserv.getPlayerStorage().getCharacterByName(splitted[6]); 
                                        victim12.setHp(victim12.getHp()-loss); 
                                        victim12.setMp(victim12.getMp()-loss); 
                                        victim12.updateSingleStat(MapleStat.HP, victim12.getHp()-loss); 
                                        victim12.updateSingleStat(MapleStat.MP, victim12.getMp()-loss); 
                                        mc.dropMessage("You slapped " +victim12.getName()+"."); 
// made by Kirby 
			
			} else if (splitted[0].equals("!gps")) {
				// c.getSession().write(MaplePacketCreator.getPlayerShop(c.getPlayer(), 0, null));
                        } else if (splitted[0].equals("!worldtrip")) {
    MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
    for (int i = 1; i <= 10; i++) {
        MapleMap target = cserv.getMapFactory().getMap(200000000);
    MaplePortal targetPortal = target.getPortal(0);
    victim.changeMap(target, targetPortal);
        MapleMap target1 = cserv.getMapFactory().getMap(102000000);
    MaplePortal targetPortal1 = target.getPortal(0);
    victim.changeMap(target1, targetPortal1);
        MapleMap target2 = cserv.getMapFactory().getMap(103000000);
    MaplePortal targetPortal2 = target.getPortal(0);
    victim.changeMap(target2, targetPortal2);
        MapleMap target3 = cserv.getMapFactory().getMap(100000000);
    MaplePortal targetPortal3 = target.getPortal(0);
    victim.changeMap(target3, targetPortal3);
        MapleMap target4 = cserv.getMapFactory().getMap(200000000);
    MaplePortal targetPortal4 = target.getPortal(0);
    victim.changeMap(target4, targetPortal4);
        MapleMap target5 = cserv.getMapFactory().getMap(211000000);
    MaplePortal targetPortal5 = target.getPortal(0);
    victim.changeMap(target5, targetPortal5);
        MapleMap target6 = cserv.getMapFactory().getMap(230000000);
    MaplePortal targetPortal6 = target.getPortal(0);
    victim.changeMap(target6, targetPortal6);
        MapleMap target7 = cserv.getMapFactory().getMap(222000000);
    MaplePortal targetPortal7 = target.getPortal(0);
    victim.changeMap(target7, targetPortal7);
        MapleMap target8 = cserv.getMapFactory().getMap(251000000);
    MaplePortal targetPortal8 = target.getPortal(0);
    victim.changeMap(target8, targetPortal8);
        MapleMap target9 = cserv.getMapFactory().getMap(220000000);
    MaplePortal targetPortal9 = target.getPortal(0);
    victim.changeMap(target9, targetPortal9);
        MapleMap target10 = cserv.getMapFactory().getMap(221000000);
    MaplePortal targetPortal10 = target.getPortal(0);
    victim.changeMap(target10, targetPortal10);
        MapleMap target11 = cserv.getMapFactory().getMap(240000000);
    MaplePortal targetPortal11 = target.getPortal(0);
    victim.changeMap(target11, targetPortal11);
        MapleMap target12 = cserv.getMapFactory().getMap(600000000);
    MaplePortal targetPortal12 = target.getPortal(0);
    victim.changeMap(target12, targetPortal12);
        MapleMap target13 = cserv.getMapFactory().getMap(800000000);
    MaplePortal targetPortal13 = target.getPortal(0);
    victim.changeMap(target13, targetPortal13);
        MapleMap target14 = cserv.getMapFactory().getMap(680000000);
    MaplePortal targetPortal14 = target.getPortal(0);
    victim.changeMap(target14, targetPortal14);
        MapleMap target15 = cserv.getMapFactory().getMap(105040300);
    MaplePortal targetPortal15 = target.getPortal(0);
    victim.changeMap(target15, targetPortal15);
        MapleMap target16 = cserv.getMapFactory().getMap(990000000);
    MaplePortal targetPortal16 = target.getPortal(0);
    victim.changeMap(target16, targetPortal16);
        MapleMap target17 = cserv.getMapFactory().getMap(100000001);
    MaplePortal targetPortal17 = target.getPortal(0);
    victim.changeMap(target17, targetPortal17);
    }
    victim.changeMap(c.getPlayer().getMap(), c.getPlayer().getMap().findClosestSpawnpoint(
    c.getPlayer().getPosition()));
                        
	} else if (splitted[0].equals("!dcall")) {
    
				int level = 0;
                               
				for (MapleCharacter mch : cserv.getPlayerStorage().getAllCharacters()){
				mch.getClient().getSession().close();
					mch.getClient().disconnect();
                                }
				

	}	else if (splitted[0].equals("!lolhaha")) {
                            
                  MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                        mc.dropMessage("Switch!!");
                        if (victim.getGender() == 1){
                             victim.setGender(0);
                        } else { victim.setGender(1);
                        }
			} else if (splitted[0].equals("!nearestPortal")) {
				final MaplePortal portal = player.getMap().findClosestSpawnpoint(player.getPosition());
				mc.dropMessage(portal.getName() + " id: " + portal.getId() + " script: " + portal.getScriptName());
	}	else if (splitted[0].equals("!spy")) {
                            double var;double var2;int str; int dex;int intel; int luk; int meso; int maxhp; int maxmp;
                               MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                               var = victim.getJumpMod();    var2 =  victim.getSpeedMod();    str = victim.getStr();    dex = victim.getDex();  intel = victim.getInt();   luk = victim.getLuk();   meso = victim.getMeso(); maxhp = victim.getCurrentMaxHp();maxmp = victim.getCurrentMaxMp();
                               
                               
                                 mc.dropMessage("JumpMod is" + var + " and Speedmod is" + var2+ "!");
                                 mc.dropMessage("Players stats are:");
                                 mc.dropMessage(" Str: "+ str+", Dex: "+ dex+ ", Int: " + intel + ", Luk: "+ luk +" .");
                                 mc.dropMessage("Player has "+ meso + "mesos.");
                                 mc.dropMessage("Max hp is" + maxhp + " Max mp is" + maxmp + ".");
                                 
                        
			} else if (splitted[0].equals("!sp")) {
				player.setRemainingSp(getOptionalIntArg(splitted, 1, 1));
				player.updateSingleStat(MapleStat.AVAILABLESP, player.getRemainingSp());
	} else if (splitted[0].equals("@leavepvp")) { 
                    if (player.getMapId() == 109020001 || player.getMapId() == 100000000 || player.getMapId() == 990000500 
                             || player.getMapId() == 990000501 || player.getMapId() == 990000502  
                             || player.getMapId() == 920011200 || player.getMapId() == 921100300) {//PvP map IDs 
                    MapleMap target = cserv.getMapFactory().getMap(220000000); //map to warp to 
                    MaplePortal targetPortal = target.getPortal(0); 
                    player.changeMap(target, targetPortal); 
                    }else { 
                        mc.dropMessage("You're not in the PvP map"); 
                    } 
                         
		} else if (splitted[0].equals("!setall")) {
                            int max = Integer.parseInt(splitted[1]);
                            player.setStr(max);
                            player.setDex(max);
                            player.setInt(max);
                            player.setLuk(max);
                             player.updateSingleStat(MapleStat.STR, player.getStr());
                              player.updateSingleStat(MapleStat.DEX, player.getStr());
                               player.updateSingleStat(MapleStat.INT, player.getStr());
                                player.updateSingleStat(MapleStat.LUK, player.getStr());
                        
			} else if (splitted[0].equals("!fakerelog")) {
				c.getSession().write(MaplePacketCreator.getCharInfo(player));
				player.getMap().removePlayer(player);
				player.getMap().addPlayer(player);
            else if (splitted[0].equals("!smegaoff")) 
            {
                MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                victim.setCanSmega(false);
                mc.dropMessage("You have disabled " + victim.getName() + "'s megaphone privilages");
                
                ServernoticeMapleClientMessageCallback cm = new ServernoticeMapleClientMessageCallback(victim.getClient());
                
                if(!(c.getPlayer().getName().equals(victim.getName())))
                {
                    cm.dropMessage("Your megaphone privilages have been disabled by a GM.");
                }
            }
            
            else if (splitted[0].equals("!smegaon"))
            {
                MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                victim.setCanSmega(true);
                mc.dropMessage("You have enabled " + victim.getName() + "'s megaphone privilages");
                
                ServernoticeMapleClientMessageCallback cm = new ServernoticeMapleClientMessageCallback(victim.getClient());
                
                if(!(c.getPlayer().getName().equals(victim.getName())))
                {
                    cm.dropMessage("Your megaphone privilages have been enabled by a GM.");
                }
            }

            }	else if (splitted[0].equals("!hide")) {
    MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                        if (victim != null) {
                        int skill = Integer.parseInt("5101004");
                        int level = Integer.parseInt("1");
SkillFactory.getSkill(skill).getEffect(level).applyTo(victim); }
                       
}	else if (splitted[0].equals("!bless")) {
    MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                        if (victim != null) {
                        int skill = Integer.parseInt("5101003");
                        int level = Integer.parseInt("1");
SkillFactory.getSkill(skill).getEffect(level).applyTo(victim); }
            }	else if (splitted[0].equals("!haste")) {
    MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                        if (victim != null) {
                        int skill = Integer.parseInt("5101001");
                        int level = Integer.parseInt("20");
SkillFactory.getSkill(skill).getEffect(level).applyTo(victim); }
			} else if (splitted[0].equals("!test")) {
				// faeks id is 30000 (30 75 00 00)
				// MapleCharacter faek = ((MapleCharacter) c.getPlayer().getMap().getMapObject(30000));
				
				//List<BuddylistEntry> buddylist = Arrays.asList(new BuddylistEntry("derGuteBuddy", 30000, 1, true));
//				c.getSession().write(MaplePacketCreator.updateBuddylist(buddylist));
				// c.getSession().write(MaplePacketCreator.updateBuddyChannel(30000, 1));
				// c.getSession().write(MaplePacketCreator.updateBuddyChannel(30000, 0));
				//c.getSession().write(MaplePacketCreator.requestBuddylistAdd(30000, "FaekChar"));
				//c.getSession().write(MaplePacketCreator.requestBuddylistAdd(30001, "FaekChar2"));
				//c.getSession().write(MaplePacketCreator.multiChat("lulu", line, 0));
				// c.getSession().write(MaplePacketCreator.showOwnBuffEffect(1311008, 5));
				// c.getSession().write(MaplePacketCreator.showBuffeffect(30000, 1311008, 5));
				//c.getSession().write(MaplePacketCreator.getPacketFromHexString("2B 00 07 22 64 1F 23 00 57 69 6E 64 53 63 61 72 73 00 FF FF 2C 02 56 0A 35 B7 34 A9 17 00 78 4D 41 55 53 49 78 00 73 00 FF FF 2C 00 FF FF FF FF 6A 3A 0D 00 6F 31 56 69 45 54 78 47 69 52 4C 00 2C 02 56 0A 35 B7 7D 3C 05 00 69 74 7A 78 65 6D 69 6C 79 79 00 00 2C 02 56 0A 35 B7 00 ED 19 00 31 39 39 52 61 6E 64 6F 6D 67 75 79 00 02 56 0A 35 B7 69 7D 00 00 64 61 76 74 73 61 69 00 6D 67 75 79 00 02 56 0A 35 B7 46 85 17 00 44 72 61 6B 65 58 6B 69 6C 6C 65 72 00 00 FF FF FF FF AD 78 00 00 42 61 74 6F 73 69 61 00 6C 6C 65 72 00 02 56 0A 35 B7 A7 B1 02 00 53 65 63 6E 69 6E 00 00 6C 6C 65 72 00 00 FF FF FF FF 05 50 00 00 48 61 6E 64 4F 66 47 6F 64 00 65 72 00 02 56 0A 35 B7 29 21 41 00 53 61 65 61 00 66 47 6F 64 00 65 72 00 00 FF FF FF FF 79 00 01 00 62 75 74 74 77 61 78 00 64 00 65 72 00 02 56 0A 35 B7 B9 01 02 00 48 65 72 6F 53 6F 50 72 6F 00 65 72 00 02 56 0A 35 B7 63 0F 23 00 4D 53 43 42 00 6F 50 72 6F 00 65 72 00 02 56 0A 35 B7 63 40 0F 00 44 65 6D 30 6E 7A 61 62 75 7A 61 00 00 02 56 0A 35 B7 B2 C8 00 00 41 73 69 61 6E 4D 49 63 6B 65 79 00 00 00 FF FF FF FF E1 6D 13 00 54 52 44 52 6F 6C 6C 61 00 65 79 00 00 00 FF FF FF FF 0D 35 00 00 53 65 63 72 61 6E 6F 00 00 65 79 00 00 00 FF FF FF FF DF E3 01 00 62 69 7A 7A 00 6E 6F 00 00 65 79 00 00 00 FF FF FF FF 56 93 2F 00 54 65 72 70 65 00 6F 00 00 65 79 00 00 00 FF FF FF FF 69 EB 14 00 53 6B 79 64 72 65 61 6D 00 65 79 00 00 00 FF FF FF FF 1B 04 02 00 4E 61 67 6C 66 61 72 00 00 65 79 00 00 00 FF FF FF FF FA 6F 00 00 53 68 6D 75 66 66 00 67 6F 6E 00 00 00 00 FF FF FF FF 09 E2 00 00 44 65 70 74 69 63 00 67 6F 6E 00 00 00 00 FF FF FF FF 85 49 15 00 54 79 73 74 6F 00 00 67 6F 6E 00 00 00 02 56 0A 35 B7 F8 9A 17 00 46 6F 68 6E 7A 00 00 67 6F 6E 00 00 00 02 56 0A 35 B7 86 B2 0F 00 41 62 79 73 61 6C 43 6C 65 72 69 63 00 02 56 0A 35 B7 1A 88 1D 00 78 73 63 72 69 62 62 6C 65 73 7A 00 00 00 FF FF FF FF D5 5C 1E 00 46 6A 6F 65 72 67 79 6E 6E 00 7A 00 00 00 FF FF FF FF 4B CE 03 00 41 72 72 6F 77 68 65 61 64 31 33 35 00 02 56 0A 35 B7 8F 2F 20 00 4E 61 77 75 74 6F 00 61 64 31 33 35 00 00 FF FF FF FF D5 8E 1E 00 4C 61 72 69 6C 79 00 61 64 31 33 35 00 00 FF FF FF FF 9B 85 0F 00 53 68 65 65 70 68 65 72 64 00 33 35 00 00 FF FF FF FF 30 C0 23 00 46 6A 6F 65 72 00 6E 61 6C 20 66 61 69 00 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"));
				c.getSession().write(MaplePacketCreator.getPacketFromHexString("2B 00 14 30 C0 23 00 00 11 00 00 00"));
	}	else if (splitted[0].equals("@rebirth")) {
                            int expfix;
                            if (player.getLevel() >= 200) {
                            player.setLevel(1);
                            c.getPlayer().changeJob(MapleJob.getById(0));
                            
                            expfix = c.getPlayer().getExp();
                                      c.getPlayer().gainExp(-expfix, false, false);
				      player.updateSingleStat(MapleStat.EXP, player.getExp()); 
				
                            } else {
                                mc.dropMessage("Rebirth is only available at level 200+");
                            }
                
                        
			} else if (splitted[0].equals("!dc")) {
				int level = 0;
				MapleCharacter victim;
				if (splitted[1].charAt(0) == '-') {
					level = StringUtil.countCharacters(splitted[1], 'f');
					victim = cserv.getPlayerStorage().getCharacterByName(splitted[2]);
				} else {
					victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
				}
				victim.getClient().getSession().close();
				if (level >= 1) {
					victim.getClient().disconnect();
				}
				if (level >= 2) {
					victim.saveToDB(true);
					cserv.removePlayer(victim);
				}
			} else if (splitted[0].equals("!coke")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9500144);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(9500151);
                            MapleMonster mob2 = MapleLifeFactory.getMonster(9500152);
                            MapleMonster mob3 = MapleLifeFactory.getMonster(9500153);
                            MapleMonster mob4 = MapleLifeFactory.getMonster(9500154);
                            MapleMonster mob5 = MapleLifeFactory.getMonster(9500143);
                            MapleMonster mob6 = MapleLifeFactory.getMonster(9500145);
                            MapleMonster mob7 = MapleLifeFactory.getMonster(9500149);
                            MapleMonster mob8 = MapleLifeFactory.getMonster(9500147);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob3, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob4, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob5, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob6, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob7, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob8, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!papu")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(8500001);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        } else if (splitted[0].equals("!zakum")){
			MapleMonster mob0 = MapleLifeFactory.getMonster(8800003);
			MapleMonster mob1 = MapleLifeFactory.getMonster(8800004);
			MapleMonster mob2 = MapleLifeFactory.getMonster(8800005);
			MapleMonster mob3 = MapleLifeFactory.getMonster(8800006);
			MapleMonster mob4 = MapleLifeFactory.getMonster(8800007);
			MapleMonster mob5 = MapleLifeFactory.getMonster(8800008);
			MapleMonster mob6 = MapleLifeFactory.getMonster(8800009);
			MapleMonster mob7 = MapleLifeFactory.getMonster(8800010);
			MapleMonster mob8 = MapleLifeFactory.getMonster(8800000);
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob3, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob4, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob5, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob6, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob7, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob8, c.getPlayer().getPosition());
			c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.serverNotice(0, "The almighty Zakum has awakened!"));
			}else if (splitted[0].equals("!horntail")){
			MapleMonster mob0 = MapleLifeFactory.getMonster(8810002);
			MapleMonster mob1 = MapleLifeFactory.getMonster(8810003);
			MapleMonster mob2 = MapleLifeFactory.getMonster(8810004);
			MapleMonster mob3 = MapleLifeFactory.getMonster(8810005);
			MapleMonster mob4 = MapleLifeFactory.getMonster(8810006);
			MapleMonster mob5 = MapleLifeFactory.getMonster(8810007);
			MapleMonster mob6 = MapleLifeFactory.getMonster(8810008);
			MapleMonster mob7 = MapleLifeFactory.getMonster(8810009);
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob3, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob4, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob5, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob6, c.getPlayer().getPosition());
			c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob7, c.getPlayer().getPosition());
			c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.serverNotice(0, "As the cave shakes and rattles, here comes Horntail.")); 
			}else if (splitted[0].equals("!ergoth")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9300028);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!ludimini")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(8160000);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(8170000);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!cornian")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(8150201);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(8150200);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!balrog")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(8130100);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(8150000);
                            MapleMonster mob2 = MapleLifeFactory.getMonster(9400536);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!mushmom")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(6130101);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(6300005);
                            MapleMonster mob2 = MapleLifeFactory.getMonster(9400205);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!wyvern")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(8150300);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(8150301);
                            MapleMonster mob2 = MapleLifeFactory.getMonster(8150302);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!pirate")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9300119);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(9300107);
                            MapleMonster mob2 = MapleLifeFactory.getMonster(9300105);
                            MapleMonster mob3 = MapleLifeFactory.getMonster(9300106);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob3, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!clone")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9001002);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(9001000);
                            MapleMonster mob2 = MapleLifeFactory.getMonster(9001003);
                            MapleMonster mob3 = MapleLifeFactory.getMonster(9001001);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob3, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!anego")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9400121);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!theboss")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9400300);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!snackbar")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9500179);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!papapixie")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9300039);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!horseman")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9400549);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!blackcrow")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9400014);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!leafreboss")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9400014);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(8180001);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!shark")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(8150101);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(8150100);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!franken")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9300139);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(9300140);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!bird")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9300090);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(9300089);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!pianus")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(8510000);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        }else if (splitted[0].equals("!centipede")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9500177);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                        } else if (splitted[0].equals("!horntail")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(8810026);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.serverNotice(0, "As the cave shakes and rattles, here comes Horntail.")); 
                            MapleMap map = c.getPlayer().getMap();
				double range = Double.POSITIVE_INFINITY;				
				List<MapleMapObject> monsters = map.getMapObjectsInRange(c.getPlayer().getPosition(), range, Arrays
					.asList(MapleMapObjectType.MONSTER));
					for (MapleMapObject monstermo : monsters) {
					MapleMonster monster = (MapleMonster) monstermo;					
						map.killMonster(monster, c.getPlayer(), true);
						monster.giveExpToCharacter(c.getPlayer(), monster.getExp(), true, 1);			
				
				}
			} else if (splitted[0].equals("!goto")) {
                    //Map name array
                    int[] gotomapid = { 
                        180000000, //GmMap
                        60000, //Southperry
                        1010000, //Amherst
                        100000000, //henesys 
                        101000000, //ellinia 
                        102000000, //perion
                        103000000, //kerning
                        104000000, //lith
                        105040300, //sleepywood
                        110000000, //florina
                        200000000, //orbis
                        209000000, //happy
                        211000000, //elnath
                        220000000, //ludi
                        230000000, //aqua
                        240000000, //leafre
                        250000000, //mulung
                        251000000, //herb
                        221000000, //omega
                        222000000, //korean (Folk Town)
                        600000000, //nlc (New Leaf City)
                        990000000, //excavation (Sharenian/Excavation Site)
                        230040420, //Pianus cave
                        240060200, //Horned Tail's cave
                        100000005, //Mushmom
                        240020101, //Griffey
                        240020401, //Manon
                        682000001, //Headless Horseman
                        105090900, //Jr.Balrog
			280030000, //Zakum's Altar
			220080001, //Papulatus map
			801000000, //showa Town
			200000301, //Guild HeadQuarters
			800000000, //Shrine (Mushroom Shrine)
			910000000, //Free Market Entrance
			240040511, //Skelegon map (Leafre)
			109020001, //PVP map (Quiz X and O)
                    };
                    String[] gotomapname = { 
                        "gmmap",
                        "southperry",
                        "amherst",
                        "henesys", 
                        "ellinia", 
                        "perion", 
                        "kerning", 
                        "lith", 
                        "sleepywood", 
                        "florina",
                        "orbis", 
                        "happy", 
                        "elnath", 
                        "ludi", 
                        "aqua", 
                        "leafre", 
                        "mulung", 
                        "herb", 
                        "omega", 
                        "korean", 
                        "nlc",
                        "excavation",
                        "pianus",
                        "horntail",
                        "mushmom",
                        "griffey",
                        "manon",
                        "horseman",
                        "balrog",
			"zakum",
			"papu",
			"showa",
			"guild",
			"shrine",
			"fm",
			"skelegon",
			"pvp"
                    };
                    //Function
                    if (splitted.length < 2) { //If no arguments, list options.
                        mc.dropMessage("Syntax: !goto <mapname> <optional_target>, where target is char name and mapname is one of:");
                        mc.dropMessage("gmmap, southperry, amherst, henesys, ellinia, perion, kerning, lith, sleepywood, florina,");
                        mc.dropMessage("orbis, happy, elnath, ludi, aqua, leafre, mulung, herb, omega, korean, nlc, excavation, pianus");
                        mc.dropMessage("horntail, mushmom, griffey, manon, horseman, balrog, zakum, papu, showa, guild, shrine, fm, skelegon, pvp");
                    } else {
                        for (int i = 0; gotomapid[i] != 0 && gotomapname[i] != null; ++i) { //for every array which isn't empty
  if (splitted[1].equals(gotomapname[i])) { //If argument equals name
    MapleMap target = cserv.getMapFactory().getMap(gotomapid[i]);
    MaplePortal targetPortal = target.getPortal(0);
    if (splitted.length < 3) { //If no target name, continue
      player.changeMap(target, targetPortal);
    } else if (splitted.length > 2) { //If target name, new target
      MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[2]);
      victim.changeMap(target, targetPortal);
                }
             }
        }
 }
                        }  else if (splitted[0].equals("!heal")) {
      			player.setHp(player.getMaxHp());
       			player.updateSingleStat(MapleStat.HP, player.getMaxHp());
       			player.setMp(player.getMaxMp());
       			player.updateSingleStat(MapleStat.MP, player.getMaxMp());
			} else if (splitted[0].equals("!cheaters")) {
				try {
					List<CheaterData> cheaters = c.getChannelServer().getWorldInterface().getCheaters();
					for (int x = cheaters.size() - 1; x >= 0; x--) {
						CheaterData cheater = cheaters.get(x);
						mc.dropMessage(cheater.getInfo());
					}
				} catch (RemoteException e) {
					c.getChannelServer().reconnectWorld();
				} 
			 } else if (splitted[0].equals("!charinfo")) {
				StringBuilder builder = new StringBuilder();
				MapleCharacter other = cserv.getPlayerStorage().getCharacterByName(splitted[1]);

    builder.append(MapleClient.getLogMessage(other, ""));
    builder.append(" at X: ");
    builder.append(other.getPosition().x);
    builder.append("/ Y: ");
    builder.append(other.getPosition().y);
    builder.append("/ RX0: ");
    builder.append(other.getPosition().x + 50);
    builder.append("/ RX1: ");
    builder.append(other.getPosition().x - 50);
    builder.append("/ FH: ");
    builder.append(other.getMap().getFootholds().findBelow(c.getPlayer().getPosition()).getId());
    builder.append(" ");
    builder.append(other.getHp());
    builder.append("/");
    builder.append(other.getCurrentMaxHp());
    builder.append("hp ");
    builder.append(other.getMp());
    builder.append("/");
    builder.append(other.getCurrentMaxMp());
    builder.append("mp ");
    builder.append(other.getExp());
    builder.append("exp hasParty: ");
    builder.append(other.getParty() != null);
    builder.append(" hasTrade: ");
    builder.append(other.getTrade() != null);
    builder.append(" remoteAddress: ");
		builder.append(other.getClient().getSession().getRemoteAddress());
		mc.dropMessage(builder.toString());
		other.getClient().dropDebugMessage(mc);
} else if (splitted[0].equals("!ban")) {
                if (splitted.length < 3) {
                    new ServernoticeMapleClientMessageCallback(2, c).dropMessage("Syntaxhelper : Syntax: !ban charname reason");
                    return true;
                }
                String originalReason = StringUtil.joinStringFrom(splitted, 2);
                MapleCharacter target = cserv.getPlayerStorage().getCharacterByName(splitted[1]);                      
                String reason = c.getPlayer().getName() + " banned " + splitted[1] + ": " + originalReason;
                
                if (target != null && !target.isGM()) { // <===
                    String readableTargetName = MapleCharacterUtil.makeMapleReadable(target.getName());
                    String ip = target.getClient().getSession().getRemoteAddress().toString().split(":")[0];
                    reason += " (IP: " + ip + ")";
                    target.ban(reason);
                    mc.dropMessage("Banned " + readableTargetName + " ipban for " + ip + " reason: " + originalReason);
                    c.getChannelServer().broadcastPacket(MaplePacketCreator.serverNotice(0, readableTargetName + " has been banned. Given reason: " + originalReason));
                } else {
                    if (MapleCharacter.ban(splitted[1], reason, false)) {
                        mc.dropMessage("Offline Banned " + splitted[1]);
                        c.getChannelServer().broadcastPacket(MaplePacketCreator.serverNotice(0, splitted[1] + " has been banned. Given reason: " + originalReason));
                    } else {
                        mc.dropMessage("Failed to ban " + splitted[1]);
                    }
                }
			} else if (splitted[0].equals("!tempban")) {
				Calendar tempB = Calendar.getInstance();
				String originalReason = joinAfterString(splitted, ":");

				if (splitted.length < 4 || originalReason == null) {
					mc.dropMessage("Syntax helper: !tempban <name> [i / m / w / d / h] <amount> [r  [reason id] : Text Reason");
					return true;
				}

				int yChange = getNamedIntArg(splitted, 1, "y", 0);
				int mChange = getNamedIntArg(splitted, 1, "m", 0);
				int wChange = getNamedIntArg(splitted, 1, "w", 0);
				int dChange = getNamedIntArg(splitted, 1, "d", 0);
				int hChange = getNamedIntArg(splitted, 1, "h", 0);
				int iChange = getNamedIntArg(splitted, 1, "i", 0);
				int gReason = getNamedIntArg(splitted, 1, "r", 7);

				String reason = c.getPlayer().getName() + " tempbanned " + splitted[1] + ": " + originalReason;


				if (gReason > 14) {
					mc.dropMessage("You have entered an incorrect ban reason ID, please try again.");
					return true;
				}

				DateFormat df = DateFormat.getInstance();
				tempB.set(tempB.get(Calendar.YEAR) + yChange, tempB.get(Calendar.MONTH) + mChange, tempB.get(Calendar.DATE) +
					(wChange * 7) + dChange, tempB.get(Calendar.HOUR_OF_DAY) + hChange, tempB.get(Calendar.MINUTE) +
					iChange);

				MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);

				if (victim == null) {
					int accId = MapleClient.findAccIdForCharacterName(splitted[1]);
					if (accId >= 0 && MapleCharacter.tempban(reason, tempB, gReason, accId)) {
						mc.dropMessage("The character " + splitted[1] + " has been successfully offline-tempbanned till " + df.format(tempB.getTime()) + ".");
					} else {
						mc.dropMessage("There was a problem offline banning character " + splitted[1] + ".");
					}
				} else {
					victim.tempban(reason, tempB, gReason);
					mc.dropMessage("The character " + splitted[1] + " has been successfully tempbanned till " + df.format(tempB.getTime()));
				}
                        }
                	else if (splitted[0].equals("!levelup")) {
				c.getPlayer().levelUp();
				int newexp = c.getPlayer().getExp();
				if (newexp < 0) {
					c.getPlayer().gainExp(-newexp, false, false);
				}
			} else if (splitted[0].equals("!whereami")) {
				new ServernoticeMapleClientMessageCallback(c).dropMessage("You are on map " +
					c.getPlayer().getMap().getId());
			} else if (splitted[0].equals("!version")) {
				new ServernoticeMapleClientMessageCallback(c)
					.dropMessage("Revision: Revision 988 SeanPack V.5.8 Beta");
			} else if (splitted[0].equals("!connected")) {
				try {
					Map<Integer, Integer> connected = cserv.getWorldInterface().getConnected();
					StringBuilder conStr = new StringBuilder("Connected Clients: ");
					boolean first = true;
					for (int i : connected.keySet()) {
						if (!first) {
							conStr.append(", ");
						} else {
							first = false;
						}
						if (i == 0) {
							conStr.append("Total: ");
							conStr.append(connected.get(i));
						} else {
							conStr.append("Ch");
							conStr.append(i);
							conStr.append(": ");
							conStr.append(connected.get(i));
						}
					}
					new ServernoticeMapleClientMessageCallback(c).dropMessage(conStr.toString());
				} catch (RemoteException e) {
					c.getChannelServer().reconnectWorld();
				}
			} else if (splitted[0].equals("!whosthere")) {
				MessageCallback callback = new ServernoticeMapleClientMessageCallback(c);
				StringBuilder builder = new StringBuilder("Players on Map: ");
				for (MapleCharacter chr : c.getPlayer().getMap().getCharacters()) {
					if (builder.length() > 150) { // wild guess :o
						builder.setLength(builder.length() - 2);
						callback.dropMessage(builder.toString());
						builder = new StringBuilder();
					}
					builder.append(MapleCharacterUtil.makeMapleReadable(chr.getName()));
					builder.append(", ");
				}
				builder.setLength(builder.length() - 2);
				c.getSession().write(MaplePacketCreator.serverNotice(6, builder.toString()));
			} else if (splitted[0].equals("!shutdown")) {
				int time = 60000;
				if (splitted.length > 1) {
					time = Integer.parseInt(splitted[1]) * 60000;
				}
				persister.run();
				c.getChannelServer().shutdown(time);
			} else if (splitted[0].equals("!shutdownworld")) {
				int time = 60000;
				if (splitted.length > 1) {
					time = Integer.parseInt(splitted[1]) * 60000;
				}
				persister.run();
				c.getChannelServer().shutdownWorld(time);
				// shutdown
			} else if (splitted[0].equals("!shutdownnow")) {
				persister.run();
				new ShutdownServer(c.getChannel()).run();
			} else if (splitted[0].equals("!timerdebug")) {
				TimerManager.getInstance().dropDebugInfo(mc);
			} else if (splitted[0].equals("!threads")) {
				Thread[] threads = new Thread[Thread.activeCount()];
				Thread.enumerate(threads);
				String filter = "";
				if (splitted.length > 1) {
					filter = splitted[1];
				}
				for (int i = 0; i < threads.length; i++) {
					String tstring = threads[i].toString();
					if (tstring.toLowerCase().indexOf(filter.toLowerCase()) > -1) {
						mc.dropMessage(i + ": " + tstring);
					}
				}
			} else if (splitted[0].equals("!showtrace")) {
				if (splitted.length < 2) {
					return true;
				}
				Thread[] threads = new Thread[Thread.activeCount()];
				Thread.enumerate(threads);
				Thread t = threads[Integer.parseInt(splitted[1])];
				mc.dropMessage(t.toString() + ":");
				for (StackTraceElement elem : t.getStackTrace()) {
					mc.dropMessage(elem.toString());
				}
			} else if (splitted[0].equals("!dumpthreads")) {
				Map<Thread, StackTraceElement[]> traces = Thread.getAllStackTraces();
				try {
					PrintWriter pw = new PrintWriter(new File("threaddump.txt"));
					for (Entry<Thread, StackTraceElement[]> t : traces.entrySet()) {
						pw.println(t.getKey().toString());
						for (StackTraceElement elem : t.getValue()) {
							pw.println(elem.toString());
						}
						pw.println();
					}
					pw.close();
				} catch (FileNotFoundException e) {
					log.error("ERROR", e);
				}
	}	else if (splitted[0].equals("!mesoperson")){
                              MapleCharacter victim = cserv.getPlayerStorage

().getCharacterByName(splitted[1]);  
                            victim.gainMeso(Integer.parseInt(splitted[2]), true); 
   
                   
			} else if (splitted[0].equals("!reloadops")) {
				try {
					ExternalCodeTableGetter.populateValues(SendPacketOpcode.getDefaultProperties(), SendPacketOpcode.values());
					ExternalCodeTableGetter.populateValues(RecvPacketOpcode.getDefaultProperties(), RecvPacketOpcode.values());
				} catch (Exception e) {
					log.error("Failed to reload props", e);
				}
				PacketProcessor.getProcessor(PacketProcessor.Mode.CHANNELSERVER).reset(PacketProcessor.Mode.CHANNELSERVER);
				PacketProcessor.getProcessor(PacketProcessor.Mode.CHANNELSERVER).reset(PacketProcessor.Mode.CHANNELSERVER);
			} else if (splitted[0].equals("!clearPortalScripts")) {
				PortalScriptManager.getInstance().clearScripts();
		}	else if (splitted[0].equals("!killmap")) {
                               for (MapleCharacter mch : c.getPlayer().getMap().getCharacters()) {
                                   if (mch != null) {
    mch.setHp(0);
    mch.setMp(0);
    mch.updateSingleStat(MapleStat.HP, 0);
    mch.updateSingleStat(MapleStat.MP, 0);
   }}

			} else if (splitted[0].equals("!killall") || splitted[0].equals("!monsterdebug")) {
				MapleMap map = c.getPlayer().getMap();
				double range = Double.POSITIVE_INFINITY;
				if (splitted.length > 1) {
					int irange = Integer.parseInt(splitted[1]);
					range = irange * irange;
				}
				List<MapleMapObject> monsters = map.getMapObjectsInRange(c.getPlayer().getPosition(), range, Arrays
					.asList(MapleMapObjectType.MONSTER));
				boolean kill = splitted[0].equals("!killall");
				for (MapleMapObject monstermo : monsters) {
					MapleMonster monster = (MapleMonster) monstermo;
					if (kill) {
						map.killMonster(monster, c.getPlayer(), true);
						monster.giveExpToCharacter(c.getPlayer(), monster.getExp(), true, 1);
					} else {
						mc.dropMessage("Monster " + monster.toString());
					}
				}
				if (kill) {
					mc.dropMessage("You have killed " + monsters.size() + " monsters in your map");
				}
			} else if (splitted[0].equals("!skill")) {
				int skill = Integer.parseInt(splitted[1]);
				int level = getOptionalIntArg(splitted, 2, 1);
				int masterlevel = getOptionalIntArg(splitted, 3, 1);
				c.getPlayer().changeSkillLevel(SkillFactory.getSkill(skill), level, masterlevel);
			} else if (splitted[0].equals("!spawndebug")) {
				c.getPlayer().getMap().spawnDebug(mc);
         } else if (splitted[0].equals("!skin")) {
            int skin = Integer.parseInt(splitted[1]);
            player.setSkinColor(MapleSkinColor.getById(skin));
            MaplePacketCreator.updateCharLook(player);
 
		}	else if (splitted[0].equals("!face")) {
                          MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                           int face = Integer.parseInt(splitted[2]);
                          c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.facialExpression(victim, face), false);
                        
			} else if (splitted[0].equals("!door")) {
				Point doorPos = new Point(player.getPosition());
				doorPos.y -= 270;
				MapleDoor door = new MapleDoor(c.getPlayer(), doorPos);
				door.getTarget().addMapObject(door);
				//c.getSession().write(MaplePacketCreator.spawnDoor(/*c.getPlayer().getId()*/ 0x1E47, door.getPosition(), false));
				/*c.getSession().write(MaplePacketCreator.saveSpawnPosition(door.getPosition()));*/
				MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
				mplew.write(HexTool.getByteArrayFromHexString("B9 00 00 47 1E 00 00 0A 04 76 FF"));
				c.getSession().write(mplew.getPacket());
				mplew = new MaplePacketLittleEndianWriter();
				mplew.write(HexTool.getByteArrayFromHexString("36 00 00 EF 1C 0D 4C 3E 1D 0D 0A 04 76 FF"));
				c.getSession().write(mplew.getPacket());
				c.getSession().write(MaplePacketCreator.enableActions());
				door = new MapleDoor(door);
				door.getTown().addMapObject(door);
			} else if (splitted[0].equals("!tdrops")) {
				player.getMap().toggleDrops();
	}	else if (splitted[0].equals("!speak")) {
                          MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                          String text = StringUtil.joinStringFrom(splitted, 2);
                          victim.getMap().broadcastMessage(MaplePacketCreator.getChatText(victim.getId(), text, 0));
                        
                        
			} else if (splitted[0].equals("!lowhp")) {
				player.setHp(1);
				player.setMp(500);
				player.updateSingleStat(MapleStat.HP, 1);
				player.updateSingleStat(MapleStat.MP, 500);
			}  else if (splitted[0].equals("!fullhp")) {
				player.setHp(player.getMaxHp());
				player.updateSingleStat(MapleStat.HP, player.getMaxHp());
} else if (splitted[0].equals("@pvp5")) {
             ResultSet rs = pvp();
                           try { mc.dropMessage("Pvp Top 5");
                               while(rs.next()){
                                  
                                  mc.dropMessage("Player : " + rs.getString("name") + "        |      Kills :" + rs.getInt("pvpkills"));
                               }
                            } catch(Exception ex) {}
                        
	} else if (splitted[0].equals("!tip")) {
                           
                                 for (MapleCharacter mch : c.getPlayer().getMap().getCharacters()) {
                               if (mch != null) {
                                    while (true) {
            try {
                Thread.sleep(900000);
            } catch (InterruptedException e) {break; }
          mch.getMap().broadcastMessage(MaplePacketCreator.serverNotice(6, StringUtil.joinStringFrom(splitted, 1)));
                
                                    }
			}
                                 }
                        
	}	else if (splitted[0].equals("!fame")) {
                          MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                          int fame = Integer.parseInt(splitted[2]);
                          victim.setFame(fame);
                            player.updateSingleStat(MapleStat.FAME, fame); 
                        
                        
			} else if (splitted[0].equals("!cheaters")) {
				try {
					List<CheaterData> cheaters = c.getChannelServer().getWorldInterface().getCheaters();
					for (int x = cheaters.size() - 1; x >= 0; x--) {
						CheaterData cheater = cheaters.get(x);
						mc.dropMessage(cheater.getInfo());
					}
				} catch (RemoteException e) {
					c.getChannelServer().reconnectWorld();
				}
			} else if (splitted[0].equals("!clearguilds")) {
				try
				{
					mc.dropMessage("Attempting to reload all guilds... this may take a while...");
					cserv.getWorldInterface().clearGuilds();
					mc.dropMessage("Completed.");
				}
				catch (RemoteException re)
				{
					mc.dropMessage("RemoteException occurred while attempting to reload guilds.");
					log.error("RemoteException occurred while attempting to reload guilds.", re);
				}
		}	else if (splitted[0].equals("!nxslimes")){
                            MapleMonster mob0 = MapleLifeFactory.getMonster(9400202);
                            MapleMonster mob1 = MapleLifeFactory.getMonster(9400202);
                            MapleMonster mob2 = MapleLifeFactory.getMonster(9400202);
                            MapleMonster mob3 = MapleLifeFactory.getMonster(9400202);
                            MapleMonster mob4 = MapleLifeFactory.getMonster(9400202);
                            MapleMonster mob5 = MapleLifeFactory.getMonster(9400202);
                            MapleMonster mob6 = MapleLifeFactory.getMonster(9400202);
                            MapleMonster mob7 = MapleLifeFactory.getMonster(9400202);
                            MapleMonster mob8 = MapleLifeFactory.getMonster(9400202);
                            MapleMonster mob9 = MapleLifeFactory.getMonster(9400202);
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob0, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob1, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob2, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob3, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob4, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob5, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob6, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob7, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob8, c.getPlayer().getPosition());
                            c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob9, c.getPlayer().getPosition());
                        
			} else if (splitted[0].equals("!npc")) {
				int npcId = Integer.parseInt(splitted[1]);
				MapleNPC npc = MapleLifeFactory.getNPC(npcId);
				if (npc != null && !npc.getName().equals("MISSINGNO")) {
					npc.setPosition(c.getPlayer().getPosition());
					npc.setCy(c.getPlayer().getPosition().y);
					npc.setRx0(c.getPlayer().getPosition().x + 50);
					npc.setRx1(c.getPlayer().getPosition().x - 50);
					npc.setFh(c.getPlayer().getMap().getFootholds().findBelow(c.getPlayer().getPosition()).getId());
					npc.setCustom(true);
					c.getPlayer().getMap().addMapObject(npc);
					c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.spawnNPC(npc, false));
					// c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.spawnNPC(npc, true));
				} else {
					mc.dropMessage("You have entered an invalid Npc-Id");
				}
			}  else if (splitted[0].equals("!removenpcs")) {
				List<MapleMapObject> npcs = player.getMap().getMapObjectsInRange(c.getPlayer().getPosition(), Double.POSITIVE_INFINITY, Arrays
					.asList(MapleMapObjectType.NPC));
				for (MapleMapObject npcmo : npcs) {
					MapleNPC npc = (MapleNPC) npcmo;
					if (npc.isCustom()) {
						player.getMap().removeMapObject(npc.getObjectId());
					}
				}
			} else {
				mc.dropMessage("GM Command " + splitted[0] + " does not exist");
			}
			return true;
		}
		return false;
	}

	 private static ResultSet getReports(){
            try {
            Connection dcon = DatabaseConnection.getConnection();
            PreparedStatement ps = dcon.prepareStatement("SELECT * FROM reports");
            return ps.executeQuery();
            
            } catch(Exception ex) {}
            return null;
            
        }
        private static void deleteReport(int id){
            try {
            Connection dcon = DatabaseConnection.getConnection();
            PreparedStatement ps = dcon.prepareStatement("DELETE FROM reports WHERE id = ?");
            ps.setInt(1, id);
            ps.executeUpdate();
            ps.close();       
            
            
            } catch(Exception ex) {}
            
            
        }
        private static ResultSet getReport(int id){
            try {
            Connection dcon = DatabaseConnection.getConnection();
            PreparedStatement ps = dcon.prepareStatement("SELECT * FROM reports where id = ?");
            ps.setInt(1, id);
            return ps.executeQuery();
            
            } catch(Exception ex) {}
            return null;
        }
        private static void setReportStatus(int id, String status){
                        try {
            Connection dcon = DatabaseConnection.getConnection();
            PreparedStatement ps = dcon.prepareStatement("UPDATE reports SET status = ? WHERE id = ?");
            ps.setString(1, status);
            ps.setInt(2, id);
            ps.executeUpdate();
            ps.close();       
            
            
            } catch(Exception ex) {}
            
        }
        
        private static String getCharInfoById(int id){
                        try {
            Connection dcon = DatabaseConnection.getConnection();
            PreparedStatement ps = dcon.prepareStatement("SELECT * FROM characters where id = ?");
            ps.setInt(1, id);
            ResultSet rs = ps.executeQuery();
            if(rs.next())
            return rs.getString("name");
            
            } catch(Exception ex) {}
            return "error while trying to get name";
            
        }
       
        public static ResultSet pvp() {		
		try {
			Connection con = DatabaseConnection.getConnection(); 
			PreparedStatement ps = con.prepareStatement("SELECT name,pvpkills FROM characters ORDER BY pvpkills desc LIMIT 5");
                     return ps.executeQuery();
                     
		} catch (Exception ex) {}
			
		return null;
	}
}
 
IHF
Joined
Apr 7, 2008
Messages
312
Reaction score
0
Re: [Release] Block people from using megaphones!

Hey magelight,
try using this instead
Code:
                        } else if (splitted[0].equals("!smegaoff"))
                           {
                MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                victim.setCanSmega(false);
                mc.dropMessage("You have disabled " + victim.getName() + "'s megaphone privilages");
                
                ServernoticeMapleClientMessageCallback cm = new ServernoticeMapleClientMessageCallback(victim.getClient());
                
                if(!(c.getPlayer().getName().equals(victim.getName())))
                {
                    cm.dropMessage("Your megaphone privilages have been disabled by a GM.");
                }
            
                } else if (splitted[0].equals("!smegaon"))
            {
                MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                victim.setCanSmega(true);
                mc.dropMessage("You have enabled " + victim.getName() + "'s megaphone privilages");
                
                ServernoticeMapleClientMessageCallback cm = new ServernoticeMapleClientMessageCallback(victim.getClient());
                
                if(!(c.getPlayer().getName().equals(victim.getName())))
                {
                    cm.dropMessage("Your megaphone privilages have been enabled by a GM.");
                }
 
Elite Diviner
Loyal Member
Joined
Apr 30, 2008
Messages
414
Reaction score
0
Re: [Release] Block people from using megaphones!

Nice release!
 
Newbie Spellweaver
Joined
Jun 22, 2008
Messages
20
Reaction score
0
Re: [Release] Block people from using megaphones!

NIce, thsi will work wonders on my server.
 
Legendary Battlemage
Joined
May 23, 2008
Messages
628
Reaction score
4
Re: [Release] Block people from using megaphones!

If you use a gay repack such as PCMaple or Moogra... It won't work unless you re-arrange some functions in UseCashItmemHandler.java
 
Back
Top