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!

How To Make A Maplestory v111 (Lithium Based) Private Server

Junior Spellweaver
Joined
Jul 4, 2012
Messages
111
Reaction score
32
How To Make A v111 Private Server!

This is a guide to show you how to complete a Lithium based private server.

1.Introduction
2.Downloads
3.Installations
4.Server Setup
5.Localhost v111
6.Common Errors
7.Notes
8.Cype-CMS
9.Add-Ons/Fixes
10.Credits



Introduction

Making private servers arent easy, but arent too hard....if you have good help!
And im here to make everyone's private server creation process very easy so lets get started!

Downloads

To start your private server you need to get the right files.
Here are the files
You need to download these and set them up.
Program/Files Needed:

Lithium (Of course)



Notepad++



Hamachi (Optional if you dont want to port-forward)



STREDIT



JDK 1.7 and JRE 7 (NOT 6...DUH)







Get anyone of these (I use NaviCat, only drawback is its only 30-Day Trial)



(Dont Use On Weak Machines)

Java Unlimited Strength Files



WinRAR



LocalHost v111



Wz Files



WampServer



Maplestory v111



Extra:

GM Handbook


Installations
Ok Lets Start With Java

1.Dowload Both JDK and JRE
2.Set them up with default settings

JCE Strength Files

1.Download them
2.Extract them anywhere
3.Copy them and paste in these directories
Code:
64bit

C:\Program Files\Java\jre7\lib\security
C:\Program Files\Java\jre7\lib/ext
C:\Program Files\Java\jre7\lib
C:\Program Files\Java\jdk1.7\jre\lib
C:\Program Files\Java\jdk1.7\jre\lib\ext
C:\Program Files\Java\jdk1.7\jre\lib\security

32bit

C:\Program Files(x86)\Java\jre7\lib\security
C:\Program Files(x86)\Java\jre7\lib/ext
C:\Program Files(x86)\Java\jre7\lib
C:\Program Files(x86)\Java\jdk1.7\jre\lib
C:\Program Files(x86)\Java\jdk1.7\jre\lib\ext
C:\Program Files(x86)\Java\jdk1.7\jre\lib\security



NetBeans

1.Download correct system format NetBeans (32bit-64bit)
2.Follow the directions given on the link page.

WinRAR

1.Download it
2.Run it
3.Just make everything default

Maplestory v111

1.Download it.
2.Run the setup.
(Optional To Keep Regular Maple)3.Make directory in folder anywhere besides C:/Nexon
4.Delete these in the folder

MapleStory.exe
Patcher.exe
GameLauncher.exe
HShield (folder)

Lithium

1.Download it.
2.Double click it
3.Extract file to desktop
Password is ragezone

NaviCat

1.Download Premium
2.Follow setup with default settings
3.If you want full version, download this
http://www.mediafire.com/?8deziz4d6785scf

Notepad++

1.Download 
2.Follow setup

Wamp

1.Download it
2.Follow setup with default settings (No need to put email at end)
3.Double ilick icon
4.On bottom right of your screen click The green [W].
5.Click put online
6.Click - Start All Services

STREDIT

1.Download it
2.Extract to desktop

Hamachi

1.Download it
2.Launch it
3.Press powerbutton 
[/SPOILER]

[CENTER][SIZE=5]Server Setup[/SIZE][/CENTER]
[SPOILER]
1.Go to Hamachi
2.Press Network
3.Create a network
4.Right click the numbers next to the power button in hamachi
5.Click - Copy IPv4 Address

Now were done with Hamachi

6.Open The extracted Lithium file
7.Right click channel.propeties
8.Click edit with Notepad++
9.Delete 127.0.0.1 
10.Replace it by pressing Ctrl-V and then save.
11.Then open db.properties in Notepad++
12.Delete it all and replace with this
[CODE]
url=jdbc:mysql://localhost:3306/Lithium?autoReconnect=true
user = root
password =
13.Save.
14.Open worldGMS.properties
15.Edit it to your liking and replace the 127.0.0.1 (Delete it, Then replace with the IPv4)
16.Save

Are you still with Me? Well then lets finish this.

17.Open all the .bat's with Notepad++ and replace them with these

Dump-Items

Code:
@echo off
@title Dump
set CLASSPATH=.;dist\Lithium.jar;dist\mina-core.jar;dist\slf4j-api.jar;dist\slf4j-jdk14.jar;dist\mysql-connector-java-bin.jar
java -server -Dnet.sf.odinms.wzpath=wz/ tools.wztosql.DumpItems
pause

Dump-MobSkills

Code:
@echo off
@title Dump
set CLASSPATH=.;dist\Lithium.jar;dist\mina-core.jar;dist\slf4j-api.jar;dist\slf4j-jdk14.jar;dist\mysql-connector-java-bin.jar;dist\bcprov-jdk16-145.jar
java -server -Dnet.sf.odinms.wzpath=wz/ tools.wztosql.DumpMobSkills
pause

Dump-Quests

Code:
@echo off
@title Dump
set CLASSPATH=.;dist\Lithium.jar;dist\mina-core.jar;dist\slf4j-api.jar;dist\slf4j-jdk14.jar;dist\mysql-connector-java-bin.jar;dist\bcprov-jdk16-145.jar
java -server -Dnet.sf.odinms.wzpath=wz/ tools.wztosql.DumpQuests
pause

Launch

Code:
@echo off
@title Lithium Server Console
set CLASSPATH=.;dist\Lithium.jar;dist\mina-core.jar;dist\slf4j-api.jar;dist\slf4j-jdk14.jar;dist\mysql-connector-java-bin.jar
java -server -Dnet.sf.odinms.wzpath=wz/ server.Start
pause

18.Go To Src
19.Go To Constants
20.Open ServerConstants.jar with Notepad++
21.Find:
Code:
public static final byte[] Gateway_IP = new byte[]{(byte) 127, (byte) 0, (byte) 0, (byte) 1};

22.Replace with your IPv4

Like this

Code:
This is What it would look like if my IPv4 was 6.201.37.159

public static final byte[] Gateway_IP = new byte[]{(byte) 6, (byte) 201, (byte) 37, (byte) 159};

23.Change SQL Password from "root" to "(Nothing)" and then save
24.Open DatabaseConnection.java and search for serverconstants and change the v111 above it to Lithium and then save
25.Open NetBeans
26.Create New Project And Name it Lithium
27.Hit Next
28.Click Java/Java Project With Existing Sources
29.Hit Next
30.Go to your extracted Lithium Folder and click on src
31.Hit Finish
32.Right click Libraries and add the jars in your source dist folder. Then hit F11
33.Find the project folder and open dist
34.Take Lithium.jar and put it in the extracted lithium folder's dist

Now were done with NetBeans

35.Make a folder called wz in the extracted lithium folder
36.Take the v111wzxml.rar and extract those files to the wz folder you just created
37.Open Etc.wz/CashPackage. Search for 10003361 and make the "/> below it, right next to it like this 10003361"/>
38.Open NaviCat
39.Click Connection
40.Click MySQL, Not MySQLServer
41.Make your host localhost and port 3306 (Default)
42.Make Your Username=root Password=(Nothing)
43.And Name your connection Lithium
44.Double click your connection
45.Right click it and select - New Database
46.Name it Lithium and Default Character Set
47.Double Click your new database
48.Right click and select - Execute SQL File
47.Click on the ... and go to your source folder
48.Open SQL and execute all of them in a row (You Will have Errors On 4-6)
49.Go to your source folder and execute the Dump.bat's
50.Then click Launch.bat

Your Server Is Finally Up!
Localhostv111

Now that your server is up lets make a client so you or anyone can join!

1.Open STREDIT
2.Click File-Open-Open File
3.Find your localhostv111 and open it
4.Edit the 127.0.0.1 on the bottom right to your Hamachi/WAN Ip
5.Make it use only 1 Ip Address

Getting In Game

1.Run Wamp
2.Run Lauch.bat
3.Go into your database-Lithium and double click accounts
4.Make a new account by entering the tables to your liking and for password, you have to SHA-1 it.
5.Go to here -
6.Put your password and copy the SHA-1'nd form of your pasword
7.Put that password into your account area
8.ID should be 1
9.Username should be your username
10.Password should be your SHA-1 converted pasword
11.Exit and save
12.Put your new localhost into your v111 Maplestory folder
13.Double Click Localhost
14.Login with your account info (Password is regular,not SHA-1 format)
15.From there its pretty much easy to find out yourself

Common Errors

Alot of the time people have lots of trouble fully creating a server even with easy to follow instructions
So here im going to post common errors that I know how to fix. Please post your errors as this will help me remember errors i had.

Newest Fixes 7/31/2012

"Unable to connect to game server"

This is a very big fix for those who have this problem

First turn on your loopback adapter, open pic at char screen, close the pic screen, open again and enter pic!
Works about 80% of the time (Meer Estimate)

Netbean Errors

Code:
init:
deps-jar:
Created dir: C:\****\****\Documents\NetBeansProjects\Lithium\build
Updating property file: C:\****\***\Documents\NetBeansProjects\Lithium\build\built-jar.properties
Created dir: C:\****\****\Documents\NetBeansProjects\Lithium\build\classes
Created dir: C:\***\***\Documents\NetBeansProjects\Lithium\build\empty
Created dir: C:\****\****\Documents\NetBeansProjects\Lithium\build\generated-sources\ap-source-output
Compiling 331 source files to C:\****\****\Documents\NetBeansProjects\Lithium\build\classes
C:\Users\User\Desktop\*****\Lithium\src\client\MapleCharacter.java:3087: error: diamond operator is not supported in -source 1.6
Map<Skill, SkillEntry> list = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\***\Lithium\src\client\PlayerStats.java:58: error: diamond operator is not supported in -source 1.6
private Map<Integer, Integer> setHandling = new HashMap<>(), skillsIncrement = new HashMap<>(), damageIncrease = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\*****\Lithium\src\handling\channel\handler\InventoryHandler.java:440: error: diamond operator is not supported in -source 1.6
final List<StructItemOption> pots = new LinkedList<>(ii.getAllSocketInfo(rank).values());
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\handling\channel\handler\ItemMakerHandler.java:691: error: diamond operator is not supported in -source 1.6
final Map<Skill, SkillEntry> sa = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\handling\channel\handler\MobHandler.java:115: error: diamond operator is not supported in -source 1.6
final List<Pair<Integer, Integer>> unk3 = new ArrayList<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\handling\channel\handler\MovementParse.java:37: error: diamond operator is not supported in -source 1.6
final List<LifeMovementFragment> res = new ArrayList<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\handling\channel\handler\PlayersHandler.java:542: error: diamond operator is not supported in -source 1.6
final List<Integer> newDrops = new ArrayList<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\handling\login\handler\CharLoginHandler.java:265: error: diamond operator is not supported in -source 1.6
final Map<Skill, SkillEntry> ss = new HashMap<>();
^
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\scripting\NPCConversationManager.java:574: error: diamond operator is not supported in -source 1.6
final List<StructItemOption> pots = new LinkedList<>(ii.getAllSocketInfo(grade).values());
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\server\CashItemFactory.java:27: error: diamond operator is not supported in -source 1.6
private final Map<Integer, List<Integer>> openBox = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\server\MapleInventoryManipulator.java:849: error: diamond operator is not supported in -source 1.6
final Map<Skill, SkillEntry> ss = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\server\MapleItemInformationProvider.java:49: error: diamond operator is not supported in -source 1.6
protected final Map<Integer, Map<Integer, StructItemOption>> socketCache = new HashMap<>(); // Grade, (id, data)
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\server\StructItemOption.java:38: error: diamond operator is not supported in -source 1.6
public Map<String, Integer> data = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\***\Lithium\src\server\maps\MapScriptMethods.java:1018: error: diamond operator is not supported in -source 1.6
final Map<Skill, SkillEntry> sa = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\***\Lithium\src\server\quest\MapleQuestAction.java:233: error: diamond operator is not supported in -source 1.6
final Map<Skill, SkillEntry> sa = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\*\Lithium\src\tools\packet\CWvsContext.java:1506: error: diamond operator is not supported in -source 1.6
partymembers = new ArrayList<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\*\Lithium\src\tools\packet\LoginPacket.java:253: error: diamond operator is not supported in -source 1.6
List<Pair<String, Integer>> flags = new LinkedList<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\***\Lithium\src\tools\packet\PacketHelper.java:152: error: diamond operator is not supported in -source 1.6
final Map<Integer, Integer> skillsWithoutMax = new LinkedHashMap<>();
(use -source 7 or higher to enable diamond operator)
18 errors
C:\Users\User\Documents\NetBeansProjects\Lithium\nbproject\build-impl.xml:596: The following error occurred while executing this line:
C:\Users\User\Documents\NetBeansProjects\Lithium\nbproject\build-impl.xml:242: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 3 seconds)

The Fix - Delete JDK/JRE 6 And Download JDK/JRE 7

Bat Errors

Bat Prob - How To Make A Maplestory v111 (Lithium Based) Private Server - RaGEZONE Forums
phpvPM8k - How To Make A Maplestory v111 (Lithium Based) Private Server - RaGEZONE Forums

To fix these, go to the .bats in notepad and replace them with these

Dump-Items

Code:
@echo off
@title Dump
set CLASSPATH=.;dist\Lithium.jar;dist\mina-core.jar;dist\slf4j-api.jar;dist\slf4j-jdk14.jar;dist\mysql-connector-java-bin.jar
java -server -Dnet.sf.odinms.wzpath=wz/ tools.wztosql.DumpItems
pause

Dump-MobSkills

Code:
@echo off
@title Dump
set CLASSPATH=.;dist\Lithium.jar;dist\mina-core.jar;dist\slf4j-api.jar;dist\slf4j-jdk14.jar;dist\mysql-connector-java-bin.jar;dist\bcprov-jdk16-145.jar
java -server -Dnet.sf.odinms.wzpath=wz/ tools.wztosql.DumpMobSkills
pause

Dump-Quests

Code:
@echo off
@title Dump
set CLASSPATH=.;dist\Lithium.jar;dist\mina-core.jar;dist\slf4j-api.jar;dist\slf4j-jdk14.jar;dist\mysql-connector-java-bin.jar;dist\bcprov-jdk16-145.jar
java -server -Dnet.sf.odinms.wzpath=wz/ tools.wztosql.DumpQuests
pause

Launch

Code:
@echo off
@title Lithium Server Console
set CLASSPATH=.;dist\Lithium.jar;dist\mina-core.jar;dist\slf4j-api.jar;dist\slf4j-jdk14.jar;dist\mysql-connector-java-bin.jar
java -server -Dnet.sf.odinms.wzpath=wz/ server.Start
pause

phpDsnwx6 - How To Make A Maplestory v111 (Lithium Based) Private Server - RaGEZONE Forums

To Fix this, make sure when you compile in NetBeans you put the new Lithium.jar in the dist folder.

Notes

Wamp

Everytime you restart your computer you must enable Wamp for it to run.
Make sure Skype is off when running Wamp.

NetBeans

You must recompile with NetBeans everythime you edit a .java file.
You can edit java files in NetBeans instead of Notepad++ if you'd like.


Cype-CMS

1.Download Cype Here
2.Extract it to your Wamp folder located at C:/wamp
3.Put your ip in your internet browser search bar.
4.Skip steps until you have to execute SQL's
5.Follow directions given on the webpage from there

Add-Ons/InGame Fixes

New Section, this one will be fun xD

Credits

Credits Go To:

AuroX/AlphaEta for the Lithium Source

kevintjuh93 for localhostv111 and v111wzxml.rar

Nexon - For making a wonderful game.

cobbbg1998 - AKA Salt - For this full guide

End

Hope This Helped You All And Have a Nice Day

~Salt
 

Attachments

You must be registered for see attachments list
Last edited:
Newbie Spellweaver
Joined
Sep 24, 2011
Messages
7
Reaction score
0
init:
deps-jar:
Created dir: C:\****\****\Documents\NetBeansProjects\Lithium\build
Updating property file: C:\****\***\Documents\NetBeansProjects\Lithium\build\built-jar.properties
Created dir: C:\****\****\Documents\NetBeansProjects\Lithium\build\classes
Created dir: C:\***\***\Documents\NetBeansProjects\Lithium\build\empty
Created dir: C:\****\****\Documents\NetBeansProjects\Lithium\build\generated-sources\ap-source-output
Compiling 331 source files to C:\****\****\Documents\NetBeansProjects\Lithium\build\classes
C:\Users\User\Desktop\*****\Lithium\src\client\MapleCharacter.java:3087: error: diamond operator is not supported in -source 1.6
Map<Skill, SkillEntry> list = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\***\Lithium\src\client\PlayerStats.java:58: error: diamond operator is not supported in -source 1.6
private Map<Integer, Integer> setHandling = new HashMap<>(), skillsIncrement = new HashMap<>(), damageIncrease = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\*****\Lithium\src\handling\channel\handler\InventoryHandler.java:440: error: diamond operator is not supported in -source 1.6
final List<StructItemOption> pots = new LinkedList<>(ii.getAllSocketInfo(rank).values());
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\handling\channel\handler\ItemMakerHandler.java:691: error: diamond operator is not supported in -source 1.6
final Map<Skill, SkillEntry> sa = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\handling\channel\handler\MobHandler.java:115: error: diamond operator is not supported in -source 1.6
final List<Pair<Integer, Integer>> unk3 = new ArrayList<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\handling\channel\handler\MovementParse.java:37: error: diamond operator is not supported in -source 1.6
final List<LifeMovementFragment> res = new ArrayList<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\handling\channel\handler\PlayersHandler.java:542: error: diamond operator is not supported in -source 1.6
final List<Integer> newDrops = new ArrayList<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\handling\login\handler\CharLoginHandler.java:265: error: diamond operator is not supported in -source 1.6
final Map<Skill, SkillEntry> ss = new HashMap<>();
^
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\scripting\NPCConversationManager.java:574: error: diamond operator is not supported in -source 1.6
final List<StructItemOption> pots = new LinkedList<>(ii.getAllSocketInfo(grade).values());
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\server\CashItemFactory.java:27: error: diamond operator is not supported in -source 1.6
private final Map<Integer, List<Integer>> openBox = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\server\MapleInventoryManipulator.java:849: error: diamond operator is not supported in -source 1.6
final Map<Skill, SkillEntry> ss = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\server\MapleItemInformationProvider.java:49: error: diamond operator is not supported in -source 1.6
protected final Map<Integer, Map<Integer, StructItemOption>> socketCache = new HashMap<>(); // Grade, (id, data)
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\server\StructItemOption.java:38: error: diamond operator is not supported in -source 1.6
public Map<String, Integer> data = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\***\Lithium\src\server\maps\MapScriptMethods.java:1018: error: diamond operator is not supported in -source 1.6
final Map<Skill, SkillEntry> sa = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\***\Lithium\src\server\quest\MapleQuestAction.java:233: error: diamond operator is not supported in -source 1.6
final Map<Skill, SkillEntry> sa = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\*\Lithium\src\tools\packet\CWvsContext.java:1506: error: diamond operator is not supported in -source 1.6
partymembers = new ArrayList<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\*\Lithium\src\tools\packet\LoginPacket.java:253: error: diamond operator is not supported in -source 1.6
List<Pair<String, Integer>> flags = new LinkedList<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\***\Lithium\src\tools\packet\PacketHelper.java:152: error: diamond operator is not supported in -source 1.6
final Map<Integer, Integer> skillsWithoutMax = new LinkedHashMap<>();
(use -source 7 or higher to enable diamond operator)
18 errors
C:\Users\User\Documents\NetBeansProjects\Lithium\nbproject\build-impl.xml:596: The following error occurred while executing this line:
C:\Users\User\Documents\NetBeansProjects\Lithium\nbproject\build-impl.xml:242: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 3 seconds)
Help?
 
Newbie Spellweaver
Joined
Jul 24, 2012
Messages
19
Reaction score
0
init:
deps-jar:
Created dir: C:\****\****\Documents\NetBeansProjects\Lithium\build
Updating property file: C:\****\***\Documents\NetBeansProjects\Lithium\build\built-jar.properties
Created dir: C:\****\****\Documents\NetBeansProjects\Lithium\build\classes
Created dir: C:\***\***\Documents\NetBeansProjects\Lithium\build\empty
Created dir: C:\****\****\Documents\NetBeansProjects\Lithium\build\generated-sources\ap-source-output
Compiling 331 source files to C:\****\****\Documents\NetBeansProjects\Lithium\build\classes
C:\Users\User\Desktop\*****\Lithium\src\client\MapleCharacter.java:3087: error: diamond operator is not supported in -source 1.6
Map<Skill, SkillEntry> list = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\***\Lithium\src\client\PlayerStats.java:58: error: diamond operator is not supported in -source 1.6
private Map<Integer, Integer> setHandling = new HashMap<>(), skillsIncrement = new HashMap<>(), damageIncrease = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\*****\Lithium\src\handling\channel\handler\InventoryHandler.java:440: error: diamond operator is not supported in -source 1.6
final List<StructItemOption> pots = new LinkedList<>(ii.getAllSocketInfo(rank).values());
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\handling\channel\handler\ItemMakerHandler.java:691: error: diamond operator is not supported in -source 1.6
final Map<Skill, SkillEntry> sa = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\handling\channel\handler\MobHandler.java:115: error: diamond operator is not supported in -source 1.6
final List<Pair<Integer, Integer>> unk3 = new ArrayList<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\handling\channel\handler\MovementParse.java:37: error: diamond operator is not supported in -source 1.6
final List<LifeMovementFragment> res = new ArrayList<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\handling\channel\handler\PlayersHandler.java:542: error: diamond operator is not supported in -source 1.6
final List<Integer> newDrops = new ArrayList<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\handling\login\handler\CharLoginHandler.java:265: error: diamond operator is not supported in -source 1.6
final Map<Skill, SkillEntry> ss = new HashMap<>();
^
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\scripting\NPCConversationManager.java:574: error: diamond operator is not supported in -source 1.6
final List<StructItemOption> pots = new LinkedList<>(ii.getAllSocketInfo(grade).values());
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\server\CashItemFactory.java:27: error: diamond operator is not supported in -source 1.6
private final Map<Integer, List<Integer>> openBox = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\server\MapleInventoryManipulator.java:849: error: diamond operator is not supported in -source 1.6
final Map<Skill, SkillEntry> ss = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\server\MapleItemInformationProvider.java:49: error: diamond operator is not supported in -source 1.6
protected final Map<Integer, Map<Integer, StructItemOption>> socketCache = new HashMap<>(); // Grade, (id, data)
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\****\Lithium\src\server\StructItemOption.java:38: error: diamond operator is not supported in -source 1.6
public Map<String, Integer> data = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\***\Lithium\src\server\maps\MapScriptMethods.java:1018: error: diamond operator is not supported in -source 1.6
final Map<Skill, SkillEntry> sa = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\***\Lithium\src\server\quest\MapleQuestAction.java:233: error: diamond operator is not supported in -source 1.6
final Map<Skill, SkillEntry> sa = new HashMap<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\*\Lithium\src\tools\packet\CWvsContext.java:1506: error: diamond operator is not supported in -source 1.6
partymembers = new ArrayList<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\*\Lithium\src\tools\packet\LoginPacket.java:253: error: diamond operator is not supported in -source 1.6
List<Pair<String, Integer>> flags = new LinkedList<>();
(use -source 7 or higher to enable diamond operator)
C:\Users\User\Desktop\***\Lithium\src\tools\packet\PacketHelper.java:152: error: diamond operator is not supported in -source 1.6
final Map<Integer, Integer> skillsWithoutMax = new LinkedHashMap<>();
(use -source 7 or higher to enable diamond operator)
18 errors
C:\Users\User\Documents\NetBeansProjects\Lithium\nbproject\build-impl.xml:596: The following error occurred while executing this line:
C:\Users\User\Documents\NetBeansProjects\Lithium\nbproject\build-impl.xml:242: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 3 seconds)
Help?

You've got the wrong JDK version.
 
Newbie Spellweaver
Joined
Sep 24, 2011
Messages
7
Reaction score
0
Bat error
ERRORcom.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could
not create connection to database server. Attempted reconnect 3 times. Giving u
p.
Exception in thread "main" java.lang.ExceptionInInitializerError
at server.Start.run(Start.java:37)
at server.Start.main(Start.java:125)
Caused by: java.lang.NullPointerException
at server.ServerProperties.<clinit>(ServerProperties.java:30)
... 2 more
Press any key to continue . . .
Edit:New Error
 
Last edited:
Junior Spellweaver
Joined
Jul 4, 2012
Messages
111
Reaction score
32
? Press f11 and copy-paste the errors

Oh i know, Right click libraries-Add Jar/File then open the jars in your dist folder. Then press f11
 
Newbie Spellweaver
Joined
Feb 14, 2008
Messages
22
Reaction score
3
here
ant -f C:\\Users\\****\\Documents\\NetBeansProjects\\Lithium jarinit:
deps-jar:
Created dir: C:\Users\****\Documents\NetBeansProjects\Lithium\build
Updating property file: C:\Users\****\Documents\NetBeansProjects\Lithium\build\built-jar.properties
Created dir: C:\Users\****\Documents\NetBeansProjects\Lithium\build\classes
Created dir: C:\Users\****\Documents\NetBeansProjects\Lithium\build\empty
Created dir: C:\Users\****\Documents\NetBeansProjects\Lithium\build\generated-sources\ap-source-output
Compiling 330 source files to C:\Users\****\Documents\NetBeansProjects\Lithium\build\classes
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\MapleClient.java:65: error: package org.apache.mina.common does not exist
import org.apache.mina.common.IoSession;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\inventory\MapleRing.java:24: error: package com.mysql.jdbc.exceptions does not exist
import com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\ChannelServer.java:49: error: package org.apache.mina.common does not exist
import org.apache.mina.common.ByteBuffer;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\ChannelServer.java:50: error: package org.apache.mina.common does not exist
import org.apache.mina.common.SimpleByteBufferAllocator;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\ChannelServer.java:51: error: package org.apache.mina.common does not exist
import org.apache.mina.common.IoAcceptor;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\ChannelServer.java:52: error: package org.apache.mina.filter.codec does not exist
import org.apache.mina.filter.codec.ProtocolCodecFilter;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\ChannelServer.java:53: error: package org.apache.mina.transport.socket.nio does not exist
import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\ChannelServer.java:54: error: package org.apache.mina.transport.socket.nio does not exist
import org.apache.mina.transport.socket.nio.SocketAcceptor;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\MapleCharacter.java:203: error: cannot find symbol
private BuddyList buddylist;
symbol: class BuddyList
location: class MapleCharacter
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\MapleCharacter.java:2819: error: cannot find symbol
public BuddyList getBuddylist() {
symbol: class BuddyList
location: class MapleCharacter
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\MapleClient.java:80: error: cannot find symbol
private transient IoSession session;
symbol: class IoSession
location: class MapleClient
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\MapleClient.java:102: error: cannot find symbol
public MapleClient(MapleAESOFB send, MapleAESOFB receive, IoSession session) {
symbol: class IoSession
location: class MapleClient
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\MapleClient.java:116: error: cannot find symbol
public final IoSession getSession() {
symbol: class IoSession
location: class MapleClient
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\ChannelServer.java:76: error: cannot find symbol
private IoAcceptor acceptor;
symbol: class IoAcceptor
location: class ChannelServer
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\MapleServerHandler.java:58: error: package org.apache.mina.common does not exist
import org.apache.mina.common.IoHandlerAdapter;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\MapleServerHandler.java:59: error: package org.apache.mina.common does not exist
import org.apache.mina.common.IdleStatus;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\MapleServerHandler.java:60: error: package org.apache.mina.common does not exist
import org.apache.mina.common.IoSession;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\MapleServerHandler.java:68: error: cannot find symbol
public class MapleServerHandler extends IoHandlerAdapter implements MapleServerHandlerMBean {
symbol: class IoHandlerAdapter
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\MapleServerHandler.java:120: error: cannot find symbol
private static FileWriter isLoggedIP(IoSession sess) {
symbol: class IoSession
location: class MapleServerHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\MapleServerHandler.java:145: error: cannot find symbol
public static void log(String packet, String op, MapleClient c, IoSession io) {
symbol: class IoSession
location: class MapleServerHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\MapleServerHandler.java:284: error: cannot find symbol
public void exceptionCaught(final IoSession session, final Throwable cause) throws Exception {
symbol: class IoSession
location: class MapleServerHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\MapleServerHandler.java:291: error: cannot find symbol
public void sessionOpened(final IoSession session) throws Exception {
symbol: class IoSession
location: class MapleServerHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\MapleServerHandler.java:400: error: cannot find symbol
public void sessionClosed(final IoSession session) throws Exception {
symbol: class IoSession
location: class MapleServerHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\MapleServerHandler.java:441: error: cannot find symbol
public void sessionIdle(final IoSession session, final IdleStatus status) throws Exception {
symbol: class IoSession
location: class MapleServerHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\MapleServerHandler.java:441: error: cannot find symbol
public void sessionIdle(final IoSession session, final IdleStatus status) throws Exception {
symbol: class IdleStatus
location: class MapleServerHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\MapleServerHandler.java:454: error: cannot find symbol
public void messageReceived(final IoSession session, final Object message) {
symbol: class IoSession
location: class MapleServerHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\cashshop\CashShopServer.java:28: error: package org.apache.mina.common does not exist
import org.apache.mina.common.ByteBuffer;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\cashshop\CashShopServer.java:29: error: package org.apache.mina.common does not exist
import org.apache.mina.common.SimpleByteBufferAllocator;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\cashshop\CashShopServer.java:30: error: package org.apache.mina.common does not exist
import org.apache.mina.common.IoAcceptor;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\cashshop\CashShopServer.java:32: error: package org.apache.mina.filter.codec does not exist
import org.apache.mina.filter.codec.ProtocolCodecFilter;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\cashshop\CashShopServer.java:33: error: package org.apache.mina.transport.socket.nio does not exist
import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\cashshop\CashShopServer.java:34: error: package org.apache.mina.transport.socket.nio does not exist
import org.apache.mina.transport.socket.nio.SocketAcceptor;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\cashshop\CashShopServer.java:43: error: cannot find symbol
private static IoAcceptor acceptor;
symbol: class IoAcceptor
location: class CashShopServer
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:23: error: package client.BuddyList does not exist
import static client.BuddyList.BuddyOperation.ADDED;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:23: error: static import only from classes and interfaces
import static client.BuddyList.BuddyOperation.ADDED;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:24: error: package client.BuddyList does not exist
import static client.BuddyList.BuddyOperation.DELETED;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:24: error: static import only from classes and interfaces
import static client.BuddyList.BuddyOperation.DELETED;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:31: error: cannot find symbol
import client.BuddyList;
symbol: class BuddyList
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:36: error: package client.BuddyList does not exist
import client.BuddyList.BuddyAddResult;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:37: error: package client.BuddyList does not exist
import client.BuddyList.BuddyOperation;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:195: error: cannot find symbol
private static final void notifyRemoteChannel(final MapleClient c, final int remoteChannel, final int otherCid, final String group, final BuddyOperation operation) {
symbol: class BuddyOperation
location: class BuddyListHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\login\LoginServer.java:32: error: package org.apache.mina.common does not exist
import org.apache.mina.common.ByteBuffer;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\login\LoginServer.java:33: error: package org.apache.mina.common does not exist
import org.apache.mina.common.SimpleByteBufferAllocator;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\login\LoginServer.java:34: error: package org.apache.mina.common does not exist
import org.apache.mina.common.IoAcceptor;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\login\LoginServer.java:36: error: package org.apache.mina.filter.codec does not exist
import org.apache.mina.filter.codec.ProtocolCodecFilter;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\login\LoginServer.java:37: error: package org.apache.mina.transport.socket.nio does not exist
import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\login\LoginServer.java:38: error: package org.apache.mina.transport.socket.nio does not exist
import org.apache.mina.transport.socket.nio.SocketAcceptor;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\login\LoginServer.java:46: error: cannot find symbol
private static IoAcceptor acceptor;
symbol: class IoAcceptor
location: class LoginServer
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MapleCodecFactory.java:23: error: package org.apache.mina.filter.codec does not exist
import org.apache.mina.filter.codec.ProtocolCodecFactory;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MapleCodecFactory.java:24: error: package org.apache.mina.filter.codec does not exist
import org.apache.mina.filter.codec.ProtocolDecoder;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MapleCodecFactory.java:25: error: package org.apache.mina.filter.codec does not exist
import org.apache.mina.filter.codec.ProtocolEncoder;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MapleCodecFactory.java:27: error: cannot find symbol
public class MapleCodecFactory implements ProtocolCodecFactory {
symbol: class ProtocolCodecFactory
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MapleCodecFactory.java:29: error: cannot find symbol
private final ProtocolEncoder encoder = new MaplePacketEncoder();
symbol: class ProtocolEncoder
location: class MapleCodecFactory
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MapleCodecFactory.java:30: error: cannot find symbol
private final ProtocolDecoder decoder = new MaplePacketDecoder();
symbol: class ProtocolDecoder
location: class MapleCodecFactory
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MapleCodecFactory.java:32: error: cannot find symbol
public ProtocolEncoder getEncoder() throws Exception {
symbol: class ProtocolEncoder
location: class MapleCodecFactory
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MapleCodecFactory.java:36: error: cannot find symbol
public ProtocolDecoder getDecoder() throws Exception {
symbol: class ProtocolDecoder
location: class MapleCodecFactory
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MaplePacketDecoder.java:27: error: package org.apache.mina.common does not exist
import org.apache.mina.common.ByteBuffer;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MaplePacketDecoder.java:28: error: package org.apache.mina.common does not exist
import org.apache.mina.common.IoSession;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MaplePacketDecoder.java:29: error: package org.apache.mina.filter.codec does not exist
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MaplePacketDecoder.java:30: error: package org.apache.mina.filter.codec does not exist
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MaplePacketDecoder.java:32: error: cannot find symbol
public class MaplePacketDecoder extends CumulativeProtocolDecoder {
symbol: class CumulativeProtocolDecoder
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MaplePacketDecoder.java:42: error: cannot find symbol
protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception {
symbol: class IoSession
location: class MaplePacketDecoder
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MaplePacketDecoder.java:42: error: cannot find symbol
protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception {
symbol: class ByteBuffer
location: class MaplePacketDecoder
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MaplePacketDecoder.java:42: error: cannot find symbol
protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception {
symbol: class ProtocolDecoderOutput
location: class MaplePacketDecoder
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MaplePacketEncoder.java:30: error: package org.apache.mina.common does not exist
import org.apache.mina.common.ByteBuffer;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MaplePacketEncoder.java:31: error: package org.apache.mina.common does not exist
import org.apache.mina.common.IoSession;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MaplePacketEncoder.java:32: error: package org.apache.mina.filter.codec does not exist
import org.apache.mina.filter.codec.ProtocolEncoder;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MaplePacketEncoder.java:33: error: package org.apache.mina.filter.codec does not exist
import org.apache.mina.filter.codec.ProtocolEncoderOutput;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MaplePacketEncoder.java:35: error: cannot find symbol
public class MaplePacketEncoder implements ProtocolEncoder {
symbol: class ProtocolEncoder
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MaplePacketEncoder.java:38: error: cannot find symbol
public void encode(final IoSession session, final Object message, final ProtocolEncoderOutput out) throws Exception {
symbol: class IoSession
location: class MaplePacketEncoder
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MaplePacketEncoder.java:38: error: cannot find symbol
public void encode(final IoSession session, final Object message, final ProtocolEncoderOutput out) throws Exception {
symbol: class ProtocolEncoderOutput
location: class MaplePacketEncoder
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\mina\MaplePacketEncoder.java:67: error: cannot find symbol
public void dispose(IoSession session) throws Exception {
symbol: class IoSession
location: class MaplePacketEncoder
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:3: error: cannot find symbol
import client.BuddyList;
symbol: class BuddyList
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:4: error: package client.BuddyList does not exist
import client.BuddyList.BuddyAddResult;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:5: error: package client.BuddyList does not exist
import client.BuddyList.BuddyOperation;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:560: error: cannot find symbol
public static void buddyChanged(int cid, int cidFrom, String name, int channel, BuddyOperation operation, String group) {
symbol: class BuddyOperation
location: class Buddy
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:584: error: cannot find symbol
public static BuddyAddResult requestBuddyAdd(String addName, int channelFrom, int cidFrom, String nameFrom, int levelFrom, int jobFrom) {
symbol: class BuddyAddResult
location: class Buddy
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\HexTool.java:25: error: package org.apache.mina.common does not exist
import org.apache.mina.common.ByteBuffer;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\HexTool.java:58: error: cannot find symbol
public static final String toString(final ByteBuffer buf) {
symbol: class ByteBuffer
location: class HexTool
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:25: error: package org.apache.mina.common does not exist
import org.apache.mina.common.CloseFuture;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:26: error: package org.apache.mina.common does not exist
import org.apache.mina.common.IoFilterChain;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:27: error: package org.apache.mina.common does not exist
import org.apache.mina.common.IoHandler;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:28: error: package org.apache.mina.common does not exist
import org.apache.mina.common.IoService;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:29: error: package org.apache.mina.common does not exist
import org.apache.mina.common.IoServiceConfig;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:30: error: package org.apache.mina.common does not exist
import org.apache.mina.common.IoSessionConfig;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:31: error: package org.apache.mina.common does not exist
import org.apache.mina.common.TransportType;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:32: error: package org.apache.mina.common does not exist
import org.apache.mina.common.WriteFuture;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:33: error: package org.apache.mina.common.IoFilter does not exist
import org.apache.mina.common.IoFilter.WriteRequest;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:34: error: package org.apache.mina.common.support does not exist
import org.apache.mina.common.support.BaseIoSession;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:48: error: cannot find symbol
public class MockIOSession extends BaseIoSession {
symbol: class BaseIoSession
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:61: error: cannot find symbol
public IoSessionConfig getConfig() {
symbol: class IoSessionConfig
location: class MockIOSession
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:69: error: cannot find symbol
public IoFilterChain getFilterChain() {
symbol: class IoFilterChain
location: class MockIOSession
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:77: error: cannot find symbol
public IoHandler getHandler() {
symbol: class IoHandler
location: class MockIOSession
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:101: error: cannot find symbol
public IoService getService() {
symbol: class IoService
location: class MockIOSession
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:117: error: cannot find symbol
public IoServiceConfig getServiceConfig() {
symbol: class IoServiceConfig
location: class MockIOSession
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:125: error: cannot find symbol
public TransportType getTransportType() {
symbol: class TransportType
location: class MockIOSession
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:133: error: cannot find symbol
public CloseFuture close() {
symbol: class CloseFuture
location: class MockIOSession
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:148: error: cannot find symbol
public WriteFuture write(Object message, SocketAddress remoteAddress) {
symbol: class WriteFuture
location: class MockIOSession
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:157: error: cannot find symbol
public WriteFuture write(Object message) {
symbol: class WriteFuture
location: class MockIOSession
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\MockIOSession.java:165: error: cannot find symbol
protected void write0(WriteRequest writeRequest) {
symbol: class WriteRequest
location: class MockIOSession
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\messages\CommandProcessor.java:56: warning: non-varargs call of varargs method with inexact argument type for last parameter;
PlayerGMRank rankNeeded = (PlayerGMRank) clasz.getMethod("getPlayerLevelRequired", new Class<?>[]{}).invoke(null, null);
cast to Object for a varargs call
cast to Object[] for a non-varargs call and to suppress this warning
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
100 errors
1 warning
C:\Users\****\Documents\NetBeansProjects\Lithium\nbproject\build-impl.xml:900: The following error occurred while executing this line:
C:\Users\****\Documents\NetBeansProjects\Lithium\nbproject\build-impl.xml:265: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 2 seconds)
after adding the jar to libraries:
ant -f C:\\Users\\****\\Documents\\NetBeansProjects\\Lithium jarinit:
Deleting: C:\Users\****\Documents\NetBeansProjects\Lithium\build\built-jar.properties
deps-jar:
Updating property file: C:\Users\****\Documents\NetBeansProjects\Lithium\build\built-jar.properties
Compiling 330 source files to C:\Users\****\Documents\NetBeansProjects\Lithium\build\classes
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\MapleCharacter.java:203: error: cannot find symbol
private BuddyList buddylist;
symbol: class BuddyList
location: class MapleCharacter
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\MapleCharacter.java:2819: error: cannot find symbol
public BuddyList getBuddylist() {
symbol: class BuddyList
location: class MapleCharacter
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:23: error: package client.BuddyList does not exist
import static client.BuddyList.BuddyOperation.ADDED;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:23: error: static import only from classes and interfaces
import static client.BuddyList.BuddyOperation.ADDED;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:24: error: package client.BuddyList does not exist
import static client.BuddyList.BuddyOperation.DELETED;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:24: error: static import only from classes and interfaces
import static client.BuddyList.BuddyOperation.DELETED;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:31: error: cannot find symbol
import client.BuddyList;
symbol: class BuddyList
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:36: error: package client.BuddyList does not exist
import client.BuddyList.BuddyAddResult;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:37: error: package client.BuddyList does not exist
import client.BuddyList.BuddyOperation;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:195: error: cannot find symbol
private static final void notifyRemoteChannel(final MapleClient c, final int remoteChannel, final int otherCid, final String group, final BuddyOperation operation) {
symbol: class BuddyOperation
location: class BuddyListHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:3: error: cannot find symbol
import client.BuddyList;
symbol: class BuddyList
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:4: error: package client.BuddyList does not exist
import client.BuddyList.BuddyAddResult;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:5: error: package client.BuddyList does not exist
import client.BuddyList.BuddyOperation;
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:560: error: cannot find symbol
public static void buddyChanged(int cid, int cidFrom, String name, int channel, BuddyOperation operation, String group) {
symbol: class BuddyOperation
location: class Buddy
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:584: error: cannot find symbol
public static BuddyAddResult requestBuddyAdd(String addName, int channelFrom, int cidFrom, String nameFrom, int levelFrom, int jobFrom) {
symbol: class BuddyAddResult
location: class Buddy
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\MapleCharacter.java:368: error: cannot find symbol
ret.buddylist = new BuddyList((byte) 20);
symbol: class BuddyList
location: class MapleCharacter
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\MapleCharacter.java:466: error: cannot find symbol
ret.buddylist = new BuddyList(ct.buddysize);
symbol: class BuddyList
location: class MapleCharacter
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\MapleCharacter.java:636: error: cannot find symbol
ret.buddylist = new BuddyList(rs.getByte("buddyCapacity"));
symbol: class BuddyList
location: class MapleCharacter
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\MapleClient.java:791: error: cannot find symbol
final BuddyList bl = player.getBuddylist();
symbol: class BuddyList
location: class MapleClient
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\messages\CommandProcessor.java:56: warning: non-varargs call of varargs method with inexact argument type for last parameter;
PlayerGMRank rankNeeded = (PlayerGMRank) clasz.getMethod("getPlayerLevelRequired", new Class<?>[]{}).invoke(null, null);
cast to Object for a varargs call
cast to Object[] for a non-varargs call and to suppress this warning
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:80: error: cannot find symbol
final BuddyList buddylist = c.getPlayer().getBuddylist();
symbol: class BuddyList
location: class BuddyListHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:114: error: cannot find symbol
BuddyAddResult buddyAddResult = null;
symbol: class BuddyAddResult
location: class BuddyListHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:130: error: cannot find symbol
buddyAddResult = BuddyAddResult.BUDDYLIST_FULL;
symbol: variable BuddyAddResult
location: class BuddyListHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:141: error: cannot find symbol
buddyAddResult = BuddyAddResult.ALREADY_ON_LIST;
symbol: variable BuddyAddResult
location: class BuddyListHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:146: error: cannot find symbol
if (buddyAddResult == BuddyAddResult.BUDDYLIST_FULL) {
symbol: variable BuddyAddResult
location: class BuddyListHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:151: error: cannot find symbol
if (buddyAddResult == BuddyAddResult.ALREADY_ON_LIST && channel > 0) {
symbol: variable BuddyAddResult
location: class BuddyListHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:153: error: cannot find symbol
notifyRemoteChannel(c, channel, otherCid, groupName, ADDED);
symbol: variable ADDED
location: class BuddyListHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:154: error: cannot find symbol
} else if (buddyAddResult != BuddyAddResult.ALREADY_ON_LIST) {
symbol: variable BuddyAddResult
location: class BuddyListHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:180: error: cannot find symbol
notifyRemoteChannel(c, channel, otherCid, "ETC", ADDED);
symbol: variable ADDED
location: class BuddyListHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\channel\handler\BuddyListHandler.java:188: error: cannot find symbol
notifyRemoteChannel(c, World.Find.findChannel(otherCid), otherCid, blz.getGroup(), DELETED);
symbol: variable DELETED
location: class BuddyListHandler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:565: error: cannot find symbol
final BuddyList buddylist = addChar.getBuddylist();
symbol: class BuddyList
location: class Buddy
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:567: error: cannot find symbol
case ADDED:
symbol: variable ADDED
location: class Buddy
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:573: error: cannot find symbol
case DELETED:
symbol: variable DELETED
location: class Buddy
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:589: error: cannot find symbol
final BuddyList buddylist = addChar.getBuddylist();
symbol: class BuddyList
location: class Buddy
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:591: error: cannot find symbol
return BuddyAddResult.BUDDYLIST_FULL;
symbol: variable BuddyAddResult
location: class Buddy
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:597: error: cannot find symbol
return BuddyAddResult.ALREADY_ON_LIST;
symbol: variable BuddyAddResult
location: class Buddy
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\handling\world\World.java:602: error: cannot find symbol
return BuddyAddResult.OK;
symbol: variable BuddyAddResult
location: class Buddy
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
36 errors
1 warning
C:\Users\****\Documents\NetBeansProjects\Lithium\nbproject\build-impl.xml:900: The following error occurred while executing this line:
C:\Users\****\Documents\NetBeansProjects\Lithium\nbproject\build-impl.xml:265: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 1 second)
 
Junior Spellweaver
Joined
Jul 4, 2012
Messages
111
Reaction score
32
Ok Hmm Replace these with my text and see if that helps

World.java

Code:
package handling.world;

import client.BuddyList;
import client.BuddyList.BuddyAddResult;
import client.BuddyList.BuddyOperation;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import client.BuddylistEntry;

import client.MapleBuffStat;
import client.MapleCharacter;

import client.MapleCoolDownValueHolder;
import client.MapleDiseaseValueHolder;
import client.inventory.MapleInventoryType;
import client.inventory.MaplePet;
import client.inventory.PetDataFactory;
import client.status.MonsterStatusEffect;
import database.DatabaseConnection;

import handling.cashshop.CashShopServer;
import handling.channel.ChannelServer;
import handling.channel.PlayerStorage;
import handling.world.exped.ExpeditionType;
import handling.world.exped.MapleExpedition;
import handling.world.exped.PartySearch;
import handling.world.exped.PartySearchType;
import handling.world.family.MapleFamily;
import handling.world.family.MapleFamilyCharacter;
import handling.world.guild.MapleBBSThread;
import handling.world.guild.MapleGuild;
import handling.world.guild.MapleGuildAlliance;
import handling.world.guild.MapleGuildCharacter;
import java.util.Collection;
import java.util.EnumMap;
import server.Timer.WorldTimer;
import server.life.MapleMonster;
import server.maps.MapleMap;
import server.maps.MapleMapItem;
import tools.CollectionUtil;
import tools.packet.CField;
import tools.packet.CWvsContext;
import tools.packet.CWvsContext.AlliancePacket;
import tools.packet.CWvsContext.BuddylistPacket;
import tools.packet.CWvsContext.ExpeditionPacket;
import tools.packet.CWvsContext.GuildPacket;
import tools.packet.CWvsContext.PartyPacket;
import tools.packet.PetPacket;

public class World {

    //Touch everything...
    public static void init() {
        World.Find.findChannel(0);
        World.Alliance.lock.toString();
        World.Messenger.getMessenger(0);
        World.Party.getParty(0);
    }

    public static String getStatus() {
        StringBuilder ret = new StringBuilder();
        int totalUsers = 0;
        for (ChannelServer cs : ChannelServer.getAllInstances()) {
            ret.append("Channel ");
            ret.append(cs.getChannel());
            ret.append(": ");
            int channelUsers = cs.getConnectedClients();
            totalUsers += channelUsers;
            ret.append(channelUsers);
            ret.append(" users\n");
        }
        ret.append("Total users online: ");
        ret.append(totalUsers);
        ret.append("\n");
        return ret.toString();
    }

    public static Map<Integer, Integer> getConnected() {
        Map<Integer, Integer> ret = new HashMap<Integer, Integer>();
        int total = 0;
        for (ChannelServer cs : ChannelServer.getAllInstances()) {
            int curConnected = cs.getConnectedClients();
            ret.put(cs.getChannel(), curConnected);
            total += curConnected;
        }
        ret.put(0, total);
        return ret;
    }

    public static List<CheaterData> getCheaters() {
        List<CheaterData> allCheaters = new ArrayList<CheaterData>();
        for (ChannelServer cs : ChannelServer.getAllInstances()) {
            allCheaters.addAll(cs.getCheaters());
        }
        Collections.sort(allCheaters);
        return CollectionUtil.copyFirst(allCheaters, 20);
    }

    public static List<CheaterData> getReports() {
        List<CheaterData> allCheaters = new ArrayList<CheaterData>();
        for (ChannelServer cs : ChannelServer.getAllInstances()) {
            allCheaters.addAll(cs.getReports());
        }
        Collections.sort(allCheaters);
        return CollectionUtil.copyFirst(allCheaters, 20);
    }

    public static boolean isConnected(String charName) {
        return Find.findChannel(charName) > 0;
    }

    public static void toggleMegaphoneMuteState() {
        for (ChannelServer cs : ChannelServer.getAllInstances()) {
            cs.toggleMegaphoneMuteState();
        }
    }

    public static void ChannelChange_Data(CharacterTransfer Data, int characterid, int toChannel) {
        getStorage(toChannel).registerPendingPlayer(Data, characterid);
    }

    public static boolean isCharacterListConnected(List<String> charName) {
        for (ChannelServer cs : ChannelServer.getAllInstances()) {
            for (final String c : charName) {
                if (cs.getPlayerStorage().getCharacterByName(c) != null) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean hasMerchant(int accountID, int characterID) {
        for (ChannelServer cs : ChannelServer.getAllInstances()) {
            if (cs.containsMerchant(accountID, characterID)) {
                return true;
            }
        }
        return false;
    }

    public static PlayerStorage getStorage(int channel) {
        if (channel == -20) {
            return CashShopServer.getPlayerStorageMTS();
        } else if (channel == -10) {
            return CashShopServer.getPlayerStorage();
        }
        return ChannelServer.getInstance(channel).getPlayerStorage();
    }

    public static int getPendingCharacterSize() {
        int ret = CashShopServer.getPlayerStorage().pendingCharacterSize() + CashShopServer.getPlayerStorageMTS().pendingCharacterSize();
        for (ChannelServer cserv : ChannelServer.getAllInstances()) {
            ret += cserv.getPlayerStorage().pendingCharacterSize();
        }
        return ret;
    }

    public static boolean isChannelAvailable(final int ch) {
        if (ChannelServer.getInstance(ch) == null || ChannelServer.getInstance(ch).getPlayerStorage() == null) {
            return false;
        }
        return ChannelServer.getInstance(ch).getPlayerStorage().getConnectedClients() < (ch == 1 ? 600 : 400);
    }

    public static class Party {

        private static Map<Integer, MapleParty> parties = new HashMap<Integer, MapleParty>();
        private static Map<Integer, MapleExpedition> expeds = new HashMap<Integer, MapleExpedition>();
        private static Map<PartySearchType, List<PartySearch>> searches = new EnumMap<PartySearchType, List<PartySearch>>(PartySearchType.class);
        private static final AtomicInteger runningPartyId = new AtomicInteger(1), runningExpedId = new AtomicInteger(1);

        static {
            try {
                PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET party = -1, fatigue = 0");
                ps.executeUpdate();
                ps.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            for (PartySearchType pst : PartySearchType.values()) {
                searches.put(pst, new ArrayList<PartySearch>()); //according to client, max 10, even though theres page numbers ?!
            }
        }

        public static void partyChat(int partyid, String chattext, String namefrom) {
            partyChat(partyid, chattext, namefrom, 1);
        }

        public static void expedChat(int expedId, String chattext, String namefrom) {
            MapleExpedition party = getExped(expedId);
            if (party == null) {
                return;
            }
            for (int i : party.getParties()) {
                partyChat(i, chattext, namefrom, 4);
            }
        }

        public static void expedPacket(int expedId, byte[] packet, MaplePartyCharacter exception) {
            MapleExpedition party = getExped(expedId);
            if (party == null) {
                return;
            }
            for (int i : party.getParties()) {
                partyPacket(i, packet, exception);
            }
        }

        public static void partyPacket(int partyid, byte[] packet, MaplePartyCharacter exception) {
            MapleParty party = getParty(partyid);
            if (party == null) {
                return;
            }

            for (MaplePartyCharacter partychar : party.getMembers()) {
                int ch = Find.findChannel(partychar.getName());
                if (ch > 0 && (exception == null || partychar.getId() != exception.getId())) {
                    MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(partychar.getName());
                    if (chr != null) { //Extra check just in case
                        chr.getClient().getSession().write(packet);
                    }
                }
            }
        }

        public static void partyChat(int partyid, String chattext, String namefrom, int mode) {
            MapleParty party = getParty(partyid);
            if (party == null) {
                return;
            }

            for (MaplePartyCharacter partychar : party.getMembers()) {
                int ch = Find.findChannel(partychar.getName());
                if (ch > 0) {
                    MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(partychar.getName());
                    if (chr != null && !chr.getName().equalsIgnoreCase(namefrom)) { //Extra check just in case
                        chr.getClient().getSession().write(CField.multiChat(namefrom, chattext, mode));
                        if (chr.getClient().isMonitored()) {
                            World.Broadcast.broadcastGMMessage(CWvsContext.serverNotice(6, "[GM Message] " + namefrom + " said to " + chr.getName() + " (Party): " + chattext));
                        }
                    }
                }
            }
        }

        public static void partyMessage(int partyid, String chattext) {
            MapleParty party = getParty(partyid);
            if (party == null) {
                return;
            }

            for (MaplePartyCharacter partychar : party.getMembers()) {
                int ch = Find.findChannel(partychar.getName());
                if (ch > 0) {
                    MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(partychar.getName());
                    if (chr != null) { //Extra check just in case
                        chr.dropMessage(5, chattext);
                    }
                }
            }
        }

        public static void expedMessage(int expedId, String chattext) {
            MapleExpedition party = getExped(expedId);
            if (party == null) {
                return;
            }
            for (int i : party.getParties()) {
                partyMessage(i, chattext);
            }
        }

        public static void updateParty(int partyid, PartyOperation operation, MaplePartyCharacter target) {
            MapleParty party = getParty(partyid);
            if (party == null) {
                return; //Don't update, just return. And definitely don't throw a damn exception.
                //throw new IllegalArgumentException("no party with the specified partyid exists");
            }
            final int oldExped = party.getExpeditionId();
            int oldInd = -1;
            if (oldExped > 0) {
                MapleExpedition exped = getExped(oldExped);
                if (exped != null) {
                    oldInd = exped.getIndex(partyid);
                }
            }
            switch (operation) {
                case JOIN:
                    party.addMember(target);
                    if (party.getMembers().size() >= 6) {
                        PartySearch toRemove = getSearchByParty(partyid);
                        if (toRemove != null) {
                            removeSearch(toRemove, "The Party Listing was removed because the party is full.");
                        } else if (party.getExpeditionId() > 0) {
                            MapleExpedition exped = getExped(party.getExpeditionId());
                            if (exped != null && exped.getAllMembers() >= exped.getType().maxMembers) {
                                toRemove = getSearchByExped(exped.getId());
                                if (toRemove != null) {
                                    removeSearch(toRemove, "The Party Listing was removed because the party is full.");
                                }
                            }
                        }
                    }
                    break;
                case EXPEL:
                case LEAVE:
                    party.removeMember(target);
                    break;
                case DISBAND:
                    disbandParty(partyid);
                    break;
                case SILENT_UPDATE:
                case LOG_ONOFF:
                    party.updateMember(target);
                    break;
                case CHANGE_LEADER:
                case CHANGE_LEADER_DC:
                    party.setLeader(target);
                    break;
                default:
                    throw new RuntimeException("Unhandeled updateParty operation " + operation.name());
            }
            if (operation == PartyOperation.LEAVE || operation == PartyOperation.EXPEL) {
                int chz = Find.findChannel(target.getName());
                if (chz > 0) {
                    MapleCharacter chr = getStorage(chz).getCharacterByName(target.getName());
                    if (chr != null) {
                        chr.setParty(null);
                        if (oldExped > 0) {
                            chr.getClient().getSession().write(ExpeditionPacket.expeditionMessage(80));
                        }
                        chr.getClient().getSession().write(PartyPacket.updateParty(chr.getClient().getChannel(), party, operation, target));
                    }
                }
                if (target.getId() == party.getLeader().getId() && party.getMembers().size() > 0) { //pass on lead
                    MaplePartyCharacter lchr = null;
                    for (MaplePartyCharacter pchr : party.getMembers()) {
                        if (pchr != null && (lchr == null || lchr.getLevel() < pchr.getLevel())) {
                            lchr = pchr;
                        }
                    }
                    if (lchr != null) {
                        updateParty(partyid, PartyOperation.CHANGE_LEADER_DC, lchr);
                    }
                }
            }
            if (party.getMembers().size() <= 0) { //no members left, plz disband
                disbandParty(partyid);
            }
            for (MaplePartyCharacter partychar : party.getMembers()) {
                if (partychar == null) {
                    continue;
                }
                int ch = Find.findChannel(partychar.getName());
                if (ch > 0) {
                    MapleCharacter chr = getStorage(ch).getCharacterByName(partychar.getName());
                    if (chr != null) {
                        if (operation == PartyOperation.DISBAND) {
                            chr.setParty(null);
                            if (oldExped > 0) {
                                chr.getClient().getSession().write(ExpeditionPacket.expeditionMessage(83));
                            }
                        } else {
                            chr.setParty(party);
                        }
                        chr.getClient().getSession().write(PartyPacket.updateParty(chr.getClient().getChannel(), party, operation, target));
                    }
                }
            }
            if (oldExped > 0) {
                expedPacket(oldExped, ExpeditionPacket.expeditionUpdate(oldInd, party), operation == PartyOperation.LOG_ONOFF || operation == PartyOperation.SILENT_UPDATE ? target : null);
            }
        }

        public static MapleParty createParty(MaplePartyCharacter chrfor) {
            MapleParty party = new MapleParty(runningPartyId.getAndIncrement(), chrfor);
            parties.put(party.getId(), party);
            return party;
        }

        public static MapleParty createParty(MaplePartyCharacter chrfor, int expedId) {
            ExpeditionType ex = ExpeditionType.getById(expedId);
            MapleParty party = new MapleParty(runningPartyId.getAndIncrement(), chrfor, ex != null ? runningExpedId.getAndIncrement() : -1);
            parties.put(party.getId(), party);
            if (ex != null) {
                final MapleExpedition exp = new MapleExpedition(ex, chrfor.getId(), party.getExpeditionId());
                exp.getParties().add(party.getId());
                expeds.put(party.getExpeditionId(), exp);
            }
            return party;
        }

        public static MapleParty createPartyAndAdd(MaplePartyCharacter chrfor, int expedId) {
            MapleExpedition ex = getExped(expedId);
            if (ex == null) {
                return null;
            }
            MapleParty party = new MapleParty(runningPartyId.getAndIncrement(), chrfor, expedId);
            parties.put(party.getId(), party);
            ex.getParties().add(party.getId());
            return party;
        }

        public static MapleParty getParty(int partyid) {
            return parties.get(partyid);
        }

        public static MapleExpedition getExped(int partyid) {
            return expeds.get(partyid);
        }

        public static MapleExpedition disbandExped(int partyid) {
            PartySearch toRemove = getSearchByExped(partyid);
            if (toRemove != null) {
                removeSearch(toRemove, "The Party Listing was removed because the party disbanded.");
            }
            final MapleExpedition ret = expeds.remove(partyid);
            if (ret != null) {
                for (int p : ret.getParties()) {
                    MapleParty pp = getParty(p);
                    if (pp != null) {
                        updateParty(p, PartyOperation.DISBAND, pp.getLeader());
                    }
                }
            }
            return ret;
        }

        public static MapleParty disbandParty(int partyid) {
            PartySearch toRemove = getSearchByParty(partyid);
            if (toRemove != null) {
                removeSearch(toRemove, "The Party Listing was removed because the party disbanded.");
            }
            final MapleParty ret = parties.remove(partyid);
            if (ret == null) {
                return null;
            }
            if (ret.getExpeditionId() > 0) {
                MapleExpedition me = getExped(ret.getExpeditionId());
                if (me != null) {
                    final int ind = me.getIndex(partyid);
                    if (ind >= 0) {
                        me.getParties().remove(ind);
                        expedPacket(me.getId(), ExpeditionPacket.expeditionUpdate(ind, null), null);
                    }
                }
            }
            ret.disband();
            return ret;
        }

        public static List<PartySearch> searchParty(PartySearchType pst) {
            return searches.get(pst);
        }

        public static void removeSearch(PartySearch ps, String text) {
            List<PartySearch> ss = searches.get(ps.getType());
            if (ss.contains(ps)) {
                ss.remove(ps);
                ps.cancelRemoval();
                if (ps.getType().exped) {
                    expedMessage(ps.getId(), text);
                } else {
                    partyMessage(ps.getId(), text);
                }
            }
        }

        public static void addSearch(PartySearch ps) {
            searches.get(ps.getType()).add(ps);
        }

        public static PartySearch getSearch(MapleParty party) {
            for (List<PartySearch> ps : searches.values()) {
                for (PartySearch p : ps) {
                    if ((p.getId() == party.getId() && !p.getType().exped) || (p.getId() == party.getExpeditionId() && p.getType().exped)) {
                        return p;
                    }
                }
            }
            return null;
        }

        public static PartySearch getSearchByParty(int partyId) {
            for (List<PartySearch> ps : searches.values()) {
                for (PartySearch p : ps) {
                    if (p.getId() == partyId && !p.getType().exped) {
                        return p;
                    }
                }
            }
            return null;
        }

        public static PartySearch getSearchByExped(int partyId) {
            for (List<PartySearch> ps : searches.values()) {
                for (PartySearch p : ps) {
                    if (p.getId() == partyId && p.getType().exped) {
                        return p;
                    }
                }
            }
            return null;
        }

        public static boolean partyListed(MapleParty party) {
            return getSearchByParty(party.getId()) != null;
        }
    }

    public static class Buddy {

        public static void buddyChat(int[] recipientCharacterIds, int cidFrom, String nameFrom, String chattext) {
            for (int characterId : recipientCharacterIds) {
                int ch = Find.findChannel(characterId);
                if (ch > 0) {
                    MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterById(characterId);
                    if (chr != null && chr.getBuddylist().containsVisible(cidFrom)) {
                        chr.getClient().getSession().write(CField.multiChat(nameFrom, chattext, 0));
                        if (chr.getClient().isMonitored()) {
                            World.Broadcast.broadcastGMMessage(CWvsContext.serverNotice(6, "[GM Message] " + nameFrom + " said to " + chr.getName() + " (Buddy): " + chattext));
                        }
                    }
                }
            }
        }

        private static void updateBuddies(int characterId, int channel, int[] buddies, boolean offline) {
            for (int buddy : buddies) {
                int ch = Find.findChannel(buddy);
                if (ch > 0) {
                    MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterById(buddy);
                    if (chr != null) {
                        BuddylistEntry ble = chr.getBuddylist().get(characterId);
                        if (ble != null && ble.isVisible()) {
                            int mcChannel;
                            if (offline) {
                                ble.setChannel(-1);
                                mcChannel = -1;
                            } else {
                                ble.setChannel(channel);
                                mcChannel = channel - 1;
                            }
                            chr.getClient().getSession().write(BuddylistPacket.updateBuddyChannel(ble.getCharacterId(), mcChannel));
                        }
                    }
                }
            }
        }

        public static void buddyChanged(int cid, int cidFrom, String name, int channel, BuddyOperation operation, String group) {
            int ch = Find.findChannel(cid);
            if (ch > 0) {
                final MapleCharacter addChar = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterById(cid);
                if (addChar != null) {
                    final BuddyList buddylist = addChar.getBuddylist();
                    switch (operation) {
                        case ADDED:
                            if (buddylist.contains(cidFrom)) {
                                buddylist.put(new BuddylistEntry(name, cidFrom, group, channel, true));
                                addChar.getClient().getSession().write(BuddylistPacket.updateBuddyChannel(cidFrom, channel - 1));
                            }
                            break;
                        case DELETED:
                            if (buddylist.contains(cidFrom)) {
                                buddylist.put(new BuddylistEntry(name, cidFrom, group, -1, buddylist.get(cidFrom).isVisible()));
                                addChar.getClient().getSession().write(BuddylistPacket.updateBuddyChannel(cidFrom, -1));
                            }
                            break;
                    }
                }
            }
        }

        public static BuddyAddResult requestBuddyAdd(String addName, int channelFrom, int cidFrom, String nameFrom, int levelFrom, int jobFrom) {
            int ch = Find.findChannel(cidFrom);
            if (ch > 0) {
                final MapleCharacter addChar = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(addName);
                if (addChar != null) {
                    final BuddyList buddylist = addChar.getBuddylist();
                    if (buddylist.isFull()) {
                        return BuddyAddResult.BUDDYLIST_FULL;
                    }
                    if (!buddylist.contains(cidFrom)) {
                        buddylist.addBuddyRequest(addChar.getClient(), cidFrom, nameFrom, channelFrom, levelFrom, jobFrom);
                    } else {
                        if (buddylist.containsVisible(cidFrom)) {
                            return BuddyAddResult.ALREADY_ON_LIST;
                        }
                    }
                }
            }
            return BuddyAddResult.OK;
        }

        public static void loggedOn(String name, int characterId, int channel, int[] buddies) {
            updateBuddies(characterId, channel, buddies, false);
        }

        public static void loggedOff(String name, int characterId, int channel, int[] buddies) {
            updateBuddies(characterId, channel, buddies, true);
        }
    }

    public static class Messenger {

        private static Map<Integer, MapleMessenger> messengers = new HashMap<Integer, MapleMessenger>();
        private static final AtomicInteger runningMessengerId = new AtomicInteger();

        static {
            runningMessengerId.set(1);
        }

        public static MapleMessenger createMessenger(MapleMessengerCharacter chrfor) {
            int messengerid = runningMessengerId.getAndIncrement();
            MapleMessenger messenger = new MapleMessenger(messengerid, chrfor);
            messengers.put(messenger.getId(), messenger);
            return messenger;
        }

        public static void declineChat(String target, String namefrom) {
            int ch = Find.findChannel(target);
            if (ch > 0) {
                ChannelServer cs = ChannelServer.getInstance(ch);
                MapleCharacter chr = cs.getPlayerStorage().getCharacterByName(target);
                if (chr != null) {
                    MapleMessenger messenger = chr.getMessenger();
                    if (messenger != null) {
                        chr.getClient().getSession().write(CField.messengerNote(namefrom, 5, 0));
                    }
                }
            }
        }

        public static MapleMessenger getMessenger(int messengerid) {
            return messengers.get(messengerid);
        }

        public static void leaveMessenger(int messengerid, MapleMessengerCharacter target) {
            MapleMessenger messenger = getMessenger(messengerid);
            if (messenger == null) {
                throw new IllegalArgumentException("No messenger with the specified messengerid exists");
            }
            int position = messenger.getPositionByName(target.getName());
            messenger.removeMember(target);

            for (MapleMessengerCharacter mmc : messenger.getMembers()) {
                if (mmc != null) {
                    int ch = Find.findChannel(mmc.getId());
                    if (ch > 0) {
                        MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(mmc.getName());
                        if (chr != null) {
                            chr.getClient().getSession().write(CField.removeMessengerPlayer(position));
                        }
                    }
                }
            }
        }

        public static void silentLeaveMessenger(int messengerid, MapleMessengerCharacter target) {
            MapleMessenger messenger = getMessenger(messengerid);
            if (messenger == null) {
                throw new IllegalArgumentException("No messenger with the specified messengerid exists");
            }
            messenger.silentRemoveMember(target);
        }

        public static void silentJoinMessenger(int messengerid, MapleMessengerCharacter target) {
            MapleMessenger messenger = getMessenger(messengerid);
            if (messenger == null) {
                throw new IllegalArgumentException("No messenger with the specified messengerid exists");
            }
            messenger.silentAddMember(target);
        }

        public static void updateMessenger(int messengerid, String namefrom, int fromchannel) {
            MapleMessenger messenger = getMessenger(messengerid);
            int position = messenger.getPositionByName(namefrom);

            for (MapleMessengerCharacter messengerchar : messenger.getMembers()) {
                if (messengerchar != null && !messengerchar.getName().equals(namefrom)) {
                    int ch = Find.findChannel(messengerchar.getName());
                    if (ch > 0) {
                        MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(messengerchar.getName());
                        if (chr != null) {
                            MapleCharacter from = ChannelServer.getInstance(fromchannel).getPlayerStorage().getCharacterByName(namefrom);
                            chr.getClient().getSession().write(CField.updateMessengerPlayer(namefrom, from, position, fromchannel - 1));
                        }
                    }
                }
            }
        }

        public static void joinMessenger(int messengerid, MapleMessengerCharacter target, String from, int fromchannel) {
            MapleMessenger messenger = getMessenger(messengerid);
            if (messenger == null) {
                throw new IllegalArgumentException("No messenger with the specified messengerid exists");
            }
            messenger.addMember(target);
            int position = messenger.getPositionByName(target.getName());
            for (MapleMessengerCharacter messengerchar : messenger.getMembers()) {
                if (messengerchar != null) {
                    int mposition = messenger.getPositionByName(messengerchar.getName());
                    int ch = Find.findChannel(messengerchar.getName());
                    if (ch > 0) {
                        MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(messengerchar.getName());
                        if (chr != null) {
                            if (!messengerchar.getName().equals(from)) {
                                MapleCharacter fromCh = ChannelServer.getInstance(fromchannel).getPlayerStorage().getCharacterByName(from);
                                if (fromCh != null) {
                                    chr.getClient().getSession().write(CField.addMessengerPlayer(from, fromCh, position, fromchannel - 1));
                                    fromCh.getClient().getSession().write(CField.addMessengerPlayer(chr.getName(), chr, mposition, messengerchar.getChannel() - 1));
                                }
                            } else {
                                chr.getClient().getSession().write(CField.joinMessenger(mposition));
                            }
                        }
                    }
                }
            }
        }

        public static void messengerChat(int messengerid, String charname, String text, String namefrom) {
            MapleMessenger messenger = getMessenger(messengerid);
            if (messenger == null) {
                throw new IllegalArgumentException("No messenger with the specified messengerid exists");
            }

            for (MapleMessengerCharacter messengerchar : messenger.getMembers()) {
                if (messengerchar != null && !messengerchar.getName().equals(namefrom)) {
                    int ch = Find.findChannel(messengerchar.getName());
                    if (ch > 0) {
                        MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(messengerchar.getName());
                        if (chr != null) {
                            chr.getClient().getSession().write(CField.messengerChat(charname, text));
                        }
                    }
                }
            }
        }

        public static void messengerInvite(String sender, int messengerid, String target, int fromchannel, boolean gm) {

            if (isConnected(target)) {

                int ch = Find.findChannel(target);
                if (ch > 0) {
                    MapleCharacter from = ChannelServer.getInstance(fromchannel).getPlayerStorage().getCharacterByName(sender);
                    MapleCharacter targeter = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(target);
                    if (targeter != null && targeter.getMessenger() == null) {
                        if (!targeter.isIntern() || gm) {
                            targeter.getClient().getSession().write(CField.messengerInvite(sender, messengerid));
                            from.getClient().getSession().write(CField.messengerNote(target, 4, 1));
                        } else {
                            from.getClient().getSession().write(CField.messengerNote(target, 4, 0));
                        }
                    } else {
                        from.getClient().getSession().write(CField.messengerChat(sender, " : " + target + " is already using Maple Messenger"));
                    }
                }
            }

        }
    }

    public static class Guild {

        private static final Map<Integer, MapleGuild> guilds = new LinkedHashMap<Integer, MapleGuild>();
        private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();

        public static void addLoadedGuild(MapleGuild f) {
            if (f.isProper()) {
                guilds.put(f.getId(), f);
            }
        }

        public static int createGuild(int leaderId, String name) {
            return MapleGuild.createGuild(leaderId, name);
        }

        public static MapleGuild getGuild(int id) {
            MapleGuild ret = null;
            lock.readLock().lock();
            try {
                ret = guilds.get(id);
            } finally {
                lock.readLock().unlock();
            }
            if (ret == null) {
                lock.writeLock().lock();
                try {
                    ret = new MapleGuild(id);
                    if (ret == null || ret.getId() <= 0 || !ret.isProper()) { //failed to load
                        return null;
                    }
                    guilds.put(id, ret);
                } finally {
                    lock.writeLock().unlock();
                }
            }
            return ret; //Guild doesn't exist?
        }

        public static MapleGuild getGuildByName(String guildName) {
            lock.readLock().lock();
            try {
                for (MapleGuild g : guilds.values()) {
                    if (g.getName().equalsIgnoreCase(guildName)) {
                        return g;
                    }
                }
                return null;
            } finally {
                lock.readLock().unlock();
            }
        }

        public static MapleGuild getGuild(MapleCharacter mc) {
            return getGuild(mc.getGuildId());
        }

        public static void setGuildMemberOnline(MapleGuildCharacter mc, boolean bOnline, int channel) {
            MapleGuild g = getGuild(mc.getGuildId());
            if (g != null) {
                g.setOnline(mc.getId(), bOnline, channel);
            }
        }

        public static void guildPacket(int gid, byte[] message) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.broadcast(message);
            }
        }

        public static int addGuildMember(MapleGuildCharacter mc) {
            MapleGuild g = getGuild(mc.getGuildId());
            if (g != null) {
                return g.addGuildMember(mc);
            }
            return 0;
        }

        public static void leaveGuild(MapleGuildCharacter mc) {
            MapleGuild g = getGuild(mc.getGuildId());
            if (g != null) {
                g.leaveGuild(mc);
            }
        }

        public static void guildChat(int gid, String name, int cid, String msg) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.guildChat(name, cid, msg);
            }
        }

        public static void changeRank(int gid, int cid, int newRank) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.changeRank(cid, newRank);
            }
        }

        public static void expelMember(MapleGuildCharacter initiator, String name, int cid) {
            MapleGuild g = getGuild(initiator.getGuildId());
            if (g != null) {
                g.expelMember(initiator, name, cid);
            }
        }

        public static void setGuildNotice(int gid, String notice) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.setGuildNotice(notice);
            }
        }

        public static void setGuildLeader(int gid, int cid) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.changeGuildLeader(cid);
            }
        }

        public static int getSkillLevel(int gid, int sid) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                return g.getSkillLevel(sid);
            }
            return 0;
        }

        public static boolean purchaseSkill(int gid, int sid, String name, int cid) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                return g.purchaseSkill(sid, name, cid);
            }
            return false;
        }

        public static boolean activateSkill(int gid, int sid, String name) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                return g.activateSkill(sid, name);
            }
            return false;
        }

        public static void memberLevelJobUpdate(MapleGuildCharacter mc) {
            MapleGuild g = getGuild(mc.getGuildId());
            if (g != null) {
                g.memberLevelJobUpdate(mc);
            }
        }

        public static void changeRankTitle(int gid, String[] ranks) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.changeRankTitle(ranks);
            }
        }

        public static void setGuildEmblem(int gid, short bg, byte bgcolor, short logo, byte logocolor) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.setGuildEmblem(bg, bgcolor, logo, logocolor);
            }
        }

        public static void disbandGuild(int gid) {
            MapleGuild g = getGuild(gid);
            lock.writeLock().lock();
            try {
                if (g != null) {
                    g.disbandGuild();
                    guilds.remove(gid);
                }
            } finally {
                lock.writeLock().unlock();
            }
        }

        public static void deleteGuildCharacter(int guildid, int charid) {

            //ensure it's loaded on world server
            //setGuildMemberOnline(mc, false, -1);
            MapleGuild g = getGuild(guildid);
            if (g != null) {
                MapleGuildCharacter mc = g.getMGC(charid);
                if (mc != null) {
                    if (mc.getGuildRank() > 1) //not leader
                    {
                        g.leaveGuild(mc);
                    } else {
                        g.disbandGuild();
                    }
                }
            }
        }

        public static boolean increaseGuildCapacity(int gid, boolean b) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                return g.increaseCapacity(b);
            }
            return false;
        }

        public static void gainGP(int gid, int amount) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.gainGP(amount);
            }
        }

        public static void gainGP(int gid, int amount, int cid) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.gainGP(amount, false, cid);
            }
        }

        public static int getGP(final int gid) {
            final MapleGuild g = getGuild(gid);
            if (g != null) {
                return g.getGP();
            }
            return 0;
        }

        public static int getInvitedId(final int gid) {
            final MapleGuild g = getGuild(gid);
            if (g != null) {
                return g.getInvitedId();
            }
            return 0;
        }

        public static void setInvitedId(final int gid, final int inviteid) {
            final MapleGuild g = getGuild(gid);
            if (g != null) {
                g.setInvitedId(inviteid);
            }
        }

        public static int getGuildLeader(final int guildName) {
            final MapleGuild mga = getGuild(guildName);
            if (mga != null) {
                return mga.getLeaderId();
            }
            return 0;
        }

        public static int getGuildLeader(final String guildName) {
            final MapleGuild mga = getGuildByName(guildName);
            if (mga != null) {
                return mga.getLeaderId();
            }
            return 0;
        }

        public static void save() {
            System.out.println("Saving guilds...");
            lock.writeLock().lock();
            try {
                for (MapleGuild a : guilds.values()) {
                    a.writeToDB(false);
                }
            } finally {
                lock.writeLock().unlock();
            }
        }

        public static List<MapleBBSThread> getBBS(final int gid) {
            final MapleGuild g = getGuild(gid);
            if (g != null) {
                return g.getBBS();
            }
            return null;
        }

        public static int addBBSThread(final int guildid, final String title, final String text, final int icon, final boolean bNotice, final int posterID) {
            final MapleGuild g = getGuild(guildid);
            if (g != null) {
                return g.addBBSThread(title, text, icon, bNotice, posterID);
            }
            return -1;
        }

        public static final void editBBSThread(final int guildid, final int localthreadid, final String title, final String text, final int icon, final int posterID, final int guildRank) {
            final MapleGuild g = getGuild(guildid);
            if (g != null) {
                g.editBBSThread(localthreadid, title, text, icon, posterID, guildRank);
            }
        }

        public static final void deleteBBSThread(final int guildid, final int localthreadid, final int posterID, final int guildRank) {
            final MapleGuild g = getGuild(guildid);
            if (g != null) {
                g.deleteBBSThread(localthreadid, posterID, guildRank);
            }
        }

        public static final void addBBSReply(final int guildid, final int localthreadid, final String text, final int posterID) {
            final MapleGuild g = getGuild(guildid);
            if (g != null) {
                g.addBBSReply(localthreadid, text, posterID);
            }
        }

        public static final void deleteBBSReply(final int guildid, final int localthreadid, final int replyid, final int posterID, final int guildRank) {
            final MapleGuild g = getGuild(guildid);
            if (g != null) {
                g.deleteBBSReply(localthreadid, replyid, posterID, guildRank);
            }
        }

        public static void changeEmblem(int gid, int affectedPlayers, MapleGuild mgs) {
            Broadcast.sendGuildPacket(affectedPlayers, GuildPacket.guildEmblemChange(gid, (short) mgs.getLogoBG(), (byte) mgs.getLogoBGColor(), (short) mgs.getLogo(), (byte) mgs.getLogoColor()), -1, gid);
            setGuildAndRank(affectedPlayers, -1, -1, -1, -1);	//respawn player
        }

        public static void setGuildAndRank(int cid, int guildid, int rank, int contribution, int alliancerank) {
            int ch = Find.findChannel(cid);
            if (ch == -1) {
                // System.out.println("ERROR: cannot find player in given channel");
                return;
            }
            MapleCharacter mc = getStorage(ch).getCharacterById(cid);
            if (mc == null) {
                return;
            }
            boolean bDifferentGuild;
            if (guildid == -1 && rank == -1) { //just need a respawn
                bDifferentGuild = true;
            } else {
                bDifferentGuild = guildid != mc.getGuildId();
                mc.setGuildId(guildid);
                mc.setGuildRank((byte) rank);
                mc.setGuildContribution(contribution);
                mc.setAllianceRank((byte) alliancerank);
                mc.saveGuildStatus();
            }
            if (bDifferentGuild && ch > 0) {
                mc.getMap().broadcastMessage(mc, CField.loadGuildName(mc), false);
				mc.getMap().broadcastMessage(mc, CField.loadGuildIcon(mc), false);
            }
        }
    }

    public static class Broadcast {

        public static void broadcastSmega(byte[] message) {
            for (ChannelServer cs : ChannelServer.getAllInstances()) {
                cs.broadcastSmega(message);
            }
        }

        public static void broadcastGMMessage(byte[] message) {
            for (ChannelServer cs : ChannelServer.getAllInstances()) {
                cs.broadcastGMMessage(message);
            }
        }

        public static void broadcastMessage(byte[] message) {
            for (ChannelServer cs : ChannelServer.getAllInstances()) {
                cs.broadcastMessage(message);
            }
        }

        public static void sendPacket(List<Integer> targetIds, byte[] packet, int exception) {
            MapleCharacter c;
            for (int i : targetIds) {
                if (i == exception) {
                    continue;
                }
                int ch = Find.findChannel(i);
                if (ch < 0) {
                    continue;
                }
                c = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterById(i);
                if (c != null) {
                    c.getClient().getSession().write(packet);
                }
            }
        }

        public static void sendPacket(int targetId, byte[] packet) {
            int ch = Find.findChannel(targetId);
            if (ch < 0) {
                return;
            }
            final MapleCharacter c = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterById(targetId);
            if (c != null) {
                c.getClient().getSession().write(packet);
            }
        }

        public static void sendGuildPacket(int targetIds, byte[] packet, int exception, int guildid) {
            if (targetIds == exception) {
                return;
            }
            int ch = Find.findChannel(targetIds);
            if (ch < 0) {
                return;
            }
            final MapleCharacter c = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterById(targetIds);
            if (c != null && c.getGuildId() == guildid) {
                c.getClient().getSession().write(packet);
            }
        }

        public static void sendFamilyPacket(int targetIds, byte[] packet, int exception, int guildid) {
            if (targetIds == exception) {
                return;
            }
            int ch = Find.findChannel(targetIds);
            if (ch < 0) {
                return;
            }
            final MapleCharacter c = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterById(targetIds);
            if (c != null && c.getFamilyId() == guildid) {
                c.getClient().getSession().write(packet);
            }
        }
    }

    public static class Find {

        private static ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
        private static HashMap<Integer, Integer> idToChannel = new HashMap<Integer, Integer>();
        private static HashMap<String, Integer> nameToChannel = new HashMap<String, Integer>();

        public static void register(int id, String name, int channel) {
            lock.writeLock().lock();
            try {
                idToChannel.put(id, channel);
                nameToChannel.put(name.toLowerCase(), channel);
            } finally {
                lock.writeLock().unlock();
            }
            //System.out.println("Char added: " + id + " " + name + " to channel " + channel);
        }

        public static void forceDeregister(int id) {
            lock.writeLock().lock();
            try {
                idToChannel.remove(id);
            } finally {
                lock.writeLock().unlock();
            }
            //System.out.println("Char removed: " + id);
        }

        public static void forceDeregister(String id) {
            lock.writeLock().lock();
            try {
                nameToChannel.remove(id.toLowerCase());
            } finally {
                lock.writeLock().unlock();
            }
            //System.out.println("Char removed: " + id);
        }

        public static void forceDeregister(int id, String name) {
            lock.writeLock().lock();
            try {
                idToChannel.remove(id);
                nameToChannel.remove(name.toLowerCase());
            } finally {
                lock.writeLock().unlock();
            }
            //System.out.println("Char removed: " + id + " " + name);
        }

        public static int findChannel(int id) {
            Integer ret;
            lock.readLock().lock();
            try {
                ret = idToChannel.get(id);
            } finally {
                lock.readLock().unlock();
            }
            if (ret != null) {
                if (ret != -10 && ret != -20 && ChannelServer.getInstance(ret) == null) { //wha
                    forceDeregister(id);
                    return -1;
                }
                return ret;
            }
            return -1;
        }

        public static int findChannel(String st) {
            Integer ret;
            lock.readLock().lock();
            try {
                ret = nameToChannel.get(st.toLowerCase());
            } finally {
                lock.readLock().unlock();
            }
            if (ret != null) {
                if (ret != -10 && ret != -20 && ChannelServer.getInstance(ret) == null) { //wha
                    forceDeregister(st);
                    return -1;
                }
                return ret;
            }
            return -1;
        }

        public static CharacterIdChannelPair[] multiBuddyFind(int charIdFrom, int[] characterIds) {
            List<CharacterIdChannelPair> foundsChars = new ArrayList<CharacterIdChannelPair>(characterIds.length);
            for (int i : characterIds) {
                int channel = findChannel(i);
                if (channel > 0) {
                    foundsChars.add(new CharacterIdChannelPair(i, channel));
                }
            }
            Collections.sort(foundsChars);
            return foundsChars.toArray(new CharacterIdChannelPair[foundsChars.size()]);
        }
    }

    public static class Alliance {

        private static final Map<Integer, MapleGuildAlliance> alliances = new LinkedHashMap<Integer, MapleGuildAlliance>();
        private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();

        static {
            Collection<MapleGuildAlliance> allGuilds = MapleGuildAlliance.loadAll();
            for (MapleGuildAlliance g : allGuilds) {
                alliances.put(g.getId(), g);
            }
        }

        public static MapleGuildAlliance getAlliance(final int allianceid) {
            MapleGuildAlliance ret = null;
            lock.readLock().lock();
            try {
                ret = alliances.get(allianceid);
            } finally {
                lock.readLock().unlock();
            }
            if (ret == null) {
                lock.writeLock().lock();
                try {
                    ret = new MapleGuildAlliance(allianceid);
                    if (ret == null || ret.getId() <= 0) { //failed to load
                        return null;
                    }
                    alliances.put(allianceid, ret);
                } finally {
                    lock.writeLock().unlock();
                }
            }
            return ret;
        }

        public static int getAllianceLeader(final int allianceid) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.getLeaderId();
            }
            return 0;
        }

        public static void updateAllianceRanks(final int allianceid, final String[] ranks) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                mga.setRank(ranks);
            }
        }

        public static void updateAllianceNotice(final int allianceid, final String notice) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                mga.setNotice(notice);
            }
        }

        public static boolean canInvite(final int allianceid) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.getCapacity() > mga.getNoGuilds();
            }
            return false;
        }

        public static boolean changeAllianceLeader(final int allianceid, final int cid) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.setLeaderId(cid);
            }
            return false;
        }

        public static boolean changeAllianceLeader(final int allianceid, final int cid, final boolean sameGuild) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.setLeaderId(cid, sameGuild);
            }
            return false;
        }

        public static boolean changeAllianceRank(final int allianceid, final int cid, final int change) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.changeAllianceRank(cid, change);
            }
            return false;
        }

        public static boolean changeAllianceCapacity(final int allianceid) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.setCapacity();
            }
            return false;
        }

        public static boolean disbandAlliance(final int allianceid) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.disband();
            }
            return false;
        }

        public static boolean addGuildToAlliance(final int allianceid, final int gid) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.addGuild(gid);
            }
            return false;
        }

        public static boolean removeGuildFromAlliance(final int allianceid, final int gid, final boolean expelled) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.removeGuild(gid, expelled);
            }
            return false;
        }

        public static void sendGuild(final int allianceid) {
            final MapleGuildAlliance alliance = getAlliance(allianceid);
            if (alliance != null) {
                sendGuild(AlliancePacket.getAllianceUpdate(alliance), -1, allianceid);
                sendGuild(AlliancePacket.getGuildAlliance(alliance), -1, allianceid);
            }
        }

        public static void sendGuild(final byte[] packet, final int exceptionId, final int allianceid) {
            final MapleGuildAlliance alliance = getAlliance(allianceid);
            if (alliance != null) {
                for (int i = 0; i < alliance.getNoGuilds(); i++) {
                    int gid = alliance.getGuildId(i);
                    if (gid > 0 && gid != exceptionId) {
                        Guild.guildPacket(gid, packet);
                    }
                }
            }
        }

        public static boolean createAlliance(final String alliancename, final int cid, final int cid2, final int gid, final int gid2) {
            final int allianceid = MapleGuildAlliance.createToDb(cid, alliancename, gid, gid2);
            if (allianceid <= 0) {
                return false;
            }
            final MapleGuild g = Guild.getGuild(gid), g_ = Guild.getGuild(gid2);
            g.setAllianceId(allianceid);
            g_.setAllianceId(allianceid);
            g.changeARank(true);
            g_.changeARank(false);

            final MapleGuildAlliance alliance = getAlliance(allianceid);

            sendGuild(AlliancePacket.createGuildAlliance(alliance), -1, allianceid);
            sendGuild(AlliancePacket.getAllianceInfo(alliance), -1, allianceid);
            sendGuild(AlliancePacket.getGuildAlliance(alliance), -1, allianceid);
            sendGuild(AlliancePacket.changeAlliance(alliance, true), -1, allianceid);
            return true;
        }

        public static void allianceChat(final int gid, final String name, final int cid, final String msg) {
            final MapleGuild g = Guild.getGuild(gid);
            if (g != null) {
                final MapleGuildAlliance ga = getAlliance(g.getAllianceId());
                if (ga != null) {
                    for (int i = 0; i < ga.getNoGuilds(); i++) {
                        final MapleGuild g_ = Guild.getGuild(ga.getGuildId(i));
                        if (g_ != null) {
                            g_.allianceChat(name, cid, msg);
                        }
                    }
                }
            }
        }

        public static void setNewAlliance(final int gid, final int allianceid) {
            final MapleGuildAlliance alliance = getAlliance(allianceid);
            final MapleGuild guild = Guild.getGuild(gid);
            if (alliance != null && guild != null) {
                for (int i = 0; i < alliance.getNoGuilds(); i++) {
                    if (gid == alliance.getGuildId(i)) {
                        guild.setAllianceId(allianceid);
                        guild.broadcast(AlliancePacket.getAllianceInfo(alliance));
                        guild.broadcast(AlliancePacket.getGuildAlliance(alliance));
                        guild.broadcast(AlliancePacket.changeAlliance(alliance, true));
                        guild.changeARank();
                        guild.writeToDB(false);
                    } else {
                        final MapleGuild g_ = Guild.getGuild(alliance.getGuildId(i));
                        if (g_ != null) {
                            g_.broadcast(AlliancePacket.addGuildToAlliance(alliance, guild));
                            g_.broadcast(AlliancePacket.changeGuildInAlliance(alliance, guild, true));
                        }
                    }
                }
            }
        }

        public static void setOldAlliance(final int gid, final boolean expelled, final int allianceid) {
            final MapleGuildAlliance alliance = getAlliance(allianceid);
            final MapleGuild g_ = Guild.getGuild(gid);
            if (alliance != null) {
                for (int i = 0; i < alliance.getNoGuilds(); i++) {
                    final MapleGuild guild = Guild.getGuild(alliance.getGuildId(i));
                    if (guild == null) {
                        if (gid != alliance.getGuildId(i)) {
                            alliance.removeGuild(gid, false, true);
                        }
                        continue; //just skip
                    }
                    if (g_ == null || gid == alliance.getGuildId(i)) {
                        guild.changeARank(5);
                        guild.setAllianceId(0);
                        guild.broadcast(AlliancePacket.disbandAlliance(allianceid));
                    } else if (g_ != null) {
                        guild.broadcast(CWvsContext.serverNotice(5, "[" + g_.getName() + "] Guild has left the alliance."));
                        guild.broadcast(AlliancePacket.changeGuildInAlliance(alliance, g_, false));
                        guild.broadcast(AlliancePacket.removeGuildFromAlliance(alliance, g_, expelled));
                    }

                }
            }

            if (gid == -1) {
                lock.writeLock().lock();
                try {
                    alliances.remove(allianceid);
                } finally {
                    lock.writeLock().unlock();
                }
            }
        }

        public static List<byte[]> getAllianceInfo(final int allianceid, final boolean start) {
            List<byte[]> ret = new ArrayList<byte[]>();
            final MapleGuildAlliance alliance = getAlliance(allianceid);
            if (alliance != null) {
                if (start) {
                    ret.add(AlliancePacket.getAllianceInfo(alliance));
                    ret.add(AlliancePacket.getGuildAlliance(alliance));
                }
                ret.add(AlliancePacket.getAllianceUpdate(alliance));
            }
            return ret;
        }

        public static void save() {
            System.out.println("Saving alliances...");
            lock.writeLock().lock();
            try {
                for (MapleGuildAlliance a : alliances.values()) {
                    a.saveToDb();
                }
            } finally {
                lock.writeLock().unlock();
            }
        }
    }

    public static class Family {

        private static final Map<Integer, MapleFamily> families = new LinkedHashMap<Integer, MapleFamily>();
        private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();

        public static void addLoadedFamily(MapleFamily f) {
            if (f.isProper()) {
                families.put(f.getId(), f);
            }
        }

        public static MapleFamily getFamily(int id) {
            MapleFamily ret = null;
            lock.readLock().lock();
            try {
                ret = families.get(id);
            } finally {
                lock.readLock().unlock();
            }
            if (ret == null) {
                lock.writeLock().lock();
                try {
                    ret = new MapleFamily(id);
                    if (ret == null || ret.getId() <= 0 || !ret.isProper()) { //failed to load
                        return null;
                    }
                    families.put(id, ret);
                } finally {
                    lock.writeLock().unlock();
                }
            }
            return ret;
        }

        public static void memberFamilyUpdate(MapleFamilyCharacter mfc, MapleCharacter mc) {
            MapleFamily f = getFamily(mfc.getFamilyId());
            if (f != null) {
                f.memberLevelJobUpdate(mc);
            }
        }

        public static void setFamilyMemberOnline(MapleFamilyCharacter mfc, boolean bOnline, int channel) {
            MapleFamily f = getFamily(mfc.getFamilyId());
            if (f != null) {
                f.setOnline(mfc.getId(), bOnline, channel);
            }
        }

        public static int setRep(int fid, int cid, int addrep, int oldLevel, String oldName) {
            MapleFamily f = getFamily(fid);
            if (f != null) {
                return f.setRep(cid, addrep, oldLevel, oldName);
            }
            return 0;
        }

        public static void save() {
            System.out.println("Saving families...");
            lock.writeLock().lock();
            try {
                for (MapleFamily a : families.values()) {
                    a.writeToDB(false);
                }
            } finally {
                lock.writeLock().unlock();
            }
        }

        public static void setFamily(int familyid, int seniorid, int junior1, int junior2, int currentrep, int totalrep, int cid) {
            int ch = Find.findChannel(cid);
            if (ch == -1) {
                // System.out.println("ERROR: cannot find player in given channel");
                return;
            }
            MapleCharacter mc = getStorage(ch).getCharacterById(cid);
            if (mc == null) {
                return;
            }
            boolean bDifferent = mc.getFamilyId() != familyid || mc.getSeniorId() != seniorid || mc.getJunior1() != junior1 || mc.getJunior2() != junior2;
            mc.setFamily(familyid, seniorid, junior1, junior2);
            mc.setCurrentRep(currentrep);
            mc.setTotalRep(totalrep);
            if (bDifferent) {
                mc.saveFamilyStatus();
            }
        }

        public static void familyPacket(int gid, byte[] message, int cid) {
            MapleFamily f = getFamily(gid);
            if (f != null) {
                f.broadcast(message, -1, f.getMFC(cid).getPedigree());
            }
        }

        public static void disbandFamily(int gid) {
            MapleFamily g = getFamily(gid);
            if (g != null) {
                lock.writeLock().lock();
                try {
                    families.remove(gid);
                } finally {
                    lock.writeLock().unlock();
                }
                g.disbandFamily();
            }
        }
    }
    private final static int CHANNELS_PER_THREAD = 3;

    public static void registerRespawn() {
        Integer[] chs = ChannelServer.getAllInstance().toArray(new Integer[0]);
        for (int i = 0; i < chs.length; i += CHANNELS_PER_THREAD) {
            WorldTimer.getInstance().register(new Respawn(chs, i), 4500); //divisible by 9000 if possible.
        }
        //3000 good or bad? ive no idea >_>
        //buffs can also be done, but eh
    }

    public static class Respawn implements Runnable { //is putting it here a good idea?

        private int numTimes = 0;
        private final List<ChannelServer> cservs = new ArrayList<ChannelServer>(CHANNELS_PER_THREAD);

        public Respawn(Integer[] chs, int c) {
            StringBuilder s = new StringBuilder("[Respawn Worker] Registered for channels ");
            for (int i = 1; i <= CHANNELS_PER_THREAD && chs.length >= (c + i); i++) {
                cservs.add(ChannelServer.getInstance(c + i));
                s.append(c + i).append(" ");
            }
            System.out.println(s.toString());
        }

        @Override
        public void run() {
            numTimes++;
            long now = System.currentTimeMillis();
            for (ChannelServer cserv : cservs) {
                if (!cserv.hasFinishedShutdown()) {
                    for (MapleMap map : cserv.getMapFactory().getAllLoadedMaps()) { //iterating through each map o_x
                        handleMap(map, numTimes, map.getCharactersSize(), now);
                    }
                }
            }
        }
    }

    public static void handleMap(final MapleMap map, final int numTimes, final int size, final long now) {
        if (map.getItemsSize() > 0) {
            for (MapleMapItem item : map.getAllItemsThreadsafe()) {
                if (item.shouldExpire(now)) {
                    item.expire(map);
                } else if (item.shouldFFA(now)) {
                    item.setDropType((byte) 2);
                }
            }
        }
        if (map.characterSize() > 0 || map.getId() == 931000500) { //jaira hack
            if (map.canSpawn(now)) {
                map.respawn(false, now);
            }
            boolean hurt = map.canHurt(now);
            for (MapleCharacter chr : map.getCharactersThreadsafe()) {
                handleCooldowns(chr, numTimes, hurt, now);
            }
            if (map.getMobsSize() > 0) {
                for (MapleMonster mons : map.getAllMonstersThreadsafe()) {
                    if (mons.isAlive() && mons.shouldKill(now)) {
                        map.killMonster(mons);
                    } else if (mons.isAlive() && mons.shouldDrop(now)) {
                        mons.doDropItem(now);
                    } else if (mons.isAlive() && mons.getStatiSize() > 0) {
                        for (MonsterStatusEffect mse : mons.getAllBuffs()) {
                            if (mse.shouldCancel(now)) {
                                mons.cancelSingleStatus(mse);
                            }
                        }
                    }
                }
            }
        }
    }

    public static void handleCooldowns(final MapleCharacter chr, final int numTimes, final boolean hurt, final long now) { //is putting it here a good idea? expensive?
        if (chr.getCooldownSize() > 0) {
            for (MapleCoolDownValueHolder m : chr.getCooldowns()) {
                if (m.startTime + m.length < now) {
                    final int skil = m.skillId;
                    chr.removeCooldown(skil);
                    chr.getClient().getSession().write(CField.skillCooldown(skil, 0));
                }
            }
        }
        if (chr.isAlive()) {
            if (chr.getJob() == 131 || chr.getJob() == 132) {
                if (chr.canBlood(now)) {
                    chr.doDragonBlood();
                }
            }
            if (chr.canRecover(now)) {
                chr.doRecovery();
            }
            if (chr.canHPRecover(now)) {
                chr.addHP((int) chr.getStat().getHealHP());
            }
            if (chr.canMPRecover(now)) {
                chr.addMP((int) chr.getStat().getHealMP());
            }
            if (chr.canFairy(now)) {
                chr.doFairy();
            }
            if (chr.canFish(now)) {
                chr.doFish(now);
            }
			if (chr.canDOT(now)) {
				chr.doDOT();
			}
        }

        if (chr.getDiseaseSize() > 0) {
            for (MapleDiseaseValueHolder m : chr.getAllDiseases()) {
                if (m != null && m.startTime + m.length < now) {
                    chr.dispelDebuff(m.disease);
                }
            }
        }
        if (numTimes % 7 == 0 && chr.getMount() != null && chr.getMount().canTire(now)) {
            chr.getMount().increaseFatigue();
        }
        if (numTimes % 13 == 0) { //we're parsing through the characters anyway (:
            chr.doFamiliarSchedule(now);
            for (MaplePet pet : chr.getSummonedPets()) {
                if (pet.getPetItemId() == 5000054 && pet.getSecondsLeft() > 0) {
                    pet.setSecondsLeft(pet.getSecondsLeft() - 1);
                    if (pet.getSecondsLeft() <= 0) {
                        chr.unequipPet(pet, true, true);
                        return;
                    }
                }
                int newFullness = pet.getFullness() - PetDataFactory.getHunger(pet.getPetItemId());
                if (newFullness <= 5) {
                    pet.setFullness(15);
                    chr.unequipPet(pet, true, true);
                } else {
                    pet.setFullness(newFullness);
                    chr.getClient().getSession().write(PetPacket.updatePet(pet, chr.getInventory(MapleInventoryType.CASH).getItem(pet.getInventoryPosition()), true));
                }
            }
        }
        if (hurt && chr.isAlive()) {
            if (chr.getInventory(MapleInventoryType.EQUIPPED).findById(chr.getMap().getHPDecProtect()) == null) {
                if (chr.getMapId() == 749040100 && chr.getInventory(MapleInventoryType.CASH).findById(5451000) == null) { //minidungeon
                    chr.addHP(-chr.getMap().getHPDec());
                } else if (chr.getMapId() != 749040100) {
                    chr.addHP(-(chr.getMap().getHPDec() - (chr.getBuffedValue(MapleBuffStat.HP_LOSS_GUARD) == null ? 0 : chr.getBuffedValue(MapleBuffStat.HP_LOSS_GUARD).intValue())));
                }
            }
        }
    }
}

MapleCharacter.java
Code:
package handling.world;

import client.BuddyList;
import client.BuddyList.BuddyAddResult;
import client.BuddyList.BuddyOperation;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import client.BuddylistEntry;

import client.MapleBuffStat;
import client.MapleCharacter;

import client.MapleCoolDownValueHolder;
import client.MapleDiseaseValueHolder;
import client.inventory.MapleInventoryType;
import client.inventory.MaplePet;
import client.inventory.PetDataFactory;
import client.status.MonsterStatusEffect;
import database.DatabaseConnection;

import handling.cashshop.CashShopServer;
import handling.channel.ChannelServer;
import handling.channel.PlayerStorage;
import handling.world.exped.ExpeditionType;
import handling.world.exped.MapleExpedition;
import handling.world.exped.PartySearch;
import handling.world.exped.PartySearchType;
import handling.world.family.MapleFamily;
import handling.world.family.MapleFamilyCharacter;
import handling.world.guild.MapleBBSThread;
import handling.world.guild.MapleGuild;
import handling.world.guild.MapleGuildAlliance;
import handling.world.guild.MapleGuildCharacter;
import java.util.Collection;
import java.util.EnumMap;
import server.Timer.WorldTimer;
import server.life.MapleMonster;
import server.maps.MapleMap;
import server.maps.MapleMapItem;
import tools.CollectionUtil;
import tools.packet.CField;
import tools.packet.CWvsContext;
import tools.packet.CWvsContext.AlliancePacket;
import tools.packet.CWvsContext.BuddylistPacket;
import tools.packet.CWvsContext.ExpeditionPacket;
import tools.packet.CWvsContext.GuildPacket;
import tools.packet.CWvsContext.PartyPacket;
import tools.packet.PetPacket;

public class World {

    //Touch everything...
    public static void init() {
        World.Find.findChannel(0);
        World.Alliance.lock.toString();
        World.Messenger.getMessenger(0);
        World.Party.getParty(0);
    }

    public static String getStatus() {
        StringBuilder ret = new StringBuilder();
        int totalUsers = 0;
        for (ChannelServer cs : ChannelServer.getAllInstances()) {
            ret.append("Channel ");
            ret.append(cs.getChannel());
            ret.append(": ");
            int channelUsers = cs.getConnectedClients();
            totalUsers += channelUsers;
            ret.append(channelUsers);
            ret.append(" users\n");
        }
        ret.append("Total users online: ");
        ret.append(totalUsers);
        ret.append("\n");
        return ret.toString();
    }

    public static Map<Integer, Integer> getConnected() {
        Map<Integer, Integer> ret = new HashMap<Integer, Integer>();
        int total = 0;
        for (ChannelServer cs : ChannelServer.getAllInstances()) {
            int curConnected = cs.getConnectedClients();
            ret.put(cs.getChannel(), curConnected);
            total += curConnected;
        }
        ret.put(0, total);
        return ret;
    }

    public static List<CheaterData> getCheaters() {
        List<CheaterData> allCheaters = new ArrayList<CheaterData>();
        for (ChannelServer cs : ChannelServer.getAllInstances()) {
            allCheaters.addAll(cs.getCheaters());
        }
        Collections.sort(allCheaters);
        return CollectionUtil.copyFirst(allCheaters, 20);
    }

    public static List<CheaterData> getReports() {
        List<CheaterData> allCheaters = new ArrayList<CheaterData>();
        for (ChannelServer cs : ChannelServer.getAllInstances()) {
            allCheaters.addAll(cs.getReports());
        }
        Collections.sort(allCheaters);
        return CollectionUtil.copyFirst(allCheaters, 20);
    }

    public static boolean isConnected(String charName) {
        return Find.findChannel(charName) > 0;
    }

    public static void toggleMegaphoneMuteState() {
        for (ChannelServer cs : ChannelServer.getAllInstances()) {
            cs.toggleMegaphoneMuteState();
        }
    }

    public static void ChannelChange_Data(CharacterTransfer Data, int characterid, int toChannel) {
        getStorage(toChannel).registerPendingPlayer(Data, characterid);
    }

    public static boolean isCharacterListConnected(List<String> charName) {
        for (ChannelServer cs : ChannelServer.getAllInstances()) {
            for (final String c : charName) {
                if (cs.getPlayerStorage().getCharacterByName(c) != null) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean hasMerchant(int accountID, int characterID) {
        for (ChannelServer cs : ChannelServer.getAllInstances()) {
            if (cs.containsMerchant(accountID, characterID)) {
                return true;
            }
        }
        return false;
    }

    public static PlayerStorage getStorage(int channel) {
        if (channel == -20) {
            return CashShopServer.getPlayerStorageMTS();
        } else if (channel == -10) {
            return CashShopServer.getPlayerStorage();
        }
        return ChannelServer.getInstance(channel).getPlayerStorage();
    }

    public static int getPendingCharacterSize() {
        int ret = CashShopServer.getPlayerStorage().pendingCharacterSize() + CashShopServer.getPlayerStorageMTS().pendingCharacterSize();
        for (ChannelServer cserv : ChannelServer.getAllInstances()) {
            ret += cserv.getPlayerStorage().pendingCharacterSize();
        }
        return ret;
    }

    public static boolean isChannelAvailable(final int ch) {
        if (ChannelServer.getInstance(ch) == null || ChannelServer.getInstance(ch).getPlayerStorage() == null) {
            return false;
        }
        return ChannelServer.getInstance(ch).getPlayerStorage().getConnectedClients() < (ch == 1 ? 600 : 400);
    }

    public static class Party {

        private static Map<Integer, MapleParty> parties = new HashMap<Integer, MapleParty>();
        private static Map<Integer, MapleExpedition> expeds = new HashMap<Integer, MapleExpedition>();
        private static Map<PartySearchType, List<PartySearch>> searches = new EnumMap<PartySearchType, List<PartySearch>>(PartySearchType.class);
        private static final AtomicInteger runningPartyId = new AtomicInteger(1), runningExpedId = new AtomicInteger(1);

        static {
            try {
                PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET party = -1, fatigue = 0");
                ps.executeUpdate();
                ps.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            for (PartySearchType pst : PartySearchType.values()) {
                searches.put(pst, new ArrayList<PartySearch>()); //according to client, max 10, even though theres page numbers ?!
            }
        }

        public static void partyChat(int partyid, String chattext, String namefrom) {
            partyChat(partyid, chattext, namefrom, 1);
        }

        public static void expedChat(int expedId, String chattext, String namefrom) {
            MapleExpedition party = getExped(expedId);
            if (party == null) {
                return;
            }
            for (int i : party.getParties()) {
                partyChat(i, chattext, namefrom, 4);
            }
        }

        public static void expedPacket(int expedId, byte[] packet, MaplePartyCharacter exception) {
            MapleExpedition party = getExped(expedId);
            if (party == null) {
                return;
            }
            for (int i : party.getParties()) {
                partyPacket(i, packet, exception);
            }
        }

        public static void partyPacket(int partyid, byte[] packet, MaplePartyCharacter exception) {
            MapleParty party = getParty(partyid);
            if (party == null) {
                return;
            }

            for (MaplePartyCharacter partychar : party.getMembers()) {
                int ch = Find.findChannel(partychar.getName());
                if (ch > 0 && (exception == null || partychar.getId() != exception.getId())) {
                    MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(partychar.getName());
                    if (chr != null) { //Extra check just in case
                        chr.getClient().getSession().write(packet);
                    }
                }
            }
        }

        public static void partyChat(int partyid, String chattext, String namefrom, int mode) {
            MapleParty party = getParty(partyid);
            if (party == null) {
                return;
            }

            for (MaplePartyCharacter partychar : party.getMembers()) {
                int ch = Find.findChannel(partychar.getName());
                if (ch > 0) {
                    MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(partychar.getName());
                    if (chr != null && !chr.getName().equalsIgnoreCase(namefrom)) { //Extra check just in case
                        chr.getClient().getSession().write(CField.multiChat(namefrom, chattext, mode));
                        if (chr.getClient().isMonitored()) {
                            World.Broadcast.broadcastGMMessage(CWvsContext.serverNotice(6, "[GM Message] " + namefrom + " said to " + chr.getName() + " (Party): " + chattext));
                        }
                    }
                }
            }
        }

        public static void partyMessage(int partyid, String chattext) {
            MapleParty party = getParty(partyid);
            if (party == null) {
                return;
            }

            for (MaplePartyCharacter partychar : party.getMembers()) {
                int ch = Find.findChannel(partychar.getName());
                if (ch > 0) {
                    MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(partychar.getName());
                    if (chr != null) { //Extra check just in case
                        chr.dropMessage(5, chattext);
                    }
                }
            }
        }

        public static void expedMessage(int expedId, String chattext) {
            MapleExpedition party = getExped(expedId);
            if (party == null) {
                return;
            }
            for (int i : party.getParties()) {
                partyMessage(i, chattext);
            }
        }

        public static void updateParty(int partyid, PartyOperation operation, MaplePartyCharacter target) {
            MapleParty party = getParty(partyid);
            if (party == null) {
                return; //Don't update, just return. And definitely don't throw a damn exception.
                //throw new IllegalArgumentException("no party with the specified partyid exists");
            }
            final int oldExped = party.getExpeditionId();
            int oldInd = -1;
            if (oldExped > 0) {
                MapleExpedition exped = getExped(oldExped);
                if (exped != null) {
                    oldInd = exped.getIndex(partyid);
                }
            }
            switch (operation) {
                case JOIN:
                    party.addMember(target);
                    if (party.getMembers().size() >= 6) {
                        PartySearch toRemove = getSearchByParty(partyid);
                        if (toRemove != null) {
                            removeSearch(toRemove, "The Party Listing was removed because the party is full.");
                        } else if (party.getExpeditionId() > 0) {
                            MapleExpedition exped = getExped(party.getExpeditionId());
                            if (exped != null && exped.getAllMembers() >= exped.getType().maxMembers) {
                                toRemove = getSearchByExped(exped.getId());
                                if (toRemove != null) {
                                    removeSearch(toRemove, "The Party Listing was removed because the party is full.");
                                }
                            }
                        }
                    }
                    break;
                case EXPEL:
                case LEAVE:
                    party.removeMember(target);
                    break;
                case DISBAND:
                    disbandParty(partyid);
                    break;
                case SILENT_UPDATE:
                case LOG_ONOFF:
                    party.updateMember(target);
                    break;
                case CHANGE_LEADER:
                case CHANGE_LEADER_DC:
                    party.setLeader(target);
                    break;
                default:
                    throw new RuntimeException("Unhandeled updateParty operation " + operation.name());
            }
            if (operation == PartyOperation.LEAVE || operation == PartyOperation.EXPEL) {
                int chz = Find.findChannel(target.getName());
                if (chz > 0) {
                    MapleCharacter chr = getStorage(chz).getCharacterByName(target.getName());
                    if (chr != null) {
                        chr.setParty(null);
                        if (oldExped > 0) {
                            chr.getClient().getSession().write(ExpeditionPacket.expeditionMessage(80));
                        }
                        chr.getClient().getSession().write(PartyPacket.updateParty(chr.getClient().getChannel(), party, operation, target));
                    }
                }
                if (target.getId() == party.getLeader().getId() && party.getMembers().size() > 0) { //pass on lead
                    MaplePartyCharacter lchr = null;
                    for (MaplePartyCharacter pchr : party.getMembers()) {
                        if (pchr != null && (lchr == null || lchr.getLevel() < pchr.getLevel())) {
                            lchr = pchr;
                        }
                    }
                    if (lchr != null) {
                        updateParty(partyid, PartyOperation.CHANGE_LEADER_DC, lchr);
                    }
                }
            }
            if (party.getMembers().size() <= 0) { //no members left, plz disband
                disbandParty(partyid);
            }
            for (MaplePartyCharacter partychar : party.getMembers()) {
                if (partychar == null) {
                    continue;
                }
                int ch = Find.findChannel(partychar.getName());
                if (ch > 0) {
                    MapleCharacter chr = getStorage(ch).getCharacterByName(partychar.getName());
                    if (chr != null) {
                        if (operation == PartyOperation.DISBAND) {
                            chr.setParty(null);
                            if (oldExped > 0) {
                                chr.getClient().getSession().write(ExpeditionPacket.expeditionMessage(83));
                            }
                        } else {
                            chr.setParty(party);
                        }
                        chr.getClient().getSession().write(PartyPacket.updateParty(chr.getClient().getChannel(), party, operation, target));
                    }
                }
            }
            if (oldExped > 0) {
                expedPacket(oldExped, ExpeditionPacket.expeditionUpdate(oldInd, party), operation == PartyOperation.LOG_ONOFF || operation == PartyOperation.SILENT_UPDATE ? target : null);
            }
        }

        public static MapleParty createParty(MaplePartyCharacter chrfor) {
            MapleParty party = new MapleParty(runningPartyId.getAndIncrement(), chrfor);
            parties.put(party.getId(), party);
            return party;
        }

        public static MapleParty createParty(MaplePartyCharacter chrfor, int expedId) {
            ExpeditionType ex = ExpeditionType.getById(expedId);
            MapleParty party = new MapleParty(runningPartyId.getAndIncrement(), chrfor, ex != null ? runningExpedId.getAndIncrement() : -1);
            parties.put(party.getId(), party);
            if (ex != null) {
                final MapleExpedition exp = new MapleExpedition(ex, chrfor.getId(), party.getExpeditionId());
                exp.getParties().add(party.getId());
                expeds.put(party.getExpeditionId(), exp);
            }
            return party;
        }

        public static MapleParty createPartyAndAdd(MaplePartyCharacter chrfor, int expedId) {
            MapleExpedition ex = getExped(expedId);
            if (ex == null) {
                return null;
            }
            MapleParty party = new MapleParty(runningPartyId.getAndIncrement(), chrfor, expedId);
            parties.put(party.getId(), party);
            ex.getParties().add(party.getId());
            return party;
        }

        public static MapleParty getParty(int partyid) {
            return parties.get(partyid);
        }

        public static MapleExpedition getExped(int partyid) {
            return expeds.get(partyid);
        }

        public static MapleExpedition disbandExped(int partyid) {
            PartySearch toRemove = getSearchByExped(partyid);
            if (toRemove != null) {
                removeSearch(toRemove, "The Party Listing was removed because the party disbanded.");
            }
            final MapleExpedition ret = expeds.remove(partyid);
            if (ret != null) {
                for (int p : ret.getParties()) {
                    MapleParty pp = getParty(p);
                    if (pp != null) {
                        updateParty(p, PartyOperation.DISBAND, pp.getLeader());
                    }
                }
            }
            return ret;
        }

        public static MapleParty disbandParty(int partyid) {
            PartySearch toRemove = getSearchByParty(partyid);
            if (toRemove != null) {
                removeSearch(toRemove, "The Party Listing was removed because the party disbanded.");
            }
            final MapleParty ret = parties.remove(partyid);
            if (ret == null) {
                return null;
            }
            if (ret.getExpeditionId() > 0) {
                MapleExpedition me = getExped(ret.getExpeditionId());
                if (me != null) {
                    final int ind = me.getIndex(partyid);
                    if (ind >= 0) {
                        me.getParties().remove(ind);
                        expedPacket(me.getId(), ExpeditionPacket.expeditionUpdate(ind, null), null);
                    }
                }
            }
            ret.disband();
            return ret;
        }

        public static List<PartySearch> searchParty(PartySearchType pst) {
            return searches.get(pst);
        }

        public static void removeSearch(PartySearch ps, String text) {
            List<PartySearch> ss = searches.get(ps.getType());
            if (ss.contains(ps)) {
                ss.remove(ps);
                ps.cancelRemoval();
                if (ps.getType().exped) {
                    expedMessage(ps.getId(), text);
                } else {
                    partyMessage(ps.getId(), text);
                }
            }
        }

        public static void addSearch(PartySearch ps) {
            searches.get(ps.getType()).add(ps);
        }

        public static PartySearch getSearch(MapleParty party) {
            for (List<PartySearch> ps : searches.values()) {
                for (PartySearch p : ps) {
                    if ((p.getId() == party.getId() && !p.getType().exped) || (p.getId() == party.getExpeditionId() && p.getType().exped)) {
                        return p;
                    }
                }
            }
            return null;
        }

        public static PartySearch getSearchByParty(int partyId) {
            for (List<PartySearch> ps : searches.values()) {
                for (PartySearch p : ps) {
                    if (p.getId() == partyId && !p.getType().exped) {
                        return p;
                    }
                }
            }
            return null;
        }

        public static PartySearch getSearchByExped(int partyId) {
            for (List<PartySearch> ps : searches.values()) {
                for (PartySearch p : ps) {
                    if (p.getId() == partyId && p.getType().exped) {
                        return p;
                    }
                }
            }
            return null;
        }

        public static boolean partyListed(MapleParty party) {
            return getSearchByParty(party.getId()) != null;
        }
    }

    public static class Buddy {

        public static void buddyChat(int[] recipientCharacterIds, int cidFrom, String nameFrom, String chattext) {
            for (int characterId : recipientCharacterIds) {
                int ch = Find.findChannel(characterId);
                if (ch > 0) {
                    MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterById(characterId);
                    if (chr != null && chr.getBuddylist().containsVisible(cidFrom)) {
                        chr.getClient().getSession().write(CField.multiChat(nameFrom, chattext, 0));
                        if (chr.getClient().isMonitored()) {
                            World.Broadcast.broadcastGMMessage(CWvsContext.serverNotice(6, "[GM Message] " + nameFrom + " said to " + chr.getName() + " (Buddy): " + chattext));
                        }
                    }
                }
            }
        }

        private static void updateBuddies(int characterId, int channel, int[] buddies, boolean offline) {
            for (int buddy : buddies) {
                int ch = Find.findChannel(buddy);
                if (ch > 0) {
                    MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterById(buddy);
                    if (chr != null) {
                        BuddylistEntry ble = chr.getBuddylist().get(characterId);
                        if (ble != null && ble.isVisible()) {
                            int mcChannel;
                            if (offline) {
                                ble.setChannel(-1);
                                mcChannel = -1;
                            } else {
                                ble.setChannel(channel);
                                mcChannel = channel - 1;
                            }
                            chr.getClient().getSession().write(BuddylistPacket.updateBuddyChannel(ble.getCharacterId(), mcChannel));
                        }
                    }
                }
            }
        }

        public static void buddyChanged(int cid, int cidFrom, String name, int channel, BuddyOperation operation, String group) {
            int ch = Find.findChannel(cid);
            if (ch > 0) {
                final MapleCharacter addChar = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterById(cid);
                if (addChar != null) {
                    final BuddyList buddylist = addChar.getBuddylist();
                    switch (operation) {
                        case ADDED:
                            if (buddylist.contains(cidFrom)) {
                                buddylist.put(new BuddylistEntry(name, cidFrom, group, channel, true));
                                addChar.getClient().getSession().write(BuddylistPacket.updateBuddyChannel(cidFrom, channel - 1));
                            }
                            break;
                        case DELETED:
                            if (buddylist.contains(cidFrom)) {
                                buddylist.put(new BuddylistEntry(name, cidFrom, group, -1, buddylist.get(cidFrom).isVisible()));
                                addChar.getClient().getSession().write(BuddylistPacket.updateBuddyChannel(cidFrom, -1));
                            }
                            break;
                    }
                }
            }
        }

        public static BuddyAddResult requestBuddyAdd(String addName, int channelFrom, int cidFrom, String nameFrom, int levelFrom, int jobFrom) {
            int ch = Find.findChannel(cidFrom);
            if (ch > 0) {
                final MapleCharacter addChar = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(addName);
                if (addChar != null) {
                    final BuddyList buddylist = addChar.getBuddylist();
                    if (buddylist.isFull()) {
                        return BuddyAddResult.BUDDYLIST_FULL;
                    }
                    if (!buddylist.contains(cidFrom)) {
                        buddylist.addBuddyRequest(addChar.getClient(), cidFrom, nameFrom, channelFrom, levelFrom, jobFrom);
                    } else {
                        if (buddylist.containsVisible(cidFrom)) {
                            return BuddyAddResult.ALREADY_ON_LIST;
                        }
                    }
                }
            }
            return BuddyAddResult.OK;
        }

        public static void loggedOn(String name, int characterId, int channel, int[] buddies) {
            updateBuddies(characterId, channel, buddies, false);
        }

        public static void loggedOff(String name, int characterId, int channel, int[] buddies) {
            updateBuddies(characterId, channel, buddies, true);
        }
    }

    public static class Messenger {

        private static Map<Integer, MapleMessenger> messengers = new HashMap<Integer, MapleMessenger>();
        private static final AtomicInteger runningMessengerId = new AtomicInteger();

        static {
            runningMessengerId.set(1);
        }

        public static MapleMessenger createMessenger(MapleMessengerCharacter chrfor) {
            int messengerid = runningMessengerId.getAndIncrement();
            MapleMessenger messenger = new MapleMessenger(messengerid, chrfor);
            messengers.put(messenger.getId(), messenger);
            return messenger;
        }

        public static void declineChat(String target, String namefrom) {
            int ch = Find.findChannel(target);
            if (ch > 0) {
                ChannelServer cs = ChannelServer.getInstance(ch);
                MapleCharacter chr = cs.getPlayerStorage().getCharacterByName(target);
                if (chr != null) {
                    MapleMessenger messenger = chr.getMessenger();
                    if (messenger != null) {
                        chr.getClient().getSession().write(CField.messengerNote(namefrom, 5, 0));
                    }
                }
            }
        }

        public static MapleMessenger getMessenger(int messengerid) {
            return messengers.get(messengerid);
        }

        public static void leaveMessenger(int messengerid, MapleMessengerCharacter target) {
            MapleMessenger messenger = getMessenger(messengerid);
            if (messenger == null) {
                throw new IllegalArgumentException("No messenger with the specified messengerid exists");
            }
            int position = messenger.getPositionByName(target.getName());
            messenger.removeMember(target);

            for (MapleMessengerCharacter mmc : messenger.getMembers()) {
                if (mmc != null) {
                    int ch = Find.findChannel(mmc.getId());
                    if (ch > 0) {
                        MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(mmc.getName());
                        if (chr != null) {
                            chr.getClient().getSession().write(CField.removeMessengerPlayer(position));
                        }
                    }
                }
            }
        }

        public static void silentLeaveMessenger(int messengerid, MapleMessengerCharacter target) {
            MapleMessenger messenger = getMessenger(messengerid);
            if (messenger == null) {
                throw new IllegalArgumentException("No messenger with the specified messengerid exists");
            }
            messenger.silentRemoveMember(target);
        }

        public static void silentJoinMessenger(int messengerid, MapleMessengerCharacter target) {
            MapleMessenger messenger = getMessenger(messengerid);
            if (messenger == null) {
                throw new IllegalArgumentException("No messenger with the specified messengerid exists");
            }
            messenger.silentAddMember(target);
        }

        public static void updateMessenger(int messengerid, String namefrom, int fromchannel) {
            MapleMessenger messenger = getMessenger(messengerid);
            int position = messenger.getPositionByName(namefrom);

            for (MapleMessengerCharacter messengerchar : messenger.getMembers()) {
                if (messengerchar != null && !messengerchar.getName().equals(namefrom)) {
                    int ch = Find.findChannel(messengerchar.getName());
                    if (ch > 0) {
                        MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(messengerchar.getName());
                        if (chr != null) {
                            MapleCharacter from = ChannelServer.getInstance(fromchannel).getPlayerStorage().getCharacterByName(namefrom);
                            chr.getClient().getSession().write(CField.updateMessengerPlayer(namefrom, from, position, fromchannel - 1));
                        }
                    }
                }
            }
        }

        public static void joinMessenger(int messengerid, MapleMessengerCharacter target, String from, int fromchannel) {
            MapleMessenger messenger = getMessenger(messengerid);
            if (messenger == null) {
                throw new IllegalArgumentException("No messenger with the specified messengerid exists");
            }
            messenger.addMember(target);
            int position = messenger.getPositionByName(target.getName());
            for (MapleMessengerCharacter messengerchar : messenger.getMembers()) {
                if (messengerchar != null) {
                    int mposition = messenger.getPositionByName(messengerchar.getName());
                    int ch = Find.findChannel(messengerchar.getName());
                    if (ch > 0) {
                        MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(messengerchar.getName());
                        if (chr != null) {
                            if (!messengerchar.getName().equals(from)) {
                                MapleCharacter fromCh = ChannelServer.getInstance(fromchannel).getPlayerStorage().getCharacterByName(from);
                                if (fromCh != null) {
                                    chr.getClient().getSession().write(CField.addMessengerPlayer(from, fromCh, position, fromchannel - 1));
                                    fromCh.getClient().getSession().write(CField.addMessengerPlayer(chr.getName(), chr, mposition, messengerchar.getChannel() - 1));
                                }
                            } else {
                                chr.getClient().getSession().write(CField.joinMessenger(mposition));
                            }
                        }
                    }
                }
            }
        }

        public static void messengerChat(int messengerid, String charname, String text, String namefrom) {
            MapleMessenger messenger = getMessenger(messengerid);
            if (messenger == null) {
                throw new IllegalArgumentException("No messenger with the specified messengerid exists");
            }

            for (MapleMessengerCharacter messengerchar : messenger.getMembers()) {
                if (messengerchar != null && !messengerchar.getName().equals(namefrom)) {
                    int ch = Find.findChannel(messengerchar.getName());
                    if (ch > 0) {
                        MapleCharacter chr = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(messengerchar.getName());
                        if (chr != null) {
                            chr.getClient().getSession().write(CField.messengerChat(charname, text));
                        }
                    }
                }
            }
        }

        public static void messengerInvite(String sender, int messengerid, String target, int fromchannel, boolean gm) {

            if (isConnected(target)) {

                int ch = Find.findChannel(target);
                if (ch > 0) {
                    MapleCharacter from = ChannelServer.getInstance(fromchannel).getPlayerStorage().getCharacterByName(sender);
                    MapleCharacter targeter = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(target);
                    if (targeter != null && targeter.getMessenger() == null) {
                        if (!targeter.isIntern() || gm) {
                            targeter.getClient().getSession().write(CField.messengerInvite(sender, messengerid));
                            from.getClient().getSession().write(CField.messengerNote(target, 4, 1));
                        } else {
                            from.getClient().getSession().write(CField.messengerNote(target, 4, 0));
                        }
                    } else {
                        from.getClient().getSession().write(CField.messengerChat(sender, " : " + target + " is already using Maple Messenger"));
                    }
                }
            }

        }
    }

    public static class Guild {

        private static final Map<Integer, MapleGuild> guilds = new LinkedHashMap<Integer, MapleGuild>();
        private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();

        public static void addLoadedGuild(MapleGuild f) {
            if (f.isProper()) {
                guilds.put(f.getId(), f);
            }
        }

        public static int createGuild(int leaderId, String name) {
            return MapleGuild.createGuild(leaderId, name);
        }

        public static MapleGuild getGuild(int id) {
            MapleGuild ret = null;
            lock.readLock().lock();
            try {
                ret = guilds.get(id);
            } finally {
                lock.readLock().unlock();
            }
            if (ret == null) {
                lock.writeLock().lock();
                try {
                    ret = new MapleGuild(id);
                    if (ret == null || ret.getId() <= 0 || !ret.isProper()) { //failed to load
                        return null;
                    }
                    guilds.put(id, ret);
                } finally {
                    lock.writeLock().unlock();
                }
            }
            return ret; //Guild doesn't exist?
        }

        public static MapleGuild getGuildByName(String guildName) {
            lock.readLock().lock();
            try {
                for (MapleGuild g : guilds.values()) {
                    if (g.getName().equalsIgnoreCase(guildName)) {
                        return g;
                    }
                }
                return null;
            } finally {
                lock.readLock().unlock();
            }
        }

        public static MapleGuild getGuild(MapleCharacter mc) {
            return getGuild(mc.getGuildId());
        }

        public static void setGuildMemberOnline(MapleGuildCharacter mc, boolean bOnline, int channel) {
            MapleGuild g = getGuild(mc.getGuildId());
            if (g != null) {
                g.setOnline(mc.getId(), bOnline, channel);
            }
        }

        public static void guildPacket(int gid, byte[] message) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.broadcast(message);
            }
        }

        public static int addGuildMember(MapleGuildCharacter mc) {
            MapleGuild g = getGuild(mc.getGuildId());
            if (g != null) {
                return g.addGuildMember(mc);
            }
            return 0;
        }

        public static void leaveGuild(MapleGuildCharacter mc) {
            MapleGuild g = getGuild(mc.getGuildId());
            if (g != null) {
                g.leaveGuild(mc);
            }
        }

        public static void guildChat(int gid, String name, int cid, String msg) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.guildChat(name, cid, msg);
            }
        }

        public static void changeRank(int gid, int cid, int newRank) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.changeRank(cid, newRank);
            }
        }

        public static void expelMember(MapleGuildCharacter initiator, String name, int cid) {
            MapleGuild g = getGuild(initiator.getGuildId());
            if (g != null) {
                g.expelMember(initiator, name, cid);
            }
        }

        public static void setGuildNotice(int gid, String notice) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.setGuildNotice(notice);
            }
        }

        public static void setGuildLeader(int gid, int cid) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.changeGuildLeader(cid);
            }
        }

        public static int getSkillLevel(int gid, int sid) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                return g.getSkillLevel(sid);
            }
            return 0;
        }

        public static boolean purchaseSkill(int gid, int sid, String name, int cid) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                return g.purchaseSkill(sid, name, cid);
            }
            return false;
        }

        public static boolean activateSkill(int gid, int sid, String name) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                return g.activateSkill(sid, name);
            }
            return false;
        }

        public static void memberLevelJobUpdate(MapleGuildCharacter mc) {
            MapleGuild g = getGuild(mc.getGuildId());
            if (g != null) {
                g.memberLevelJobUpdate(mc);
            }
        }

        public static void changeRankTitle(int gid, String[] ranks) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.changeRankTitle(ranks);
            }
        }

        public static void setGuildEmblem(int gid, short bg, byte bgcolor, short logo, byte logocolor) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.setGuildEmblem(bg, bgcolor, logo, logocolor);
            }
        }

        public static void disbandGuild(int gid) {
            MapleGuild g = getGuild(gid);
            lock.writeLock().lock();
            try {
                if (g != null) {
                    g.disbandGuild();
                    guilds.remove(gid);
                }
            } finally {
                lock.writeLock().unlock();
            }
        }

        public static void deleteGuildCharacter(int guildid, int charid) {

            //ensure it's loaded on world server
            //setGuildMemberOnline(mc, false, -1);
            MapleGuild g = getGuild(guildid);
            if (g != null) {
                MapleGuildCharacter mc = g.getMGC(charid);
                if (mc != null) {
                    if (mc.getGuildRank() > 1) //not leader
                    {
                        g.leaveGuild(mc);
                    } else {
                        g.disbandGuild();
                    }
                }
            }
        }

        public static boolean increaseGuildCapacity(int gid, boolean b) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                return g.increaseCapacity(b);
            }
            return false;
        }

        public static void gainGP(int gid, int amount) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.gainGP(amount);
            }
        }

        public static void gainGP(int gid, int amount, int cid) {
            MapleGuild g = getGuild(gid);
            if (g != null) {
                g.gainGP(amount, false, cid);
            }
        }

        public static int getGP(final int gid) {
            final MapleGuild g = getGuild(gid);
            if (g != null) {
                return g.getGP();
            }
            return 0;
        }

        public static int getInvitedId(final int gid) {
            final MapleGuild g = getGuild(gid);
            if (g != null) {
                return g.getInvitedId();
            }
            return 0;
        }

        public static void setInvitedId(final int gid, final int inviteid) {
            final MapleGuild g = getGuild(gid);
            if (g != null) {
                g.setInvitedId(inviteid);
            }
        }

        public static int getGuildLeader(final int guildName) {
            final MapleGuild mga = getGuild(guildName);
            if (mga != null) {
                return mga.getLeaderId();
            }
            return 0;
        }

        public static int getGuildLeader(final String guildName) {
            final MapleGuild mga = getGuildByName(guildName);
            if (mga != null) {
                return mga.getLeaderId();
            }
            return 0;
        }

        public static void save() {
            System.out.println("Saving guilds...");
            lock.writeLock().lock();
            try {
                for (MapleGuild a : guilds.values()) {
                    a.writeToDB(false);
                }
            } finally {
                lock.writeLock().unlock();
            }
        }

        public static List<MapleBBSThread> getBBS(final int gid) {
            final MapleGuild g = getGuild(gid);
            if (g != null) {
                return g.getBBS();
            }
            return null;
        }

        public static int addBBSThread(final int guildid, final String title, final String text, final int icon, final boolean bNotice, final int posterID) {
            final MapleGuild g = getGuild(guildid);
            if (g != null) {
                return g.addBBSThread(title, text, icon, bNotice, posterID);
            }
            return -1;
        }

        public static final void editBBSThread(final int guildid, final int localthreadid, final String title, final String text, final int icon, final int posterID, final int guildRank) {
            final MapleGuild g = getGuild(guildid);
            if (g != null) {
                g.editBBSThread(localthreadid, title, text, icon, posterID, guildRank);
            }
        }

        public static final void deleteBBSThread(final int guildid, final int localthreadid, final int posterID, final int guildRank) {
            final MapleGuild g = getGuild(guildid);
            if (g != null) {
                g.deleteBBSThread(localthreadid, posterID, guildRank);
            }
        }

        public static final void addBBSReply(final int guildid, final int localthreadid, final String text, final int posterID) {
            final MapleGuild g = getGuild(guildid);
            if (g != null) {
                g.addBBSReply(localthreadid, text, posterID);
            }
        }

        public static final void deleteBBSReply(final int guildid, final int localthreadid, final int replyid, final int posterID, final int guildRank) {
            final MapleGuild g = getGuild(guildid);
            if (g != null) {
                g.deleteBBSReply(localthreadid, replyid, posterID, guildRank);
            }
        }

        public static void changeEmblem(int gid, int affectedPlayers, MapleGuild mgs) {
            Broadcast.sendGuildPacket(affectedPlayers, GuildPacket.guildEmblemChange(gid, (short) mgs.getLogoBG(), (byte) mgs.getLogoBGColor(), (short) mgs.getLogo(), (byte) mgs.getLogoColor()), -1, gid);
            setGuildAndRank(affectedPlayers, -1, -1, -1, -1);	//respawn player
        }

        public static void setGuildAndRank(int cid, int guildid, int rank, int contribution, int alliancerank) {
            int ch = Find.findChannel(cid);
            if (ch == -1) {
                // System.out.println("ERROR: cannot find player in given channel");
                return;
            }
            MapleCharacter mc = getStorage(ch).getCharacterById(cid);
            if (mc == null) {
                return;
            }
            boolean bDifferentGuild;
            if (guildid == -1 && rank == -1) { //just need a respawn
                bDifferentGuild = true;
            } else {
                bDifferentGuild = guildid != mc.getGuildId();
                mc.setGuildId(guildid);
                mc.setGuildRank((byte) rank);
                mc.setGuildContribution(contribution);
                mc.setAllianceRank((byte) alliancerank);
                mc.saveGuildStatus();
            }
            if (bDifferentGuild && ch > 0) {
                mc.getMap().broadcastMessage(mc, CField.loadGuildName(mc), false);
				mc.getMap().broadcastMessage(mc, CField.loadGuildIcon(mc), false);
            }
        }
    }

    public static class Broadcast {

        public static void broadcastSmega(byte[] message) {
            for (ChannelServer cs : ChannelServer.getAllInstances()) {
                cs.broadcastSmega(message);
            }
        }

        public static void broadcastGMMessage(byte[] message) {
            for (ChannelServer cs : ChannelServer.getAllInstances()) {
                cs.broadcastGMMessage(message);
            }
        }

        public static void broadcastMessage(byte[] message) {
            for (ChannelServer cs : ChannelServer.getAllInstances()) {
                cs.broadcastMessage(message);
            }
        }

        public static void sendPacket(List<Integer> targetIds, byte[] packet, int exception) {
            MapleCharacter c;
            for (int i : targetIds) {
                if (i == exception) {
                    continue;
                }
                int ch = Find.findChannel(i);
                if (ch < 0) {
                    continue;
                }
                c = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterById(i);
                if (c != null) {
                    c.getClient().getSession().write(packet);
                }
            }
        }

        public static void sendPacket(int targetId, byte[] packet) {
            int ch = Find.findChannel(targetId);
            if (ch < 0) {
                return;
            }
            final MapleCharacter c = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterById(targetId);
            if (c != null) {
                c.getClient().getSession().write(packet);
            }
        }

        public static void sendGuildPacket(int targetIds, byte[] packet, int exception, int guildid) {
            if (targetIds == exception) {
                return;
            }
            int ch = Find.findChannel(targetIds);
            if (ch < 0) {
                return;
            }
            final MapleCharacter c = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterById(targetIds);
            if (c != null && c.getGuildId() == guildid) {
                c.getClient().getSession().write(packet);
            }
        }

        public static void sendFamilyPacket(int targetIds, byte[] packet, int exception, int guildid) {
            if (targetIds == exception) {
                return;
            }
            int ch = Find.findChannel(targetIds);
            if (ch < 0) {
                return;
            }
            final MapleCharacter c = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterById(targetIds);
            if (c != null && c.getFamilyId() == guildid) {
                c.getClient().getSession().write(packet);
            }
        }
    }

    public static class Find {

        private static ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
        private static HashMap<Integer, Integer> idToChannel = new HashMap<Integer, Integer>();
        private static HashMap<String, Integer> nameToChannel = new HashMap<String, Integer>();

        public static void register(int id, String name, int channel) {
            lock.writeLock().lock();
            try {
                idToChannel.put(id, channel);
                nameToChannel.put(name.toLowerCase(), channel);
            } finally {
                lock.writeLock().unlock();
            }
            //System.out.println("Char added: " + id + " " + name + " to channel " + channel);
        }

        public static void forceDeregister(int id) {
            lock.writeLock().lock();
            try {
                idToChannel.remove(id);
            } finally {
                lock.writeLock().unlock();
            }
            //System.out.println("Char removed: " + id);
        }

        public static void forceDeregister(String id) {
            lock.writeLock().lock();
            try {
                nameToChannel.remove(id.toLowerCase());
            } finally {
                lock.writeLock().unlock();
            }
            //System.out.println("Char removed: " + id);
        }

        public static void forceDeregister(int id, String name) {
            lock.writeLock().lock();
            try {
                idToChannel.remove(id);
                nameToChannel.remove(name.toLowerCase());
            } finally {
                lock.writeLock().unlock();
            }
            //System.out.println("Char removed: " + id + " " + name);
        }

        public static int findChannel(int id) {
            Integer ret;
            lock.readLock().lock();
            try {
                ret = idToChannel.get(id);
            } finally {
                lock.readLock().unlock();
            }
            if (ret != null) {
                if (ret != -10 && ret != -20 && ChannelServer.getInstance(ret) == null) { //wha
                    forceDeregister(id);
                    return -1;
                }
                return ret;
            }
            return -1;
        }

        public static int findChannel(String st) {
            Integer ret;
            lock.readLock().lock();
            try {
                ret = nameToChannel.get(st.toLowerCase());
            } finally {
                lock.readLock().unlock();
            }
            if (ret != null) {
                if (ret != -10 && ret != -20 && ChannelServer.getInstance(ret) == null) { //wha
                    forceDeregister(st);
                    return -1;
                }
                return ret;
            }
            return -1;
        }

        public static CharacterIdChannelPair[] multiBuddyFind(int charIdFrom, int[] characterIds) {
            List<CharacterIdChannelPair> foundsChars = new ArrayList<CharacterIdChannelPair>(characterIds.length);
            for (int i : characterIds) {
                int channel = findChannel(i);
                if (channel > 0) {
                    foundsChars.add(new CharacterIdChannelPair(i, channel));
                }
            }
            Collections.sort(foundsChars);
            return foundsChars.toArray(new CharacterIdChannelPair[foundsChars.size()]);
        }
    }

    public static class Alliance {

        private static final Map<Integer, MapleGuildAlliance> alliances = new LinkedHashMap<Integer, MapleGuildAlliance>();
        private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();

        static {
            Collection<MapleGuildAlliance> allGuilds = MapleGuildAlliance.loadAll();
            for (MapleGuildAlliance g : allGuilds) {
                alliances.put(g.getId(), g);
            }
        }

        public static MapleGuildAlliance getAlliance(final int allianceid) {
            MapleGuildAlliance ret = null;
            lock.readLock().lock();
            try {
                ret = alliances.get(allianceid);
            } finally {
                lock.readLock().unlock();
            }
            if (ret == null) {
                lock.writeLock().lock();
                try {
                    ret = new MapleGuildAlliance(allianceid);
                    if (ret == null || ret.getId() <= 0) { //failed to load
                        return null;
                    }
                    alliances.put(allianceid, ret);
                } finally {
                    lock.writeLock().unlock();
                }
            }
            return ret;
        }

        public static int getAllianceLeader(final int allianceid) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.getLeaderId();
            }
            return 0;
        }

        public static void updateAllianceRanks(final int allianceid, final String[] ranks) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                mga.setRank(ranks);
            }
        }

        public static void updateAllianceNotice(final int allianceid, final String notice) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                mga.setNotice(notice);
            }
        }

        public static boolean canInvite(final int allianceid) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.getCapacity() > mga.getNoGuilds();
            }
            return false;
        }

        public static boolean changeAllianceLeader(final int allianceid, final int cid) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.setLeaderId(cid);
            }
            return false;
        }

        public static boolean changeAllianceLeader(final int allianceid, final int cid, final boolean sameGuild) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.setLeaderId(cid, sameGuild);
            }
            return false;
        }

        public static boolean changeAllianceRank(final int allianceid, final int cid, final int change) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.changeAllianceRank(cid, change);
            }
            return false;
        }

        public static boolean changeAllianceCapacity(final int allianceid) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.setCapacity();
            }
            return false;
        }

        public static boolean disbandAlliance(final int allianceid) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.disband();
            }
            return false;
        }

        public static boolean addGuildToAlliance(final int allianceid, final int gid) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.addGuild(gid);
            }
            return false;
        }

        public static boolean removeGuildFromAlliance(final int allianceid, final int gid, final boolean expelled) {
            final MapleGuildAlliance mga = getAlliance(allianceid);
            if (mga != null) {
                return mga.removeGuild(gid, expelled);
            }
            return false;
        }

        public static void sendGuild(final int allianceid) {
            final MapleGuildAlliance alliance = getAlliance(allianceid);
            if (alliance != null) {
                sendGuild(AlliancePacket.getAllianceUpdate(alliance), -1, allianceid);
                sendGuild(AlliancePacket.getGuildAlliance(alliance), -1, allianceid);
            }
        }

        public static void sendGuild(final byte[] packet, final int exceptionId, final int allianceid) {
            final MapleGuildAlliance alliance = getAlliance(allianceid);
            if (alliance != null) {
                for (int i = 0; i < alliance.getNoGuilds(); i++) {
                    int gid = alliance.getGuildId(i);
                    if (gid > 0 && gid != exceptionId) {
                        Guild.guildPacket(gid, packet);
                    }
                }
            }
        }

        public static boolean createAlliance(final String alliancename, final int cid, final int cid2, final int gid, final int gid2) {
            final int allianceid = MapleGuildAlliance.createToDb(cid, alliancename, gid, gid2);
            if (allianceid <= 0) {
                return false;
            }
            final MapleGuild g = Guild.getGuild(gid), g_ = Guild.getGuild(gid2);
            g.setAllianceId(allianceid);
            g_.setAllianceId(allianceid);
            g.changeARank(true);
            g_.changeARank(false);

            final MapleGuildAlliance alliance = getAlliance(allianceid);

            sendGuild(AlliancePacket.createGuildAlliance(alliance), -1, allianceid);
            sendGuild(AlliancePacket.getAllianceInfo(alliance), -1, allianceid);
            sendGuild(AlliancePacket.getGuildAlliance(alliance), -1, allianceid);
            sendGuild(AlliancePacket.changeAlliance(alliance, true), -1, allianceid);
            return true;
        }

        public static void allianceChat(final int gid, final String name, final int cid, final String msg) {
            final MapleGuild g = Guild.getGuild(gid);
            if (g != null) {
                final MapleGuildAlliance ga = getAlliance(g.getAllianceId());
                if (ga != null) {
                    for (int i = 0; i < ga.getNoGuilds(); i++) {
                        final MapleGuild g_ = Guild.getGuild(ga.getGuildId(i));
                        if (g_ != null) {
                            g_.allianceChat(name, cid, msg);
                        }
                    }
                }
            }
        }

        public static void setNewAlliance(final int gid, final int allianceid) {
            final MapleGuildAlliance alliance = getAlliance(allianceid);
            final MapleGuild guild = Guild.getGuild(gid);
            if (alliance != null && guild != null) {
                for (int i = 0; i < alliance.getNoGuilds(); i++) {
                    if (gid == alliance.getGuildId(i)) {
                        guild.setAllianceId(allianceid);
                        guild.broadcast(AlliancePacket.getAllianceInfo(alliance));
                        guild.broadcast(AlliancePacket.getGuildAlliance(alliance));
                        guild.broadcast(AlliancePacket.changeAlliance(alliance, true));
                        guild.changeARank();
                        guild.writeToDB(false);
                    } else {
                        final MapleGuild g_ = Guild.getGuild(alliance.getGuildId(i));
                        if (g_ != null) {
                            g_.broadcast(AlliancePacket.addGuildToAlliance(alliance, guild));
                            g_.broadcast(AlliancePacket.changeGuildInAlliance(alliance, guild, true));
                        }
                    }
                }
            }
        }

        public static void setOldAlliance(final int gid, final boolean expelled, final int allianceid) {
            final MapleGuildAlliance alliance = getAlliance(allianceid);
            final MapleGuild g_ = Guild.getGuild(gid);
            if (alliance != null) {
                for (int i = 0; i < alliance.getNoGuilds(); i++) {
                    final MapleGuild guild = Guild.getGuild(alliance.getGuildId(i));
                    if (guild == null) {
                        if (gid != alliance.getGuildId(i)) {
                            alliance.removeGuild(gid, false, true);
                        }
                        continue; //just skip
                    }
                    if (g_ == null || gid == alliance.getGuildId(i)) {
                        guild.changeARank(5);
                        guild.setAllianceId(0);
                        guild.broadcast(AlliancePacket.disbandAlliance(allianceid));
                    } else if (g_ != null) {
                        guild.broadcast(CWvsContext.serverNotice(5, "[" + g_.getName() + "] Guild has left the alliance."));
                        guild.broadcast(AlliancePacket.changeGuildInAlliance(alliance, g_, false));
                        guild.broadcast(AlliancePacket.removeGuildFromAlliance(alliance, g_, expelled));
                    }

                }
            }

            if (gid == -1) {
                lock.writeLock().lock();
                try {
                    alliances.remove(allianceid);
                } finally {
                    lock.writeLock().unlock();
                }
            }
        }

        public static List<byte[]> getAllianceInfo(final int allianceid, final boolean start) {
            List<byte[]> ret = new ArrayList<byte[]>();
            final MapleGuildAlliance alliance = getAlliance(allianceid);
            if (alliance != null) {
                if (start) {
                    ret.add(AlliancePacket.getAllianceInfo(alliance));
                    ret.add(AlliancePacket.getGuildAlliance(alliance));
                }
                ret.add(AlliancePacket.getAllianceUpdate(alliance));
            }
            return ret;
        }

        public static void save() {
            System.out.println("Saving alliances...");
            lock.writeLock().lock();
            try {
                for (MapleGuildAlliance a : alliances.values()) {
                    a.saveToDb();
                }
            } finally {
                lock.writeLock().unlock();
            }
        }
    }

    public static class Family {

        private static final Map<Integer, MapleFamily> families = new LinkedHashMap<Integer, MapleFamily>();
        private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();

        public static void addLoadedFamily(MapleFamily f) {
            if (f.isProper()) {
                families.put(f.getId(), f);
            }
        }

        public static MapleFamily getFamily(int id) {
            MapleFamily ret = null;
            lock.readLock().lock();
            try {
                ret = families.get(id);
            } finally {
                lock.readLock().unlock();
            }
            if (ret == null) {
                lock.writeLock().lock();
                try {
                    ret = new MapleFamily(id);
                    if (ret == null || ret.getId() <= 0 || !ret.isProper()) { //failed to load
                        return null;
                    }
                    families.put(id, ret);
                } finally {
                    lock.writeLock().unlock();
                }
            }
            return ret;
        }

        public static void memberFamilyUpdate(MapleFamilyCharacter mfc, MapleCharacter mc) {
            MapleFamily f = getFamily(mfc.getFamilyId());
            if (f != null) {
                f.memberLevelJobUpdate(mc);
            }
        }

        public static void setFamilyMemberOnline(MapleFamilyCharacter mfc, boolean bOnline, int channel) {
            MapleFamily f = getFamily(mfc.getFamilyId());
            if (f != null) {
                f.setOnline(mfc.getId(), bOnline, channel);
            }
        }

        public static int setRep(int fid, int cid, int addrep, int oldLevel, String oldName) {
            MapleFamily f = getFamily(fid);
            if (f != null) {
                return f.setRep(cid, addrep, oldLevel, oldName);
            }
            return 0;
        }

        public static void save() {
            System.out.println("Saving families...");
            lock.writeLock().lock();
            try {
                for (MapleFamily a : families.values()) {
                    a.writeToDB(false);
                }
            } finally {
                lock.writeLock().unlock();
            }
        }

        public static void setFamily(int familyid, int seniorid, int junior1, int junior2, int currentrep, int totalrep, int cid) {
            int ch = Find.findChannel(cid);
            if (ch == -1) {
                // System.out.println("ERROR: cannot find player in given channel");
                return;
            }
            MapleCharacter mc = getStorage(ch).getCharacterById(cid);
            if (mc == null) {
                return;
            }
            boolean bDifferent = mc.getFamilyId() != familyid || mc.getSeniorId() != seniorid || mc.getJunior1() != junior1 || mc.getJunior2() != junior2;
            mc.setFamily(familyid, seniorid, junior1, junior2);
            mc.setCurrentRep(currentrep);
            mc.setTotalRep(totalrep);
            if (bDifferent) {
                mc.saveFamilyStatus();
            }
        }

        public static void familyPacket(int gid, byte[] message, int cid) {
            MapleFamily f = getFamily(gid);
            if (f != null) {
                f.broadcast(message, -1, f.getMFC(cid).getPedigree());
            }
        }

        public static void disbandFamily(int gid) {
            MapleFamily g = getFamily(gid);
            if (g != null) {
                lock.writeLock().lock();
                try {
                    families.remove(gid);
                } finally {
                    lock.writeLock().unlock();
                }
                g.disbandFamily();
            }
        }
    }
    private final static int CHANNELS_PER_THREAD = 3;

    public static void registerRespawn() {
        Integer[] chs = ChannelServer.getAllInstance().toArray(new Integer[0]);
        for (int i = 0; i < chs.length; i += CHANNELS_PER_THREAD) {
            WorldTimer.getInstance().register(new Respawn(chs, i), 4500); //divisible by 9000 if possible.
        }
        //3000 good or bad? ive no idea >_>
        //buffs can also be done, but eh
    }

    public static class Respawn implements Runnable { //is putting it here a good idea?

        private int numTimes = 0;
        private final List<ChannelServer> cservs = new ArrayList<ChannelServer>(CHANNELS_PER_THREAD);

        public Respawn(Integer[] chs, int c) {
            StringBuilder s = new StringBuilder("[Respawn Worker] Registered for channels ");
            for (int i = 1; i <= CHANNELS_PER_THREAD && chs.length >= (c + i); i++) {
                cservs.add(ChannelServer.getInstance(c + i));
                s.append(c + i).append(" ");
            }
            System.out.println(s.toString());
        }

        @Override
        public void run() {
            numTimes++;
            long now = System.currentTimeMillis();
            for (ChannelServer cserv : cservs) {
                if (!cserv.hasFinishedShutdown()) {
                    for (MapleMap map : cserv.getMapFactory().getAllLoadedMaps()) { //iterating through each map o_x
                        handleMap(map, numTimes, map.getCharactersSize(), now);
                    }
                }
            }
        }
    }

    public static void handleMap(final MapleMap map, final int numTimes, final int size, final long now) {
        if (map.getItemsSize() > 0) {
            for (MapleMapItem item : map.getAllItemsThreadsafe()) {
                if (item.shouldExpire(now)) {
                    item.expire(map);
                } else if (item.shouldFFA(now)) {
                    item.setDropType((byte) 2);
                }
            }
        }
        if (map.characterSize() > 0 || map.getId() == 931000500) { //jaira hack
            if (map.canSpawn(now)) {
                map.respawn(false, now);
            }
            boolean hurt = map.canHurt(now);
            for (MapleCharacter chr : map.getCharactersThreadsafe()) {
                handleCooldowns(chr, numTimes, hurt, now);
            }
            if (map.getMobsSize() > 0) {
                for (MapleMonster mons : map.getAllMonstersThreadsafe()) {
                    if (mons.isAlive() && mons.shouldKill(now)) {
                        map.killMonster(mons);
                    } else if (mons.isAlive() && mons.shouldDrop(now)) {
                        mons.doDropItem(now);
                    } else if (mons.isAlive() && mons.getStatiSize() > 0) {
                        for (MonsterStatusEffect mse : mons.getAllBuffs()) {
                            if (mse.shouldCancel(now)) {
                                mons.cancelSingleStatus(mse);
                            }
                        }
                    }
                }
            }
        }
    }

    public static void handleCooldowns(final MapleCharacter chr, final int numTimes, final boolean hurt, final long now) { //is putting it here a good idea? expensive?
        if (chr.getCooldownSize() > 0) {
            for (MapleCoolDownValueHolder m : chr.getCooldowns()) {
                if (m.startTime + m.length < now) {
                    final int skil = m.skillId;
                    chr.removeCooldown(skil);
                    chr.getClient().getSession().write(CField.skillCooldown(skil, 0));
                }
            }
        }
        if (chr.isAlive()) {
            if (chr.getJob() == 131 || chr.getJob() == 132) {
                if (chr.canBlood(now)) {
                    chr.doDragonBlood();
                }
            }
            if (chr.canRecover(now)) {
                chr.doRecovery();
            }
            if (chr.canHPRecover(now)) {
                chr.addHP((int) chr.getStat().getHealHP());
            }
            if (chr.canMPRecover(now)) {
                chr.addMP((int) chr.getStat().getHealMP());
            }
            if (chr.canFairy(now)) {
                chr.doFairy();
            }
            if (chr.canFish(now)) {
                chr.doFish(now);
            }
			if (chr.canDOT(now)) {
				chr.doDOT();
			}
        }

        if (chr.getDiseaseSize() > 0) {
            for (MapleDiseaseValueHolder m : chr.getAllDiseases()) {
                if (m != null && m.startTime + m.length < now) {
                    chr.dispelDebuff(m.disease);
                }
            }
        }
        if (numTimes % 7 == 0 && chr.getMount() != null && chr.getMount().canTire(now)) {
            chr.getMount().increaseFatigue();
        }
        if (numTimes % 13 == 0) { //we're parsing through the characters anyway (:
            chr.doFamiliarSchedule(now);
            for (MaplePet pet : chr.getSummonedPets()) {
                if (pet.getPetItemId() == 5000054 && pet.getSecondsLeft() > 0) {
                    pet.setSecondsLeft(pet.getSecondsLeft() - 1);
                    if (pet.getSecondsLeft() <= 0) {
                        chr.unequipPet(pet, true, true);
                        return;
                    }
                }
                int newFullness = pet.getFullness() - PetDataFactory.getHunger(pet.getPetItemId());
                if (newFullness <= 5) {
                    pet.setFullness(15);
                    chr.unequipPet(pet, true, true);
                } else {
                    pet.setFullness(newFullness);
                    chr.getClient().getSession().write(PetPacket.updatePet(pet, chr.getInventory(MapleInventoryType.CASH).getItem(pet.getInventoryPosition()), true));
                }
            }
        }
        if (hurt && chr.isAlive()) {
            if (chr.getInventory(MapleInventoryType.EQUIPPED).findById(chr.getMap().getHPDecProtect()) == null) {
                if (chr.getMapId() == 749040100 && chr.getInventory(MapleInventoryType.CASH).findById(5451000) == null) { //minidungeon
                    chr.addHP(-chr.getMap().getHPDec());
                } else if (chr.getMapId() != 749040100) {
                    chr.addHP(-(chr.getMap().getHPDec() - (chr.getBuffedValue(MapleBuffStat.HP_LOSS_GUARD) == null ? 0 : chr.getBuffedValue(MapleBuffStat.HP_LOSS_GUARD).intValue())));
                }
            }
        }
    }
}

MapleClient.java

Code:
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 ~ 2010 Patrick Huy <patrick.huy@frz.cc> 
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation. You may not use, modify
or distribute this program under any other version of the
GNU Affero General Public License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITESS 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 client;

import constants.GameConstants;
import constants.ServerConstants;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
import java.io.Serializable;

import javax.script.ScriptEngine;

import database.DatabaseConnection;
import database.DatabaseException;
import handling.cashshop.CashShopServer;
import handling.channel.ChannelServer;
import handling.login.LoginServer;
import handling.world.MapleMessengerCharacter;
import handling.world.MapleParty;
import handling.world.MaplePartyCharacter;
import handling.world.PartyOperation;
import handling.world.World;
import handling.world.family.MapleFamilyCharacter;
import handling.world.guild.MapleGuildCharacter;
import server.maps.MapleMap;
import server.shops.IMaplePlayerShop;
import tools.FileoutputUtil;
import tools.MapleAESOFB;
import tools.packet.LoginPacket;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.apache.mina.common.IoSession;
import server.Timer.PingTimer;
import server.quest.MapleQuest;
import tools.packet.CField;

public class MapleClient implements Serializable {

    private static final long serialVersionUID = 9179541993413738569L;
    public static final byte LOGIN_NOTLOGGEDIN = 0,
            LOGIN_SERVER_TRANSITION = 1,
            LOGIN_LOGGEDIN = 2,
            CHANGE_CHANNEL = 3;
    public static final int DEFAULT_CHARSLOT = 6;
    public static final String CLIENT_KEY = "CLIENT";
    private transient MapleAESOFB send, receive;
    private transient IoSession session;
    private MapleCharacter player;
    private int channel = 1, accId = -1, world, birthday;
    private int charslots = DEFAULT_CHARSLOT;
    private boolean loggedIn = false, serverTransition = false;
    private transient Calendar tempban = null;
    private String accountName;
    private transient long lastPong = 0, lastPing = 0;
    private boolean monitored = false, receiving = true;
    private boolean gm;
    private byte greason = 1, gender = -1;
    public transient short loginAttempt = 0;
    private transient List<Integer> allowedChar = new LinkedList<Integer>();
    private transient Set<String> macs = new HashSet<String>();
    private transient Map<String, ScriptEngine> engines = new HashMap<String, ScriptEngine>();
    private transient ScheduledFuture<?> idleTask = null;
    private transient String secondPassword, salt2, tempIP = ""; // To be used only on login
    private final transient Lock mutex = new ReentrantLock(true);
    private final transient Lock npc_mutex = new ReentrantLock();
    private long lastNpcClick = 0;
    private final static Lock login_mutex = new ReentrantLock(true);

    public MapleClient(MapleAESOFB send, MapleAESOFB receive, IoSession session) {
        this.send = send;
        this.receive = receive;
        this.session = session;
    }

    public final MapleAESOFB getReceiveCrypto() {
        return receive;
    }

    public final MapleAESOFB getSendCrypto() {
        return send;
    }

    public final IoSession getSession() {
        return session;
    }

    public final Lock getLock() {
        return mutex;
    }

    public final Lock getNPCLock() {
        return npc_mutex;
    }

    public MapleCharacter getPlayer() {
        return player;
    }

    public void setPlayer(MapleCharacter player) {
        this.player = player;
    }

    public void createdChar(final int id) {
        allowedChar.add(id);
    }

    public final boolean login_Auth(final int id) {
        return allowedChar.contains(id);
    }

    public final List<MapleCharacter> loadCharacters(final int serverId) { // TODO make this less costly zZz
        final List<MapleCharacter> chars = new LinkedList<MapleCharacter>();

        for (final CharNameAndId cni : loadCharactersInternal(serverId)) {
            final MapleCharacter chr = MapleCharacter.loadCharFromDB(cni.id, this, false);
            //if (chr.isSuperGM() && !ServerConstants.isEligible(getSessionIPAddress())) {
            //	continue;
            //}
            chars.add(chr);
            if (!login_Auth(chr.getId())) {
                allowedChar.add(chr.getId());
            }
        }
        return chars;
    }

    public boolean canMakeCharacter(int serverId) {
        return loadCharactersSize(serverId) < getCharacterSlots();
    }

    public List<String> loadCharacterNames(int serverId) {
        List<String> chars = new LinkedList<String>();
        for (CharNameAndId cni : loadCharactersInternal(serverId)) {
            chars.add(cni.name);
        }
        return chars;
    }

    private List<CharNameAndId> loadCharactersInternal(int serverId) {
        List<CharNameAndId> chars = new LinkedList<CharNameAndId>();
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT id, name, gm FROM characters WHERE accountid = ? AND world = ?");
            ps.setInt(1, accId);
            ps.setInt(2, serverId);

            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                chars.add(new CharNameAndId(rs.getString("name"), rs.getInt("id")));
                LoginServer.getLoginAuth(rs.getInt("id"));
            }
            rs.close();
            ps.close();
        } catch (SQLException e) {
            System.err.println("error loading characters internal");
            e.printStackTrace();
        }
        return chars;
    }

    private int loadCharactersSize(int serverId) {
        int chars = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT count(*) FROM characters WHERE accountid = ? AND world = ?");
            ps.setInt(1, accId);
            ps.setInt(2, serverId);

            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                chars = rs.getInt(1);
            }
            rs.close();
            ps.close();
        } catch (SQLException e) {
            System.err.println("error loading characters internal");
            e.printStackTrace();
        }
        return chars;
    }

    public boolean isLoggedIn() {
        return loggedIn && accId >= 0;
    }

    private Calendar getTempBanCalendar(ResultSet rs) throws SQLException {
        Calendar lTempban = Calendar.getInstance();
        if (rs.getLong("tempban") == 0) { // basically if timestamp in db is 0000-00-00
            lTempban.setTimeInMillis(0);
            return lTempban;
        }
        Calendar today = Calendar.getInstance();
        lTempban.setTimeInMillis(rs.getTimestamp("tempban").getTime());
        if (today.getTimeInMillis() < lTempban.getTimeInMillis()) {
            return lTempban;
        }

        lTempban.setTimeInMillis(0);
        return lTempban;
    }

    public Calendar getTempBanCalendar() {
        return tempban;
    }

    public byte getBanReason() {
        return greason;
    }

    public boolean hasBannedIP() {
        boolean ret = false;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM ipbans WHERE ? LIKE CONCAT(ip, '%')");
            ps.setString(1, getSessionIPAddress());
            ResultSet rs = ps.executeQuery();
            rs.next();
            if (rs.getInt(1) > 0) {
                ret = true;
            }
            rs.close();
            ps.close();
        } catch (SQLException ex) {
            System.err.println("Error checking ip bans" + ex);
        }
        return ret;
    }

    public boolean hasBannedMac() {
        if (macs.isEmpty()) {
            return false;
        }
        boolean ret = false;
        int i = 0;
        try {
            Connection con = DatabaseConnection.getConnection();
            StringBuilder sql = new StringBuilder("SELECT COUNT(*) FROM macbans WHERE mac IN (");
            for (i = 0; i < macs.size(); i++) {
                sql.append("?");
                if (i != macs.size() - 1) {
                    sql.append(", ");
                }
            }
            sql.append(")");
            PreparedStatement ps = con.prepareStatement(sql.toString());
            i = 0;
            for (String mac : macs) {
                i++;
                ps.setString(i, mac);
            }
            ResultSet rs = ps.executeQuery();
            rs.next();
            if (rs.getInt(1) > 0) {
                ret = true;
            }
            rs.close();
            ps.close();
        } catch (SQLException ex) {
            System.err.println("Error checking mac bans" + ex);
        }
        return ret;
    }

    private void loadMacsIfNescessary() throws SQLException {
        if (macs.isEmpty()) {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT macs FROM accounts WHERE id = ?");
            ps.setInt(1, accId);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                if (rs.getString("macs") != null) {
                    String[] macData = rs.getString("macs").split(", ");
                    for (String mac : macData) {
                        if (!mac.equals("")) {
                            macs.add(mac);
                        }
                    }
                }
            } else {
                rs.close();
                ps.close();
                throw new RuntimeException("No valid account associated with this client.");
            }
            rs.close();
            ps.close();
        }
    }

    public void banMacs() {
        try {
            loadMacsIfNescessary();
            if (this.macs.size() > 0) {
                String[] macBans = new String[this.macs.size()];
                int z = 0;
                for (String mac : this.macs) {
                    macBans[z] = mac;
                    z++;
                }
                banMacs(macBans);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static final void banMacs(String[] macs) {
        Connection con = DatabaseConnection.getConnection();
        try {
            List<String> filtered = new LinkedList<String>();
            PreparedStatement ps = con.prepareStatement("SELECT filter FROM macfilters");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                filtered.add(rs.getString("filter"));
            }
            rs.close();
            ps.close();

            ps = con.prepareStatement("INSERT INTO macbans (mac) VALUES (?)");
            for (String mac : macs) {
                boolean matched = false;
                for (String filter : filtered) {
                    if (mac.matches(filter)) {
                        matched = true;
                        break;
                    }
                }
                if (!matched) {
                    ps.setString(1, mac);
                    try {
                        ps.executeUpdate();
                    } catch (SQLException e) {
                        // can fail because of UNIQUE key, we dont care
                    }
                }
            }
            ps.close();
        } catch (SQLException e) {
            System.err.println("Error banning MACs" + e);
        }
    }

    /**
     * Returns 0 on success, a state to be used for
     * {@link CField#getLoginFailed(int)} otherwise.
     *
     * @param success
     * @return The state of the login.
     */
    public int finishLogin() {
        login_mutex.lock();
        try {
            final byte state = getLoginState();
            if (state > MapleClient.LOGIN_NOTLOGGEDIN) { // already loggedin
                loggedIn = false;
                return 7;
            }
            updateLoginState(MapleClient.LOGIN_LOGGEDIN, getSessionIPAddress());
        } finally {
            login_mutex.unlock();
        }
        return 0;
    }

    public void clearInformation() {
        accountName = null;
        accId = -1;
        secondPassword = null;
        salt2 = null;
        gm = false;
        loggedIn = false;
        greason = (byte) 1;
        tempban = null;
        gender = (byte) -1;
    }

    public int login(String login, String pwd, boolean ipMacBanned) {
        int loginok = 5;
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM accounts WHERE name = ?");
            ps.setString(1, login);
            ResultSet rs = ps.executeQuery();

            if (rs.next()) {
                final int banned = rs.getInt("banned");
                final String passhash = rs.getString("password");
                final String salt = rs.getString("salt");
                final String oldSession = rs.getString("SessionIP");

                accountName = login;
                accId = rs.getInt("id");
                secondPassword = rs.getString("2ndpassword");
                salt2 = rs.getString("salt2");
                gm = rs.getInt("gm") > 0;
                greason = rs.getByte("greason");
                tempban = getTempBanCalendar(rs);
                gender = rs.getByte("gender");

                final boolean admin = rs.getInt("gm") > 1;

                if (secondPassword != null && salt2 != null) {
                    secondPassword = LoginCrypto.rand_r(secondPassword);
                }
                ps.close();

                if (banned > 0 && !gm) {
                    loginok = 3;
                } else {
                    if (banned == -1) {
                        unban();
                    }
                    byte loginstate = getLoginState();
                    if (loginstate > MapleClient.LOGIN_NOTLOGGEDIN) { // already loggedin
                        loggedIn = false;
                        loginok = 7;
                    } else {
                        boolean updatePasswordHash = false;
                        // Check if the passwords are correct here. :B
                        if (passhash == null || passhash.isEmpty()) {
                            //match by sessionIP
                            if (oldSession != null && !oldSession.isEmpty()) {
                                loggedIn = getSessionIPAddress().equals(oldSession);
                                loginok = loggedIn ? 0 : 4;
                                updatePasswordHash = loggedIn;
                            } else {
                                loginok = 4;
                                loggedIn = false;
                            }
                        } else if (LoginCryptoLegacy.isLegacyPassword(passhash) && LoginCryptoLegacy.checkPassword(pwd, passhash)) {
                            // Check if a password upgrade is needed.
                            loginok = 0;
                            updatePasswordHash = true;
                        } else if (salt == null && LoginCrypto.checkSha1Hash(passhash, pwd)) {
                            loginok = 0;
                            updatePasswordHash = true;
                        } else if (LoginCrypto.checkSaltedSha512Hash(passhash, pwd, salt)) {
                            loginok = 0;
                        } else {
                            loggedIn = false;
                            loginok = 4;
                        }
                        if (updatePasswordHash) {
                            PreparedStatement pss = con.prepareStatement("UPDATE `accounts` SET `password` = ?, `salt` = ? WHERE id = ?");
                            try {
                                final String newSalt = LoginCrypto.makeSalt();
                                pss.setString(1, LoginCrypto.makeSaltedSha512Hash(pwd, newSalt));
                                pss.setString(2, newSalt);
                                pss.setInt(3, accId);
                                pss.executeUpdate();
                            } finally {
                                pss.close();
                            }
                        }
                    }
                }
            }
            rs.close();
            ps.close();
        } catch (SQLException e) {
            System.err.println("ERROR" + e);
        }
        return loginok;
    }

    public boolean CheckSecondPassword(String in) {
        boolean allow = false;
        boolean updatePasswordHash = false;

        // Check if the passwords are correct here. :B
        if (LoginCryptoLegacy.isLegacyPassword(secondPassword) && LoginCryptoLegacy.checkPassword(in, secondPassword)) {
            // Check if a password upgrade is needed.
            allow = true;
            updatePasswordHash = true;
        } else if (salt2 == null && LoginCrypto.checkSha1Hash(secondPassword, in)) {
            allow = true;
            updatePasswordHash = true;
        } else if (LoginCrypto.checkSaltedSha512Hash(secondPassword, in, salt2)) {
            allow = true;
        }
        if (updatePasswordHash) {
            Connection con = DatabaseConnection.getConnection();
            try {
                PreparedStatement ps = con.prepareStatement("UPDATE `accounts` SET `2ndpassword` = ?, `salt2` = ? WHERE id = ?");
                final String newSalt = LoginCrypto.makeSalt();
                ps.setString(1, LoginCrypto.rand_s(LoginCrypto.makeSaltedSha512Hash(in, newSalt)));
                ps.setString(2, newSalt);
                ps.setInt(3, accId);
                ps.executeUpdate();
                ps.close();
            } catch (SQLException e) {
                return false;
            }
        }
        return allow;
    }

    private void unban() {
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("UPDATE accounts SET banned = 0, banreason = '' WHERE id = ?");
            ps.setInt(1, accId);
            ps.executeUpdate();
            ps.close();
        } catch (SQLException e) {
            System.err.println("Error while unbanning" + e);
        }
    }

    public static final byte unban(String charname) {
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT accountid from characters where name = ?");
            ps.setString(1, charname);

            ResultSet rs = ps.executeQuery();
            if (!rs.next()) {
                rs.close();
                ps.close();
                return -1;
            }
            final int accid = rs.getInt(1);
            rs.close();
            ps.close();

            ps = con.prepareStatement("UPDATE accounts SET banned = 0, banreason = '' WHERE id = ?");
            ps.setInt(1, accid);
            ps.executeUpdate();
            ps.close();
        } catch (SQLException e) {
            System.err.println("Error while unbanning" + e);
            return -2;
        }
        return 0;
    }

    public void updateMacs(String macData) {
        for (String mac : macData.split(", ")) {
            macs.add(mac);
        }
        StringBuilder newMacData = new StringBuilder();
        Iterator<String> iter = macs.iterator();
        while (iter.hasNext()) {
            newMacData.append(iter.next());
            if (iter.hasNext()) {
                newMacData.append(", ");
            }
        }
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("UPDATE accounts SET macs = ? WHERE id = ?");
            ps.setString(1, newMacData.toString());
            ps.setInt(2, accId);
            ps.executeUpdate();
            ps.close();
        } catch (SQLException e) {
            System.err.println("Error saving MACs" + e);
        }
    }

    public void setAccID(int id) {
        this.accId = id;
    }

    public int getAccID() {
        return this.accId;
    }

    public final void updateLoginState(final int newstate, final String SessionID) { // TODO hide?
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("UPDATE accounts SET loggedin = ?, SessionIP = ?, lastlogin = CURRENT_TIMESTAMP() WHERE id = ?");
            ps.setInt(1, newstate);
            ps.setString(2, SessionID);
            ps.setInt(3, getAccID());
            ps.executeUpdate();
            ps.close();
        } catch (SQLException e) {
            System.err.println("error updating login state" + e);
        }
        if (newstate == MapleClient.LOGIN_NOTLOGGEDIN) {
            loggedIn = false;
            serverTransition = false;
        } else {
            serverTransition = (newstate == MapleClient.LOGIN_SERVER_TRANSITION || newstate == MapleClient.CHANGE_CHANNEL);
            loggedIn = !serverTransition;
        }
    }

    public final void updateSecondPassword() {
        try {
            final Connection con = DatabaseConnection.getConnection();

            PreparedStatement ps = con.prepareStatement("UPDATE `accounts` SET `2ndpassword` = ?, `salt2` = ? WHERE id = ?");
            final String newSalt = LoginCrypto.makeSalt();
            ps.setString(1, LoginCrypto.rand_s(LoginCrypto.makeSaltedSha512Hash(secondPassword, newSalt)));
            ps.setString(2, newSalt);
            ps.setInt(3, accId);
            ps.executeUpdate();
            ps.close();

        } catch (SQLException e) {
            System.err.println("error updating login state" + e);
        }
    }

    public final byte getLoginState() { // TODO hide?
        Connection con = DatabaseConnection.getConnection();
        try {
            PreparedStatement ps;
            ps = con.prepareStatement("SELECT loggedin, lastlogin, banned, `birthday` + 0 AS `bday` FROM accounts WHERE id = ?");
            ps.setInt(1, getAccID());
            ResultSet rs = ps.executeQuery();
            if (!rs.next() || rs.getInt("banned") > 0) {
                ps.close();
                rs.close();
                session.close();
                throw new DatabaseException("Account doesn't exist or is banned");
            }
            birthday = rs.getInt("bday");
            byte state = rs.getByte("loggedin");

            if (state == MapleClient.LOGIN_SERVER_TRANSITION || state == MapleClient.CHANGE_CHANNEL) {
                if (rs.getTimestamp("lastlogin").getTime() + 20000 < System.currentTimeMillis()) { // connecting to chanserver timeout
                    state = MapleClient.LOGIN_NOTLOGGEDIN;
                    updateLoginState(state, getSessionIPAddress());
                }
            }
            rs.close();
            ps.close();
            if (state == MapleClient.LOGIN_LOGGEDIN) {
                loggedIn = true;
            } else {
                loggedIn = false;
            }
            return state;
        } catch (SQLException e) {
            loggedIn = false;
            throw new DatabaseException("error getting login state", e);
        }
    }

    public final boolean checkBirthDate(final int date) {
        return birthday == date;
    }

    public final void removalTask(boolean shutdown) {
        try {
            player.cancelAllBuffs_();
            player.cancelAllDebuffs();
            if (player.getMarriageId() > 0) {
                final MapleQuestStatus stat1 = player.getQuestNoAdd(MapleQuest.getInstance(160001));
                final MapleQuestStatus stat2 = player.getQuestNoAdd(MapleQuest.getInstance(160002));
                if (stat1 != null && stat1.getCustomData() != null && (stat1.getCustomData().equals("2_") || stat1.getCustomData().equals("2"))) {
                    //dc in process of marriage
                    if (stat2 != null && stat2.getCustomData() != null) {
                        stat2.setCustomData("0");
                    }
                    stat1.setCustomData("3");
                }
            }
            if (player.getMapId() == GameConstants.JAIL && !player.isIntern()) {
                final MapleQuestStatus stat1 = player.getQuestNAdd(MapleQuest.getInstance(GameConstants.JAIL_TIME));
                final MapleQuestStatus stat2 = player.getQuestNAdd(MapleQuest.getInstance(GameConstants.JAIL_QUEST));
                if (stat1.getCustomData() == null) {
                    stat1.setCustomData(String.valueOf(System.currentTimeMillis()));
                } else if (stat2.getCustomData() == null) {
                    stat2.setCustomData("0"); //seconds of jail
                } else { //previous seconds - elapsed seconds
                    int seconds = Integer.parseInt(stat2.getCustomData()) - (int) ((System.currentTimeMillis() - Long.parseLong(stat1.getCustomData())) / 1000);
                    if (seconds < 0) {
                        seconds = 0;
                    }
                    stat2.setCustomData(String.valueOf(seconds));
                }
            }
            player.changeRemoval(true);
            if (player.getEventInstance() != null) {
                player.getEventInstance().playerDisconnected(player, player.getId());
            }
            final IMaplePlayerShop shop = player.getPlayerShop();
            if (shop != null) {
                shop.removeVisitor(player);
                if (shop.isOwner(player)) {
                    if (shop.getShopType() == 1 && shop.isAvailable() && !shutdown) {
                        shop.setOpen(true);
                    } else {
                        shop.closeShop(true, !shutdown);
                    }
                }
            }
            player.setMessenger(null);
            if (player.getMap() != null) {
                if (shutdown || (getChannelServer() != null && getChannelServer().isShutdown())) {
                    int questID = -1;
                    switch (player.getMapId()) {
                        case 240060200: //HT
                            questID = 160100;
                            break;
                        case 240060201: //ChaosHT
                            questID = 160103;
                            break;
                        case 280030000: //Zakum
                            questID = 160101;
                            break;
                        case 280030001: //ChaosZakum
                            questID = 160102;
                            break;
                        case 270050100: //PB
                            questID = 160101;
                            break;
                        case 105100300: //Balrog
                        case 105100400: //Balrog
                            questID = 160106;
                            break;
                        case 211070000: //VonLeon
                        case 211070100: //VonLeon
                        case 211070101: //VonLeon
                        case 211070110: //VonLeon
                            questID = 160107;
                            break;
                        case 551030200: //scartar
                            questID = 160108;
                            break;
                        case 271040100: //cygnus
                            questID = 160109;
                            break;
                    }
                    if (questID > 0) {
                        player.getQuestNAdd(MapleQuest.getInstance(questID)).setCustomData("0"); //reset the time.
                    }
                } else if (player.isAlive()) {
                    switch (player.getMapId()) {
                        case 541010100: //latanica
                        case 541020800: //krexel
                        case 220080001: //pap
                            player.getMap().addDisconnected(player.getId());
                            break;
                    }
                }
                player.getMap().removePlayer(player);
            }
        } catch (final Throwable e) {
            FileoutputUtil.outputFileError(FileoutputUtil.Acc_Stuck, e);
        }
    }

    public final void disconnect(final boolean RemoveInChannelServer, final boolean fromCS) {
        disconnect(RemoveInChannelServer, fromCS, false);
    }

    public final void disconnect(final boolean RemoveInChannelServer, final boolean fromCS, final boolean shutdown) {
        if (player != null) {
            MapleMap map = player.getMap();
            final MapleParty party = player.getParty();
            final boolean clone = player.isClone();
            final String namez = player.getName();
            final int idz = player.getId(), messengerid = player.getMessenger() == null ? 0 : player.getMessenger().getId(), gid = player.getGuildId(), fid = player.getFamilyId();
            final BuddyList bl = player.getBuddylist();
            final MaplePartyCharacter chrp = new MaplePartyCharacter(player);
            final MapleMessengerCharacter chrm = new MapleMessengerCharacter(player);
            final MapleGuildCharacter chrg = player.getMGC();
            final MapleFamilyCharacter chrf = player.getMFC();

            removalTask(shutdown);
            LoginServer.getLoginAuth(player.getId());
            player.saveToDB(true, fromCS);
            if (shutdown) {
                player = null;
                receiving = false;
                return;
            }

            if (!fromCS) {
                final ChannelServer ch = ChannelServer.getInstance(map == null ? channel : map.getChannel());
                final int chz = World.Find.findChannel(idz);
                if (chz < -1) {
                    disconnect(RemoveInChannelServer, true);//u lie
                    return;
                }
                try {
                    if (chz == -1 || ch == null || clone || ch.isShutdown()) {
                        player = null;
                        return;//no idea
                    }
                    if (messengerid > 0) {
                        World.Messenger.leaveMessenger(messengerid, chrm);
                    }
                    if (party != null) {
                        chrp.setOnline(false);
                        World.Party.updateParty(party.getId(), PartyOperation.LOG_ONOFF, chrp);
                        if (map != null && party.getLeader().getId() == idz) {
                            MaplePartyCharacter lchr = null;
                            for (MaplePartyCharacter pchr : party.getMembers()) {
                                if (pchr != null && map.getCharacterById(pchr.getId()) != null && (lchr == null || lchr.getLevel() < pchr.getLevel())) {
                                    lchr = pchr;
                                }
                            }
                            if (lchr != null) {
                                World.Party.updateParty(party.getId(), PartyOperation.CHANGE_LEADER_DC, lchr);
                            }
                        }
                    }
                    if (bl != null) {
                        if (!serverTransition) {
                            World.Buddy.loggedOff(namez, idz, channel, bl.getBuddyIds());
                        } else { // Change channel
                            World.Buddy.loggedOn(namez, idz, channel, bl.getBuddyIds());
                        }
                    }
                    if (gid > 0 && chrg != null) {
                        World.Guild.setGuildMemberOnline(chrg, false, -1);
                    }
                    if (fid > 0 && chrf != null) {
                        World.Family.setFamilyMemberOnline(chrf, false, -1);
                    }
                } catch (final Exception e) {
                    e.printStackTrace();
                    FileoutputUtil.outputFileError(FileoutputUtil.Acc_Stuck, e);
                    System.err.println(getLogMessage(this, "ERROR") + e);
                } finally {
                    if (RemoveInChannelServer && ch != null) {
                        ch.removePlayer(idz, namez);
                    }
                    player = null;
                }
            } else {
                final int ch = World.Find.findChannel(idz);
                if (ch > 0) {
                    disconnect(RemoveInChannelServer, false);//u lie
                    return;
                }
                try {
                    if (party != null) {
                        chrp.setOnline(false);
                        World.Party.updateParty(party.getId(), PartyOperation.LOG_ONOFF, chrp);
                    }
                    if (!serverTransition) {
                        World.Buddy.loggedOff(namez, idz, channel, bl.getBuddyIds());
                    } else { // Change channel
                        World.Buddy.loggedOn(namez, idz, channel, bl.getBuddyIds());
                    }
                    if (gid > 0 && chrg != null) {
                        World.Guild.setGuildMemberOnline(chrg, false, -1);
                    }
                    if (fid > 0 && chrf != null) {
                        World.Family.setFamilyMemberOnline(chrf, false, -1);
                    }
                    if (player != null) {
                        player.setMessenger(null);
                    }
                } catch (final Exception e) {
                    e.printStackTrace();
                    FileoutputUtil.outputFileError(FileoutputUtil.Acc_Stuck, e);
                    System.err.println(getLogMessage(this, "ERROR") + e);
                } finally {
                    if (RemoveInChannelServer && ch > 0) {
                        CashShopServer.getPlayerStorage().deregisterPlayer(idz, namez);
                    }
                    player = null;
                }
            }
        }
        if (!serverTransition && isLoggedIn()) {
            updateLoginState(MapleClient.LOGIN_NOTLOGGEDIN, getSessionIPAddress());
        }
        engines.clear();
    }

    public final String getSessionIPAddress() {
        return session.getRemoteAddress().toString().split(":")[0];
    }

    public final boolean CheckIPAddress() {
        if (this.accId < 0) {
            return false;
        }
        try {
            final PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT SessionIP, banned FROM accounts WHERE id = ?");
            ps.setInt(1, this.accId);
            final ResultSet rs = ps.executeQuery();

            boolean canlogin = false;

            if (rs.next()) {
                final String sessionIP = rs.getString("SessionIP");

                if (sessionIP != null) { // Probably a login proced skipper?
                    canlogin = getSessionIPAddress().equals(sessionIP.split(":")[0]);
                }
                if (rs.getInt("banned") > 0) {
                    canlogin = false; //canlogin false = close client
                }
            }
            rs.close();
            ps.close();

            return canlogin;
        } catch (final SQLException e) {
            System.out.println("Failed in checking IP address for client.");
        }
        return true;
    }

    public final void DebugMessage(final StringBuilder sb) {
        sb.append(getSession().getRemoteAddress());
        sb.append("Connected: ");
        sb.append(getSession().isConnected());
        sb.append(" Closing: ");
        sb.append(getSession().isClosing());
        sb.append(" ClientKeySet: ");
        sb.append(getSession().getAttribute(MapleClient.CLIENT_KEY) != null);
        sb.append(" loggedin: ");
        sb.append(isLoggedIn());
        sb.append(" has char: ");
        sb.append(getPlayer() != null);
    }

    public final int getChannel() {
        return channel;
    }

    public final ChannelServer getChannelServer() {
        return ChannelServer.getInstance(channel);
    }

    public final int deleteCharacter(final int cid) {
        try {
            final Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT guildid, guildrank, familyid, name FROM characters WHERE id = ? AND accountid = ?");
            ps.setInt(1, cid);
            ps.setInt(2, accId);
            ResultSet rs = ps.executeQuery();
            if (!rs.next()) {
                rs.close();
                ps.close();
                return 9;
            }
            if (rs.getInt("guildid") > 0) { // is in a guild when deleted
                if (rs.getInt("guildrank") == 1) { //cant delete when leader
                    rs.close();
                    ps.close();
                    return 22;
                }
                World.Guild.deleteGuildCharacter(rs.getInt("guildid"), cid);
            }
            if (rs.getInt("familyid") > 0 && World.Family.getFamily(rs.getInt("familyid")) != null) {
                World.Family.getFamily(rs.getInt("familyid")).leaveFamily(cid);
            }
            rs.close();
            ps.close();

            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM characters WHERE id = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "UPDATE pokemon SET active = 0 WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM hiredmerch WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM mts_cart WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM mts_items WHERE characterid = ?", cid);
            //MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM cheatlog WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM mountdata WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM inventoryitems WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM famelog WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM famelog WHERE characterid_to = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM dueypackages WHERE RecieverId = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM wishlist WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM buddies WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM buddies WHERE buddyid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM keymap WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM trocklocations WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM regrocklocations WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM hyperrocklocations WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM savedlocations WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM skills WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM familiars WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM mountdata WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM skillmacros WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM trocklocations WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM queststatus WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM inventoryslot WHERE characterid = ?", cid);
            MapleCharacter.deleteWhereCharacterId(con, "DELETE FROM extendedSlots WHERE characterid = ?", cid);
            return 0;
        } catch (Exception e) {
            FileoutputUtil.outputFileError(FileoutputUtil.PacketEx_Log, e);
            e.printStackTrace();
        }
        return 10;
    }

    public final byte getGender() {
        return gender;
    }

    public final void setGender(final byte gender) {
        this.gender = gender;
    }

    public final String getSecondPassword() {
        return secondPassword;
    }

    public final void setSecondPassword(final String secondPassword) {
        this.secondPassword = secondPassword;
    }

    public final String getAccountName() {
        return accountName;
    }

    public final void setAccountName(final String accountName) {
        this.accountName = accountName;
    }

    public final void setChannel(final int channel) {
        this.channel = channel;
    }

    public final int getWorld() {
        return world;
    }

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

    public final int getLatency() {
        return (int) (lastPong - lastPing);
    }

    public final long getLastPong() {
        return lastPong;
    }

    public final long getLastPing() {
        return lastPing;
    }

    public final void pongReceived() {
        lastPong = System.currentTimeMillis();
    }

    public final void sendPing() {
        lastPing = System.currentTimeMillis();
        session.write(LoginPacket.getPing());

        PingTimer.getInstance().schedule(new Runnable() {

            @Override
            public void run() {
                try {
                    if (getLatency() < 0) {
                        disconnect(true, false);
                        if (getSession().isConnected()) {
                            getSession().close();
                        }
                    }
                } catch (final NullPointerException e) {
                    // client already gone
                }
            }
        }, 60000); // note: idletime gets added to this too
    }

    public static final String getLogMessage(final MapleClient cfor, final String message) {
        return getLogMessage(cfor, message, new Object[0]);
    }

    public static final String getLogMessage(final MapleCharacter cfor, final String message) {
        return getLogMessage(cfor == null ? null : cfor.getClient(), message);
    }

    public static final String getLogMessage(final MapleCharacter cfor, final String message, final Object... parms) {
        return getLogMessage(cfor == null ? null : cfor.getClient(), message, parms);
    }

    public static final String getLogMessage(final MapleClient cfor, final String message, final Object... parms) {
        final StringBuilder builder = new StringBuilder();
        if (cfor != null) {
            if (cfor.getPlayer() != null) {
                builder.append("<");
                builder.append(MapleCharacterUtil.makeMapleReadable(cfor.getPlayer().getName()));
                builder.append(" (cid: ");
                builder.append(cfor.getPlayer().getId());
                builder.append(")> ");
            }
            if (cfor.getAccountName() != null) {
                builder.append("(Account: ");
                builder.append(cfor.getAccountName());
                builder.append(") ");
            }
        }
        builder.append(message);
        int start;
        for (final Object parm : parms) {
            start = builder.indexOf("{}");
            builder.replace(start, start + 2, parm.toString());
        }
        return builder.toString();
    }

    public static final int findAccIdForCharacterName(final String charName) {
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT accountid FROM characters WHERE name = ?");
            ps.setString(1, charName);
            ResultSet rs = ps.executeQuery();

            int ret = -1;
            if (rs.next()) {
                ret = rs.getInt("accountid");
            }
            rs.close();
            ps.close();

            return ret;
        } catch (final SQLException e) {
            System.err.println("findAccIdForCharacterName SQL error");
        }
        return -1;
    }

    public final Set<String> getMacs() {
        return Collections.unmodifiableSet(macs);
    }

    public final boolean isGm() {
        return gm;
    }

    public final void setScriptEngine(final String name, final ScriptEngine e) {
        engines.put(name, e);
    }

    public final ScriptEngine getScriptEngine(final String name) {
        return engines.get(name);
    }

    public final void removeScriptEngine(final String name) {
        engines.remove(name);
    }

    public final ScheduledFuture<?> getIdleTask() {
        return idleTask;
    }

    public final void setIdleTask(final ScheduledFuture<?> idleTask) {
        this.idleTask = idleTask;
    }

    protected static final class CharNameAndId {

        public final String name;
        public final int id;

        public CharNameAndId(final String name, final int id) {
            super();
            this.name = name;
            this.id = id;
        }
    }

    public int getCharacterSlots() {
        if (isGm()) {
            return 15;
        }
        if (charslots != DEFAULT_CHARSLOT) {
            return charslots; //save a sql
        }
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT * FROM character_slots WHERE accid = ? AND worldid = ?");
            ps.setInt(1, accId);
            ps.setInt(2, world);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                charslots = rs.getInt("charslots");
            } else {
                PreparedStatement psu = con.prepareStatement("INSERT INTO character_slots (accid, worldid, charslots) VALUES (?, ?, ?)");
                psu.setInt(1, accId);
                psu.setInt(2, world);
                psu.setInt(3, charslots);
                psu.executeUpdate();
                psu.close();
            }
            rs.close();
            ps.close();
        } catch (SQLException sqlE) {
            sqlE.printStackTrace();
        }

        return charslots;
    }

    public boolean gainCharacterSlot() {
        if (getCharacterSlots() >= 15) {
            return false;
        }
        charslots++;

        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("UPDATE character_slots SET charslots = ? WHERE worldid = ? AND accid = ?");
            ps.setInt(1, charslots);
            ps.setInt(2, world);
            ps.setInt(3, accId);
            ps.executeUpdate();
            ps.close();
        } catch (SQLException sqlE) {
            sqlE.printStackTrace();
            return false;
        }
        return true;
    }

    public static final byte unbanIPMacs(String charname) {
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT accountid from characters where name = ?");
            ps.setString(1, charname);

            ResultSet rs = ps.executeQuery();
            if (!rs.next()) {
                rs.close();
                ps.close();
                return -1;
            }
            final int accid = rs.getInt(1);
            rs.close();
            ps.close();

            ps = con.prepareStatement("SELECT * FROM accounts WHERE id = ?");
            ps.setInt(1, accid);
            rs = ps.executeQuery();
            if (!rs.next()) {
                rs.close();
                ps.close();
                return -1;
            }
            final String sessionIP = rs.getString("sessionIP");
            final String macs = rs.getString("macs");
            rs.close();
            ps.close();
            byte ret = 0;
            if (sessionIP != null) {
                PreparedStatement psa = con.prepareStatement("DELETE FROM ipbans WHERE ip like ?");
                psa.setString(1, sessionIP);
                psa.execute();
                psa.close();
                ret++;
            }
            if (macs != null) {
                String[] macz = macs.split(", ");
                for (String mac : macz) {
                    if (!mac.equals("")) {
                        PreparedStatement psa = con.prepareStatement("DELETE FROM macbans WHERE mac = ?");
                        psa.setString(1, mac);
                        psa.execute();
                        psa.close();
                    }
                }
                ret++;
            }
            return ret;
        } catch (SQLException e) {
            System.err.println("Error while unbanning" + e);
            return -2;
        }
    }

    public static final byte unHellban(String charname) {
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT accountid from characters where name = ?");
            ps.setString(1, charname);

            ResultSet rs = ps.executeQuery();
            if (!rs.next()) {
                rs.close();
                ps.close();
                return -1;
            }
            final int accid = rs.getInt(1);
            rs.close();
            ps.close();

            ps = con.prepareStatement("SELECT * FROM accounts WHERE id = ?");
            ps.setInt(1, accid);
            rs = ps.executeQuery();
            if (!rs.next()) {
                rs.close();
                ps.close();
                return -1;
            }
            final String sessionIP = rs.getString("sessionIP");
            final String email = rs.getString("email");
            rs.close();
            ps.close();
            ps = con.prepareStatement("UPDATE accounts SET banned = 0, banreason = '' WHERE email = ?" + (sessionIP == null ? "" : " OR sessionIP = ?"));
            ps.setString(1, email);
            if (sessionIP != null) {
                ps.setString(2, sessionIP);
            }
            ps.execute();
            ps.close();
            return 0;
        } catch (SQLException e) {
            System.err.println("Error while unbanning" + e);
            return -2;
        }
    }

    public boolean isMonitored() {
        return monitored;
    }

    public void setMonitored(boolean m) {
        this.monitored = m;
    }

    public boolean isReceiving() {
        return receiving;
    }

    public void setReceiving(boolean m) {
        this.receiving = m;
    }

    public boolean canClickNPC() {
        return lastNpcClick + 500 < System.currentTimeMillis();
    }

    public void setClickedNPC() {
        lastNpcClick = System.currentTimeMillis();
    }

    public void removeClickedNPC() {
        lastNpcClick = 0;
    }

    public final Timestamp getCreated() { // TODO hide?
        Connection con = DatabaseConnection.getConnection();
        try {
            PreparedStatement ps;
            ps = con.prepareStatement("SELECT createdat FROM accounts WHERE id = ?");
            ps.setInt(1, getAccID());
            ResultSet rs = ps.executeQuery();
            if (!rs.next()) {
                rs.close();
                ps.close();
                return null;
            }
            Timestamp ret = rs.getTimestamp("createdat");
            rs.close();
            ps.close();
            return ret;
        } catch (SQLException e) {
            throw new DatabaseException("error getting create", e);
        }
    }

    public String getTempIP() {
        return tempIP;
    }

    public void setTempIP(String s) {
        this.tempIP = s;
    }

    public boolean isLocalhost() {
        return ServerConstants.Use_Localhost;
    }
}

BuddyListHandler
Code:
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 ~ 2010 Patrick Huy <patrick.huy@frz.cc> 
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation. You may not use, modify
or distribute this program under any other version of the
GNU Affero General Public License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package handling.channel.handler;

import static client.BuddyList.BuddyOperation.ADDED;
import static client.BuddyList.BuddyOperation.DELETED;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import client.BuddyList;
import client.BuddylistEntry;
import client.CharacterNameAndId;
import client.MapleCharacter;
import client.MapleClient;
import client.BuddyList.BuddyAddResult;
import client.BuddyList.BuddyOperation;
import database.DatabaseConnection;
import handling.channel.ChannelServer;
import handling.world.World;
import tools.data.LittleEndianAccessor;
import tools.packet.CWvsContext.BuddylistPacket;

public class BuddyListHandler {

    private static final class CharacterIdNameBuddyCapacity extends CharacterNameAndId {

        private int buddyCapacity;

        public CharacterIdNameBuddyCapacity(int id, String name, String group, int buddyCapacity) {
            super(id, name, group);
            this.buddyCapacity = buddyCapacity;
        }

        public int getBuddyCapacity() {
            return buddyCapacity;
        }
    }

    private static final CharacterIdNameBuddyCapacity getCharacterIdAndNameFromDatabase(final String name, final String group) throws SQLException {
        Connection con = DatabaseConnection.getConnection();

        PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE name LIKE ?");
        ps.setString(1, name);
        ResultSet rs = ps.executeQuery();
        CharacterIdNameBuddyCapacity ret = null;
        if (rs.next()) {
            if (rs.getInt("gm") < 3) {
                ret = new CharacterIdNameBuddyCapacity(rs.getInt("id"), rs.getString("name"), group, rs.getInt("buddyCapacity"));
            }
        }
        rs.close();
        ps.close();

        return ret;
    }

    public static final void BuddyOperation(final LittleEndianAccessor slea, final MapleClient c) {
        final int mode = slea.readByte();
        final BuddyList buddylist = c.getPlayer().getBuddylist();

        if (mode == 1) { // add
            final String addName = slea.readMapleAsciiString();
            final String groupName = slea.readMapleAsciiString();
            final BuddylistEntry ble = buddylist.get(addName);

            if (addName.length() > 13 || groupName.length() > 16) {
                return;
            }
            if (ble != null && (ble.getGroup().equals(groupName) || !ble.isVisible())) {
                c.getSession().write(BuddylistPacket.buddylistMessage((byte) 11));
	    } else if (ble != null && ble.isVisible()) {
	    	ble.setGroup(groupName);
		c.getSession().write(BuddylistPacket.updateBuddylist(buddylist.getBuddies(), 10));
            } else if (buddylist.isFull()) {
                c.getSession().write(BuddylistPacket.buddylistMessage((byte) 11));
            } else {
                try {
                    CharacterIdNameBuddyCapacity charWithId = null;
                    int channel = World.Find.findChannel(addName);
                    MapleCharacter otherChar = null;
                    if (channel > 0) {
			otherChar = ChannelServer.getInstance(channel).getPlayerStorage().getCharacterByName(addName);
			if (otherChar == null) {
			    charWithId = getCharacterIdAndNameFromDatabase(addName, groupName);
                        } else if (!otherChar.isIntern() || c.getPlayer().isIntern()) {
                            charWithId = new CharacterIdNameBuddyCapacity(otherChar.getId(), otherChar.getName(), groupName, otherChar.getBuddylist().getCapacity());
                        }
                    } else {
                        charWithId = getCharacterIdAndNameFromDatabase(addName, groupName);
                    }

                    if (charWithId != null) {
                        BuddyAddResult buddyAddResult = null;
                        if (channel > 0) {
                            buddyAddResult = World.Buddy.requestBuddyAdd(addName, c.getChannel(), c.getPlayer().getId(), c.getPlayer().getName(), c.getPlayer().getLevel(), c.getPlayer().getJob());
                        } else {
                            Connection con = DatabaseConnection.getConnection();
                            PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) as buddyCount FROM buddies WHERE characterid = ? AND pending = 0");
                            ps.setInt(1, charWithId.getId());
                            ResultSet rs = ps.executeQuery();

                            if (!rs.next()) {
                                ps.close();
                                rs.close();
                                throw new RuntimeException("Result set expected");
                            } else {
                                int count = rs.getInt("buddyCount");
                                if (count >= charWithId.getBuddyCapacity()) {
                                    buddyAddResult = BuddyAddResult.BUDDYLIST_FULL;
                                }
                            }
                            rs.close();
                            ps.close();

                            ps = con.prepareStatement("SELECT pending FROM buddies WHERE characterid = ? AND buddyid = ?");
                            ps.setInt(1, charWithId.getId());
                            ps.setInt(2, c.getPlayer().getId());
                            rs = ps.executeQuery();
                            if (rs.next()) {
                                buddyAddResult = BuddyAddResult.ALREADY_ON_LIST;
                            }
                            rs.close();
                            ps.close();
                        }
                        if (buddyAddResult == BuddyAddResult.BUDDYLIST_FULL) {
                            c.getSession().write(BuddylistPacket.buddylistMessage((byte) 12));
                        } else {
                            int displayChannel = -1;
                            int otherCid = charWithId.getId();
                            if (buddyAddResult == BuddyAddResult.ALREADY_ON_LIST && channel > 0) {
                                displayChannel = channel;
                                notifyRemoteChannel(c, channel, otherCid, groupName, ADDED);
                            } else if (buddyAddResult != BuddyAddResult.ALREADY_ON_LIST) {
                                Connection con = DatabaseConnection.getConnection();
                                PreparedStatement ps = con.prepareStatement("INSERT INTO buddies (`characterid`, `buddyid`, `groupname`, `pending`) VALUES (?, ?, ?, 1)");
                                ps.setInt(1, charWithId.getId());
                                ps.setInt(2, c.getPlayer().getId());
                                ps.setString(3, groupName);
                                ps.executeUpdate();
                                ps.close();
                            }
                            buddylist.put(new BuddylistEntry(charWithId.getName(), otherCid, groupName, displayChannel, true));
                            c.getSession().write(BuddylistPacket.updateBuddylist(buddylist.getBuddies(), 10));
                        }
                    } else {
                        c.getSession().write(BuddylistPacket.buddylistMessage((byte) 15));
                    }
                } catch (SQLException e) {
                    System.err.println("SQL THROW" + e);
                }
            }
        } else if (mode == 2) { // accept buddy
            int otherCid = slea.readInt();
            final BuddylistEntry ble = buddylist.get(otherCid);
            if (!buddylist.isFull() && ble != null && !ble.isVisible()) {
                final int channel = World.Find.findChannel(otherCid);
                buddylist.put(new BuddylistEntry(ble.getName(), otherCid, "ETC", channel, true));
                c.getSession().write(BuddylistPacket.updateBuddylist(buddylist.getBuddies(), 10));
                notifyRemoteChannel(c, channel, otherCid, "ETC", ADDED);
            } else {
                c.getSession().write(BuddylistPacket.buddylistMessage((byte) 11));
            }
        } else if (mode == 3) { // delete
            final int otherCid = slea.readInt();
	    final BuddylistEntry blz = buddylist.get(otherCid);
            if (blz != null && blz.isVisible()) {
                notifyRemoteChannel(c, World.Find.findChannel(otherCid), otherCid, blz.getGroup(), DELETED);
            }
            buddylist.remove(otherCid);
            c.getSession().write(BuddylistPacket.updateBuddylist(buddylist.getBuddies(), 18));
	}
    }

    private static final void notifyRemoteChannel(final MapleClient c, final int remoteChannel, final int otherCid, final String group, final BuddyOperation operation) {
        final MapleCharacter player = c.getPlayer();

        if (remoteChannel > 0) {
            World.Buddy.buddyChanged(otherCid, player.getId(), player.getName(), c.getChannel(), operation, group);
        }
    }
}
 
Newbie Spellweaver
Joined
Feb 14, 2008
Messages
22
Reaction score
3
result:
ant -f C:\\Users\\****\\Documents\\NetBeansProjects\\Lithium jar
init:
Deleting: C:\Users\****\Documents\NetBeansProjects\Lithium\build\built-jar.properties
deps-jar:
Updating property file: C:\Users\****\Documents\NetBeansProjects\Lithium\build\built-jar.properties
Compiling 330 source files to C:\Users\****\Documents\NetBeansProjects\Lithium\build\classes
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\MapleCharacter.java:70: error: class MapleClient is public, should be declared in a file named MapleClient.java
public class MapleClient implements Serializable {
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\MapleClient.java:70: error: duplicate class: client.MapleClient
public class MapleClient implements Serializable {
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\status\MonsterStatusEffect.java:24: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\life\MapleMonster.java:39: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:22: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:43: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\MapleSquad.java:6: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CField.java:21: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\events\MapleSnowball.java:24: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\events\MapleEvent.java:24: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\Battler.java:771: error: cannot find symbol
public void gainExp(int xp, MapleCharacter chr) {
symbol: class MapleCharacter
location: class Battler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\Battler.java:791: error: cannot find symbol
public void evolve(boolean skipCheck, MapleCharacter chr) {
symbol: class MapleCharacter
location: class Battler
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\life\MobSkill.java:32: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\status\MonsterStatusEffect.java:35: error: cannot find symbol
private WeakReference<MapleCharacter> weakChr = null;
symbol: class MapleCharacter
location: class MonsterStatusEffect
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\status\MonsterStatusEffect.java:91: error: cannot find symbol
public final void setPoisonSchedule(final int poisonSchedule, MapleCharacter chrr) {
symbol: class MapleCharacter
location: class MonsterStatusEffect
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\life\MapleMonster.java:75: error: cannot find symbol
private WeakReference<MapleCharacter> controller = new WeakReference<MapleCharacter>(null);
symbol: class MapleCharacter
location: class MapleMonster
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\scripting\EventInstanceManager.java:33: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\life\MapleMonster.java:213: error: cannot find symbol
public final void damage(final MapleCharacter from, final long damage, final boolean updateAttackTime) {
symbol: class MapleCharacter
location: class MapleMonster
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\life\MapleMonster.java:217: error: cannot find symbol
public final void damage(final MapleCharacter from, final long damage, final boolean updateAttackTime, final int lastSkill) {
symbol: class MapleCharacter
location: class MapleMonster
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\life\MapleMonster.java:357: error: cannot find symbol
private final void giveExpToCharacter(final MapleCharacter attacker, int exp, final boolean highestDamage, final int numExpSharers, final byte pty, final byte Class_Bonus_EXP_PERCENT, final byte Premium_Bonus_EXP_PERCENT, final int lastskillID) {
symbol: class MapleCharacter
location: class MapleMonster
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\life\MapleMonster.java:401: error: cannot find symbol
public final int killBy(final MapleCharacter killer, final int lastSkill) {
symbol: class MapleCharacter
location: class MapleMonster
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\life\MapleMonster.java:661: error: cannot find symbol
public final MapleCharacter getController() {
symbol: class MapleCharacter
location: class MapleMonster
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\life\MapleMonster.java:665: error: cannot find symbol
public final void setController(final MapleCharacter controller) {
symbol: class MapleCharacter
location: class MapleMonster
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\life\MapleMonster.java:669: error: cannot find symbol
public final void switchController(final MapleCharacter newController, final boolean immediateAggro) {
symbol: class MapleCharacter
location: class MapleMonster
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\life\MapleMonster.java:806: error: cannot find symbol
public final void applyStatus(final MapleCharacter from, final MonsterStatusEffect status, final boolean poison, long duration, final boolean checkboss, final MapleStatEffect eff) {
symbol: class MapleCharacter
location: class MapleMonster
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\MapleStatEffect.java:16: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\life\MapleMonster.java:1104: error: cannot find symbol
public final void doPoison(final MonsterStatusEffect status, final WeakReference<MapleCharacter> weakChr) {
symbol: class MapleCharacter
location: class MapleMonster
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\life\MapleMonster.java:1445: error: cannot find symbol
public final void handleSteal(MapleCharacter chr) {
symbol: class MapleCharacter
location: class MapleMonster
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\MapleTrait.java:65: error: cannot find symbol
public void addExp(int e, MapleCharacter c) {
symbol: class MapleCharacter
location: class MapleTrait
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\MapleTrait.java:69: error: cannot find symbol
public void addTrueExp(int e, MapleCharacter c) {
symbol: class MapleCharacter
location: class MapleTrait
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:2503: error: cannot find symbol
public static byte[] updatePlayerStats(final Map<MapleStat, Integer> stats, final MapleCharacter chr) {
symbol: class MapleCharacter
location: class CWvsContext
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:2507: error: cannot find symbol
public static byte[] updatePlayerStats(final Map<MapleStat, Integer> mystats, final boolean itemReaction, final MapleCharacter chr) {
symbol: class MapleCharacter
location: class CWvsContext
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:2587: error: cannot find symbol
public static byte[] temporaryStats_Balrog(final MapleCharacter chr) {
symbol: class MapleCharacter
location: class CWvsContext
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:2729: error: cannot find symbol
public static byte[] updateMount(MapleCharacter chr, boolean levelup) {
symbol: class MapleCharacter
location: class CWvsContext
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:2751: error: cannot find symbol
public static byte[] useSkillBook(MapleCharacter chr, int skillid, int maxlevel, boolean canuse, boolean success) {
symbol: class MapleCharacter
location: class CWvsContext
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:2808: error: cannot find symbol
public static byte[] updateGender(MapleCharacter chr) { // Send this upon entering cs
symbol: class MapleCharacter
location: class CWvsContext
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:2817: error: cannot find symbol
public static byte[] charInfo(final MapleCharacter chr, final boolean isSelf) {
symbol: class MapleCharacter
location: class CWvsContext
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:2921: error: cannot find symbol
public static byte[] getMonsterBookInfo(MapleCharacter chr) {
symbol: class MapleCharacter
location: class CWvsContext
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\shops\HiredMerchant.java:27: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\shops\AbstractPlayerStore.java:35: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\shops\IMaplePlayerShop.java:24: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:3221: error: cannot find symbol
public static byte[] sendEngagement(final byte msg, final int item, final MapleCharacter male, final MapleCharacter female) {
symbol: class MapleCharacter
location: class CWvsContext
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:3221: error: cannot find symbol
public static byte[] sendEngagement(final byte msg, final int item, final MapleCharacter male, final MapleCharacter female) {
symbol: class MapleCharacter
location: class CWvsContext
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\life\PlayerNPC.java:33: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:3397: error: cannot find symbol
public static byte[] upgradeBook(Item book, MapleCharacter chr) { //slot -55
symbol: class MapleCharacter
location: class CWvsContext
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:3422: error: cannot find symbol
public static byte[] getFamiliarInfo(MapleCharacter chr) {
symbol: class MapleCharacter
location: class CWvsContext
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:3540: error: cannot find symbol
public static byte[] getAvatarMega(final MapleCharacter chr, final int channel, final int itemId, final List<String> text, final boolean ear) {
symbol: class MapleCharacter
location: class CWvsContext
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:3622: error: cannot find symbol
public static byte[] updateJaguar(MapleCharacter from) {
symbol: class MapleCharacter
location: class CWvsContext
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:3690: error: cannot find symbol
public static byte[] findFriendResult(final List<MapleCharacter> friends) {
symbol: class MapleCharacter
location: class CWvsContext
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CWvsContext.java:3718: error: cannot find symbol
public static byte[] friendCharacterInfo(final MapleCharacter chr) {
symbol: class MapleCharacter
location: class CWvsContext
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:112: error: cannot find symbol
private final List<MapleCharacter> characters = new ArrayList<MapleCharacter>();
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:440: error: cannot find symbol
private void dropFromMonster(final MapleCharacter chr, final MapleMonster mob, final boolean instanced) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:568: error: cannot find symbol
public final void killMonster(final MapleMonster monster, final MapleCharacter chr, final boolean withDrops, final boolean second, byte animation) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:572: error: cannot find symbol
public final void killMonster(final MapleMonster monster, final MapleCharacter chr, final boolean withDrops, final boolean second, byte animation, final int lastSkill) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleSummon.java:25: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleDoor.java:29: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MechDoor.java:29: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleExtractor.java:3: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMist.java:27: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:1688: error: cannot find symbol
public final void disappearingItemDrop(final MapleMapObject dropper, final MapleCharacter owner, final Item item, final Point pos) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:1694: error: cannot find symbol
public final void spawnMesoDrop(final int meso, final Point position, final MapleMapObject dropper, final MapleCharacter owner, final boolean playerDrop, final byte droptype) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:1713: error: cannot find symbol
public final void spawnMobMesoDrop(final int meso, final Point position, final MapleMapObject dropper, final MapleCharacter owner, final boolean playerDrop, final byte droptype) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:1730: error: cannot find symbol
public final void spawnMobDrop(final Item idrop, final Point dropPos, final MapleMonster mob, final MapleCharacter chr, final byte droptype, final int questid) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:1807: error: cannot find symbol
public final void spawnItemDrop(final MapleMapObject dropper, final MapleCharacter owner, final Item item, Point pos, final boolean ffaDrop, final boolean playerDrop) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMapItem.java:25: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:1908: error: cannot find symbol
public final void returnEverLastItem(final MapleCharacter chr) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:1977: error: cannot find symbol
public final void addPlayer(final MapleCharacter chr) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\scripting\EventManager.java:31: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:2436: error: cannot find symbol
public final void removePlayer(final MapleCharacter chr) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:2494: error: cannot find symbol
public final void broadcastMessage(final MapleCharacter source, final byte[] packet, final boolean repeatToSource) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:2505: error: cannot find symbol
public final void broadcastMessage(final MapleCharacter source, final byte[] packet, final Point rangedFrom) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:2509: error: cannot find symbol
public void broadcastMessage(final MapleCharacter source, final byte[] packet, final double rangeSq, final Point rangedFrom) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:2528: error: cannot find symbol
private void sendObjectPlacement(final MapleCharacter c) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:2614: error: cannot find symbol
public final List<MapleCharacter> getCharactersIntersect(final Rectangle box) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:2629: error: cannot find symbol
public final List<MapleCharacter> getPlayersInRectAndInList(final Rectangle box, final List<MapleCharacter> chrList) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:2629: error: cannot find symbol
public final List<MapleCharacter> getPlayersInRectAndInList(final Rectangle box, final List<MapleCharacter> chrList) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:2777: error: cannot find symbol
public final List<MapleCharacter> getCharacters() {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:2781: error: cannot find symbol
public final List<MapleCharacter> getCharactersThreadsafe() {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:2796: error: cannot find symbol
public final MapleCharacter getCharacterByName(final String id) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:2810: error: cannot find symbol
public final MapleCharacter getCharacterById_InMap(final int id) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:2814: error: cannot find symbol
public final MapleCharacter getCharacterById(final int id) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:2828: error: cannot find symbol
public final void updateMapObjectVisibility(final MapleCharacter chr, final MapleMapObject mo) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:2862: error: cannot find symbol
public void movePlayer(final MapleCharacter player, final Point newPosition) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:3508: error: cannot find symbol
public void broadcastGMMessage(MapleCharacter source, byte[] packet, boolean repeatToSource) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleMap.java:3512: error: cannot find symbol
private void broadcastGMMessage(MapleCharacter source, byte[] packet) {
symbol: class MapleCharacter
location: class MapleMap
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\MapleSquad.java:35: error: cannot find symbol
private WeakReference<MapleCharacter> leader;
symbol: class MapleCharacter
location: class MapleSquad
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\MapleSquad.java:47: error: cannot find symbol
public MapleSquad(final int ch, final String type, final MapleCharacter leader, final int expiration, final String toSay) {
symbol: class MapleCharacter
location: class MapleSquad
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\MapleSquad.java:121: error: cannot find symbol
public MapleCharacter getChar(String name) {
symbol: class MapleCharacter
location: class MapleSquad
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\MapleSquad.java:185: error: cannot find symbol
public MapleCharacter getLeader() {
symbol: class MapleCharacter
location: class MapleSquad
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\MapleSquad.java:199: error: cannot find symbol
public boolean containsMember(MapleCharacter member) {
symbol: class MapleCharacter
location: class MapleSquad
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\MapleSquad.java:220: error: cannot find symbol
public boolean isBanned(MapleCharacter member) {
symbol: class MapleCharacter
location: class MapleSquad
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\MapleSquad.java:224: error: cannot find symbol
public int addMember(MapleCharacter member, boolean join) {
symbol: class MapleCharacter
location: class MapleSquad
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\MapleSquad.java:263: error: cannot find symbol
public void reAddMember(MapleCharacter chr) {
symbol: class MapleCharacter
location: class MapleSquad
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\MapleSquad.java:268: error: cannot find symbol
public void removeMember(MapleCharacter chr) {
symbol: class MapleCharacter
location: class MapleSquad
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CField.java:1115: error: cannot find symbol
public static byte[] getPVPResult(List<Pair<Integer, MapleCharacter>> flags, int exp, int winningTeam, int playerTeam) { //Flag_R_1 to 0, etc
symbol: class MapleCharacter
location: class CField
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CField.java:1154: error: cannot find symbol
public static byte[] getPVPScoreboard(List<Pair<Integer, MapleCharacter>> flags, int type) { //Flag_R_1 to 0, etc
symbol: class MapleCharacter
location: class CField
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CField.java:1372: error: cannot find symbol
public static byte[] getCharInfo(final MapleCharacter chr) {
symbol: class MapleCharacter
location: class CField
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CField.java:1399: error: cannot find symbol
public static byte[] getWarpToMap(final MapleMap to, final int spawnPoint, final MapleCharacter chr) {
symbol: class MapleCharacter
location: class CField
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\tools\packet\CField.java:1878: error: cannot find symbol
public static byte[] spawnPlayerMapobject(MapleCharacter chr) {
symbol: class MapleCharacter
location: class CField
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\server\maps\MapleDragon.java:29: error: cannot find symbol
import client.MapleCharacter;
symbol: class MapleCharacter
location: package client
C:\Users\****\Desktop\Server\LithiumREV96\trunk\src\client\messages\CommandProcessor.java:56: warning: non-varargs call of varargs method with inexact argument type for last parameter;
PlayerGMRank rankNeeded = (PlayerGMRank) clasz.getMethod("getPlayerLevelRequired", new Class<?>[]{}).invoke(null, null);
cast to Object for a varargs call
cast to Object[] for a non-varargs call and to suppress this warning
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
100 errors
1 warning
C:\Users\****\Documents\NetBeansProjects\Lithium\nbproject\build-impl.xml:900: The following error occurred while executing this line:
C:\Users\****\Documents\NetBeansProjects\Lithium\nbproject\build-impl.xml:265: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 4 seconds)
 
Junior Spellweaver
Joined
Jul 4, 2012
Messages
111
Reaction score
32
Did you download the repack i listed? Cause these problems are coming from not having the correct source
 
Junior Spellweaver
Joined
Jul 4, 2012
Messages
111
Reaction score
32
I know just stick with it.
Turn on wamp

And if that doesnt help show me your database settings
 
Junior Spellweaver
Joined
Jul 4, 2012
Messages
111
Reaction score
32
in your Lithium folder copy and paste your db.properties on here
 
Back
Top