Guest User

Idek

a guest
Oct 3rd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 193.43 KB | None | 0 0
  1. package Sockets;
  2.  
  3. import java.io.*;
  4. import java.net.Socket;
  5. import java.sql.*;
  6. import Json.*;
  7. import Preload.*;
  8. import Handler.*;
  9. import java.nio.charset.Charset;
  10. import java.text.SimpleDateFormat;
  11. import java.util.*;
  12. import org.jboss.netty.buffer.ChannelBuffer;
  13. import org.jboss.netty.buffer.ChannelBuffers;
  14. import org.jboss.netty.channel.Channel;
  15.  
  16. public class ConnectionHandler {
  17. protected Channel socket;
  18. protected ServerLobby lobby;
  19. protected boolean _running = true;
  20. protected SqlConnection _sql;
  21. protected Room cRoom;
  22. protected Party cParty;
  23. protected Auras _auras = new Auras();
  24. protected StringBuffer _sb = new StringBuffer();
  25. protected List<Skill> _skills = new ArrayList<Skill>();
  26. protected List<Passive> _passives = new ArrayList<Passive>();
  27. protected List<String> _friends = new ArrayList<String>();
  28. protected List<Integer> _loadedItems = new ArrayList<Integer>();
  29. protected HashMap<Integer, Integer> _tempItems = new HashMap<Integer, Integer>();
  30. protected HashMap<String, Integer> _equipment = new HashMap<String, Integer>();
  31.  
  32. protected int[] qAccepted = new int[20];
  33.  
  34. Random _gen = new Random();
  35.  
  36.  
  37. public boolean afk;
  38. public boolean _trace;
  39.  
  40. public boolean ptInvite;
  41. public boolean frndInvite;
  42. public boolean acceptPMs;
  43. public boolean acceptGoto;
  44. public boolean bTT;
  45. public boolean showPet;
  46. public boolean showCloak;
  47. public boolean showHelm;
  48. public boolean soundOn;
  49. public boolean fbShare;
  50.  
  51. public int guildID;
  52. public String guildName;
  53. public int guildColor;
  54.  
  55. public int rankID;
  56. public String rankName;
  57. public int rankColor;
  58.  
  59. public int isReferred;
  60. public int refGold;
  61. public int refExp;
  62. public int ia1;
  63. public int pkSend;
  64. public int iDrops;
  65. public int curTurn;
  66. public int level;
  67. public int classPoints;
  68. public int giveTo;
  69. public int hp;
  70. public int hpmax;
  71. public int mp;
  72. public int mpmax;
  73. public int uID;
  74. public int pID;
  75. public int tx;
  76. public int ty;
  77. public int state = 1;
  78. public int statsEND;
  79. public int ClassID;
  80. public int classRank;
  81. public int access;
  82. public int isFounder;
  83. public int upgrade;
  84. public int upgDays;
  85. public int pvpTeam;
  86.  
  87. public int wepDPS;
  88. public int wepRng;
  89. public int wepLvl;
  90.  
  91. public int expToLevel;
  92.  
  93. public String username = "User";
  94. public String gender;
  95. public String className;
  96. public String frame = "Enter";
  97. public String pad = "Spawn";
  98. public String strQuests;
  99. public String giveToName;
  100. public String referredBy;
  101.  
  102. public ConnectionHandler(Channel _socket) {
  103. socket = _socket;
  104. lobby = Server.lobby;
  105. _trace = Interface._debugAllConnections;
  106. }
  107.  
  108. public boolean parseBoolean(int i) {
  109. if(i > 0) {
  110. return true;
  111. } else {
  112. return false;
  113. }
  114. }
  115.  
  116. public String buildString(String ... _s) {
  117. _sb.setLength(0);
  118. for(int i = 0; i < _s.length; i++) {
  119. _sb.append(_s[i]);
  120. }
  121. return _sb.toString();
  122. }
  123.  
  124. public void readA1Pref() {
  125. if(showCloak)
  126. updateAchievement(0, 0);
  127. else
  128. updateAchievement(0, 1);
  129. if(showHelm)
  130. updateAchievement(1, 0);
  131. else
  132. updateAchievement(1, 1);
  133. if(showPet)
  134. updateAchievement(2, 0);
  135. else
  136. updateAchievement(2, 1);
  137. updateAchievement(3, 0);
  138. updateAchievement(4, 0);
  139. updateAchievement(5, 0);
  140. updateAchievement(6, 0);
  141. updateAchievement(7, 0);
  142. updateAchievement(8, 0);
  143. updateAchievement(9, 0);
  144.  
  145. if(ptInvite) {
  146. sendData("%xt%server%-1%Accepting party invites.%");
  147. updateAchievement(8, 0);
  148. } else {
  149. sendData("%xt%warning%-1%Ignoring party invites.%");
  150. updateAchievement(8, 1);
  151. }
  152.  
  153. if(acceptGoto) {
  154. sendData("%xt%server%-1%Accepting goto requests.%");
  155. updateAchievement(4, 0);
  156. } else {
  157. sendData("%xt%warning%-1%Blocking goto requests.%");
  158. updateAchievement(4, 1);
  159. }
  160.  
  161. if(frndInvite) {
  162. sendData("%xt%server%-1%Accepting Friend requests.%");
  163. updateAchievement(7, 0);
  164. } else {
  165. updateAchievement(7, 1);
  166. sendData("%xt%warning%-1%Ignoring Friend requests.%");
  167. }
  168.  
  169. if(soundOn)
  170. updateAchievement(5, 0);
  171. else
  172. updateAchievement(5, 1);
  173.  
  174. if(acceptPMs) {
  175. sendData("%xt%server%-1%Accepting PMs.%");
  176. updateAchievement(10, 0);
  177. } else {
  178. updateAchievement(10, 1);
  179. sendData("%xt%warning%-1%Ignoring PMs.%");
  180. }
  181.  
  182. if(bTT) {
  183. updateAchievement(11, 0);
  184. sendData("%xt%server%-1%Ability ToolTips will always show on mouseover.%");
  185. } else {
  186. updateAchievement(11, 1);
  187. sendData("%xt%warning%-1%Ability ToolTips will not show on mouseover during combat.%");
  188. }
  189.  
  190. if(fbShare) {
  191. updateAchievement(12, 1);
  192. sendData("%xt%server%-1%Event sharing via Facebook is enabled. Badges you have earned can now be shared from the Book of Lore!%");
  193. } else {
  194. updateAchievement(12, 0);
  195. sendData("%xt%warning%-1%Event sharing via Facebook is disabled.%");
  196. }
  197.  
  198. trace("User Preferences Loaded!");
  199. }
  200.  
  201. public void updateAchievement(int index, int value)
  202. {
  203. if (value == 0)
  204. ia1 = ia1 & ~(int)Math.pow(2, index);
  205. else if (value == 1)
  206. ia1 = ia1 | (int)Math.pow(2, index);
  207.  
  208. }
  209.  
  210. public int getAchievement(int isOpen)
  211. {
  212. if (isOpen < 0 || isOpen > 31)
  213. {
  214. return -1;
  215. }
  216. return (ia1 & (int)Math.pow(2, isOpen)) == 0 ? (0) : (1);
  217. }
  218.  
  219. private void trace(String msg) {
  220. if(_trace)
  221. Interface.writeLog(buildString("[", username, "] ", msg), 2);
  222. }
  223.  
  224. private void traceError(String msg) {
  225. Interface.writeLog(buildString("[", username, "] ", msg), 2);
  226. }
  227.  
  228. protected void traceLogin(String msg) {
  229. //Interface.writeLog("[User] " + msg, 1);
  230. }
  231.  
  232. protected void traceChat(String msg) {
  233. if(cRoom.roomNick.length() > 0)
  234. Interface.writeLog(buildString("[", cRoom.roomName, "-", cRoom.roomNick, "] ", username, ": ", lobby.cleanStr(msg)), 3);
  235. else
  236. Interface.writeLog(buildString("[", cRoom.roomName, "-", Integer.toString(cRoom.roomNum), "] ", username, ": ", lobby.cleanStr(msg)).toString(), 3);
  237. }
  238.  
  239. protected void tracePacket(String msg) {
  240. if(_trace)
  241. Interface.writeLog(msg, 4);
  242. }
  243.  
  244. public synchronized void closeSocket()
  245. {
  246. lobby.removeClient(this);
  247. trace("Socket Closed.");
  248. }
  249.  
  250. private String getCmd(String data){
  251. if (data.startsWith("<")) {
  252. int endArrow = data.indexOf(">");
  253. int endSlash = data.indexOf("/>");
  254. if (endSlash < 0)
  255. endSlash = endArrow + 1;
  256. if (endSlash < endArrow)
  257. return data.substring(1, endSlash);
  258. else
  259. return data.substring(1, endArrow);
  260. } else if (data.startsWith("%")) {
  261. String data_handled[] = data.split("%");
  262. return data_handled[3];
  263. }
  264. return "Error";
  265. }
  266.  
  267. public synchronized void sendData(String data) {
  268. tracePacket(data);
  269.  
  270. ChannelBuffer packet = ChannelBuffers.copiedBuffer(data, 0, data.length(), Charset.forName("UTF-8"));
  271. packet.writeByte(0);
  272.  
  273. if (socket.isWritable()) {
  274. socket.write(packet);
  275. }
  276. }
  277.  
  278. public synchronized void sendData(JSONObject data) {
  279. try {
  280. JSONObject json = new JSONObject();
  281. JSONObject b = new JSONObject();
  282. b.put("r", -1);
  283. b.put("o", data);
  284. json.put("t","xt");
  285. json.put("b", b);
  286. String pData = json.toString();
  287. tracePacket(pData);
  288.  
  289. ChannelBuffer packet = ChannelBuffers.copiedBuffer(pData, 0, pData.length(), Charset.forName("UTF-8"));
  290. packet.writeByte(0);
  291.  
  292. if (socket.isWritable()) {
  293. socket.write(packet);
  294. }
  295. } catch (JSONException e) {
  296. traceError(e.getMessage());
  297. }
  298. }
  299.  
  300. protected void parsePacket(String data) {
  301. try {
  302. Long start = null;
  303. if(_trace)
  304. start = System.currentTimeMillis();
  305.  
  306. data = data.substring(0, (data.length() - 1));
  307. String cmd = getCmd(data);
  308. Packet recvPack = new Packet();
  309. recvPack.setPacket(data);
  310. recvPack.removeHeader();
  311. tracePacket(data);
  312.  
  313. pkSend += 1;
  314.  
  315. if(pkSend > 250)
  316. lobby.kickPlayer(username, "packet spamming");
  317.  
  318. String dataNod[] = recvPack.getPacket().split("%");
  319. if(cmd.equals("policy-file-request")) {
  320. sendData("<cross-domain-policy><allow-access-from domain='*' to-ports='5588' /></cross-domain-policy>");
  321. } else if (cmd.equals("msg t='sys'")) {
  322. String sys = recvPack.getXMLSingle("body action");
  323. if(sys.equals("verChk")) {
  324. sendData("<msg t='sys'><body action='apiOK'></body></msg>");
  325. } else if (sys.equals("login")) {
  326. handleLogin(recvPack.getCDATA(recvPack.getXML("nick")), recvPack.getCDATA(recvPack.getXML("pword")));
  327. }
  328. } else if(cmd.equals("firstJoin")) {
  329. joinRoom("battleon", -1, "Enter", "Spawn", false);
  330. } else if(cmd.equals("moveToCell")) {
  331. moveToCell(dataNod[2], dataNod[3]);
  332. } else if(cmd.equals("retrieveUserDatas")) {
  333. initUserDatas(recvPack.getPacket());
  334. } else if(cmd.equals("retrieveUserData")) {
  335. initUserData(Integer.parseInt(dataNod[2]));
  336. } else if(cmd.equals("retrieveInventory")) {
  337. loadInventoryBig();
  338. } else if (cmd.equals("isModerator")) {
  339. if(lobby.getHandler(dataNod[2]).access > 39) {
  340. sendData(new JSONObject().put("cmd", "isModerator").put("val", true).put("unm", dataNod[2]));
  341. } else {
  342. sendData(new JSONObject().put("cmd", "isModerator").put("val", false).put("unm", dataNod[2]));
  343. }
  344. } else if (cmd.equals("mv")) {
  345. userMove(Integer.parseInt(dataNod[2]), Integer.parseInt(dataNod[3]), Integer.parseInt(dataNod[4]), true);
  346. } else if (cmd.equals("message")) {
  347. if(Interface._rankChat) {
  348. if (access > 0 && access < 40) dataNod[3] = "vip";
  349. if (access > 39) dataNod[3] = "mod";
  350. if (access > 59) dataNod[3] = "trade";
  351. }
  352. userChat(Integer.parseInt(dataNod[1]), dataNod[2], dataNod[3]);
  353. } else if (cmd.equals("cmd")) {
  354. String cmdSwitch = dataNod[2];
  355. if (cmdSwitch.equals("tfer")) {
  356. try {
  357. if (dataNod[4].indexOf("-") > 0) {
  358. String room[] = dataNod[4].split("-");
  359. if(!isInteger(room[1])) {
  360. joinRoom(room[0], room[1], "Enter", "Spawn", false);
  361. } else {
  362. joinRoom(room[0], Integer.parseInt(room[1]), "Enter", "Spawn", false);
  363. }
  364. } else {
  365. if (dataNod.length > 6) {
  366. joinRoom(dataNod[4], -1, dataNod[5], dataNod[6], false);
  367. } else {
  368. joinRoom(dataNod[4], -1, "Enter", "Spawn", false);
  369. }
  370. }
  371. } catch (Exception e) {
  372. traceError(e.getMessage());
  373. }
  374. } else if (cmdSwitch.equals("house")) {
  375. if(doUserHaveHouse(dataNod[3]))
  376. joinHouse(lobby.getUID(dataNod[3]));
  377. else
  378. sendData(new JSONObject().put("cmd", cmdSwitch).put("msg", "House not Found").put("unm", dataNod[3]));
  379. } else if (cmdSwitch.equals("saveHouseSetup")) {
  380. _sql.update("UPDATE etl_users SET sHouseInfo='"+dataNod[4]+"' WHERE strUsername='"+dataNod[3]+"'");
  381. } else if (cmdSwitch.equals("uopref")) {
  382. changeUserSettings(Boolean.parseBoolean(dataNod[4]), dataNod[3]);
  383. } else if (cmdSwitch.equals("goto")) {
  384. boolean ignore = false;
  385. if(dataNod[3].contains("@")) {
  386. dataNod[3] = dataNod[3].substring(1);
  387. ignore = true;
  388. }
  389. if(lobby.getPID(dataNod[3]) > 0) {
  390. ConnectionHandler _temp = lobby.getHandler(dataNod[3]);
  391. if(_temp.acceptGoto || (ignore && access > 39)) {
  392. if(!_temp.cRoom.roomName.equals("bludrutbrawl")) {
  393. if(_temp.cRoom.roomName.equals("house")) {
  394. joinHouse(cRoom.roomNum);
  395. return;
  396. }
  397. if(_temp.cRoom.roomNick.length() > 0)
  398. joinRoom(_temp.cRoom.roomName, _temp.cRoom.roomNick, _temp.frame, _temp.pad, false);
  399. else
  400. joinRoom(_temp.cRoom.roomName, _temp.cRoom.roomNum, _temp.frame, _temp.pad, false);
  401. } else {
  402. sendData(buildString("%xt%warning%-1%", dataNod[3], " is currently busy.%"));
  403. }
  404. } else {
  405. sendData(buildString("%xt%server%-1%", dataNod[3], " is ignoring goto requests.%"));
  406. sendData("%xt%warning%-1%Invalid /goto request.%");
  407. }
  408. } else {
  409. sendData(buildString("%xt%server%-1%Player \"", dataNod[3], "\" could not be found%"));
  410. }
  411. } else if (cmdSwitch.equals("myid")) {
  412. sendData("%xt%warning%-1%Your pID is: "+pID+"%");
  413. } else if ((cmdSwitch.equals("guildcreate")) &&(this.access > 5)) {
  414.  
  415. _sql.update("UPDATE etl_guilds SET guildID="+pID+", GuildColor=16777215, guildName='"+dataNod[3]+"' WHERE strUsername='"+dataNod[4]+"'");
  416. sendData("%xt%server%-1%You have created a guild named "+dataNod[3]+".");
  417.  
  418. } else if ((cmdSwitch.equals("rankcreate")) && (this.access > 59)) {
  419. this._sql.update("UPDATE etl_ranks SET RankColor=16777215, RankName='"+dataNod[3]+"' WHERE strUsername='"+dataNod[4]+"'");
  420. sendData("%xt%server%-1%You have created a rank named "+dataNod[3]+"");
  421.  
  422. }
  423. else if (cmdSwitch.equals("changename") && access > 59) {
  424. if(lobby.getPID(dataNod[3]) > 0 && dataNod[4].length() > 0) {
  425. if (lobby.getAnChange(dataNod[4]) > 0) {
  426. _sql.update("UPDATE etl_users SET strUsername='" + dataNod[4] + "' WHERE strUsername='" + dataNod[3] + "'");
  427. lobby.kickPlayerNC(dataNod[3]);
  428. sendData("%xt%server%-1%You changed "+dataNod[3]+"'s name to: "+dataNod[4]+"%");
  429. } else {
  430. sendData("%xt%warning%-1%There is already a player named "+dataNod[4]+"%");
  431. }
  432.  
  433. } else if(lobby.getPIDFD(dataNod[3]) > 0 && dataNod[4].length() > 0) {
  434. if (lobby.getAnChange(dataNod[4]) > 0) {
  435. _sql.update("UPDATE etl_users SET strUsername='" + dataNod[4] + "' WHERE strUsername='" + dataNod[3] + "'");
  436. sendData("%xt%server%-1%You changed "+dataNod[3]+"'s name to: "+dataNod[4]+"%");
  437. } else {
  438. sendData("%xt%warning%-1%There is already a player named "+dataNod[4]+"%");
  439. }
  440. } else {
  441. sendData(buildString("%xt%server%-1%Player \"", dataNod[3], "\" could not be found%"));
  442. }
  443.  
  444. } else if (cmdSwitch.equals("mute") && access > 39) {
  445. if(dataNod[4].length() > 0 && Integer.parseInt(dataNod[3]) > 0) {
  446. if(lobby.getPID(dataNod[4]) > 0) {
  447. lobby.sendDataToPlayer(dataNod[4], "%xt%mute%-1%" + (Integer.parseInt(dataNod[3]) * 1000 * 60) + "%");
  448. lobby.sendDataToPlayer(dataNod[4], "%xt%warning%-1%"+username+" muted you for "+dataNod[3]+" minutes.%");
  449. sendData("%xt%warning%-1%You muted "+dataNod[4]+" for "+dataNod[3]+" minutes.%");
  450. } else if(lobby.getPIDFD(dataNod[4]) > 0) {
  451. lobby.sendDataToPlayer(dataNod[4], "%xt%mute%-1%" + (Integer.parseInt(dataNod[3]) * 1000 * 60) + "%");
  452. sendData("%xt%warning%-1%You muted "+dataNod[4]+" for "+dataNod[3]+" minutes.%");
  453. } else {
  454. sendData(buildString("%xt%server%-1%Player \"", dataNod[4], "\" could not be found%"));
  455. }
  456. }
  457. } else if (cmdSwitch.equals("unmute") && access > 39) {
  458. if(lobby.getPID(dataNod[3]) > 0) {
  459. lobby.sendDataToPlayer(dataNod[3], "%xt%unmute%-1%");
  460. sendData("%xt%server%-1%You unmuted "+dataNod[3]+".%");
  461. } else if(lobby.getPIDFD(dataNod[3]) > 0) {
  462. lobby.sendDataToPlayer(dataNod[3], "%xt%unmute%-1%");
  463. sendData("%xt%server%-1%You unmuted "+dataNod[3]+".%");
  464. } else {
  465. sendData(buildString("%xt%server%-1%Player \"", dataNod[3], "\" could not be found%"));
  466. }
  467. } else if ((cmdSwitch.equals("iay") || cmdSwitch.equals("adminyell"))) {
  468. if(access > 39) {
  469. lobby.sendData(buildString("%xt%moderator%-1%(", username, "): ", dataNod[3], "%"));
  470. Interface.writeLog(buildString("[Global] (", username, "): ", dataNod[3]), 3);
  471. } else if (access > 0 && access < 40) {
  472. lobby.sendData(buildString("%xt%server%-1%(", username, "): ", dataNod[3], "%"));
  473. Interface.writeLog(buildString("[Global] (", username, "): ", dataNod[3]), 3);
  474. }
  475. } else if (cmdSwitch.equals("clock") && (access > 0 && access < 40)) {
  476. loadShop(Integer.parseInt(dataNod[3]));
  477. } else if (cmdSwitch.equals("level") && access > 39) {
  478. if(isInteger(dataNod[3]))
  479. if(Integer.parseInt(dataNod[3]) <= lobby.maxLevel && Integer.parseInt(dataNod[3]) > 0)
  480. levelUp(Integer.parseInt(dataNod[3]));
  481. else if(Integer.parseInt(dataNod[3]) > lobby.maxLevel)
  482. sendData("%xt%warning%-1%Maximum level is "+lobby.maxLevel+"!%");
  483. else if(Integer.parseInt(dataNod[3]) < 1)
  484. sendData("%xt%warning%-1%Minimum level is 1!%");
  485. } else if (cmdSwitch.equals("kick") && access > 39) {
  486. String player = dataNod[3];
  487. String reason = "";
  488. if(dataNod[3].contains("@")) {
  489. String[] lul = dataNod[3].split("@");
  490. player = lul[0];
  491. reason = lul[1];
  492. }
  493. if(lobby.getPID(player) > 0) {
  494. if(reason.length() > 0) {
  495. lobby.kickPlayer(player, reason);
  496. } else
  497. lobby.kickPlayer(player);
  498. } else
  499. sendData(buildString("%xt%server%-1%Player \"", player, "\" could not be found%"));
  500. } else if (cmdSwitch.equals("ban") && access > 39) {
  501. sendData(buildString("%xt%server%-1%\"ban\" is deprecated. Please use /modban%"));
  502. } else if (cmdSwitch.equals("modban") && access > 39) {
  503. if(lobby.getPID(dataNod[3]) > 0)
  504. lobby.updatePlayer(dataNod[3], "banned", 1);
  505. else
  506. if(lobby.getPIDFD(dataNod[3]) > 0)
  507. lobby.updatePlayer(dataNod[3], "banned", 1);
  508. else
  509. sendData(buildString("%xt%server%-1%Player \"", (dataNod[3]), "\" could not be found%"));
  510. } else if (cmdSwitch.equals("unban") && access > 39) {
  511. if(lobby.getPID(dataNod[3]) > 0)
  512. lobby.updatePlayer(dataNod[3], "banned", 0);
  513. else
  514. if(lobby.getPIDFD(dataNod[3]) > 0)
  515. lobby.updatePlayer(dataNod[3], "banned", 0);
  516. else
  517. sendData(buildString("%xt%server%-1%Player \"", dataNod[3], "\" could not be found%"));
  518. } else if (cmdSwitch.equals("addgold") && access > 39) {
  519. if(dataNod.length >= 5) {
  520. giveToName = dataNod[4];
  521. giveTo = lobby.getPID(giveToName);
  522. } else {
  523. giveTo = 0;
  524. }
  525. if(isInteger(dataNod[3]) && giveTo > 0) {
  526. lobby.addRewards(giveTo, 0, Integer.parseInt(dataNod[3]), 0, "q", giveTo, -1, 0);
  527. sendData(buildString("%xt%server%-1%You added "+dataNod[3]+" gold to "+giveToName+"'s account.%"));
  528. lobby.sendDataToPlayer(giveToName, "%xt%server%-1%"+username+" added "+dataNod[3]+" gold to your account.%");
  529. } else if(isInteger(dataNod[3]) && dataNod.length <= 4) {
  530. lobby.addRewards(pID, 0, Integer.parseInt(dataNod[3]), 0, "q", pID, -1, 0);
  531. } else {
  532. sendData(buildString("%xt%server%-1%Player \"", giveToName, "\" could not be found%"));
  533. }
  534. } else if (cmdSwitch.equals("addcp") && access > 39) {
  535. sendData(buildString("%xt%server%-1%\"addcp\" is deprecated. Please use /addrep%"));
  536. } else if (cmdSwitch.equals("addrep") && access > 39) {
  537. if(dataNod.length >= 5) {
  538. giveToName = dataNod[4];
  539. giveTo = lobby.getPID(giveToName);
  540. } else {
  541. giveTo = 0;
  542. }
  543. if(isInteger(dataNod[3]) && giveTo > 0) {
  544. lobby.addRewards(giveTo, Integer.parseInt(dataNod[3]), 0, 0, "q", giveTo, -1, 0);
  545. sendData(buildString("%xt%server%-1%You added "+dataNod[3]+" class points to "+giveToName+"'s account.%"));
  546. lobby.sendDataToPlayer(giveToName, "%xt%server%-1%"+username+" added "+dataNod[3]+" class points to your account.%");
  547. } else if(isInteger(dataNod[3]) && dataNod.length <= 4) {
  548. lobby.addRewards(pID, Integer.parseInt(dataNod[3]), 0, 0, "q", pID, -1, 0);
  549. } else {
  550. sendData(buildString("%xt%server%-1%Player \"", giveToName, "\" could not be found%"));
  551. }
  552. } else if (cmdSwitch.equals("addcoin") && access > 59) {
  553. if(dataNod.length >= 5) {
  554. giveToName = dataNod[4];
  555. giveTo = lobby.getUID(giveToName);
  556. } else {
  557. giveTo = 0;
  558. }
  559. if(isInteger(dataNod[3]) && giveTo > 0) {
  560. _sql.update("UPDATE etl_users SET iCoins=iCoins+" + Integer.parseInt(dataNod[3]) + " WHERE id=" + giveTo);
  561. sendData(buildString("%xt%server%-1%You added "+dataNod[3]+" AdventureCoins to "+giveToName+"'s account.%"));
  562. lobby.sendDataToPlayer(giveToName, "%xt%loginResponse%-1%0%-1%%"+username+" added "+dataNod[3]+" AdventureCoins to your account. Congratulations!%");
  563. } else if(isInteger(dataNod[3]) && dataNod.length <= 4) {
  564. _sql.update("UPDATE etl_users SET iCoins=iCoins+" + Integer.parseInt(dataNod[3]) + " WHERE id=" + giveTo);
  565. lobby.sendDataToPlayer(giveToName, "%xt%loginResponse%-1%0%-1%%You added "+dataNod[3]+" AdventureCoins to your account. ^__^%");
  566. } else {
  567. sendData(buildString("%xt%server%-1%Player \"", giveToName, "\" could not be found%"));
  568. }
  569. } else if (cmdSwitch.equals("addexp") && access > 39) {
  570. if(dataNod.length >= 5) {
  571. giveToName = dataNod[4];
  572. giveTo = lobby.getPID(giveToName);
  573. } else {
  574. giveTo = 0;
  575. }
  576. if(isInteger(dataNod[3]) && giveTo > 0) {
  577. lobby.addRewards(giveTo, 0, 0, Integer.parseInt(dataNod[3]), "q", giveTo, -1, 0);
  578. sendData(buildString("%xt%server%-1%You added "+dataNod[3]+" experience to "+giveToName+"'s account.%"));
  579. lobby.sendDataToPlayer(giveToName, "%xt%server%-1%"+username+" added "+dataNod[3]+" experience to your account.%");
  580. } else if(isInteger(dataNod[3]) && dataNod.length <= 4) {
  581. lobby.addRewards(pID, 0, 0, Integer.parseInt(dataNod[3]), "p", pID, -1, 0);
  582. } else {
  583. sendData(buildString("%xt%server%-1%Player \"", giveToName, "\" could not be found%"));
  584. }
  585.  
  586. } else if (cmdSwitch.equals("shutdown") && access > 59) {
  587. Interface._beginShutdown(false);
  588. Interface._Boot();
  589. } else if (cmdSwitch.equals("shutdownnow") && access > 59) {
  590. Interface._Shutdown(false);
  591. Interface._Boot();
  592. } else if (cmdSwitch.equals("restart") && access > 59) {
  593. Interface._beginShutdown(true);
  594. Interface._Boot();
  595. } else if (cmdSwitch.equals("restartnow") && access > 59) {
  596. Interface._Shutdown(true);
  597. Interface._Boot();
  598. } else if (cmdSwitch.equals("help")) {
  599. sendData(buildString("%xt%server%-1%List of avalaible commands:%"));
  600. if(access > 59) {
  601. sendData(buildString("%xt%server%-1%/changename #player name# #new name# - Change name.%"));
  602. sendData(buildString("%xt%server%-1%/togglerc - Toggle ranked chat on/off.%"));
  603. sendData(buildString("%xt%server%-1%/shutdown - Shutdown server in 15 seconds.%"));
  604. sendData(buildString("%xt%server%-1%/shutdownnow - Shutdown server instantly.%"));
  605. sendData(buildString("%xt%server%-1%/restart - Restart server in 15 seconds.%"));
  606. sendData(buildString("%xt%server%-1%/restartnow - Restart server instantly.%"));
  607. sendData(buildString("%xt%server%-1%/clear (items,shops) - Refresh preloaded datas.%"));
  608. sendData(buildString("%xt%server%-1%/version - Displays server version.%"));
  609. }
  610. if(access > 39) {
  611. sendData(buildString("%xt%server%-1%/iay or /adminyell #message# - Send a global message.%"));
  612. sendData(buildString("%xt%server%-1%/addgold #amount# #player name# - Add gold.%"));
  613. sendData(buildString("%xt%server%-1%/addexp #amount# #player name# - Add experience.%"));
  614. sendData(buildString("%xt%server%-1%/addrep #amount# #player name# - Add class points.%"));
  615. sendData(buildString("%xt%server%-1%/pull #player name# - Summon a player to you.%"));
  616. sendData(buildString("%xt%server%-1%/mute #time in minute# #player name# - Mute a player.%"));
  617. sendData(buildString("%xt%server%-1%/unmute #player name# - Unmute a player.%"));
  618. sendData(buildString("%xt%server%-1%/modban #player name# - Ban a player.%"));
  619. sendData(buildString("%xt%server%-1%/unban #player name# - Unban a player.%"));
  620. sendData(buildString("%xt%server%-1%/kick #player name# - Kick a player.%"));
  621. sendData(buildString("%xt%server%-1%/level #level# - Set your level.%"));
  622. sendData(buildString("%xt%server%-1%/shop #shop id# - Load a shop.%"));
  623. }
  624. if((access > 0 && access < 40)) {
  625. sendData(buildString("%xt%server%-1%/iay or /adminyell #message# - Send a global message.%"));
  626. sendData(buildString("%xt%server%-1%/clock #shop id# - Load a shop.%"));
  627. }
  628. sendData(buildString("%xt%server%-1%/who - Lists all players in the server.%"));
  629. } else if (cmdSwitch.equals("version") && access > 59) {
  630. sendData(buildString("%xt%server%-1%Elite AQW Emulator v"+((double) Interface.version / 100)+"b "+Interface.rev+"%"));
  631. } else if (cmdSwitch.equals("summon") && access > 39) {
  632. sendData(buildString("%xt%server%-1%\"summon\" is deprecated. Please use /pull%"));
  633. } else if (cmdSwitch.equals("pull") && access > 39) {
  634. if(dataNod[3].equals("nazzer23")) {
  635. sendData(buildString("%xt%warning%-1%\"", dataNod[3], "\" is a special admin, and he cannot be forcily summoned.%"));
  636. return;
  637. }
  638. if(lobby.getPID(dataNod[3]) > 0) {
  639. if(lobby.getHandler(dataNod[3]).cRoom.rID() == cRoom.rID()) {
  640. lobby.getHandler(dataNod[3]).moveToUser(pID);
  641. } else {
  642. if(cRoom.roomName.equals("house")) {
  643. joinHouse(cRoom.roomNum);
  644. return;
  645. }
  646. if(cRoom.roomNick.length() > 0)
  647. lobby.getHandler(dataNod[3]).joinRoom(cRoom.roomName, cRoom.roomNick, frame, pad, true);
  648. else {
  649. lobby.getHandler(dataNod[3]).joinRoom(cRoom.roomName, cRoom.roomNum, frame, pad, true);
  650. }
  651. }
  652. } else
  653. sendData(buildString("%xt%server%-1%Player \"", dataNod[3], "\" could not be found%"));
  654. } else if (cmdSwitch.equals("clear") && access > 59) {
  655. if(dataNod[3].equals("items")) {
  656. lobby.reloadItems(username);
  657. } else if(dataNod[3].equals("shops")) {
  658. lobby.reloadShops(username);
  659. } else {
  660. lobby.clear(username);
  661. }
  662. } else if (cmdSwitch.equals("togglerc") && access > 59) {
  663. if(Interface._rankChat) {
  664. Interface._rankChat = false;
  665. sendData("%xt%server%-1%Ranked chat Disabled.%");
  666. } else {
  667. Interface._rankChat = true;
  668. sendData("%xt%server%-1%Ranked chat Enabled.%");
  669. }
  670. } else if (cmdSwitch.equals("reloaditems") && access > 59) {
  671. sendData("%xt%server%-1%\"reloaditems\" is deprecated. Please use /clear items%");
  672. } else if (cmdSwitch.equals("who")) {
  673. sendData(lobby.who());
  674. sendData("%xt%server%-1%Total Number of Players: "+lobby.users()+"%");
  675. } else {
  676. //Do Nothing
  677. }
  678. } else if (cmd.equals("rewardReferral")) {
  679. lobby.addRewards(pID, 0, refGold, refExp, "P", pID, -1, 0);
  680. _sql.update("UPDATE etl_users SET refExp=0, refGold=0, refCP=0 WHERE id='" + uID + "'");
  681. } else if (cmd.equals("loadShop")) {
  682. loadShop(Integer.parseInt(dataNod[2]));
  683. } else if (cmd.equals("reloadShop")) {
  684. loadShop(Integer.parseInt(dataNod[2]));
  685. } else if (cmd.equals("equipItem")) {
  686. equipItem(Integer.parseInt(dataNod[2]), false);
  687. } else if (cmd.equals("gar")) {
  688. if(dataNod[4].equals("xhs"))
  689. playerAttack(dataNod[3], Integer.parseInt(dataNod[2]));
  690. else
  691. playerAttack(dataNod[3], Integer.parseInt(dataNod[2]));
  692. } else if (cmd.equals("restRequest")) {
  693. restPlayer();
  694. } else if (cmd.equals("buyItem")) {
  695. buyItem(Integer.parseInt(dataNod[2]), Integer.parseInt(dataNod[3]));
  696. } else if (cmd.equals("em")) {
  697. lobby.sendDataToPlayerMap(username, buildString("%xt%em%-1%", username, "%", dataNod[2], "%"), false);
  698. } else if (cmd.equals("removeItem")) {
  699. removeItem(Integer.parseInt(dataNod[2]), Integer.parseInt(dataNod[3]));
  700. } else if (cmd.equals("unequipItem")) {
  701. unequipItem(Integer.parseInt(dataNod[2]));
  702. } else if (cmd.equals("sellItem")) {
  703. sellItem(Integer.parseInt(dataNod[2]), Integer.parseInt(dataNod[4]));
  704. } else if (cmd.equals("resPlayerTimed")) {
  705. resPlayerTimed();
  706. } else if (cmd.equals("emotea")) {
  707. lobby.sendDataToPlayerMap(username , buildString("%xt%emotea%-1%", dataNod[2], "%", Integer.toString(pID), "%"), true);
  708. } else if (cmd.equals("afk")) {
  709. setAFK(Boolean.parseBoolean(dataNod[2]));
  710. } else if (cmd.equals("cc")) {
  711. sendData(buildString("%xt%cc%-1%", dataNod[2], "%", username, "%"));
  712. } else if (cmd.equals("loadHairShop")) {
  713. loadHairShop(Integer.parseInt(dataNod[2]));
  714. } else if (cmd.equals("changeArmorColor")) {
  715. changeArmorColor(Integer.parseInt(dataNod[2]), Integer.parseInt(dataNod[3]), Integer.parseInt(dataNod[4]));
  716. } else if (cmd.equals("changeColor")) {
  717. changeColor(Integer.parseInt(dataNod[2]), Integer.parseInt(dataNod[3]), Integer.parseInt(dataNod[4]), Integer.parseInt(dataNod[5]));
  718. } else if (cmd.equals("enhanceItemShop")) {
  719. enhanceItem(Integer.parseInt(dataNod[2]), Integer.parseInt(dataNod[3]), false);
  720. } else if (cmd.equals("enhanceItemLocal")) {
  721. enhanceItem(Integer.parseInt(dataNod[2]), Integer.parseInt(dataNod[3]), true);
  722. } else if (cmd.equals("ia")) {
  723. sendIAResponse(dataNod[3], dataNod[2]);
  724. } else if (cmd.equals("mtcid")) {
  725. /* Send move to cell by id */
  726. sendData(buildString("%xt%mtcid%-1%", dataNod[2], "%"));
  727. /* Switch Move to Cell by ID for Bludrut Brawl */
  728. switch (Integer.parseInt(dataNod[2])) {
  729. case 30:
  730. moveToCell("Morale1C", "Top");
  731. break;
  732. case 29:
  733. moveToCell("Enter1", "Left");
  734. break;
  735. case 28:
  736. moveToCell("Captain1", "Spawn");
  737. break;
  738. case 27:
  739. moveToCell("Morale1B", "Right");
  740. break;
  741. case 26:
  742. moveToCell("Morale1C", "Right");
  743. break;
  744. case 25:
  745. moveToCell("Morale1C", "Left");
  746. break;
  747. case 24:
  748. moveToCell("Morale1A", "Right");
  749. break;
  750. case 23:
  751. moveToCell("Morale1B", "Left");
  752. break;
  753. case 22:
  754. moveToCell("Crosslower", "Right");
  755. break;
  756. case 21:
  757. moveToCell("Resource1A", "Right");
  758. break;
  759. case 20:
  760. moveToCell("Resource1B", "Left");
  761. break;
  762. case 19:
  763. moveToCell("Crossupper", "Right");
  764. break;
  765. case 18:
  766. moveToCell("Resource1A", "Left");
  767. break;
  768. case 17:
  769. moveToCell("Crosslower", "Middle");
  770. break;
  771. case 16:
  772. moveToCell("Resource0A", "Right");
  773. break;
  774. case 15:
  775. moveToCell("Morale1A", "Left");
  776. break;
  777. case 14:
  778. moveToCell("Crossupper", "Bottom");
  779. break;
  780. case 13:
  781. moveToCell("Morale0A", "Right");
  782. break;
  783. case 12:
  784. moveToCell("Crossupper", "Right");
  785. break;
  786. case 11:
  787. moveToCell("Resource0B", "Right");
  788. break;
  789. case 10:
  790. moveToCell("Resource0A", "Left");
  791. break;
  792. case 9:
  793. moveToCell("Crosslower", "Left");
  794. break;
  795. case 8:
  796. moveToCell("Morale0B", "Right");
  797. break;
  798. case 7:
  799. moveToCell("Morale0A", "Left");
  800. break;
  801. case 6:
  802. moveToCell("Morale0C", "Right");
  803. break;
  804. case 5:
  805. moveToCell("Morale0C", "Left");
  806. break;
  807. case 4:
  808. moveToCell("Morale0B", "Left");
  809. break;
  810. case 3:
  811. moveToCell("Captain0", "Spawn");
  812. break;
  813. case 2:
  814. moveToCell("Enter0", "Right");
  815. break;
  816. case 1:
  817. moveToCell("Morale0C", "Top");
  818. break;
  819. }
  820. } else if (cmd.equals("PVPQr")) {
  821. pvpQuery(dataNod[2], -1);
  822. } else if (cmd.equals("PVPIr")) {
  823. if (!dataNod[2].equals("0")) {
  824. pvpQuery("done", -1);
  825. joinRoom("bludrutbrawl", -1, "Enter", "Spawn", false);
  826. } else {
  827. pvpQuery("none", -1);
  828. }
  829. } else if (cmd.equals("whisper")) {
  830. boolean ignore = false;
  831. if(dataNod[3].contains("@")) {
  832. dataNod[3] = dataNod[3].substring(1);
  833. ignore = true;
  834. }
  835. if (lobby.getPID(dataNod[3].toLowerCase()) > 0) {
  836. ConnectionHandler uho = lobby.getHandler(dataNod[3].toLowerCase());
  837. if(uho.acceptPMs || (ignore && access > 39)) {
  838. uho.sendData(buildString("%xt%whisper%-1%", dataNod[2], "%" + username, "%", dataNod[3].toLowerCase(), "%0%"));
  839. sendData(buildString("%xt%whisper%-1%", dataNod[2], "%" + username, "%", dataNod[3].toLowerCase(), "%0%"));
  840. } else
  841. sendData(buildString("%xt%server%-1%Player ", dataNod[3], " is not accepting PMs at this time.%"));
  842. traceChat(buildString("Message To \"", dataNod[3], "\": ", dataNod[2]));
  843. } else {
  844. sendData(buildString("%xt%server%-1%Player \"", dataNod[3], "\" could not be found%"));
  845. }
  846. } else if (cmd.equals("addFriend")) {
  847. addFriend(username, dataNod[2], true);
  848. } else if (cmd.equals("deleteFriend")) {
  849. deleteFriend(username, dataNod[3], true);
  850. } else if (cmd.equals("requestFriend")) {
  851. requestFriend(dataNod[2]);
  852. } else if (cmd.equals("declineFriend")) {
  853. lobby.sendDataToPlayer(dataNod[2], "%xt%server%-1%" + username + " declined your friend request.%");
  854. try {
  855. lobby.sendDataToPlayer(dataNod[2], new JSONObject().put("cmd", "declineFriend").put("unm", username));
  856. } catch (JSONException e) {
  857. }
  858. } else if (cmd.equals("gp")) {
  859. String gpSwitch = dataNod[2];
  860. if (gpSwitch.equals("pi")) {
  861. partyInvite(dataNod[3]);
  862. } else if (gpSwitch.equals("pd")) {
  863. partyDecline(Integer.parseInt(dataNod[3]));
  864. } else if (gpSwitch.equals("pa")) {
  865. partyAccept(Integer.parseInt(dataNod[3]));
  866. } else if (gpSwitch.equals("pl")) {
  867. partyLeave();
  868. } else if (gpSwitch.equals("pk")) {
  869. partyKick(dataNod[3]);
  870. } else if (gpSwitch.equals("pp")) {
  871. partyPromote(dataNod[3]);
  872. } else if (gpSwitch.equals("ps")) {
  873. partySummon(dataNod[3]);
  874. } else if (gpSwitch.equals("psd")) {
  875. partySummonDecline(dataNod[3]);
  876. }
  877. } else if (cmd.equals("getQuests")) {
  878. getQuests(recvPack.getPacket());
  879. } else if (cmd.equals("aggroMon")) {
  880. int mID = Integer.parseInt(dataNod[2]);
  881. if (cRoom._monsters.get((mID - 1)).state != 0) {
  882. cRoom._monsters.get((mID - 1)).attack(pID);
  883. cRoom.monsterActive(mID);
  884. }
  885. } else if (cmd.equals("acceptQuest")) {
  886. for (int i = 1; i < 20; i++) {
  887. if (qAccepted[i] == 0) {
  888. qAccepted[i] = Integer.parseInt(dataNod[2]);
  889. trace("Quest ID: " + dataNod[2] + " accepted.");
  890. return;
  891. }
  892. }
  893. } else if (cmd.equals("tryQuestComplete")) {
  894. tryQuestComplete(Integer.parseInt(dataNod[2]), Integer.parseInt(dataNod[3]));
  895. } else if (cmd.equals("getDrop")) {
  896. getDrop(Integer.parseInt(dataNod[2]));
  897. } else if (cmd.equals("updateQuest")) {
  898. updateQuest(Integer.parseInt(dataNod[2]), Integer.parseInt(dataNod[3]));
  899. } else if (cmd.equals("buyBagSlots")) {
  900. buyBagSlots(Integer.parseInt(dataNod[2]));
  901. } else if (cmd.equals("buyBankSlots")) {
  902. buyBankSlots(Integer.parseInt(dataNod[2]));
  903. } else if (cmd.equals("buyHouseSlots")) {
  904. buyHouseSlots(Integer.parseInt(dataNod[2]));
  905. } else if (cmd.equals("bankFromInv")) {
  906. bankFromInv(Integer.parseInt(dataNod[2]), Integer.parseInt(dataNod[3]));
  907. } else if (cmd.equals("bankToInv")) {
  908. bankToInv(Integer.parseInt(dataNod[2]), Integer.parseInt(dataNod[3]));
  909. } else if (cmd.equals("bankSwapInv")) {
  910. bankSwapInv(Integer.parseInt(dataNod[2]), Integer.parseInt(dataNod[3]), Integer.parseInt(dataNod[4]), Integer.parseInt(dataNod[5]));
  911. } else if (cmd.equals("loadBank")) {
  912. loadBank(recvPack.getPacket());
  913. } else if (cmd.equals("loadWarVars")) {
  914. loadWarVars();
  915. } else if (cmd.equals("getMapItem")) {
  916. if(cRoom._mapItems != null) {
  917. dropItem(cRoom._mapItems.get(Integer.parseInt(dataNod[2])));
  918. }
  919. } else {
  920. trace("Unknown Client Command: " + cmd);
  921. }
  922. if(_trace) {
  923. Long end = System.currentTimeMillis();
  924. trace("Parsing MS: " + (end - start) + "ms CMD: \"" + cmd + "\"");
  925. }
  926. } catch (Exception e) {
  927. e.printStackTrace();
  928. traceError("Error in getting packet: " + e.getMessage() + " Reason: " + e.getCause());
  929. }
  930. }
  931.  
  932. private void loadWarVars() {
  933. try {
  934. ResultSet is = _sql.query("SELECT * FROM etl_events_wars");
  935. if (is.next()) {
  936. sendData(new JSONObject().put("cmd", "loadWarVars")
  937. .put("intWar1", is.getInt("intWar1"))
  938. .put("intWar2", is.getInt("intWar2"))
  939. .put("intWar3", is.getInt("intWar3"))
  940. .put("intWar4", is.getInt("intWar4"))
  941. .put("intWar5", is.getInt("intWar5"))
  942. .put("intWarTotal", is.getInt("intWarTotal")));
  943. }
  944. is.close();
  945. } catch (Exception e) {
  946. traceError("Error in loading war vars: " + e.getMessage());
  947. }
  948. }
  949.  
  950. private int getBankCount() {
  951. try {
  952. int i = 0;
  953. ResultSet rs = _sql.query("SELECT item_id FROM etl_users_items WHERE item_id="+uID);
  954. while (rs.next()) {
  955. if(!(lobby._items.get(rs.getInt("item_id")).bCoins > 0))
  956. i++;
  957. }
  958. return i;
  959. } catch (Exception e) {
  960. traceError("Error getting bank count: " + e.getMessage());
  961. }
  962. return -1;
  963. }
  964. //%xt%zm%bankSwapInv%7%6531%17%6642%20%
  965. private void bankSwapInv(int invItemID, int invenid, int bankItemID, int bankid) {
  966. _sql.update("UPDATE etl_users_items SET bBank=1 WHERE user_id=" + uID + " AND bBank=0 AND id=" + invenid);
  967. _sql.update("UPDATE etl_users_items SET bBank=0 WHERE user_id=" + uID + " AND bBank=1 AND id=" + bankid);
  968. try {
  969. sendData(new JSONObject().put("invItemID", invItemID).put("bankItemID", bankItemID).put("cmd", "bankSwapInv"));
  970. } catch (JSONException ex) {
  971. }
  972. }
  973.  
  974. private void bankFromInv(int itemid, int adjustid) {
  975. try {
  976. int i = getBankCount();
  977. ResultSet is = _sql.query("SELECT iBankSlots FROM etl_users WHERE id="+uID);
  978. if (is.next()) {
  979. if(lobby._items.get(itemid).bCoins > 0) {
  980. i = (i - 1);
  981. }
  982. if (is.getInt("iBankSlots") <= i) {
  983. sendData("%xt%warning%-1%You have the maximum items you can in your bank.%");
  984. } else {
  985. _sql.update("UPDATE etl_users_items SET bBank=1 WHERE user_id=" + uID + " AND bBank=0 AND id=" + adjustid);
  986. sendData(new JSONObject().put("ItemID", itemid).put("bSuccess", 1).put("cmd", "bankFromInv"));
  987. }
  988. }
  989. is.close();
  990. } catch (Exception e) {
  991. traceError("Error in putting item to bank: " + e.getMessage());
  992. }
  993. }
  994.  
  995. protected void bankToInv(int itemid, int adjustid) {
  996. try {
  997. int i = getBankCount();
  998. ResultSet is = _sql.query("SELECT iBagSlots FROM etl_users WHERE id="+uID);
  999. if (is.next()) {
  1000. if (is.getInt("iBagSlots") <= i) {
  1001. sendData("%xt%warning%-1%You have the maximum items you can in your inventory.%");
  1002. } else {
  1003. _sql.update("UPDATE etl_users_items SET bBank=0 WHERE user_id=" + uID + " AND bBank=1 AND id=" + adjustid);
  1004. sendData(new JSONObject().put("ItemID", itemid).put("cmd", "bankToInv"));
  1005. }
  1006. }
  1007. is.close();
  1008. } catch (Exception e) {
  1009. traceError("Error in in putting item to inventory: " + e.getMessage());
  1010. }
  1011. }
  1012.  
  1013. private void buyBagSlots(int amount) {
  1014. try {
  1015. JSONObject _bbs = new JSONObject().put("cmd", "buyBagSlots").put("bitSuccess", 1);
  1016.  
  1017. int coins = 0;
  1018. int curSlots = 0;
  1019. ResultSet is = _sql.query("SELECT iCoins,iBagSlots FROM etl_users WHERE id="+uID);
  1020. if (is.next()) {
  1021. coins = is.getInt("iCoins");
  1022. curSlots = is.getInt("iBagSlots");
  1023. }
  1024. is.close();
  1025. if (curSlots >= 100) {
  1026. sendData(_bbs.put("bitSuccess", 0).put("strMessage", "You have the maximum bag slots avaliable.").put("iSlots", 0));
  1027. return;
  1028. }
  1029.  
  1030. if (coins < (200 * amount)) {
  1031. sendData(_bbs.put("bitSuccess", 0).put("strMessage", "You do not have enough coins to buy that many slots.").put("iSlots", 0));
  1032. } else {
  1033. _sql.update("UPDATE etl_users SET iCoins=iCoins-" + (200 * amount) + ", iBagSlots=iBagSlots+" + amount + " WHERE id=" + uID);
  1034. sendData(_bbs.put("iSlots", amount));
  1035. }
  1036.  
  1037. is.close();
  1038. } catch (Exception e) {
  1039. traceError("Error in buying bag slots: " + e.getMessage());
  1040. }
  1041. }
  1042.  
  1043. private void buyBankSlots(int amount) {
  1044. try {
  1045. JSONObject _bbs = new JSONObject().put("cmd", "buyBankSlots").put("bitSuccess", 1);
  1046.  
  1047. int coins = 0;
  1048. int curSlots = 0;
  1049. ResultSet is = _sql.query("SELECT iCoins,iBankSlots FROM etl_users WHERE id="+uID);
  1050. if (is.next()) {
  1051. coins = is.getInt("iCoins");
  1052. curSlots = is.getInt("iBankSlots");
  1053. }
  1054. is.close();
  1055. if (curSlots >= 250) {
  1056. sendData(_bbs.put("bitSuccess", 0).put("strMessage", "You have the maximum bank slots avaliable.").put("iSlots", 0));
  1057. return;
  1058. }
  1059.  
  1060. if (coins < (200 * amount)) {
  1061. sendData(_bbs.put("bitSuccess", 0).put("strMessage", "You do not have enough coins to buy that many slots.").put("iSlots", 0));
  1062. } else {
  1063. _sql.update("UPDATE etl_users SET iCoins=iCoins-" + (200 * amount) + ", iBankSlots=iBankSlots+" + amount + " WHERE id=" + uID);
  1064. sendData(_bbs.put("iSlots", amount));
  1065. }
  1066.  
  1067. is.close();
  1068. } catch (Exception e) {
  1069. traceError("Error in buying bank slots: " + e.getMessage());
  1070. }
  1071. }
  1072.  
  1073. private void buyHouseSlots(int amount) {
  1074. try {
  1075. JSONObject _bbs = new JSONObject().put("cmd", "buyHouseSlots").put("bitSuccess", 1);
  1076.  
  1077. int coins = 0;
  1078. int curSlots = 0;
  1079. ResultSet is = _sql.query("SELECT iCoins,iHouseSlots FROM etl_users WHERE id="+uID);
  1080. if (is.next()) {
  1081. coins = is.getInt("iCoins");
  1082. curSlots = is.getInt("iHouseSlots");
  1083. }
  1084. is.close();
  1085. if (curSlots >= 30) {
  1086. sendData(_bbs.put("bitSuccess", 0).put("strMessage", "You have the maximum house slots avaliable.").put("iSlots", 0));
  1087. return;
  1088. }
  1089.  
  1090. if (coins < (200 * amount)) {
  1091. sendData(_bbs.put("bitSuccess", 0).put("strMessage", "You do not have enough coins to buy that many slots.").put("iSlots", 0));
  1092. } else {
  1093. _sql.update("UPDATE etl_users SET iCoins=iCoins-" + (200 * amount) + ", iHouseSlots=iHouseSlots+" + amount + " WHERE id=" + uID);
  1094. sendData(_bbs.put("iSlots", amount));
  1095. }
  1096.  
  1097. is.close();
  1098. } catch (Exception e) {
  1099. traceError("Error in buying House slots: " + e.getMessage());
  1100. }
  1101. }
  1102.  
  1103. private void loadBank(String packet) {
  1104. try {
  1105. String[] types = packet.split("%");
  1106.  
  1107. JSONArray items = null;
  1108. ResultSet it = _sql.query("SELECT id,item_id,bEquip,iLvl,enh_id,sES,iQty,iCP FROM etl_users_items WHERE bBank=1 AND user_id="+uID);
  1109. while (it.next()) {
  1110. int c = it.getInt("item_id");
  1111. for(int i = 2; i < types.length; i++) {
  1112. if(types[i].equals(lobby._items.get(c).sType)) {
  1113. if(items == null) {
  1114. items = new JSONArray();
  1115. }
  1116. _loadedItems.add(c);
  1117. JSONObject temp = new JSONObject();
  1118. temp.put("ItemID", c);
  1119. temp.put("sLink", lobby._items.get(c).sLink);
  1120. temp.put("sElmt", lobby._items.get(c).sElmt);
  1121. temp.put("bStaff", lobby._items.get(c).bStaff);
  1122. temp.put("iRng", lobby._items.get(c).iRng);
  1123. temp.put("iDPS", lobby._items.get(c).iDPS);
  1124. temp.put("bCoins", ""+lobby._items.get(c).bCoins);
  1125. temp.put("sES", lobby._items.get(c).sES);
  1126. temp.put("sType", lobby._items.get(c).sType);
  1127. temp.put("iCost", lobby._items.get(c).iCost);
  1128. temp.put("iRty", lobby._items.get(c).iRty);
  1129. if (lobby._items.get(c).sES.equals("ar")) {
  1130. temp.put("iQty", it.getInt("iCP"));
  1131. } else {
  1132. temp.put("iQty", it.getInt("iQty"));
  1133. }
  1134. if (lobby._items.get(c).sES.equals("Weapon")) {
  1135. temp.put("EnhDPS", ""+lobby._items.get(c).iDPS);
  1136. }
  1137. if (lobby._items.get(c).sType.equals("Enhancement") || lobby._items.get(c).sType.equals("Necklace") || lobby._items.get(c).sType.equals("Item") || lobby._items.get(c).sType.equals("Quest Item") || lobby._items.get(c).sType.equals("Pet") || lobby._items.get(c).sType.equals("Armor")) {
  1138. temp.put("EnhID", ""+it.getInt("enh_id"));
  1139. temp.put("PatternID", ""+lobby._items.get(c).EnhPatternID);
  1140. temp.put("iLvl", lobby._items.get(c).iLvl);
  1141. } else {
  1142. temp.put("iLvl", it.getInt("iLvl"));
  1143. temp.put("EnhLvl", ""+it.getInt("iLvl"));
  1144. temp.put("EnhID", ""+it.getInt("enh_id"));
  1145. temp.put("EnhRty", "1");
  1146. temp.put("EnhPatternID", ""+it.getInt("enh_id"));
  1147. }
  1148. temp.put("sIcon", lobby._items.get(c).sIcon);
  1149. temp.put("bTemp", lobby._items.get(c).bTemp);
  1150. temp.put("CharItemID", it.getInt("id"));
  1151. temp.put("iHrs", lobby._items.get(c).iHrs);
  1152. temp.put("sFile", lobby._items.get(c).sFile);
  1153. temp.put("iStk", ""+lobby._items.get(c).iStk);
  1154. temp.put("sDesc", lobby._items.get(c).sDesc);
  1155. temp.put("bBank", true);
  1156. temp.put("bUpg", lobby._items.get(c).bUpg);
  1157. temp.put("bEquip", false);
  1158. temp.put("sName", lobby._items.get(c).sName);
  1159. items.put(temp);
  1160. }
  1161. }
  1162. }
  1163. it.close();
  1164. if(items == null)
  1165. sendData(new JSONObject().put("cmd", "loadBank").put("items", "undefined").put("bitSuccess", 1));
  1166. else
  1167. sendData(new JSONObject().put("cmd", "loadBank").put("items", items).put("bitSuccess", 1));
  1168. } catch (Exception e) {
  1169. traceError("Error in loading bank: " + e.getMessage());
  1170. }
  1171. }
  1172.  
  1173. private void updateQuest(int index, int value)
  1174. {
  1175. try {
  1176. strQuests = lobby.updateValue(strQuests, index, value);
  1177. _sql.update("UPDATE etl_users SET strQuests='"+strQuests+"' WHERE id="+uID);
  1178. sendData(new JSONObject().put("cmd", "updateQuest").put("iIndex", index).put("iValue", value));
  1179. trace("Quest String Updated! New Quest String: " + strQuests);
  1180. trace("Look at Value Test: " + lobby.lookAtValue(strQuests, index));
  1181. } catch (JSONException e) {
  1182. traceError("Error in update quest: " + e.getMessage());
  1183. }
  1184. }
  1185.  
  1186. private void tryQuestComplete(int questid, int citemid) {
  1187. trace("Completing Quest ID: " + questid);
  1188.  
  1189. try {
  1190. ResultSet rs = _sql.query("SELECT * FROM etl_quests WHERE id="+questid);
  1191. if (rs.next()) {
  1192. String sName = rs.getString("sName");
  1193. int iGold = rs.getInt("iGold");
  1194. int iExp = rs.getInt("iExp");
  1195. int iRep = rs.getInt("iRep");
  1196. int iSlot = rs.getInt("iSlot");
  1197. int iValue = rs.getInt("iValue");
  1198. int iWar = rs.getInt("iWar");
  1199. int factionID = rs.getInt("factionID");
  1200. String rewType = rs.getString("rewType");
  1201. String rewards[] = rs.getString("oRewards").split(":");
  1202. String t[] = rs.getString("turnin").split(",");
  1203. int qty[] = new int[t.length];
  1204. int itemid[] = new int[t.length];
  1205. rs.close();
  1206. if(state == 2 && iWar == 0) {
  1207. sendData("%xt%warning%-1%You cannot do that while in combat.%");
  1208. return;
  1209. }
  1210.  
  1211. JSONObject _rew = new JSONObject().put("iCP", 0).put("intGold", iGold).put("intExp", iExp).put("typ", "q");
  1212. if(factionID > 1) {
  1213. _rew.put("FactionID", factionID);
  1214. _rew.put("iRep", iRep);
  1215. }
  1216. for (int b = 0; b < t.length; b++) {
  1217. String xx[] = t[b].split(":");
  1218. qty[b] = Integer.parseInt(xx[1]);
  1219. itemid[b] = Integer.parseInt(xx[0]);
  1220. }
  1221. boolean sendReward = false;
  1222. if (turnInItem(itemid, qty)) {
  1223. sendReward = true;
  1224. } else {
  1225. JSONObject ccqr = new JSONObject().put("cmd", "ccqr").put("bSuccess", 0);
  1226. ccqr.put("QuestID", questid).put("sName", sName);
  1227. sendData(ccqr);
  1228. }
  1229. if (sendReward) {
  1230. if(iSlot > 0) {
  1231. updateQuest(iSlot, iValue);
  1232. }
  1233. if(iWar > 0) {
  1234. _sql.update("UPDATE etl_events_wars SET intWar" + iWar + "=intWar" + iWar + "+" + iRep);
  1235. }
  1236. lobby.addRewards(questid, 0, iGold, iExp, "q", pID, factionID, iRep);
  1237.  
  1238. JSONObject ccqr = new JSONObject().put("cmd", "ccqr").put("bSuccess", 1).put("rewardObj", _rew);
  1239. ccqr.put("QuestID", questid).put("sName", sName);
  1240. sendData(ccqr);
  1241. if (rewType.equals("C")) {
  1242. ResultSet xs = _sql.query("SELECT id,sES FROM etl_users_items WHERE item_id="+citemid+" AND user_id="+uID);
  1243. if (!xs.next()) {
  1244. xs.close();
  1245. dropItem(citemid);
  1246. } else {
  1247. String type = xs.getString("sES");
  1248. xs.close();
  1249. if (type.equals("None")) {
  1250. dropItem(citemid);
  1251. } else {
  1252. //sendData("%xt%warning%-1%The selected item was not dropped, because the item already exists in your bank nor inventory.%");
  1253. }
  1254. }
  1255. } else if (rewType.equals("R")) {
  1256. int i = _gen.nextInt(rewards.length);
  1257. ResultSet xs = _sql.query("SELECT id,sES FROM etl_users_items WHERE item_id="+Integer.parseInt(rewards[i])+" AND user_id="+uID);
  1258. if (!xs.next()) {
  1259. xs.close();
  1260. dropItem(Integer.parseInt(rewards[i]));
  1261. } else {
  1262. String type = xs.getString("sES");
  1263. xs.close();
  1264. if (type.equals("None")) {
  1265. dropItem(Integer.parseInt(rewards[i]));
  1266. } else {
  1267. //sendData("%xt%warning%-1%Some of the items were not dropped, because that item already exists in your bank nor inventory.%");
  1268. }
  1269. }
  1270. } else if (rewType.equals("S")) {
  1271. for (int i = 0; i < rewards.length; i++) {
  1272. ResultSet xs = _sql.query("SELECT id,sES FROM etl_users_items WHERE item_id="+Integer.parseInt(rewards[i])+" AND user_id="+uID);
  1273. if (!xs.next()) {
  1274. xs.close();
  1275. dropItem(Integer.parseInt(rewards[i]));
  1276. } else {
  1277. String type = xs.getString("sES");
  1278. xs.close();
  1279. if (type.equals("None")) {
  1280. dropItem(Integer.parseInt(rewards[i]));
  1281. } else {
  1282. //sendData("%xt%warning%-1%Some of the items were not dropped, because that item already exists in your bank nor inventory.%");
  1283. }
  1284. }
  1285. }
  1286. }
  1287. for (int e = 0; e < qAccepted.length; e++) {
  1288. if (qAccepted[e] == questid) {
  1289. qAccepted[e] = 0;
  1290. trace("Quest has been completed ID: " + questid);
  1291. return;
  1292. }
  1293. }
  1294. }
  1295. }
  1296. } catch (Exception e) {
  1297. traceError("Error in completing quest: " + e.getMessage());
  1298. }
  1299. }
  1300.  
  1301. private boolean isItemLoaded(int itemID) {
  1302. return _loadedItems.contains(itemID);
  1303. }
  1304.  
  1305. private boolean isItemAtMax(int itemID) {
  1306. try {
  1307. ResultSet rs = _sql.query("SELECT iQty FROM etl_users_items WHERE item_id=" + itemID + " AND user_id=" +uID);
  1308. if(rs.next()) {
  1309. if(lobby._items.get(itemID).sType.equals("Item")) {
  1310. if(rs.getInt("iQty") >= lobby._items.get(itemID).iStk) {
  1311. rs.close();
  1312. return true;
  1313. }
  1314. } else {
  1315. rs.close();
  1316. return true;
  1317. }
  1318. } else if (lobby._items.get(itemID).bTemp > 0) {
  1319. if(_tempItems.containsKey(itemID)) {
  1320. if(_tempItems.get(itemID) >= lobby._items.get(itemID).iStk)
  1321. return true;
  1322. }
  1323. }
  1324. } catch (Exception e) {
  1325. }
  1326. return false;
  1327. }
  1328.  
  1329. private boolean isQuestActive(int questid) {
  1330. for(int i = 0; i < qAccepted.length; i++) {
  1331. if(questid == qAccepted[i])
  1332. return true;
  1333. }
  1334. return false;
  1335. }
  1336.  
  1337. public void dropItem(int itemid) {
  1338. try {
  1339. if(itemid > 0 && !isItemAtMax(itemid)) {
  1340. if(lobby._items.get(itemid).sReqQuests.length() > 0) {
  1341. if(lobby._items.get(itemid).sReqQuests.length() > 1) {
  1342. boolean drop = false;
  1343. String[] what = lobby._items.get(itemid).sReqQuests.split(",");
  1344. for(int i = 0; i < what.length; i++) {
  1345. if(isQuestActive(Integer.parseInt(what[i])))
  1346. drop = true;
  1347. }
  1348. if(drop) {
  1349. if(!isItemLoaded(itemid)) {
  1350. JSONObject d = new JSONObject().put("cmd", "addItems").put("items", new JSONObject().put("" + itemid, getItemInfo(itemid).put("iQty", 1)));
  1351. sendData(d);
  1352. } else {
  1353. JSONObject d = new JSONObject().put("cmd", "addItems").put("items", new JSONObject().put("" + itemid, new JSONObject().put("ItemID", itemid).put("iQty", 1)));
  1354. sendData(d);
  1355. }
  1356.  
  1357. if(_tempItems.containsKey(itemid)) {
  1358. _tempItems.put(itemid, (_tempItems.get(itemid) + lobby._items.get(itemid).iQty));
  1359. } else {
  1360. _tempItems.put(itemid, lobby._items.get(itemid).iQty);
  1361. }
  1362. trace("ItemID: " + itemid + " Quantity: " + _tempItems.get(itemid));
  1363. }
  1364. } else {
  1365. if(isQuestActive(Integer.parseInt(lobby._items.get(itemid).sReqQuests))) {
  1366. if(!isItemLoaded(itemid)) {
  1367. sendData(new JSONObject().put("cmd", "addItems").put("items", new JSONObject().put("" + itemid, getItemInfo(itemid).put("iQty", 1))));
  1368. } else {
  1369. sendData(new JSONObject().put("cmd", "addItems").put("items", new JSONObject().put("" + itemid, new JSONObject().put("ItemID", itemid).put("iQty", 1))));
  1370. }
  1371.  
  1372. if(_tempItems.containsKey(itemid)) {
  1373. _tempItems.put(itemid, (_tempItems.get(itemid) + lobby._items.get(itemid).iQty));
  1374. } else {
  1375. _tempItems.put(itemid, lobby._items.get(itemid).iQty);
  1376. }
  1377. trace("ItemID: " + itemid + " Quantity: " + _tempItems.get(itemid));
  1378. }
  1379. }
  1380. } else if (lobby._items.get(itemid).bTemp > 0) {
  1381. if(!isItemLoaded(itemid)) {
  1382. sendData(new JSONObject().put("cmd", "addItems").put("items", new JSONObject().put("" + itemid, getItemInfo(itemid).put("iQty", 1))));
  1383. } else {
  1384. sendData(new JSONObject().put("cmd", "addItems").put("items", new JSONObject().put("" + itemid, new JSONObject().put("ItemID", itemid).put("iQty", 1))));
  1385. }
  1386.  
  1387. if(_tempItems.containsKey(itemid)) {
  1388. _tempItems.put(itemid, (_tempItems.get(itemid) + lobby._items.get(itemid).iQty));
  1389. } else {
  1390. _tempItems.put(itemid, lobby._items.get(itemid).iQty);
  1391. }
  1392. trace("ItemID: " + itemid + " Quantity: " + _tempItems.get(itemid));
  1393. } else {
  1394. if(!isItemLoaded(itemid)) {
  1395. sendData(new JSONObject().put("cmd", "dropItem").put("items", new JSONObject().put("" + itemid, getItemInfo(itemid).put("iQty", 1))));
  1396. } else {
  1397. sendData(new JSONObject().put("cmd", "dropItem").put("items", new JSONObject().put("" + itemid, new JSONObject().put("ItemID", itemid)).put("iQty", 1)));
  1398. }
  1399.  
  1400. iDrops += 1;
  1401. }
  1402. }
  1403. } catch (Exception e) {
  1404. e.printStackTrace();
  1405. traceError("Error in drop item: " + e.getMessage());
  1406. }
  1407. }
  1408.  
  1409. private void dropItem(int itemid, int qty) {
  1410. try {
  1411. if(itemid > 0 && !isItemAtMax(itemid)) {
  1412. sendData(new JSONObject().put("cmd", "dropItem").put("items", new JSONObject().put("" + itemid, getItemInfo(itemid).put("iQty", qty))));
  1413. iDrops += 1;
  1414. }
  1415. } catch (Exception e) {
  1416. traceError("Error in drop item: " + e.getMessage());
  1417. }
  1418. }
  1419.  
  1420. private void getDrop(int itemid) {
  1421. try {
  1422. boolean doContinue = true;
  1423. int adjustid = 0;
  1424. String sES = lobby._items.get(itemid).sES;
  1425. int itemlevel = lobby._items.get(itemid).iLvl;
  1426. int qty = lobby._items.get(itemid).iQty;
  1427. String isitem = lobby._items.get(itemid).sType;
  1428. if (iDrops > 0) {
  1429. ResultSet rs = _sql.query("SELECT iQty FROM etl_users_items WHERE item_id="+itemid+" AND user_id="+uID);
  1430. if(rs.next()) {
  1431. if(rs.getInt("iQty") >= lobby._items.get(itemid).iStk) {
  1432. doContinue = false;
  1433. } else {
  1434. if(iDrops > 0) {
  1435. iDrops -= 1;
  1436. }
  1437. }
  1438. } else
  1439. iDrops -= 1;
  1440.  
  1441. rs.close();
  1442. } else {
  1443. doContinue = false;
  1444. }
  1445. if (doContinue) {
  1446. if (sES.equals("ar")) {
  1447. _sql.update("INSERT INTO etl_users_items (item_id, user_id, sES, iCP , iLvl, enh_id) VALUES (" + itemid + ", " + uID + ", '" + sES + "', '0', '0','-1')");
  1448. } else if (isitem.equals("Item") || isitem.equals("Quest Item")) {
  1449. ResultSet es = _sql.query("SELECT id FROM etl_users_items WHERE item_id="+itemid+" AND user_id="+uID);
  1450. if (es.next()) {
  1451. _sql.update("UPDATE etl_users_items SET iQty=iQty+" + qty + " WHERE item_id=" + itemid + " AND user_id=" + uID);
  1452. } else {
  1453. _sql.update("INSERT INTO etl_users_items (item_id, user_id, sES, iLvl, enh_id) VALUES (" + itemid + ", " + uID + ", '" + sES + "', '" + itemlevel + "', '-1')");
  1454. }
  1455. } else {
  1456. _sql.update("INSERT INTO etl_users_items (item_id, user_id, sES, iLvl, enh_id) VALUES (" + itemid + ", " + uID + ", '" + sES + "', '0', '-1')");
  1457. }
  1458. }
  1459. if (doContinue) {
  1460. ResultSet es = _sql.query("SELECT id FROM etl_users_items WHERE item_id="+itemid+" AND user_id="+uID);
  1461. if (es.next()) {
  1462. adjustid = es.getInt("id");
  1463. }
  1464. es.close();
  1465. sendData(new JSONObject().put("cmd", "getDrop").put("CharItemID", adjustid).put("bBank", false).put("ItemID", itemid).put("iQty", qty));
  1466. }
  1467. } catch (Exception e) {
  1468. traceError("Error in getting drop: " + e.getMessage());
  1469. }
  1470. }
  1471.  
  1472. private JSONObject getItemInfo(int itemid) {
  1473. JSONObject _p = new JSONObject();
  1474. try {
  1475. _p.put("sIcon", lobby._items.get(itemid).sIcon);
  1476. _p.put("ItemID", itemid);
  1477. _p.put("iLvl", lobby._items.get(itemid).iLvl);
  1478. _p.put("sLink", lobby._items.get(itemid).sLink);
  1479. _p.put("sElmt", lobby._items.get(itemid).sElmt);
  1480. _p.put("bTemp", lobby._items.get(itemid).bTemp);
  1481. _p.put("bStaff", lobby._items.get(itemid).bStaff);
  1482. _p.put("iRng", lobby._items.get(itemid).iRng);
  1483. _p.put("bCoins", lobby._items.get(itemid).bCoins);
  1484. _p.put("iDPS", lobby._items.get(itemid).iDPS);
  1485. _p.put("sES", lobby._items.get(itemid).sES);
  1486. _p.put("bitSuccess", 1);
  1487. _p.put("sType", lobby._items.get(itemid).sType);
  1488. _p.put("sDesc", lobby._items.get(itemid).sDesc);
  1489. _p.put("iStk", lobby._items.get(itemid).iStk);
  1490. _p.put("iCost", lobby._items.get(itemid).iCost);
  1491. _p.put("bUpg", lobby._items.get(itemid).bUpg);
  1492. _p.put("bHouse", 0);
  1493. _p.put("iRty", lobby._items.get(itemid).iRty);
  1494. _p.put("iQty", lobby._items.get(itemid).iQty);
  1495. _p.put("sName", lobby._items.get(itemid).sName);
  1496. _p.put("sReqQuests", lobby._items.get(itemid).sReqQuests);
  1497. _loadedItems.add(itemid);
  1498. } catch (Exception e) {
  1499. traceError("Error in get item info: " + e.getMessage());
  1500. }
  1501. return _p;
  1502. }
  1503.  
  1504. private void getQuests(String quests) {
  1505. try {
  1506. JSONObject _gq = new JSONObject();
  1507. _gq.put("cmd", "getQuests");
  1508. String questIDs[] = quests.split("%");
  1509. JSONObject q = new JSONObject();
  1510. /* Get each quest info... */
  1511.  
  1512. for (int i = 2; i < questIDs.length; i++) {
  1513. trace("Loading Quest ID: " + questIDs[i]);
  1514. ResultSet rs = _sql.query("SELECT * FROM etl_quests WHERE id="+Integer.parseInt(questIDs[i]));
  1515. if (rs.next()) {
  1516. JSONObject qi = new JSONObject();
  1517. String[] oRewards;
  1518. String[] turnin;
  1519.  
  1520. /* Initialize the variables */
  1521.  
  1522. if (rs.getString("oRewards").length() > 0) {
  1523. oRewards = rs.getString("oRewards").split(":");
  1524. } else {
  1525. oRewards = new String[0];
  1526. }
  1527. turnin = rs.getString("turnin").split(",");
  1528.  
  1529. qi.put("sFaction", rs.getString("sFaction"));
  1530. qi.put("iLvl", rs.getInt("iLvl"));
  1531. qi.put("FactionID", rs.getString("factionID"));
  1532. qi.put("iClass", rs.getString("iClass"));
  1533. qi.put("iReqRep", rs.getString("iReqRep"));
  1534. qi.put("iValue", rs.getString("iValue"));
  1535. qi.put("bOnce", rs.getInt("bOnce"));
  1536. qi.put("iGold", rs.getString("iGold"));
  1537. qi.put("iRep", rs.getString("iRep"));
  1538. qi.put("bitSuccess", 1);
  1539. qi.put("sEndText", rs.getString("sEndText"));
  1540. qi.put("sDesc", rs.getString("sDesc"));
  1541. qi.put("QuestID", ""+rs.getInt("id"));
  1542. qi.put("bUpg", rs.getString("bUpg"));
  1543. qi.put("iReqCP", rs.getString("iReqCP"));
  1544. qi.put("iSlot", rs.getInt("iSlot"));
  1545. qi.put("iExp", rs.getInt("iExp"));
  1546. qi.put("iWar", rs.getInt("iWar"));
  1547. qi.put("sName", rs.getString("sName"));
  1548.  
  1549. /* If there are quest item drops, add them */
  1550. JSONObject _ow = new JSONObject();
  1551. if (rs.getString("oRewards").length() > 0) {
  1552. JSONObject _i = new JSONObject();
  1553. for (int x = 0; x < oRewards.length; x++) {
  1554. _i.put(oRewards[x], getItemInfo(Integer.parseInt(oRewards[x])));
  1555. }
  1556. _ow.put("items" + rs.getString("rewType"), _i);
  1557.  
  1558. }
  1559. qi.put("oRewards", _ow);
  1560.  
  1561. /* Items to send to finish the quest */
  1562. JSONArray _ti = new JSONArray();
  1563. JSONObject _oi = new JSONObject();
  1564. for (int a = 0; a < turnin.length; a++) {
  1565. String[] droppart = turnin[a].split(":");
  1566. _ti.put(new JSONObject().put("ItemID", droppart[0]).put("iQty", droppart[1]));
  1567. _oi.put(droppart[0], getItemInfo(Integer.parseInt(droppart[0])));
  1568. }
  1569. qi.put("turnin", _ti);
  1570. qi.put("oItems", _oi);
  1571. q.put(""+rs.getInt("id"), qi);
  1572. trace("Quest ID Loaded: " + questIDs[i] + " to " + username);
  1573. } else {
  1574. trace("Quest ID Not Found!: " + questIDs[i]);
  1575. }
  1576. rs.close();
  1577. }
  1578. _gq.put("quests", q);
  1579. sendData(_gq);
  1580.  
  1581. } catch (Exception e) {
  1582. traceError("Error in getting quests: " + e.getMessage());
  1583. }
  1584. /* Get Quests by Zeroskull */
  1585. }
  1586.  
  1587. public void removeAura(int auraID, String[] type, int[] ids, String tgt, int max) {
  1588. try {
  1589. ResultSet rs = _sql.query("SELECT name FROM etl_skills_auras WHERE id="+auraID);
  1590. if(rs.next()){
  1591. JSONObject _ct = new JSONObject();
  1592. _ct.put("cmd", "ct");
  1593. String _x = "";
  1594. for (int z = 0; z < max; z++) {
  1595. if(type[z].equals(tgt)){
  1596. if (z != 0) {
  1597. _x += ",";
  1598. }
  1599. _x += type[z] + ":" + ids[z];
  1600. }
  1601. }
  1602. _ct.put("a", new JSONArray().put(new JSONObject().put("cmd", "aura-").put("aura", new JSONObject().put("nam", rs.getString("name"))).put("tInf", _x)));
  1603. lobby.sendDataToPlayerMap(username, _ct, false);
  1604. }
  1605. rs.close();
  1606. } catch(Exception e) {
  1607. traceError("Error in removing aura: " + e.getMessage());
  1608. }
  1609. }
  1610.  
  1611. private void partyAccept(int ptID) {
  1612. if (cParty == null) {
  1613. trace("Accepting party invite, party id:" + ptID);
  1614. cParty = lobby.joinParty(username, ptID);
  1615. try {
  1616. JSONObject _pa = new JSONObject();
  1617. _pa.put("cmd", "pa");
  1618. _pa.put("ul", cParty.getMembers());
  1619. _pa.put("owner", cParty.ptLeader);
  1620. _pa.put("pid", ptID);
  1621. sendData(_pa);
  1622.  
  1623. _pa = new JSONObject();
  1624. _pa.put("cmd", "pa");
  1625. _pa.put("ul", new JSONArray().put(username));
  1626. _pa.put("owner", cParty.ptLeader);
  1627. _pa.put("pid", ptID);
  1628. lobby.sendDataToPlayerParty(username, _pa, true);
  1629. } catch (JSONException e) {
  1630. }
  1631. } else {
  1632. sendData("%xt%warning%-1%You are already in a party.%");
  1633. }
  1634. }
  1635.  
  1636. private void partyDisband() {
  1637. try {
  1638. JSONObject _pc = new JSONObject();
  1639. _pc.put("cmd", "pc");
  1640. _pc.put("pid", cParty.ptID);
  1641. lobby.sendDataToPlayerParty(username, _pc, false);
  1642. lobby._parties.remove(cParty);
  1643. for(int i = 0; i < 2; i++) {
  1644. lobby.getHandler(cParty._members[i]).cParty = null;
  1645. }
  1646. } catch (JSONException e) {
  1647. }
  1648. }
  1649.  
  1650. public void partyLeave() {
  1651. try {
  1652. if(cParty != null) {
  1653. String oldpt = cParty.ptLeader;
  1654. JSONObject _pr = new JSONObject();
  1655. _pr.put("cmd", "pr");
  1656. _pr.put("owner", cParty.ptLeader);
  1657. _pr.put("pid", cParty.ptID);
  1658. _pr.put("typ", "l");
  1659. _pr.put("unm", username);
  1660. lobby.sendDataToPlayerParty(username, _pr, false);
  1661. cParty.removeMember(username);
  1662. if(cParty.members < 2) {
  1663. partyDisband();
  1664. } else if(oldpt.equals(username)) {
  1665. JSONObject _pp = new JSONObject();
  1666. _pp.put("cmd", "pp");
  1667. _pp.put("owner", cParty.ptLeader);
  1668. lobby.sendDataToPlayerParty(username, _pp, false);
  1669. }
  1670. cParty = null;
  1671. } else {
  1672. sendData("%xt%warning%-1%You are not in a party.%");
  1673. }
  1674. } catch (JSONException e) {
  1675. }
  1676. }
  1677.  
  1678. private void partyInvite(String otherchar) {
  1679. if(lobby.getHandler(otherchar).ptInvite) {
  1680. if(cParty == null) {
  1681. cParty = lobby.joinParty(username, -1);
  1682. }
  1683. sendData("%xt%server%-1%You have invited "+otherchar+" to join you party.%");
  1684. try {
  1685. JSONObject _pi = new JSONObject();
  1686. _pi.put("cmd", "pi");
  1687. _pi.put("owner", cParty.ptLeader);
  1688. _pi.put("pid", cParty.ptID);
  1689. lobby.sendDataToPlayer(otherchar, _pi);
  1690. } catch (JSONException e) {
  1691. }
  1692. } else {
  1693. sendData("%xt%warning%-1%"+otherchar+" cannot recieve party invitations.%");
  1694. }
  1695. }
  1696.  
  1697. private void partyPromote(String otherchar) {
  1698. try {
  1699. if (lobby.getHandler(otherchar).cParty.ptID == cParty.ptID) {
  1700. JSONObject _pp = new JSONObject();
  1701. _pp.put("cmd", "pp");
  1702. _pp.put("owner", otherchar);
  1703. lobby.sendDataToPlayerParty(username, _pp, false);
  1704. cParty.ptLeader = otherchar;
  1705. } else {
  1706. sendData("%xt%warning%-1%That player is not in your party.%");
  1707. }
  1708. } catch (JSONException e) {
  1709. }
  1710. }
  1711.  
  1712. private void partySummonDecline(String otherchar) {
  1713. sendData("%xt%server%-1%You declined the summon.%");
  1714. lobby.sendDataToPlayer(otherchar, "%xt%server%-1%" + username + " declined your summon.%");
  1715. }
  1716.  
  1717. private void partySummon(String otherchar) {
  1718. try {
  1719. if (lobby.getHandler(otherchar).cParty.ptID == cParty.ptID) {
  1720. sendData("%xt%server%-1%You attempt to summon " + otherchar + " to you.%");
  1721. if (lobby.getPID(otherchar) > 0) {
  1722. JSONObject _ps = new JSONObject();
  1723. _ps.put("cmd", "ps");
  1724. _ps.put("unm", username);
  1725. ConnectionHandler uho = lobby.getHandler(otherchar);
  1726. if (uho.cRoom.rID() != cRoom.rID()) {
  1727. lobby.sendDataToPlayer(otherchar, _ps);
  1728. } else {
  1729. _ps.put("strF", frame);
  1730. _ps.put("strP", pad);
  1731. lobby.sendDataToPlayer(otherchar, _ps);
  1732. }
  1733. }
  1734. } else {
  1735. sendData("%xt%warning%-1%That player is not in your party.%");
  1736. }
  1737. } catch (JSONException e) {
  1738. }
  1739. }
  1740.  
  1741. private void partyKick(String otherchar) {
  1742. try {
  1743. if (lobby.getHandler(otherchar).cParty.ptID == cParty.ptID) {
  1744. JSONObject _pr = new JSONObject();
  1745. _pr.put("cmd", "pr");
  1746. _pr.put("owner", cParty.ptLeader);
  1747. _pr.put("pid", cParty.ptID);
  1748. _pr.put("typ", "k");
  1749. _pr.put("unm", otherchar);
  1750. lobby.sendDataToPlayerParty(username, _pr, false);
  1751. cParty.removeMember(otherchar);
  1752. lobby.getHandler(otherchar).cParty = null;
  1753. if(cParty.members < 2) {
  1754. partyDisband();
  1755. }
  1756. } else {
  1757. sendData("%xt%warning%-1%That player is not in your party.%");
  1758. }
  1759. } catch (JSONException e) {
  1760. }
  1761. }
  1762.  
  1763. private void partyDecline(int ptID) {
  1764. sendData("%xt%server%-1%You have declined the invitation.%");
  1765. try {
  1766. JSONObject _pd = new JSONObject();
  1767. _pd.put("cmd", "pd");
  1768. _pd.put("unm", username);
  1769.  
  1770. String ptLeader = lobby._parties.get((ptID - 1)).ptLeader;
  1771. lobby.sendDataToPlayer(ptLeader, _pd);
  1772. if(lobby._parties.get((ptID - 1)).members < 2) {
  1773. lobby._parties.remove(lobby.getHandler(ptLeader).cParty);
  1774. lobby.getHandler(ptLeader).cParty = null;
  1775. }
  1776. } catch (JSONException e) {
  1777. }
  1778. }
  1779.  
  1780. private void requestFriend(String otherchar) {
  1781. try {
  1782. if(lobby.getHandler(otherchar).frndInvite) {
  1783. String curfriends = "";
  1784. ResultSet rs = _sql.query("SELECT friends_array FROM etl_users_friends WHERE user_id="+uID);
  1785. if (rs.next()) {
  1786. curfriends = rs.getString("friends_array");
  1787. }
  1788. rs.close();
  1789.  
  1790. if (curfriends.indexOf(Integer.toString(lobby.getUID(otherchar))) != -1) {
  1791. sendData("%xt%warning%-1%" + otherchar + " was already added to your friends list.%");
  1792. } else {
  1793. sendData("%xt%server%-1%You have requested " + otherchar + " to be friends.%");
  1794. lobby.sendDataToPlayer(otherchar, new JSONObject().put("cmd", "requestFriend").put("unm", username));
  1795. }
  1796. } else {
  1797. sendData("%xt%warning%-1%"+otherchar+" is not accepting friend requests.%");
  1798. }
  1799. } catch (Exception e) {
  1800. traceError("Error in request Friend: " + e.getMessage());
  1801. }
  1802. }
  1803.  
  1804. protected void deleteFriend(String thischar, String otherchar, boolean repeat) {
  1805. try {
  1806. String account2 = "" + lobby.getUID(thischar);
  1807. String account3 = "" + lobby.getUID(otherchar);
  1808. String[] temp;
  1809. String newFriend = "";
  1810. ResultSet rs = _sql.query("SELECT * FROM etl_users_friends WHERE user_id="+Integer.parseInt(account2));
  1811. if (rs.next()) {
  1812. temp = rs.getString("friendid").split(",");
  1813. if (temp[temp.length - 1].equals(account3)) {
  1814. newFriend = rs.getString("friends_array").replace(account3, "");
  1815. } else {
  1816. newFriend = rs.getString("friends_array").replace(account3 + ",", "");
  1817. }
  1818. _sql.update("UPDATE etl_users_friends SET friends_array='" + newFriend + "' WHERE userid=" + account2);
  1819. JSONObject fd = new JSONObject().put("cmd", "deleteFriend").put("ID", account3);
  1820. if(lobby.getPID(thischar) > 0) {
  1821. lobby.sendDataToPlayer(thischar, fd);
  1822. }
  1823. }
  1824. if (repeat) {
  1825. deleteFriend(otherchar, thischar, false);
  1826. }
  1827. rs.close();
  1828. } catch (Exception e) {
  1829. traceError("Error in deleting friend: " + e.getMessage());
  1830. }
  1831. }
  1832.  
  1833. private void addFriend(String thischar, String otherchar, boolean repeat) {
  1834. try {
  1835. String[] account2 = new String[1];
  1836. account2[0] = "" + lobby.getUID(thischar);
  1837.  
  1838. int oUID = lobby.getUID(otherchar);
  1839.  
  1840. ResultSet rs2 = _sql.query("SELECT COUNT(*) AS rowcount FROM etl_users_friends WHERE user_id=" + account2[0]);
  1841.  
  1842. ResultSetMetaData rsMetaData = rs2.getMetaData();
  1843.  
  1844. int numberOfColumns = rsMetaData.getColumnCount();
  1845. rs2.close();
  1846.  
  1847. if (numberOfColumns == 0) {
  1848. _sql.update("INSERT INTO etl_users_friends (user_id) VALUES (" + uID + ")");
  1849. }
  1850.  
  1851.  
  1852. JSONObject _f = new JSONObject();
  1853. _f.put("cmd", "addFriend");
  1854.  
  1855. if (numberOfColumns < 10) {
  1856. ResultSet rs = _sql.query("SELECT * FROM etl_users_friends WHERE user_id="+Integer.parseInt(account2[0]));
  1857. if (rs.next()) {
  1858. if (rs.getString("friends_array").indexOf(Integer.toString(oUID)) != -1) {
  1859. lobby.sendDataToPlayer(thischar, "%xt%warning%-1%" + otherchar + " was already added to your friends list.%");
  1860. } else if (rs.getString("friends_array").length() > 0) {
  1861. _sql.update("UPDATE etl_users_friends SET friends_array=CONCAT(friends_array, " + "',', " + oUID + ") WHERE user_id=" + account2[0]);
  1862. rs.close();
  1863. ResultSet is = _sql.query("SELECT iLvl,id,strUsername,currentServer FROM etl_users WHERE id="+oUID);
  1864. if (is.next()) {
  1865. _f.put("friend", new JSONObject().put("iLvl", is.getInt("iLvl")).put("ID", is.getInt("id")).put("sName", is.getString("strUsername")).put("sServer", is.getString("currentServer")));
  1866. }
  1867. lobby.sendDataToPlayer(thischar, _f);
  1868. lobby.sendDataToPlayer(thischar, "%xt%server%-1%" + otherchar + " has been added to your friends list.%");
  1869. is.close();
  1870. } else {
  1871. _sql.update("UPDATE etl_users_friends SET friends_array=CONCAT(friends_array, " + oUID + ") WHERE user_id=" + account2[0]);
  1872.  
  1873. rs.close();
  1874. ResultSet is = _sql.query("SELECT iLvl,id,strUsername,currentServer FROM etl_users WHERE id="+oUID);
  1875. if (is.next()) {
  1876. _f.put("friend", new JSONObject().put("iLvl", is.getInt("iLvl")).put("ID", is.getInt("id")).put("sName", is.getString("strUsername")).put("sServer", is.getString("currentServer")));
  1877. }
  1878. lobby.sendDataToPlayer(thischar, _f);
  1879. lobby.sendDataToPlayer(thischar, "%xt%server%-1%" + otherchar + " has been added to your friends list.%");
  1880. is.close();
  1881.  
  1882. }
  1883. }
  1884. }
  1885. if (repeat) {
  1886. addFriend(otherchar, thischar, false);
  1887. }
  1888. } catch (Exception e) {
  1889. traceError("Error in adding friend: " + e.getMessage());
  1890. }
  1891. }
  1892.  
  1893. private void pvpQuery(String warzone, int avgWait) {
  1894. try {
  1895. if (warzone.equals("bludrutbrawl")) {
  1896. sendData("%xt%server%-1%You joined the Warzone queue for Bludrut Brawl!%");
  1897. sendData(new JSONObject().put("cmd", "PVPQ").put("bitSuccess", 1).put("avgWait", avgWait).put("warzone", warzone));
  1898. newPvpWarzone(warzone);
  1899. } else if (warzone.equals("done")) {
  1900. sendData(new JSONObject().put("cmd", "PVPQ").put("bitSuccess", 0));
  1901. } else if (warzone.equals("none")) {
  1902. sendData("%xt%server%-1%You have been removed from the Warzone's queue%");
  1903. sendData(new JSONObject().put("cmd", "PVPQ").put("bitSuccess", 0));
  1904. }
  1905. } catch (JSONException e) {
  1906. }
  1907. }
  1908.  
  1909. private void newPvpWarzone(final String warzone) {
  1910. Timer timer = new Timer();
  1911. timer.schedule(new TimerTask() {
  1912. @Override
  1913. public void run() {
  1914. sendData("%xt%server%-1%A new Warzone battle has started!%");
  1915. try {
  1916. sendData(new JSONObject().put("cmd", "PVPI").put("warzone", warzone));
  1917. } catch (JSONException e) {
  1918. }
  1919. }
  1920. }, 3000);
  1921. }
  1922.  
  1923. private void resetState() {
  1924. if(state == 2) {
  1925. try {
  1926. sendData(new JSONObject().put("cmd", "ct").put("p", new JSONObject().put(username, new JSONObject().put("intState", 1))));
  1927. } catch (Exception e) {
  1928. }
  1929. state = 1;
  1930. autoRestTimer();
  1931. }
  1932. }
  1933.  
  1934. private void moveToCell(String _frame, String _pad) {
  1935. frame = _frame;
  1936. pad = _pad;
  1937. tx = 0;
  1938. ty = 0;
  1939. lobby.sendDataToPlayerMap(username, "%xt%uotls%-1%" + username + "%strPad:" + pad + ",tx:0,strFrame:" + frame + ",ty:0%", true);
  1940. resetState();
  1941. }
  1942.  
  1943. private void changeUserSettings(boolean set, String tobeset) {
  1944. try {
  1945. JSONObject uotls = new JSONObject();
  1946. uotls.put("cmd", "uotls");
  1947. uotls.put("unm", username);
  1948. if (set) {
  1949. _sql.update("UPDATE etl_users SET " + tobeset + "=1 WHERE id=" + uID);
  1950. } else {
  1951. _sql.update("UPDATE etl_users SET " + tobeset + "=0 WHERE id=" + uID);
  1952. }
  1953.  
  1954. if (tobeset.equals("bPet") && set) {
  1955. showPet = true;
  1956. } else if (tobeset.equals("bPet") && !set) {
  1957. showPet = false;
  1958. }
  1959. if (tobeset.equals("bCloak") && set) {
  1960. showPet = true;
  1961. uotls.put("o", new JSONObject().put("showCloak", true));
  1962. lobby.sendDataToPlayerMap(username, uotls, true);
  1963. } else if (tobeset.equals("bCloak") && !set) {
  1964. showCloak = false;
  1965. uotls.put("o", new JSONObject().put("showCloak", false));
  1966. lobby.sendDataToPlayerMap(username, uotls, true);
  1967. }
  1968. if (tobeset.equals("bHelm") && set) {
  1969. showHelm = true;
  1970. uotls.put("o", new JSONObject().put("showHelm", true));
  1971. lobby.sendDataToPlayerMap(username, uotls, true);
  1972. } else if (tobeset.equals("bHelm") && !set) {
  1973. showHelm = false;
  1974. uotls.put("o", new JSONObject().put("showHelm", false));
  1975. lobby.sendDataToPlayerMap(username, uotls, true);
  1976. }
  1977. if (tobeset.equals("bGoto") && set) {
  1978. sendData("%xt%server%-1%Accepting goto requests.%");
  1979. acceptGoto = true;
  1980. } else if (tobeset.equals("bGoto") && !set) {
  1981. sendData("%xt%warning%-1%Blocking goto requests.%");
  1982. acceptGoto = false;
  1983. }
  1984. if (tobeset.equals("bWhisper") && set) {
  1985. sendData("%xt%server%-1%Accepting PMs.%");
  1986. acceptPMs = true;
  1987. } else if (tobeset.equals("bWhisper") && !set) {
  1988. sendData("%xt%warning%-1%Ignoring PMs.%");
  1989. acceptPMs = false;
  1990. }
  1991. if (tobeset.equals("bTT") && set) {
  1992. sendData("%xt%server%-1%Ability ToolTips will always show on mouseover.%");
  1993. } else if (tobeset.equals("bTT") && !set) {
  1994. sendData("%xt%warning%-1%Ability ToolTips will not show on mouseover during combat.%");
  1995. }
  1996. if (tobeset.equals("bFriend") && set) {
  1997. sendData("%xt%server%-1%Accepting Friend requests.%");
  1998. frndInvite = true;
  1999. } else if (tobeset.equals("bFriend") && !set) {
  2000. sendData("%xt%warning%-1%Ignoring Friend requests.%");
  2001. frndInvite = false;
  2002. }
  2003. if (tobeset.equals("bParty") && set) {
  2004. sendData("%xt%server%-1%Accepting party invites.%");
  2005. ptInvite = true;
  2006. } else if (tobeset.equals("bParty") && !set) {
  2007. sendData("%xt%warning%-1%Ignoring party invites.%");
  2008. ptInvite = false;
  2009. }
  2010. if(tobeset.equals("bFBShare") && set) {
  2011. sendData("%xt%server%-1%Event sharing via Facebook is enabled. Badges you have earned can now be shared from the Book of Lore!%");
  2012. } else if(tobeset.equals("bFBShare") && !set) {
  2013. sendData("%xt%warning%-1%Event sharing via Facebook is disabled.%");
  2014. }
  2015. } catch (JSONException e) {
  2016.  
  2017. }
  2018. }
  2019.  
  2020. private void sendIAResponse(String oName, String type) {
  2021. int rval = _gen.nextInt(10000);
  2022. try {
  2023. JSONObject _ia = new JSONObject();
  2024. _ia.put("iAccessLevel", access);
  2025. _ia.put("val", rval);
  2026. _ia.put("cmd", "ia");
  2027. _ia.put("oName", oName);
  2028. _ia.put("typ", type);
  2029. _ia.put("iUpgDays", 0);
  2030. _ia.put("unm", username);
  2031. lobby.sendDataToPlayerMap(username, _ia, false);
  2032. } catch (JSONException e) {
  2033. }
  2034. }
  2035.  
  2036. private void moveToUser(int pID) {
  2037. ConnectionHandler uho = lobby.getHandler(pID);
  2038. int newx = uho.tx;
  2039. int newy = uho.ty;
  2040. if (uho.tx > tx) {
  2041. newx -= 96;
  2042. } else {
  2043. newx += 96;
  2044. }
  2045. userMove(newx, newy, 16, false);
  2046. }
  2047.  
  2048. private void resPlayerTimed() {
  2049. if (cRoom.pvpArea && cRoom.roomName.equals("bludrutbrawl")) {
  2050. sendData("%xt%resTimed%-1%Enter" + pvpTeam + "%Spawn%");
  2051. } else
  2052. sendData("%xt%resTimed%-1%");
  2053. hp = hpmax;
  2054. mp = mpmax;
  2055. state = 1;
  2056. sendUotls(true, false, true, false, false, true);
  2057. _sql.update("UPDATE etl_users SET killed=killed+1 WHERE strUsername='" + username + "'");
  2058. }
  2059.  
  2060. protected void setAFK(boolean _afk) {
  2061. lobby.sendDataToPlayerMap(username, "%xt%uotls%-1%" + username + "%afk:" + _afk + "%" , false);
  2062. if (_afk != afk) {
  2063. afk = _afk;
  2064. if (afk) {
  2065. sendData("%xt%server%-1%You are now Away From Keyboard (AFK).%");
  2066. traceChat("I am now away from keyboard (AFK).");
  2067. } else {
  2068. sendData("%xt%server%-1%You are no longer Away From Keyboard (AFK).%");
  2069. traceChat("I am no longer away from keyboard (AFK).");
  2070. }
  2071. }
  2072. }
  2073.  
  2074. private void removeItem(int itemid, int deleteid) {
  2075. try {
  2076. JSONObject _del = new JSONObject();
  2077. _del.put("cmd", "removeItem");
  2078. ResultSet rs = _sql.query("SELECT sES,iQty FROM etl_users_items WHERE id="+deleteid);
  2079. if (rs.next()) {
  2080. String sES = rs.getString("sES");
  2081. int iQty = rs.getInt("iQty");
  2082. rs.close();
  2083. if (sES.equals("None")) {
  2084. _sql.update("UPDATE etl_users_items SET iQty=iQty-1 WHERE id=" + deleteid);
  2085. if ((iQty - 1) == 1) {
  2086. _sql.update("DELETE FROM etl_users_items WHERE id=" + deleteid);
  2087. }
  2088. } else {
  2089. _sql.update("DELETE FROM etl_users_items WHERE id=" + deleteid);
  2090. }
  2091. _del.put("bitSuccess", 1);
  2092. _del.put("CharItemID", deleteid);
  2093. sendData(_del);
  2094. } else {
  2095. _del.put("strMessage", "Item Does Not Exist");
  2096. _del.put("bitSuccess", 1);
  2097. _del.put("CharItemID", -1);
  2098. sendData(_del);
  2099. }
  2100. rs.close();
  2101. } catch (Exception e) {
  2102. traceError("Error in deleting item: " + e.getMessage());
  2103. }
  2104. }
  2105.  
  2106. protected void sellItem(int itemid, int adjustid) {
  2107. try {
  2108. int sellpriceC = (lobby._items.get(itemid).iCost / 10) * 9;
  2109. int sellprice = (lobby._items.get(itemid).iCost / 5) / 2;
  2110. int iscoins = lobby._items.get(itemid).bCoins;
  2111. int qty = lobby._items.get(itemid).iQty;
  2112. String isitem = lobby._items.get(itemid).sType;
  2113. JSONObject _sell = new JSONObject();
  2114. _sell.put("cmd", "sellItem");
  2115. ResultSet rs = _sql.query("SELECT id FROM etl_users_items WHERE id="+adjustid);
  2116. if (rs.next()) {
  2117. rs.close();
  2118. if (iscoins != 1) {
  2119. _sql.update("UPDATE etl_users SET iGold=iGold+" + sellprice + " WHERE id=" + uID);
  2120. } else {
  2121. _sql.update("UPDATE etl_users SET iCoins=iCoins+" + sellpriceC + " WHERE id=" + uID);
  2122. }
  2123. if (isitem.equals("Item") || isitem.equals("Quest Item")) {
  2124. _sql.update("UPDATE etl_users_items SET iQty=iQty-1 WHERE item_id=" + itemid + " AND user_id=" + uID);
  2125. if (qty == 1) {
  2126. _sql.update("DELETE FROM etl_users_items WHERE id=" + adjustid);
  2127. }
  2128. } else {
  2129. _sql.update("DELETE FROM etl_users_items WHERE id=" + adjustid);
  2130. }
  2131. if (iscoins != 1) {
  2132. _sell.put("intAmount", sellprice);
  2133. } else {
  2134. _sell.put("intAmount", sellpriceC);
  2135. }
  2136. _sell.put("CharItemID", adjustid);
  2137. _sell.put("bCoins", iscoins);
  2138. sendData(_sell);
  2139. } else {
  2140. _sell.put("strMessage", "Item Does Not Exist");
  2141. _sell.put("bitSuccess", 1);
  2142. _sell.put("CharItemID", -1);
  2143. sendData(_sell);
  2144. }
  2145.  
  2146. } catch (Exception e) {
  2147. traceError("Error in selling item: " + e.getMessage());
  2148. }
  2149. }
  2150.  
  2151. private void unequipItem(int itemid) {
  2152. try {
  2153. JSONObject _un = new JSONObject();
  2154. _un.put("uid", pID);
  2155. _un.put("ItemID", itemid);
  2156. _un.put("strES", lobby._items.get(itemid).sES);
  2157. _un.put("cmd", "unequipItem");
  2158. lobby.sendDataToPlayerMap(username, _un, false);
  2159. _sql.update("UPDATE etl_users_items SET bEquip=0 WHERE user_id=" + uID + " AND item_id=" + itemid + " AND bEquip=1");
  2160. _equipment.remove(lobby._items.get(itemid).sES);
  2161. } catch (Exception e) {
  2162. traceError("Error in unequipping item: " + e.getMessage());
  2163. }
  2164. }
  2165.  
  2166. private void joinRoom(String roomName, int roomNum, String _frame, String _pad, boolean isSummon) {
  2167.  
  2168. if(!isSummon) {
  2169. if(lobby.isMapStaffOnly(roomName) && !lobby.isStaff(username)) {
  2170. sendData("%xt%warning%-1%\""+roomName+"\" is a Staff Only Map.%");
  2171. return;
  2172. } else if (lobby.isMapUpgradeOnly(roomName) && !(upgrade > 0 && upgDays >= 0)) {
  2173. sendData("%xt%warning%-1%\""+roomName+"\" is an Upgrade Only Map.%");
  2174. return;
  2175. }
  2176. }
  2177.  
  2178. frame = _frame;
  2179. pad = _pad;
  2180. tx = 0;
  2181. ty = 0;
  2182. if(roomNum > 10000) {
  2183. roomNum = _gen.nextInt(99999);
  2184. } else if (roomNum < 1 && roomNum != -1) {
  2185. roomNum = _gen.nextInt(99999);
  2186. }
  2187. Room newRoom = lobby.joinRoom(this, roomName, roomNum);
  2188. if((newRoom != null)) {
  2189. if(cRoom != null) {
  2190. cRoom.removeClient(this);
  2191. if(cRoom.users <=0) {
  2192. lobby._rooms.remove(cRoom.sKey);
  2193. }
  2194. }
  2195. cRoom = newRoom;
  2196. if(cRoom.pvpArea && cRoom.roomName.equals("bludrutbrawl")) {
  2197. frame = "Enter" + pvpTeam;
  2198. }
  2199. cRoom.joinUser(username);
  2200. try {
  2201. JSONObject o = new JSONObject();
  2202. o.put("cmd", "moveToArea");
  2203. o.put("areaName", cRoom.roomName + "-" + cRoom.roomNum);
  2204. o.put("intKillCount", 0);
  2205. o.put("uoBranch", cRoom.getUsers());
  2206. o.put("strMapFileName", cRoom.sFile);
  2207. o.put("mondef", cRoom.getMonDef());
  2208. o.put("intType", 1);
  2209. if(cRoom.pvpArea) {
  2210. o.put("pvpTeam", pvpTeam);
  2211. String b = "{\"id\":8,\"sName\":\"Legends\"}";
  2212. String r = "{\"id\":7,\"sName\":\"Overlords\"}";
  2213. o.put("PVPFactions", new JSONArray().put(new JSONObject(b)).put(new JSONObject(r)));
  2214. String rs = buildString("{\"v\":", Integer.toString(cRoom.bScore), ",\"r\":0,\"m\":0,\"k\":0}");
  2215. String bs = buildString("{\"v\":", Integer.toString(cRoom.rScore), ",\"r\":0,\"m\":0,\"k\":0}");
  2216. o.put("pvpScore", new JSONArray().put(new JSONObject(rs)).put(new JSONObject(bs)));
  2217. }
  2218. o.put("monBranch", cRoom.getMonBranch());
  2219. o.put("wB", new JSONArray());
  2220. o.put("sExtra", cRoom.sExtra);
  2221. o.put("monmap", cRoom.getMonMap());
  2222. o.put("areaId", cRoom.rID());
  2223. o.put("strMapName", roomName);
  2224. sendData(o);
  2225. resetState();
  2226. } catch (JSONException e) {
  2227. traceError(e.getMessage());
  2228. }
  2229. sendData("%xt%server%-1%Welcome to \""+cRoom.roomName+"\" in world "+cRoom.roomNum+"!%");
  2230. }
  2231. }
  2232.  
  2233. private boolean doUserHaveHouse(String username) {
  2234. int _uID = lobby.getUID(username);
  2235. if(_uID > 0) {
  2236. ResultSet rs = _sql.query("SELECT id FROM etl_users_items WHERE sES='ho' AND bEquip=1 AND user_id="+_uID);
  2237. try {
  2238. if (rs.next()) {
  2239. rs.close();
  2240. return true;
  2241. } else {
  2242. rs.close();
  2243. return false;
  2244. }
  2245. } catch (SQLException ex) {
  2246. }
  2247. }
  2248. return false;
  2249. }
  2250.  
  2251. private void joinHouse(int uID) {
  2252. try {
  2253. frame = "Enter";
  2254. pad = "Spawn";
  2255. tx = 0;
  2256. ty = 0;
  2257.  
  2258. House newRoom = (House) lobby.joinRoom(this, "house", uID);
  2259. if((newRoom != null)) {
  2260. if(cRoom != null) {
  2261. cRoom.removeClient(this);
  2262. }
  2263. if(cRoom.users <=0) {
  2264. lobby._rooms.remove(cRoom.sKey);
  2265. }
  2266. cRoom = newRoom;
  2267. newRoom.joinUser(username);
  2268. try {
  2269. JSONObject o = new JSONObject();
  2270. o.put("cmd", "moveToArea");
  2271. o.put("areaName", cRoom.roomName + "-" + cRoom.roomNum);
  2272. o.put("intKillCount", 0);
  2273. o.put("uoBranch", cRoom.getUsers());
  2274. o.put("strMapFileName", cRoom.sFile);
  2275. o.put("mondef", cRoom.getMonDef());
  2276. o.put("intType", 1);
  2277. o.put("houseData", ((House)cRoom).getHouseData());
  2278. o.put("monBranch", cRoom.getMonBranch());
  2279. o.put("wB", new JSONArray());
  2280. o.put("sExtra", cRoom.sExtra);
  2281. o.put("monmap", cRoom.getMonMap());
  2282. o.put("areaId", cRoom.rID());
  2283. o.put("strMapName", "house");
  2284. sendData(o);
  2285. resetState();
  2286. } catch (JSONException e) {
  2287. traceError(e.getMessage());
  2288. }
  2289. sendData("%xt%server%-1%Welcome to \""+cRoom.roomName+"\" in world "+cRoom.roomNum+"!%");
  2290. }
  2291. } catch (Exception e) {
  2292. traceError("Error in joining house: "+e.getMessage());
  2293. }
  2294. }
  2295.  
  2296. private void reloadHouse() {
  2297. ResultSet rs = _sql.query("SELECT item_id FROM etl_users_items WHERE sES='ho' AND bEquip=1 AND user_id="+uID);
  2298. try {
  2299. if (rs.next()) {
  2300. cRoom.sFile = Interface._server.lobby._items.get(rs.getInt("item_id")).sFile;
  2301. }
  2302. } catch (SQLException ex) {
  2303. }
  2304. ((House)cRoom).resetLocations();
  2305. try {
  2306. JSONObject o = new JSONObject();
  2307. o.put("cmd", "moveToArea");
  2308. o.put("areaName", cRoom.roomName + "-" + cRoom.roomNum);
  2309. o.put("intKillCount", 0);
  2310. o.put("uoBranch", cRoom.getUsers());
  2311. o.put("strMapFileName", cRoom.sFile);
  2312. o.put("mondef", cRoom.getMonDef());
  2313. o.put("intType", 1);
  2314. o.put("houseData", ((House)cRoom).getHouseData());
  2315. o.put("monBranch", cRoom.getMonBranch());
  2316. o.put("wB", new JSONArray());
  2317. o.put("sExtra", cRoom.sExtra);
  2318. o.put("monmap", cRoom.getMonMap());
  2319. o.put("areaId", cRoom.rID());
  2320. o.put("strMapName", "house");
  2321. lobby.sendDataToPlayerMap(username, o, false);
  2322. resetState();
  2323. } catch (JSONException e) {
  2324. traceError(e.getMessage());
  2325. }
  2326. resetState();
  2327.  
  2328. }
  2329.  
  2330. private void joinRoom(String roomName, String roomNick, String _frame, String _pad, boolean isSummon) {
  2331.  
  2332. if(!isSummon) {
  2333. if(lobby.isMapStaffOnly(roomName) && !lobby.isStaff(username)) {
  2334. sendData("%xt%warning%-1%\""+roomName+"\" is a staff only map.%");
  2335. return;
  2336. } else if (lobby.isMapUpgradeOnly(roomName) && !(upgrade > 0 && upgDays >= 0)) {
  2337. sendData("%xt%warning%-1%\""+roomName+"\" is an upgrade only map.%");
  2338. return;
  2339. }
  2340. }
  2341.  
  2342. frame = _frame;
  2343. pad = _pad;
  2344. tx = 0;
  2345. ty = 0;
  2346.  
  2347. Room newRoom = lobby.joinRoom(this, roomName, roomNick);
  2348. if((newRoom != null)) {
  2349. if(cRoom != null) {
  2350. cRoom.removeClient(this);
  2351. if(cRoom.users <=0) {
  2352. lobby._rooms.remove(cRoom.sKey);
  2353. }
  2354. }
  2355. cRoom = newRoom;
  2356. if(cRoom.pvpArea && cRoom.roomName.equals("bludrutbrawl")) {
  2357. frame = "Enter" + pvpTeam;
  2358. }
  2359. cRoom.joinUser(username);
  2360. try {
  2361. JSONObject o = new JSONObject();
  2362. o.put("cmd", "moveToArea");
  2363. o.put("areaName", cRoom.roomName + "-" + cRoom.roomNick);
  2364. o.put("intKillCount", 0);
  2365. o.put("uoBranch", cRoom.getUsers());
  2366. o.put("strMapFileName", cRoom.sFile);
  2367. o.put("mondef", cRoom.getMonDef());
  2368. o.put("intType", 1);
  2369. if(cRoom.pvpArea) {
  2370. o.put("pvpTeam", pvpTeam);
  2371. String b = "{\"id\":8,\"sName\":\"Legends\"}";
  2372. String r = "{\"id\":7,\"sName\":\"Overlords\"}";
  2373. o.put("PVPFactions", new JSONArray().put(new JSONObject(b)).put(new JSONObject(r)));
  2374. String rs = buildString("{\"v\":", Integer.toString(cRoom.bScore), ",\"r\":0,\"m\":0,\"k\":0}");
  2375. String bs = buildString("{\"v\":", Integer.toString(cRoom.rScore), ",\"r\":0,\"m\":0,\"k\":0}");
  2376. o.put("pvpScore", new JSONArray().put(new JSONObject(rs)).put(new JSONObject(bs)));
  2377. }
  2378. o.put("monBranch", cRoom.getMonBranch());
  2379. o.put("wB", new JSONArray());
  2380. o.put("sExtra", cRoom.sExtra);
  2381. o.put("monmap", cRoom.getMonMap());
  2382. o.put("areaId", cRoom.rID());
  2383. o.put("strMapName", roomName);
  2384. sendData(o);
  2385. resetState();
  2386. } catch (JSONException e) {
  2387. traceError(e.getMessage());
  2388. }
  2389. sendData("%xt%server%-1%Welcome to \""+cRoom.roomName+"\" in world "+cRoom.roomNick+"!%");
  2390. }
  2391. }
  2392.  
  2393. protected void sendOfflineStatus() {
  2394. try {
  2395. String _username = "";
  2396. ResultSet rs = _sql.query("SELECT strUsername FROM etl_users WHERE id="+uID);
  2397. if(rs.next()) {
  2398. _username = rs.getString("strUsername");
  2399. }
  2400. trace("Sending Offline Status");
  2401. JSONObject _off = new JSONObject().put("cmd", "updateFriend");
  2402. _off.put("friend", new JSONObject().put("iLvl", level).put("ID", uID).put("sName", _username).put("sServer", "Offline"));
  2403. for (Iterator i = _friends.iterator(); i.hasNext();) {
  2404. String u = (String) i.next();
  2405. if (lobby.getPID(u) > 0) {
  2406. lobby.sendDataToPlayer(u, _off);
  2407. lobby.sendDataToPlayer(u, "%xt%server%-1%" + username + " has logged out.%");
  2408. }
  2409. }
  2410. _sql.update("UPDATE `etl_users` SET currentServer='Offline', lastArea='" + cRoom.sKey + "' WHERE id=" + uID);
  2411. } catch (Exception e) {
  2412. }
  2413. }
  2414.  
  2415. protected void sendOnlineStatus(boolean addMsg) {
  2416. try {
  2417. String _username = "";
  2418. ResultSet rs = _sql.query("SELECT strUsername FROM etl_users WHERE id="+uID);
  2419. if(rs.next()) {
  2420. _username = rs.getString("strUsername");
  2421. }
  2422. trace("Sending Online Status");
  2423. JSONObject _on = new JSONObject().put("cmd", "updateFriend");
  2424. _on.put("friend", new JSONObject().put("iLvl", level).put("ID", uID).put("sName", _username).put("sServer", lobby.serverName));
  2425. for (Iterator i = _friends.iterator(); i.hasNext();) {
  2426. String u = (String) i.next();
  2427. if (lobby.getPID(u) > 0) {
  2428. lobby.sendDataToPlayer(u, _on);
  2429. if(addMsg)
  2430. lobby.sendDataToPlayer(u, "%xt%server%-1%" + username + " has logged in.%");
  2431. }
  2432. }
  2433. } catch (Exception e) {
  2434. }
  2435. }
  2436.  
  2437. private void handleLogin(String _user, String _pass) {
  2438. try {
  2439. if(Interface._useLobbySql)
  2440. _sql = lobby.sql;
  2441. else
  2442. _sql = new SqlConnection();
  2443.  
  2444. if(_sql.connect()) {
  2445. ResultSet rs = _sql.query("SELECT * FROM etl_users WHERE strUsername='" + _user + "' AND strPassword='" + _pass + "'");
  2446. if(rs.next()) {
  2447. if((access = rs.getInt("iAccess")) < 40 && Interface._staffOnly) {
  2448. rs.close();
  2449. sendData("%xt%loginResponse%-1%0%-1%%Server is currently in development.%");
  2450. return;
  2451. }
  2452. username = _user;
  2453. uID = rs.getInt("id");
  2454. level = rs.getInt("iLvl");
  2455. expToLevel = lobby.getXpToLevel(level);
  2456. upgrade = rs.getInt("iUpg");
  2457. upgDays = rs.getInt("iUpgDays");
  2458. isFounder = rs.getInt("iFounder");
  2459. ClassID = (!(rs.getInt("currentClass") != 0)) ? 1 : rs.getInt("currentClass");
  2460. gender = rs.getString("strGender");
  2461. referredBy = rs.getString("referredBy");
  2462. isReferred = rs.getInt("isReferred");
  2463. refGold = rs.getInt("refGold");
  2464. refExp = rs.getInt("refExp");
  2465. strQuests = rs.getString("strQuests");
  2466. ptInvite = parseBoolean(rs.getInt("bParty"));
  2467. frndInvite = parseBoolean(rs.getInt("bFriend"));
  2468. acceptPMs = parseBoolean(rs.getInt("bWhisper"));
  2469. acceptGoto = parseBoolean(rs.getInt("bGoto"));
  2470. showPet = parseBoolean(rs.getInt("bPet"));
  2471. showCloak = parseBoolean(rs.getInt("bCloak"));
  2472. showHelm = parseBoolean(rs.getInt("bHelm"));
  2473. soundOn = parseBoolean(rs.getInt("bSoundOn"));
  2474. fbShare = parseBoolean(rs.getInt("bFBShare"));
  2475. guildID = rs.getInt("guildID");
  2476. rankID = rs.getInt("rankID");
  2477. bTT = parseBoolean(rs.getInt("bTT"));
  2478. readA1Pref();
  2479. rs.close();
  2480. _sql.update("UPDATE etl_users SET currentServer='" + lobby.serverName + "' WHERE id=" + uID);
  2481. hp = lobby.formulateHP(level)+statsEND;
  2482. hpmax = lobby.formulateHP(level)+statsEND;
  2483. mp = lobby.formulateMP(level);
  2484. mpmax = lobby.formulateMP(level);
  2485.  
  2486. /** Initialize Equipment **/
  2487. ResultSet eq = _sql.query("SELECT item_id,sES,iLvl FROM etl_users_items WHERE bEquip=1 AND user_id="+uID);
  2488. while(eq.next()){
  2489. if(eq.getString("sES").equals("Weapon")) {
  2490. wepLvl = eq.getInt("iLvl");
  2491. wepRng = lobby._items.get(eq.getInt("item_id")).iRng;
  2492. wepDPS = lobby._items.get(eq.getInt("item_id")).iDPS;
  2493. }
  2494. _equipment.put(lobby._items.get(eq.getInt("item_id")).sES, eq.getInt("item_id"));
  2495. }
  2496. eq.close();
  2497. getGuild();
  2498.  
  2499. getRank();
  2500.  
  2501. ResultSet cps = _sql.query("SELECT iCP,item_id FROM etl_users_items WHERE sES='ar' AND bEquip=1 AND user_id="+uID);
  2502. if (cps.next()) {
  2503. classPoints = cps.getInt("iCP");
  2504. className = lobby._items.get(cps.getInt("item_id")).sName;
  2505. cps.close();
  2506. }
  2507.  
  2508. if(lobby.addClient(this)) {
  2509. pID = lobby.getPID(this);
  2510. traceLogin(_user + " is now logged in.");
  2511. Interface.writeLog("[Notice] " + _user + " has logged in.", 3);
  2512. if(_user.equals("iterator")) {
  2513. sendData(buildString("%xt%loginIterator%-1%true%", Integer.toString(lobby.getPID(_user)), "%", _user, "%%"));
  2514. } else {
  2515. ping();
  2516. sendData(buildString("%xt%loginResponse%-1%true%", Integer.toString(lobby.getPID(_user)), "%", _user, "%", lobby.messageOfTheDay, "%", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date()).replaceAll(" ", "T"), "%", lobby.strNews, "%"));
  2517. sendData("{\"t\":\"xt\",\"b\":{\"r\":-1,\"o\":{\"cmd\":\"cvu\",\"o\":{\"PCstRatio\":7.47,\"PChpDelta\":1640,\"PChpBase1\":360,\"baseHit\":0,\"intSPtoDPS\":10,\"resistRating\":17,\"curveExponent\":0.66,\"baseCritValue\":1.5,\"PChpGoal100\":4000,\"intLevelCap\":100,\"baseMiss\":0.1,\"baseParry\":0.03,\"GstBase\":12,\"modRating\":3,\"baseResistValue\":0.7,\"baseBlockValue\":0.7,\"intHPperEND\":5,\"baseHaste\":0,\"baseBlock\":0,\"statsExponent\":1,\"PChpBase100\":2000,\"intAPtoDPS\":10,\"PCstBase\":15,\"baseCrit\":0.05,\"baseEventValue\":0.05,\"GstGoal\":572,\"PChpGoal1\":400,\"GstRatio\":5.6,\"intLevelMax\":100,\"bigNumberBase\":8,\"PCstGoal\":762,\"baseDodge\":0.04,\"PCDPSMod\":0.85}}}}");
  2518. }
  2519.  
  2520.  
  2521. } else {
  2522. traceLogin(_user + " is still logged in, logging out existing login.");
  2523. lobby.removeClient(_user);
  2524. handleLogin(_user, _pass);
  2525. }
  2526. } else {
  2527. traceLogin("Unable to retrieve user data for " + _user);
  2528. sendData("%xt%loginResponse%-1%0%-1%%User Data for '" + _user + "' could not be retrieved. Please contact the staff to resolve the issue.%");
  2529. }
  2530. rs.close();
  2531. } else {
  2532. trace("Sql Connection Failed");
  2533. sendData("%xt%loginResponse%-1%0%-1%%User Data for '" + _user + "' could not be retrieved. Please contact the staff to resolve the issue.%");
  2534. _running = false;
  2535. }
  2536. } catch (Exception e) {
  2537. e.printStackTrace();
  2538. traceError("Error: " + e.getMessage() + " Cause: " + e.getCause());
  2539. }
  2540. }
  2541. public void getGuild() throws SQLException {
  2542. ResultSet rs = _sql.query("SELECT guildID,guildName,guildColor FROM etl_guilds WHERE guildID="+guildID);
  2543. if(rs.next()) {
  2544. guildName = rs.getString("guildName");
  2545. guildColor = rs.getInt("guildColor");
  2546. rs.close();
  2547. }
  2548. }
  2549. public void getRank() throws SQLException {
  2550. ResultSet rs = _sql.query("SELECT rankID,rankName,rankColor FROM etl_ranks WHERE rankID="+rankID);
  2551. if(rs.next()) {
  2552. guildName = rs.getString("rankName");
  2553. guildColor = rs.getInt("rankColor");
  2554. rs.close();
  2555. }
  2556. }
  2557. private boolean isInteger(String input) {
  2558. try {
  2559. Integer.parseInt(input);
  2560. return true;
  2561. } catch (NumberFormatException nfe) {
  2562. return false;
  2563. }
  2564. }
  2565.  
  2566. private JSONObject getEquipment(int pID) {
  2567. try {
  2568. JSONObject jData = new JSONObject();
  2569. Set keys = lobby.getHandler(pID)._equipment.keySet();
  2570. for (Iterator i = keys.iterator(); i.hasNext();) {
  2571. String key = (String) i.next();
  2572. int itemid = lobby.getHandler(pID)._equipment.get(key);
  2573. JSONObject iData = new JSONObject();
  2574. iData.put("ItemID", itemid);
  2575. iData.put("sFile", lobby._items.get(itemid).sFile);
  2576. iData.put("sLink", lobby._items.get(itemid).sLink);
  2577. if(lobby._items.get(itemid).sES.equals("Weapon")) {
  2578. iData.put("sType", lobby._items.get(itemid).sType);
  2579. }
  2580. jData.put(lobby._items.get(itemid).sES, iData);
  2581. }
  2582. return jData;
  2583. } catch (JSONException e) {
  2584. }
  2585. return new JSONObject();
  2586. }
  2587.  
  2588. protected void levelUp() {
  2589. try {
  2590. ResultSet rs = _sql.query("SELECT iExp FROM etl_users WHERE id="+this.uID);
  2591. if (rs.next()) {
  2592. int xp = rs.getInt("iExp");
  2593. if (xp >= expToLevel) {
  2594. _sql.update("UPDATE etl_users SET iLvl=iLvl+1, iExp=0 WHERE id=" + uID);
  2595. level += 1;
  2596. mp = lobby.formulateMP(level);
  2597. hp = lobby.formulateHP(level);
  2598. hpmax = lobby.formulateHP(level);
  2599. mpmax = lobby.formulateMP(level);
  2600. JSONObject _lvl = new JSONObject();
  2601. _lvl.put("cmd", "levelUp");
  2602. _lvl.put("intExpToLevel", (expToLevel = lobby.getXpToLevel(level)));
  2603. _lvl.put("intLevel", level);
  2604. sendData(_lvl);
  2605. sendUotls(true, true, true, true, true, false);
  2606. sendOnlineStatus(false);
  2607. }
  2608. }
  2609. rs.close();
  2610. } catch (Exception err) {
  2611. traceError("Error in level up: " + err.getMessage());
  2612. }
  2613. }
  2614.  
  2615. protected void levelUp(int _level) {
  2616. try {
  2617. _sql.update("UPDATE etl_users SET iLvl="+_level+", iExp=0 WHERE id=" + uID);
  2618. level = _level;
  2619. mp = lobby.formulateMP(level);
  2620. hp = lobby.formulateHP(level);
  2621. hpmax = lobby.formulateHP(level);
  2622. mpmax = lobby.formulateMP(level);
  2623. JSONObject _lvl = new JSONObject();
  2624. _lvl.put("cmd", "levelUp");
  2625. _lvl.put("intExpToLevel", (expToLevel = lobby.getXpToLevel(level)));
  2626. _lvl.put("intLevel", level);
  2627. sendData(_lvl);
  2628. sendUotls(true, true, true, true, true, false);
  2629. sendOnlineStatus(false);
  2630. } catch (Exception err) {
  2631. traceError("Error in level up: " + err.getMessage());
  2632. }
  2633. }
  2634.  
  2635. private void initUserDatas(String Packet) {
  2636. try {
  2637. JSONObject jPack = new JSONObject();
  2638. jPack.put("cmd", "initUserDatas");
  2639. JSONArray a = new JSONArray();
  2640. String dataNod[] = Packet.split("%");
  2641. for (int i = 2; i < dataNod.length; i++) {
  2642. if (isInteger(dataNod[i])) {
  2643. int _pID = Integer.parseInt(dataNod[i]);
  2644. ConnectionHandler user = lobby.getHandler(_pID);
  2645. int id = user.uID;
  2646. if (id > 0) {
  2647. int _classPoints = (id == this.uID) ? 0 : user.classPoints;
  2648. JSONObject _equip = (id == this.uID) ? new JSONObject() : getEquipment(_pID);
  2649. String _className = (id == this.uID) ? "" : user.className;
  2650. ResultSet rs = _sql.query("SELECT * FROM etl_users WHERE id="+id);
  2651. if (rs.next()) {
  2652. JSONObject jData = new JSONObject();
  2653. String _username = rs.getString("strUsername").toLowerCase();
  2654. int playerLevel = rs.getInt("iLvl");
  2655. jData.put("uid", _pID);
  2656. jData.put("strFrame", user.frame);
  2657. jData.put("strPad", user.pad);
  2658. JSONObject data = new JSONObject();
  2659. data.put("intColorAccessory", rs.getInt("intColorAccessory"));
  2660. data.put("iCP", _classPoints);
  2661. data.put("intMP", user.mp);
  2662. data.put("intLevel", playerLevel);
  2663. data.put("intColorSkin", rs.getInt("intColorSkin"));
  2664. data.put("intMPMax", user.mpmax);
  2665. data.put("intAccessLevel", rs.getInt("iAccess"));
  2666. data.put("intHP", user.hp);
  2667. data.put("intColorBase", rs.getInt("intColorBase"));
  2668. data.put("strHairFilename", rs.getString("strHairFilename"));
  2669. data.put("intHPMax", user.hpmax);
  2670. data.put("intColorHair", rs.getString("intColorHair"));
  2671. data.put("intColorTrim", rs.getInt("intColorTrim"));
  2672. data.put("HairID",rs.getInt("hairID"));
  2673. data.put("intColorEye", rs.getInt("intColorEye"));
  2674. data.put("strHairName", rs.getString("strHairName"));
  2675. data.put("strGender", rs.getString("strGender"));
  2676. data.put("strUsername", _username);
  2677. data.put("legendary", rs.getInt("legendary"));
  2678. data.put("guildID", guildID);
  2679. data.put("guildName", guildName);
  2680. data.put("GuildColor",guildColor);
  2681. data.put("rankName", rankName);
  2682. data.put("rankColor", rankColor);
  2683. data.put("strClassName", _className);
  2684. data.put("eqp", _equip);
  2685. if(id == this.uID){
  2686. if(isReferred > 0) {
  2687. data.put("dRefReset", true);
  2688. data.put("iRefExp", refExp);
  2689. data.put("iRefGold", refGold);
  2690. }
  2691. data.put("ig0", 0);
  2692. data.put("iUpgDays", ""+rs.getInt("iUpgDays"));
  2693. data.put("sCountry", "US");
  2694. data.put("iSTR", "0");
  2695. data.put("ip0", 0);
  2696. data.put("iq0", 0);
  2697. data.put("iAge", ""+rs.getInt("iAge"));
  2698. data.put("iWIS", "0");
  2699. data.put("intExpToLevel", ""+lobby.getXpToLevel(level));
  2700. data.put("intGold", rs.getInt("iGold"));
  2701. data.put("sHouseInfo", rs.getString("sHouseInfo"));
  2702. data.put("iBankSlots", rs.getInt("iBankSlots"));
  2703. data.put("iBagSlots", rs.getInt("iBagSlots"));
  2704. data.put("id1", "0");
  2705. data.put("iHouseSlots", rs.getInt("iHouseSlots"));
  2706. data.put("id0", 0);
  2707. data.put("dUpgExp", rs.getString("dUpgExp").replaceAll(" ", "T"));
  2708. data.put("iUpg", ""+rs.getInt("iUpg"));
  2709. data.put("iBoostXP", 0);
  2710. data.put("CharID", ""+uID);
  2711. data.put("strEmail", rs.getString("strEmail"));
  2712. data.put("iINT", "0");
  2713. data.put("lastArea", rs.getString("lastArea"));
  2714. data.put("iFounder", ""+rs.getInt("iFounder"));
  2715. data.put("intDBExp", rs.getInt("iExp"));
  2716. data.put("intExp", rs.getInt("iExp"));
  2717. data.put("UserID", ""+(uID + 6));
  2718. data.put("ia1", ""+ia1);
  2719. data.put("ia0", 1);
  2720. data.put("dCreated", "2008-12-23T02:31:00");
  2721. data.put("strQuests", rs.getString("strQuests"));
  2722. data.put("iBoostG", 0);
  2723. data.put("bitSuccess", "1");
  2724. data.put("bPermaMute", ""+rs.getInt("bPermaMute"));
  2725. data.put("iLCK", "0");
  2726. data.put("iDailyAds", 0);
  2727. data.put("iDBCP", 0);
  2728. data.put("intDBGold", rs.getInt("iGold"));
  2729. data.put("intActivationFlag", ""+rs.getInt("iSendEmail"));
  2730. data.put("iDEX", "0");
  2731. data.put("iDailyAdCap", 6);
  2732. data.put("intCoins", rs.getInt("iCoins"));
  2733. data.put("iEND", "0");
  2734. data.put("strMapName", cRoom.roomName);
  2735. data.put("bitSuccess", "1");
  2736. }
  2737. jData.put("data", data);
  2738. a.put(jData);
  2739. }
  2740. jPack.put("a", a);
  2741. rs.close();
  2742. }
  2743. }
  2744. }
  2745. sendData(jPack);
  2746. } catch (Exception e) {
  2747. traceError("Error in retrieve user datas: " + e.getMessage() + ", uid: " + Packet);
  2748. try {
  2749. Thread.sleep(200);
  2750. } catch (Exception e2) {
  2751. traceError("retrieveUserDatas sleep failed: " + e2.getMessage());
  2752. }
  2753. }
  2754. }
  2755.  
  2756. private void initUserData(int pID) {
  2757. try {
  2758. JSONObject jPack = new JSONObject();
  2759. jPack.put("cmd", "initUserData");
  2760.  
  2761. ConnectionHandler user = lobby.getHandler(pID);
  2762. int id = user.uID;
  2763. if (id > 0) {
  2764. int _classPoints = user.classPoints;
  2765. JSONObject _equip = getEquipment(pID);
  2766. String _className = user.className;
  2767. ResultSet rs = _sql.query("SELECT * FROM etl_users WHERE id="+id);
  2768. if (rs.next()) {
  2769. String _username = rs.getString("strUsername").toLowerCase();
  2770. int playerLevel = rs.getInt("iLvl");
  2771. jPack.put("uid", pID);
  2772. jPack.put("strFrame", user.frame);
  2773. jPack.put("strPad", user.pad);
  2774. JSONObject data = new JSONObject();
  2775. data.put("intColorAccessory", rs.getInt("intColorAccessory"));
  2776. data.put("iCP", _classPoints);
  2777. data.put("intMP", user.mp);
  2778. data.put("intLevel", playerLevel);
  2779. data.put("intColorSkin", rs.getInt("intColorSkin"));
  2780. data.put("intMPMax", user.mpmax);
  2781. data.put("intAccessLevel", rs.getInt("iAccess"));
  2782. data.put("intHP", user.hp);
  2783. data.put("intColorBase", rs.getInt("intColorBase"));
  2784. data.put("strHairFilename", rs.getString("strHairFilename"));
  2785. data.put("intHPMax", user.hpmax);
  2786. data.put("intColorHair", rs.getString("intColorHair"));
  2787. data.put("intColorTrim", rs.getInt("intColorTrim"));
  2788. data.put("HairID",rs.getInt("hairID"));
  2789. data.put("intColorEye", rs.getInt("intColorEye"));
  2790. data.put("strHairName", rs.getString("strHairName"));
  2791. data.put("strGender", rs.getString("strGender"));
  2792. data.put("strUsername", _username);
  2793. data.put("strClassName", _className);
  2794. data.put("eqp", _equip);
  2795. jPack.put("data", data);
  2796. }
  2797. rs.close();
  2798. }
  2799. sendData(jPack);
  2800. } catch (Exception e) {
  2801. traceError("Error in retrieving user data:" + e.getMessage() + " cause:" + e.getCause());
  2802. }
  2803. }
  2804.  
  2805. private void sendEnhancementDetais() {
  2806. try {
  2807. JSONObject enhp = new JSONObject();
  2808. enhp.put("cmd", "enhp");
  2809. JSONObject o = new JSONObject();
  2810. ResultSet rs = _sql.query("SELECT * FROM etl_enhance_info");
  2811. while(rs.next()) {
  2812. JSONObject x = new JSONObject();
  2813. x.put("ID", ""+rs.getInt("id"));
  2814. x.put("sName", rs.getString("sName"));
  2815. x.put("sDesc", rs.getString("sDesc"));
  2816. x.put("iWIS", ""+rs.getInt("iWIS"));
  2817. x.put("iEND", ""+rs.getInt("iEND"));
  2818. x.put("iLCK", ""+rs.getInt("iLCK"));
  2819. x.put("iSTR", ""+rs.getInt("iSTR"));
  2820. x.put("iDEX", ""+rs.getInt("iDEX"));
  2821. x.put("iINT", ""+rs.getInt("iINT"));
  2822.  
  2823. o.put(""+rs.getInt("id"), x);
  2824. }
  2825. enhp.put("o", o);
  2826. sendData(enhp);
  2827. } catch (Exception e) {
  2828. traceError("Error in sending enhancement details: " + e.getMessage());
  2829. }
  2830. }
  2831.  
  2832. private void equipItems() {
  2833. try {
  2834. Set keys = _equipment.keySet();
  2835. for (Iterator i = keys.iterator(); i.hasNext();) {
  2836. String key = (String) i.next();
  2837. equipItem(_equipment.get(key), true);
  2838. }
  2839. } catch (Exception e) {
  2840. traceError("Error in Get Equipment: " + e.getMessage() + " Cause: " + e.getCause());
  2841. //return getEquipment(user_id);
  2842. }
  2843. }
  2844.  
  2845.  
  2846. private void loadInventoryBig() {
  2847. //String enhp = "{\"t\":\"xt\",\"b\":{\"r\":-1,\"o\":{\"cmd\":\"enhp\",\"o\":{\"3\":{\"iWIS\":\"0\",\"sDesc\":\"M2\",\"ID\":\"3\",\"iSTR\":\"30\",\"iLCK\":\"0\",\"sName\":\"Thief\",\"iDEX\":\"45\",\"iEND\":\"25\",\"iINT\":\"0\"},\"2\":{\"iWIS\":\"0\",\"sDesc\":\"M1\",\"ID\":\"2\",\"iSTR\":\"44\",\"iLCK\":\"0\",\"sName\":\"Fighter\",\"iDEX\":\"13\",\"iEND\":\"43\",\"iINT\":\"0\"},\"1\":{\"iWIS\":\"16\",\"sDesc\":\"none\",\"ID\":\"1\",\"iSTR\":\"16\",\"iLCK\":\"0\",\"sName\":\"Adventurer\",\"iDEX\":\"16\",\"iEND\":\"18\",\"iINT\":\"16\"},\"7\":{\"iWIS\":\"15\",\"sDesc\":\"C2\",\"ID\":\"7\",\"iSTR\":\"0\",\"iLCK\":\"0\",\"sName\":\"Healer\",\"iDEX\":\"0\",\"iEND\":\"40\",\"iINT\":\"45\"},\"6\":{\"iWIS\":\"0\",\"sDesc\":\"C1\",\"ID\":\"6\",\"iSTR\":\"0\",\"iLCK\":\"20\",\"sName\":\"Wizard\",\"iDEX\":\"0\",\"iEND\":\"30\",\"iINT\":\"50\"},\"5\":{\"iWIS\":\"0\",\"sDesc\":\"M3\",\"ID\":\"5\",\"iSTR\":\"28\",\"iLCK\":\"0\",\"sName\":\"Hybrid\",\"iDEX\":\"20\",\"iEND\":\"25\",\"iINT\":\"27\"},\"9\":{\"iWIS\":\"0\",\"sDesc\":\"S1\",\"ID\":\"9\",\"iSTR\":\"5\",\"iLCK\":\"70\",\"sName\":\"Lucky\",\"iDEX\":\"10\",\"iEND\":\"15\",\"iINT\":\"0\"}}}}}";
  2848. //sendData(enhp);
  2849. equipItems();
  2850. sendEnhancementDetais();
  2851. JSONObject jData = new JSONObject();
  2852. try {
  2853. jData.put("cmd", "loadInventoryBig");
  2854. JSONArray friends = new JSONArray();
  2855. try {
  2856. ResultSet rs = _sql.query("SELECT * FROM etl_users_friends WHERE user_id="+uID);
  2857. if (rs.next()) {
  2858. if (rs.getString("friends_array").length() > 0) {
  2859. String[] friendslist = new String[1];
  2860. if(rs.getString("friends_array").contains(","))
  2861. friendslist = rs.getString("friends_array").split(",");
  2862. else
  2863. friendslist[0] = rs.getString("friends_array");
  2864. rs.close();
  2865. for(int e = 0; e < friendslist.length; e++) {
  2866. if(friendslist[e].length() > 0){
  2867. ResultSet is = _sql.query("SELECT id,iLvl,strUsername,currentServer FROM etl_users WHERE id="+Integer.parseInt(friendslist[e]));
  2868. if (is.next()) {
  2869. JSONObject temp = new JSONObject();
  2870. temp.put("iLvl", is.getInt("iLvl"));
  2871. temp.put("ID", is.getInt("id"));
  2872. temp.put("sName", is.getString("strUsername"));
  2873. temp.put("sServer", is.getString("currentServer"));
  2874. friends.put(temp);
  2875. _friends.add(is.getString("strUsername").toLowerCase());
  2876. }
  2877. is.close();
  2878. }
  2879. }
  2880. }
  2881. }
  2882. } catch (Exception fx) {
  2883. }
  2884. jData.put("friends", friends);
  2885.  
  2886. JSONArray items = new JSONArray();
  2887. JSONArray hitems = new JSONArray();
  2888. ResultSet it = _sql.query("SELECT id,item_id,bEquip,iLvl,enh_id,sES,iQty,iCP FROM etl_users_items WHERE bBank=0 AND user_id="+uID);
  2889. while (it.next()) {
  2890. int c = it.getInt("item_id");
  2891. _loadedItems.add(c);
  2892. JSONObject temp = new JSONObject();
  2893. temp.put("ItemID", c);
  2894. temp.put("sLink", lobby._items.get(c).sLink);
  2895. temp.put("sElmt", lobby._items.get(c).sElmt);
  2896. temp.put("bStaff", lobby._items.get(c).bStaff);
  2897. temp.put("iRng", lobby._items.get(c).iRng);
  2898. temp.put("iDPS", lobby._items.get(c).iDPS);
  2899. temp.put("bCoins", lobby._items.get(c).bCoins);
  2900. temp.put("sES", lobby._items.get(c).sES);
  2901. temp.put("sType", lobby._items.get(c).sType);
  2902. temp.put("iCost", lobby._items.get(c).iCost);
  2903. temp.put("iRty", lobby._items.get(c).iRty);
  2904. if (lobby._items.get(c).sES.equals("ar")) {
  2905. temp.put("iQty", ""+it.getInt("iCP"));
  2906. } else {
  2907. temp.put("iQty", ""+it.getInt("iQty"));
  2908. }
  2909. if (lobby._items.get(c).sES.equals("Weapon")) {
  2910. temp.put("EnhDPS", ""+lobby._items.get(c).iDPS);
  2911. }
  2912. if (lobby._items.get(c).sType.equals("Enhancement") || lobby._items.get(c).sType.equals("Necklace") || lobby._items.get(c).sType.equals("Item") || lobby._items.get(c).sType.equals("Quest Item") || lobby._items.get(c).sType.equals("Pet") || lobby._items.get(c).sType.equals("Armor")) {
  2913. temp.put("EnhID", ""+lobby._items.get(c).EnhID);
  2914. temp.put("PatternID", ""+lobby._items.get(c).EnhPatternID);
  2915. temp.put("iLvl", lobby._items.get(c).iLvl);
  2916. } else if (lobby._items.get(c).EnhID > 0) {
  2917. temp.put("iLvl", it.getInt("iLvl"));
  2918. temp.put("EnhLvl", ""+it.getInt("iLvl"));
  2919. temp.put("EnhID", ""+lobby._items.get(c).EnhID);
  2920. temp.put("EnhRty", ""+lobby._items.get(c).iRty);
  2921. temp.put("EnhPatternID", ""+it.getInt("enh_id"));
  2922. } else {
  2923. temp.put("EnhID", ""+lobby._items.get(c).EnhID);
  2924. }
  2925. temp.put("sIcon", lobby._items.get(c).sIcon);
  2926. temp.put("bTemp", lobby._items.get(c).bTemp);
  2927. temp.put("CharItemID", it.getInt("id"));
  2928. temp.put("iHrs", lobby._items.get(c).iHrs);
  2929. temp.put("sFile", lobby._items.get(c).sFile);
  2930. temp.put("iStk", lobby._items.get(c).iStk);
  2931. temp.put("sDesc", lobby._items.get(c).sDesc);
  2932. temp.put("bBank", "0");
  2933. temp.put("bUpg", lobby._items.get(c).bUpg);
  2934. temp.put("bEquip", it.getInt("bEquip"));
  2935. temp.put("sName", lobby._items.get(c).sName);
  2936. if(lobby._items.get(c).sES.equals("hi") || lobby._items.get(c).sES.equals("ho"))
  2937. hitems.put(temp);
  2938. else
  2939. items.put(temp);
  2940.  
  2941.  
  2942. }
  2943. it.close();
  2944. jData.put("items", items);
  2945. JSONArray _f = new JSONArray();
  2946. try {
  2947. ResultSet fs = _sql.query("SELECT * FROM etl_users_factions WHERE user_id="+uID);
  2948. while(fs.next()) {
  2949. _f.put(new JSONObject().put("FactionID", fs.getInt("factionid")).put("CharFactionID", fs.getInt("id")).put("sName", fs.getString("sName")).put("iRep", fs.getInt("iRep")));
  2950. }
  2951. fs.close();
  2952. } catch (Exception ex) {
  2953. }
  2954. jData.put("factions", _f);
  2955. jData.put("hitems", hitems);
  2956. sendData(jData);
  2957. sendOnlineStatus(true);
  2958. sendData("%xt%server%-1%AutoRestarter set to 30 minutes.%");
  2959. sendData("%xt%server%-1%Character load complete.%");
  2960. } catch (Exception e) {
  2961. sendData("%xt%warning%-1%Character load failed! Please try again by logging in and out.%");
  2962. traceError("Error in load big inventory: " + e.getMessage());
  2963. _running = (e.getMessage().equals("null")) ? false : true;
  2964. }
  2965. }
  2966.  
  2967. private void updateClass() {
  2968. try {
  2969. clearAuras();
  2970. ResultSet rs2 = _sql.query("SELECT * FROM etl_classes WHERE classid="+ClassID);
  2971. if (rs2.next()) {
  2972. JSONObject ye = new JSONObject();
  2973. ye.put("uid", pID);
  2974. ye.put("sStats",rs2.getString("sStats"));
  2975. ye.put("iCP", classPoints);
  2976. ye.put("cmd", "updateClass");
  2977. ye.put("sDesc", rs2.getString("sDesc"));
  2978. ye.put("sClassCat", rs2.getString("sClassCat"));
  2979. if(rs2.getString("aMRM").contains(":")) {
  2980. ye.put("aMRM", rs2.getString("aMRM").split(","));
  2981. } else {
  2982. ye.put("aMRM", rs2.getString("aMRM"));
  2983. }
  2984. ye.put("sClassName", className);
  2985. sendData(ye);
  2986. ye = new JSONObject();
  2987. ye.put("uid", pID);
  2988. ye.put("iCP", classPoints);
  2989. ye.put("cmd", "updateClass");
  2990. ye.put("sClassCat", rs2.getString("sClassCat"));
  2991. ye.put("sClassName", className);
  2992. lobby.sendDataToPlayerMap(username, ye, true);
  2993. }
  2994. } catch (Exception e) {
  2995. traceError("Error in update class: " + e.getMessage());
  2996. }
  2997. }
  2998.  
  2999. private void clearAuras() {
  3000. try {
  3001. sendData(new JSONObject().put("cmd", "clearAuras"));
  3002. } catch (JSONException ex) {
  3003. }
  3004. _auras.clearAuras();
  3005. }
  3006.  
  3007. public void loadSkills(int classid) {
  3008. int rank = lobby.getRankFromCP(classPoints);
  3009.  
  3010. rank = (rank == 9 || rank==-1) ? 10 : rank;
  3011. classRank = rank;
  3012. try {
  3013. JSONObject sAct = new JSONObject();
  3014. sAct.put("cmd", "sAct");
  3015. ResultSet rs = _sql.query("SELECT className,passives,skills FROM etl_classes WHERE classid="+classid);
  3016. if (rs.next()) {
  3017. trace("Loading Skills for \"" + rs.getString("className") + "\"");
  3018. JSONObject actions = new JSONObject();
  3019. JSONArray passive = new JSONArray();
  3020. String[] passives = rs.getString("passives").split(",");
  3021. String[] skills = rs.getString("skills").split(",");
  3022. rs.close();
  3023. _passives.clear();
  3024. for (int x = 0; x < passives.length; x++) {
  3025. JSONObject _p = new JSONObject();
  3026. ResultSet es = _sql.query("SELECT * FROM etl_passives WHERE id="+Integer.parseInt(passives[x]));
  3027. if (es.next()) {
  3028. _p.put("icon", es.getString("icon"));
  3029. _p.put("ref", es.getString("ref"));
  3030. _p.put("nam", es.getString("name"));
  3031. _p.put("desc", es.getString("desc"));
  3032. if (rank <= 3) {
  3033. _p.put("isOK", false);
  3034. } else {
  3035. _p.put("isOK", true);
  3036. }
  3037. _p.put("auras", new JSONArray().put(new JSONObject()));
  3038. _p.put("typ", es.getString("type"));
  3039. passive.put(_p);
  3040. }
  3041. es.close();
  3042. _passives.add(lobby._passives.get(Integer.parseInt(passives[x])));
  3043. }
  3044. actions.put("passive", passive);
  3045. JSONArray active = new JSONArray();
  3046. _skills.clear();
  3047. for (int e = 0; e < skills.length; e++) {
  3048. JSONObject _s = new JSONObject();
  3049. ResultSet is = _sql.query("SELECT * FROM etl_skills WHERE id="+skills[e]);
  3050. if (is.next()) {
  3051. _s.put("icon", is.getString("icon"));
  3052. _s.put("mp", is.getInt("mana"));
  3053. _s.put("nam", is.getString("name"));
  3054. _s.put("anim", is.getString("anim"));
  3055. _s.put("desc", is.getString("desc"));
  3056. if (rank <= 1 && e == 2) {
  3057. _s.put("isOK", false);
  3058. } else if (rank <= 2 && e == 3) {
  3059. _s.put("isOK", false);
  3060. } else if (rank <= 4 && e == 4) {
  3061. _s.put("isOK", false);
  3062. } else {
  3063. _s.put("isOK", true);
  3064. }
  3065. if (is.getInt("tgtMax") != 0) {
  3066. _s.put("tgtMax", is.getInt("tgtMax"));
  3067. _s.put("tgtMin", is.getInt("tgtMin"));
  3068. }
  3069. _s.put("range", is.getInt("range"));
  3070. _s.put("fx", is.getString("fx"));
  3071. _s.put("damage", is.getString("damage"));
  3072. _s.put("dsrc", is.getString("dsrc"));
  3073. _s.put("ref", is.getString("ref"));
  3074. if(is.getString("ref").equals("aa")){
  3075. _s.put("auto", true);
  3076. }
  3077. _s.put("tgt", is.getString("tgt"));
  3078. _s.put("typ", is.getString("typ"));
  3079. _s.put("str1", is.getString("str1"));
  3080. _s.put("cd", is.getInt("cd"));
  3081. active.put(_s);
  3082. }
  3083. is.close();
  3084. _skills.add(lobby._skills.get(Integer.parseInt(skills[e])));
  3085. }
  3086. String x = "{\"icon\":\"icu1\",\"nam\":\"Potions\",\"anim\":\"Salute\",\"mp\":0,\"desc\":\"Equip a potion or scroll from your inventory to use it here.\",\"isOK\":true,\"range\":808,\"fx\":\"\",\"ref\":\"i1\",\"tgt\":\"f\",\"typ\":\"m\",\"strl\":\"\",\"cd\":5000}";
  3087. active.put(new JSONObject(x));
  3088. actions.put("active", active);
  3089. sAct.put("actions", actions);
  3090. sendData(sAct);
  3091. x = "{\"t\":\"xt\",\"b\":{\"r\":-1,\"o\":{\"tempSta\":{\"ba\":{\"STR\":9,\"INT\":9,\"DEX\":7,\"END\":8},\"Weapon\":{\"STR\":24,\"DEX\":7,\"END\":23},\"innate\":{\"STR\":61,\"INT\":11,\"DEX\":50,\"WIS\":23,\"LCK\":14,\"END\":68},\"ar\":{\"STR\":14,\"DEX\":4,\"END\":13},\"he\":{\"STR\":12,\"INT\":12,\"DEX\":9,\"END\":11}},\"cmd\":\"stu\",\"sta\":{\"$tdo\":0.115,\"$thi\":0.038500000000000006,\"_cmi\":1,\"$smb\":0,\"_tdo\":0.04,\"_cmo\":1,\"_sem\":0.05,\"$WIS\":23,\"$tha\":0.00000000000232,\"$tpa\":0.03,\"_cdi\":1,\"_sp\":0,\"$cpo\":1.1,\"_chi\":1,\"$cpi\":1,\"_cdo\":1,\"_tbl\":0,\"_tpa\":0.03,\"_cho\":1,\"$LCK\":14,\"$shb\":0,\"$STR\":120,\"$sem\":0.12000000000000001,\"_ap\":0,\"_sbm\":0.7,\"$cmi\":0.92,\"$cai\":0.9,\"$tbl\":0,\"_srm\":0.7,\"_cai\":1,\"$DEX\":77,\"_STR\":61,\"$ap\":240,\"$cao\":1,\"_DEX\":50,\"$sbm\":0.61,\"$cmc\":1,\"$INT\":32,\"_cpi\":1,\"$chi\":1,\"$cho\":1,\"_INT\":11,\"_scm\":1.5,\"_cao\":1,\"_END\":68,\"_WIS\":23,\"_shb\":0,\"_tre\":0.07,\"$cdo\":1,\"$tcr\":0.16999999999999998,\"$END\":123,\"$cdi\":1,\"_cpo\":1,\"$scm\":1.675,\"_tcr\":0.05,\"_tha\":0,\"_thi\":0,\"$srm\":0.7,\"$cmo\":1,\"$sp\":64,\"_LCK\":14,\"_cmc\":1,\"$tre\":0.07,\"_smb\":0},\"wDPS\":500}}}";
  3092. sendData(x);
  3093. }
  3094. rs.close();
  3095. } catch (Exception e) {
  3096. traceError("Error in load skills: " + e.getMessage());
  3097. }
  3098. }
  3099.  
  3100.  
  3101. private void userMove(int _tx, int _ty, int speed, boolean cansee) {
  3102. _tx = (_tx < 0) ? 0 : _tx;
  3103. _ty = (_ty > 1000) ? 1000 : _ty;
  3104. _tx = (_tx < 0) ? 0 : _tx;
  3105. _ty = (_ty > 800) ? 800 : _ty;
  3106. tx = _tx;
  3107. ty = _ty;
  3108. String data ="%xt%uotls%-1%" + username + "%sp:" + speed + ",tx:" + tx + ",ty:" + ty + ",strFrame:" + frame + "%";
  3109. lobby.sendDataToPlayerMap(username, data, cansee);
  3110. }
  3111.  
  3112. private void userChat(int rID, String msg, String typ) {
  3113. String data = "%xt%chatm%" + rID + "%" + typ + "~" + msg + "%" + username + "%" + uID + "%" + rID + "%";
  3114. if(typ.equals("party"))
  3115. lobby.sendDataToPlayerParty(username, data, false);
  3116. else {
  3117. if(lobby.isStaff(username)) {
  3118. //data = "%xt%chatm%" + rID + "%moderator~" + msg + "%" + username + "%" + uID + "%" + rID + "%";
  3119. lobby.sendDataToPlayerMap(username, data, false);
  3120. } else {
  3121. lobby.sendDataToPlayerMap(username, data, false);
  3122. }
  3123. }
  3124. traceChat(msg);
  3125. }
  3126.  
  3127. private void loadShop(int shopID) {
  3128. try {
  3129. if (lobby._shops.containsKey(shopID)) {
  3130. if(parseBoolean(lobby._shops.get(shopID).bStaff) && !lobby.isStaff(username)) {
  3131. sendData("%xt%warning%-1%\""+lobby._shops.get(shopID).sName+"\" is a X.G. staff only shop.%");
  3132. return;
  3133. } else if (parseBoolean(lobby._shops.get(shopID).bUpg) && !(upgrade > 0 && upgDays >= 0)) {
  3134. sendData("%xt%warning%-1%\""+lobby._shops.get(shopID).sName+"\" is a member shop.%");
  3135. return;
  3136. }
  3137. JSONObject _shop = new JSONObject();
  3138. _shop.put("cmd", "loadShop");
  3139. JSONObject _info = new JSONObject();
  3140. _info.put("sName", lobby._shops.get(shopID).sName);
  3141. _info.put("bitSuccess", "1");
  3142. JSONArray _items = new JSONArray();
  3143. String[] items = lobby._shops.get(shopID).shopItems.split(",");
  3144. for (int e = 0; e < items.length; e++) {
  3145. int c = Integer.parseInt(items[e]);
  3146. if(lobby._items.containsKey(c)) {
  3147. JSONObject temp = new JSONObject();
  3148. temp.put("ItemID", c);
  3149. temp.put("sLink", lobby._items.get(c).sLink);
  3150. temp.put("sElmt", lobby._items.get(c).sElmt);
  3151. temp.put("bStaff", lobby._items.get(c).bStaff);
  3152. temp.put("iRng", lobby._items.get(c).iRng);
  3153. temp.put("iDPS", lobby._items.get(c).iDPS);
  3154. temp.put("bCoins", lobby._items.get(c).bCoins);
  3155. temp.put("sES", lobby._items.get(c).sES);
  3156. temp.put("sType", lobby._items.get(c).sType);
  3157. temp.put("iCost", lobby._items.get(c).iCost);
  3158. temp.put("iRty", lobby._items.get(c).iRty);
  3159. // temp.put("ShopItemID", (shopID + e));
  3160. if (lobby._items.get(c).sES.equals("ar")) {
  3161. temp.put("iQty", 0);
  3162. } else {
  3163. temp.put("iQty", lobby._items.get(c).iQty);
  3164. }
  3165. if (lobby._items.get(c).sType.equals("Enhancement") || lobby._items.get(c).sType.equals("Necklace") || lobby._items.get(c).sType.equals("Item") || lobby._items.get(c).sType.equals("Quest Item") || lobby._items.get(c).sType.equals("Pet") || lobby._items.get(c).sType.equals("Armor")) {
  3166. temp.put("EnhID", ""+lobby._items.get(c).EnhID);
  3167. temp.put("PatternID", ""+lobby._items.get(c).EnhPatternID);
  3168. temp.put("iLvl", lobby._items.get(c).iLvl);
  3169. } else if (lobby._items.get(c).EnhID > 0) {
  3170. temp.put("iLvl", lobby._items.get(c).iLvl);
  3171. temp.put("EnhLvl", ""+lobby._items.get(c).iLvl);
  3172. temp.put("EnhID", ""+lobby._items.get(c).EnhID);
  3173. temp.put("EnhRty", ""+lobby._items.get(c).iRty);
  3174. temp.put("EnhPatternID", ""+lobby._items.get(c).EnhPatternID);
  3175. } else {
  3176. temp.put("EnhID", ""+lobby._items.get(c).EnhID);
  3177. }
  3178. temp.put("sIcon", lobby._items.get(c).sIcon);
  3179. if(lobby._shops.get(shopID).bLimited > 0)
  3180. temp.put("iQtyRemain", lobby._items.get(c).iQtyRemain);
  3181. temp.put("bTemp", lobby._items.get(c).bTemp);
  3182. temp.put("iHrs", lobby._items.get(c).iHrs);
  3183. temp.put("sFile", lobby._items.get(c).sFile);
  3184. temp.put("iStk", lobby._items.get(c).iStk);
  3185. temp.put("sDesc", lobby._items.get(c).sDesc);
  3186. temp.put("sFaction", lobby._items.get(c).sFaction);
  3187. temp.put("iReqRep", lobby._items.get(c).iReqRep);
  3188. temp.put("bHouse", 0);
  3189. temp.put("iReqCP", lobby._items.get(c).iReqCP);
  3190. temp.put("FactionID", lobby._items.get(c).FactionID);
  3191. temp.put("iClass", lobby._items.get(c).iClass);
  3192. temp.put("iQSValue", 0);
  3193. temp.put("iQSindex", -1);
  3194. temp.put("bUpg", ""+lobby._items.get(c).bUpg);
  3195. temp.put("bHouse", ""+lobby._items.get(c).bHouse);
  3196. temp.put("sName", lobby._items.get(c).sName);
  3197. _items.put(temp);
  3198. } else {
  3199. traceError("Error in loading shop item: ItemID: " + c + " does not exists!");
  3200. }
  3201. }
  3202. _info.put("items", _items);
  3203. _info.put("ShopID", shopID);
  3204. _info.put("sField", lobby._shops.get(shopID).sField);
  3205. _info.put("bStaff", lobby._shops.get(shopID).bStaff);
  3206. _info.put("bHouse", lobby._shops.get(shopID).bHouse);
  3207. _info.put("bLimited", lobby._shops.get(shopID).bLimited);
  3208. _info.put("iIndex", -1);
  3209. _shop.put("shopinfo", _info);
  3210. sendData(_shop);
  3211. } else {
  3212. sendData("%xt%warning%-1%Shop is currently unavailable or it does not exist yet!%");
  3213. }
  3214. } catch (Exception e) {
  3215. traceError("Error in loading shop: " + e.getMessage());
  3216. }
  3217. }
  3218.  
  3219. private void equipItem(int itemID, boolean init) {
  3220. try {
  3221. JSONObject _equip = new JSONObject();
  3222. _equip.put("uid", pID);
  3223. _equip.put("cmd", "equipItem");
  3224. _equip.put("ItemID", itemID);
  3225. _equip.put("strES", lobby._items.get(itemID).sES);
  3226. _equip.put("sFile", lobby._items.get(itemID).sFile);
  3227. _equip.put("sLink", lobby._items.get(itemID).sLink);
  3228. _equipment.put(lobby._items.get(itemID).sES, itemID);
  3229. if (lobby._items.get(itemID).sES.equals("Weapon")) {
  3230. _equip.put("sType", lobby._items.get(itemID).sType);
  3231. ResultSet gItems = _sql.query("SELECT iLvl FROM etl_users_items WHERE item_id=" + itemID + " AND sES='Weapon' AND user_id=" + uID);
  3232. if (gItems.next()) {
  3233. wepLvl = gItems.getInt("iLvl");
  3234. wepRng = lobby._items.get(itemID).iRng;
  3235. wepDPS = lobby._items.get(itemID).iDPS;
  3236. }
  3237. gItems.close();
  3238. }
  3239.  
  3240. if(!init) {
  3241. _sql.update("UPDATE etl_users_items SET bEquip=0 WHERE user_id=" + uID + " AND bEquip=1 AND sES='" + lobby._items.get(itemID).sES + "'");
  3242. _sql.update("UPDATE etl_users_items SET bEquip=1 WHERE user_id=" + uID + " AND item_id=" + itemID + " AND bEquip=0");
  3243. }
  3244.  
  3245. if (lobby._items.get(itemID).sES.equals("ar")) {
  3246. this.ClassID = lobby._items.get(itemID).ClassID;
  3247. className = lobby._items.get(itemID).sName;
  3248. trace("Class ID: " + ClassID);
  3249. if(!init) {
  3250. _sql.update("UPDATE etl_users SET currentClass=" + lobby._items.get(itemID).ClassID + " WHERE id=" + uID);
  3251. ResultSet cps = _sql.query("SELECT iCP FROM etl_users_items WHERE sES='ar' AND bEquip=1 AND user_id="+uID);
  3252. if (cps.next()) {
  3253. classPoints = cps.getInt("iCP");
  3254. cps.close();
  3255. }
  3256. }
  3257. updateClass();
  3258. loadSkills(this.ClassID);
  3259. }
  3260. if(init) {
  3261. sendData(_equip);
  3262. return;
  3263. } else {
  3264. lobby.sendDataToPlayerMap(username, _equip, false);
  3265. }
  3266. if (lobby._items.get(itemID).sES.equals("ho")) {
  3267. _sql.update("UPDATE etl_users SET sHouseInfo='' WHERE id="+uID);
  3268. reloadHouse();
  3269. }
  3270. } catch (Exception e) {
  3271. traceError("Error in equipping item: " + e.getMessage());
  3272. }
  3273. }
  3274.  
  3275. int getBonusDamage(int level) {
  3276. int maxBonus = 500;
  3277. float xValue = (level + 1) / (float)(lobby.maxLevel + 1);
  3278. return Math.round(xValue * maxBonus);
  3279. }
  3280.  
  3281. protected void playerAttack(String attack, int turn) {
  3282. try {
  3283. int monsterid[] = new int[15];
  3284. int monsterid2[] = new int[15];
  3285. int weaponDmg = 1;
  3286.  
  3287. weaponDmg = wepDPS * 2;//2 = weapon speed
  3288. int iRng = wepRng / 100;
  3289. weaponDmg = (int)(weaponDmg * _skills.get(0).damage);//1 = autoattack damage AA.damage
  3290. int weaponDmgMin = (int) Math.floor((weaponDmg + weaponDmg * iRng) / 2);
  3291. int weaponDmgMax = (int) Math.ceil(weaponDmg + weaponDmg * iRng);
  3292. //trace("/Min"+ weaponDmgMin +"/Max"+ weaponDmgMax +"/iRng"+ iRng +"/iDps"+ wepDPS+"/iLvl"+wepLvl);
  3293. int damage = weaponDmgMin + (int)(wepLvl * 3 - wepLvl / 1.5) + (100 + getBonusDamage(level));
  3294. int damage2 = weaponDmgMax + (int)(wepLvl * 3 - wepLvl / 1.5) + (100 + getBonusDamage(level));
  3295. trace("damage: " + damage + " damage2: " +damage2);
  3296. int crit[] = new int[15];
  3297. int dodge[] = new int[15];
  3298. int miss[] = new int[15];
  3299. int damage3[] = new int[15];
  3300. String type[] = new String[15];
  3301. String skill[] = new String[15];
  3302. String mToAttack[];
  3303. if (attack.indexOf(",") != -1) {
  3304. mToAttack = attack.split(",");
  3305. } else {
  3306. mToAttack = new String[1];
  3307. mToAttack[0] = attack;
  3308. }
  3309. String hit[] = new String[15];
  3310.  
  3311. int skillpos = 0;
  3312. boolean addState = false;
  3313.  
  3314. for (int i = 0; i < mToAttack.length; i++) {
  3315. String[] monsters = mToAttack[i].split(">");
  3316. skill[i] = monsters[0];
  3317. String[] tobehit = monsters[1].split(":");
  3318. monsterid[i] = Integer.parseInt(tobehit[1]);
  3319. monsterid2[i] = Integer.parseInt(tobehit[1]) - 1;
  3320. type[i] = tobehit[0];
  3321.  
  3322. crit[i] = _gen.nextInt(15);
  3323. dodge[i] = _gen.nextInt(10);
  3324. miss[i] = _gen.nextInt(15);
  3325. }
  3326.  
  3327. if (skill[0].equals("a1")) {
  3328. skillpos = 1;
  3329. } else if (skill[0].equals("a2")) {
  3330. skillpos = 2;
  3331. } else if (skill[0].equals("a3")) {
  3332. skillpos = 3;
  3333. } else if (skill[0].equals("a4")) {
  3334. skillpos = 4;
  3335. }
  3336.  
  3337. mp -= _skills.get(skillpos).mp;
  3338.  
  3339. for (int e = 0; e < mToAttack.length; e++) {
  3340. boolean acrit = false;
  3341. boolean pcrit = (_passives.get(0).iscrit || _passives.get(1).iscrit) ? true : false;
  3342. boolean nulled = false;
  3343.  
  3344. double adamage = 1;
  3345. //double sdamage = _skills.get(0).damage;
  3346. double pdamage = _passives.get(0).damage + _passives.get(1).damage;
  3347. /** Checks for Active Auras **/
  3348. for(int xd = 0; xd < 5; xd++) {
  3349. if(_skills.get(xd).auraID > 0) {
  3350. if(_auras.isAuraActive(_skills.get(xd).auraID)) {
  3351. acrit = (!acrit) ? _skills.get(xd).aura.iscrit : acrit;
  3352. adamage += _skills.get(xd).aura.damage;
  3353. nulled = (_skills.get(xd).aura.cat.equals("nl")) ? true : false;
  3354. }
  3355. }
  3356. }
  3357.  
  3358. damage3[e] = (int)(damage + _gen.nextInt(damage2 - damage));
  3359. damage3[e] = (int)(damage3[e] * adamage);
  3360. //damage3[e] = (int)(damage3[e] + (damage3[e] * sdamage));
  3361. damage3[e] = (int)(damage3[e] + (damage3[e] * pdamage));
  3362. trace("damage3: " + damage3[e] + " adamage: " + adamage + " pdamage: " + pdamage);
  3363. hit[e] = "hit";
  3364. damage3[e] = (damage3[e] < 0) ? 0 : damage3[e];
  3365.  
  3366. if ((crit[e] > 10 || _skills.get(skillpos).iscrit || acrit || pcrit) && damage3[e] > 0) {
  3367. hit[e] = "crit";
  3368. damage3[e] = (int)(damage3[e] + (damage3[e] * .02));
  3369. } else if (dodge[e] > 9) {
  3370. hit[e] = "dodge";
  3371. damage3[e] = 0;
  3372. } else if (miss[e] > 11) {
  3373. hit[e] = "miss";
  3374. damage3[e] = 0;
  3375. }
  3376.  
  3377. hit[e] = (damage3[e] <= 0 && hit[e].equals("crit")) ? "hit" : hit[e];
  3378.  
  3379. if (hp >= 1 && type[e].equals("m") && cRoom._monsters.get(monsterid2[e]).state > 0 && !skill[e].equals("i1")) {
  3380. if(cRoom._monsters.get(monsterid2[e]).checkUser(pID))
  3381. {
  3382. cRoom._monsters.get(monsterid2[e]).attack(pID);
  3383. cRoom.monsterActive(monsterid[e]);
  3384. state = 2;
  3385. }
  3386. cRoom._monsters.get(monsterid2[e]).hp -= damage3[e];
  3387. if (cRoom._monsters.get(monsterid2[e]).hp <= 0 && cRoom._monsters.get(monsterid2[e]).state >= 1 && type[e].equals("m")) {
  3388.  
  3389. /** Give Drops and Rewards **/
  3390.  
  3391. if(cParty != null) {
  3392. for(int i = 0; i < cParty._members.length; i++)
  3393. cRoom._monsters.get(monsterid2[e]).attack(Integer.parseInt(cParty._members[i]));
  3394. }
  3395.  
  3396. cRoom.giveRewards(monsterid2[e]);
  3397. cRoom.dropItems(monsterid2[e]);
  3398.  
  3399. /** Old Method
  3400. int[] it = cRoom._monsters.get(monsterid2[e]).getRandomDrop();
  3401. if (it[1] > isDropped) {
  3402. dropItem(it[0]);
  3403. }
  3404. **/
  3405.  
  3406. cRoom._monsters.get(monsterid2[e]).hp = 0;
  3407. cRoom._monsters.get(monsterid2[e]).mp = 0;
  3408. cRoom._monsters.get(monsterid2[e]).state = 0;
  3409. cRoom._monsters.get(monsterid2[e]).die();
  3410. cRoom.respawnMonster(monsterid2[e]);
  3411. cRoom.givePvPScore(username, "m", monsterid2[e]);
  3412. _sql.update("UPDATE etl_users SET monkill=monkill+1 WHERE id=" + uID);
  3413. addState = true;
  3414. state = 1;
  3415. }
  3416. } else if (type[e].equals("p") && hp >= 1 && !skill[e].equals("i1")) {
  3417. ConnectionHandler uho = lobby.getHandler(monsterid[e]);
  3418. if (uho.pID != pID && uho.state > 0) {
  3419. if (uho.hp >= uho.hpmax) {
  3420. addState = true;
  3421. }
  3422.  
  3423. double areduce = 0;
  3424. double preduce = uho._passives.get(0).reduction + uho._passives.get(1).reduction;
  3425.  
  3426.  
  3427. for(int xd = 0; xd < 5; xd++) {
  3428. if(uho._skills.get(xd).auraID > 0) {
  3429. if(uho._auras.isAuraActive(uho._skills.get(xd).auraID)) {
  3430. areduce = uho._skills.get(xd).aura.reduction;
  3431.  
  3432. }
  3433. }
  3434. }
  3435.  
  3436. if(!nulled) {
  3437. damage3[e] = (int) (damage3[e] - (damage3[e] * (areduce + preduce)));
  3438. }
  3439.  
  3440. state = 2;
  3441. uho.hp -= damage3[e];
  3442. trace("Player " + uho.username + " hp:" + uho.hp + " damage: " + damage3[e]);
  3443. if (uho.hp <= 0) {
  3444. uho.hp = 0;
  3445. uho.mp = 0;
  3446. uho.state = 0;
  3447. state = 1;
  3448. cRoom.givePvPScore(username, "p", uho.pID);
  3449. _sql.update("UPDATE etl_users SET pvpkill=pvpkill+1 WHERE strUsername='" + username + "'");
  3450. addState = true;
  3451. }
  3452. }
  3453. }
  3454. }
  3455.  
  3456. lobby.sendDataToPlayerMap(username, skillPacket(skillpos, addState, mToAttack, type, hit, damage3, monsterid, turn), false);
  3457. if(state == 1) {
  3458. autoRestTimer();
  3459. }
  3460. } catch (Exception e) {
  3461. traceError("Error in player attack: " + e.getMessage() + " cause: " + e.getCause());
  3462. }
  3463. }
  3464.  
  3465. protected JSONObject skillPacket(int i, boolean addState, String[] monsters, String[] type, String[] hit, int[] damage3, int[] monsterid, int turn) {
  3466. try {
  3467. JSONObject ct = new JSONObject();
  3468.  
  3469. /** Sometimes bugged, removed..
  3470. if(turn != curTurn) {
  3471. lobby.kickPlayer(username, "hacking (spamming attack packets).");
  3472. }
  3473.  
  3474. curTurn += 1;
  3475. if(curTurn == 31) {
  3476. curTurn = 0;
  3477. }
  3478.  
  3479. **/
  3480.  
  3481. /* Initialize the variables */
  3482. boolean addSarsa = true;
  3483. int monsterid2[] = new int[15];
  3484. boolean addMonsters = false;
  3485. for (int x = 0; x < monsters.length; x++) {
  3486. monsterid2[x] = monsterid[x] - 1;
  3487. }
  3488.  
  3489. ct.put("cmd", "ct");
  3490.  
  3491. JSONArray anims = new JSONArray();
  3492. JSONObject _anim = new JSONObject();
  3493. _anim.put("strFrame", frame);
  3494. _anim.put("cInf", "p:" + pID);
  3495. _anim.put("fx", _skills.get(i).fx);
  3496. _anim.put("animStr", _skills.get(i).anim);
  3497. /* Adds the player or monster ids to be healed or attack */
  3498. String _mon = "";
  3499. for (int z = 0; z < monsters.length; z++) {
  3500. if (z != 0) {
  3501. _mon += ",";
  3502. }
  3503. _mon += type[z] + ":" + monsterid[z];
  3504. }
  3505. _anim.put("tInf", _mon);
  3506. _anim.put("str1", _skills.get(i).str1);
  3507. anims.put(_anim);
  3508.  
  3509. /** Check if skill has an aura or not **/
  3510.  
  3511. if(_skills.get(i).auraID > 0) {
  3512. addSarsa = false;
  3513. JSONArray _a = new JSONArray();
  3514. String _x = "";
  3515. if(_skills.get(i).aura.type.equals("passive")) {
  3516. if(_auras.addAura(this, _skills.get(i).auraID, _skills.get(i).aura.seconds, monsterid, type, "p", monsters.length)){
  3517. for (int z = 0; z < monsters.length; z++) {
  3518. if(type[z].equals("p")){
  3519. if (z != 0) {
  3520. _x += ",";
  3521. }
  3522. _x += type[z] + ":" + monsterid[z];
  3523. }
  3524. }
  3525.  
  3526. JSONObject _ar = new JSONObject();
  3527. _ar.put("cat", _skills.get(i).aura.cat);
  3528. _ar.put("nam", _skills.get(i).aura.name);
  3529. _ar.put("t", "s");
  3530. _ar.put("s", "s");
  3531. _ar.put("dur", _skills.get(i).aura.seconds);
  3532. _ar.put("isNew", true);
  3533. _a.put(new JSONObject().put("cInf", "p:" + pID).put("cmd", "aura+").put("auras", new JSONArray().put(_ar)).put("tInf", _x));
  3534. }
  3535. } else {
  3536. if(_auras.addAura(this, _skills.get(i).auraID, _skills.get(i).aura.seconds, monsterid, type, "p", monsters.length)){
  3537. for (int z = 0; z < monsters.length; z++) {
  3538. if(type[z].equals("m")){
  3539. if (z != 0) {
  3540. _x += ",";
  3541. }
  3542. _x += type[z] + ":" + monsterid[z];
  3543. }
  3544. }
  3545.  
  3546. JSONObject _ar = new JSONObject();
  3547. _ar.put("cat", _skills.get(i).aura.cat);
  3548. _ar.put("nam", _skills.get(i).aura.name);
  3549. _ar.put("t", "s");
  3550. _ar.put("s", "s");
  3551. _ar.put("dur", _skills.get(i).aura.seconds);
  3552. _ar.put("isNew", true);
  3553. _a.put(new JSONObject().put("cInf", "p:" + pID).put("cmd", "aura+").put("auras", new JSONArray().put(_ar)).put("tInf", _x));
  3554.  
  3555. addSarsa = true;
  3556. }
  3557. }
  3558.  
  3559. ct.put("a", _a);
  3560. }
  3561.  
  3562.  
  3563. ct.put("anims", anims);
  3564.  
  3565. if(addSarsa){
  3566. JSONArray sarsa = new JSONArray();
  3567. JSONObject _sar = new JSONObject();
  3568. _sar.put("cInf", "p:"+pID);
  3569.  
  3570. JSONArray a = new JSONArray();
  3571. /* Shows the damage for each monster or player ids */
  3572. for (int l = 0; l < monsters.length; l++) {
  3573. JSONObject _a = new JSONObject();
  3574. if (type[l].equals("m")) {
  3575. /* Monster type is found set to true to add monster uotls */
  3576. addMonsters = true;
  3577. }
  3578. _a.put("hp", damage3[l]);
  3579. _a.put("tInf", type[l] + ":" + monsterid[l]);
  3580. _a.put("type", hit[l]);
  3581. a.put(_a);
  3582. }
  3583. _sar.put("a", a);
  3584. _sar.put("actID", turn);
  3585. _sar.put("iRes", 1);
  3586. sarsa.put(_sar);
  3587. ct.put("sarsa", sarsa);
  3588. } else {
  3589. JSONArray sarsa = new JSONArray();
  3590. JSONArray a = new JSONArray().put(new JSONObject().put("hp", 0).put("tInf", "p:" + pID).put("type", "none"));
  3591. sarsa.put(new JSONObject().put("cInf", "p:" + pID).put("a", a).put("actID", turn).put("iRes", 1));
  3592. ct.put("sarsa", sarsa);
  3593. }
  3594.  
  3595. /* Refreshes all the player ids to their real current hp or level and etc... */
  3596. JSONObject p = new JSONObject();
  3597. JSONObject _self = new JSONObject();
  3598. _self.put("intMP", mp);
  3599. if (addState) {
  3600. _self.put("intState", state);
  3601. }
  3602. p.put(username, _self);
  3603. for (int b = 0; b < monsters.length; b++) {
  3604. if (type[b].equals("p") && monsterid[b]!=pID) {
  3605. JSONObject _inf = new JSONObject();
  3606. ConnectionHandler uho = lobby.getHandler(monsterid[b]);
  3607. trace("Player " + uho.username + " hp:" + uho.hp);
  3608. _inf.put("intHP", uho.hp);
  3609. if (uho.hp <= 0) {
  3610. /* Player died, set its state to dead */
  3611. _inf.put("intState", 0);
  3612. uho.state = 0;
  3613. } else if (addState && uho.state == 1) {
  3614. /* Player is fighting, set its state to fighting */
  3615. _inf.put("intState", 2);
  3616. uho.state = 2;
  3617. }
  3618. p.put(uho.username, _inf);
  3619. }
  3620. }
  3621. ct.put("p", p);
  3622.  
  3623. /* Refreshes all the monster ids to their real current hp or level and etc... */
  3624. if (addMonsters) {
  3625. JSONObject m = new JSONObject();
  3626. for (int b = 0; b < monsters.length; b++) {
  3627. if (type[b].equals("m")) {
  3628. JSONObject _minf = new JSONObject();
  3629. if (cRoom._monsters.get(monsterid2[b]).hp <= 0) {
  3630. _minf.put("intHP", 0);
  3631. } else {
  3632. _minf.put("intHP", cRoom._monsters.get(monsterid2[b]).hp);
  3633. }
  3634. if (cRoom._monsters.get(monsterid2[b]).hp <= 0 || cRoom._monsters.get(monsterid2[b]).state == 0) {
  3635. cRoom._monsters.get(monsterid2[b]).state = 0;
  3636. /* Monster died, set its state to dead */
  3637. _minf.put("intState", 0);
  3638. }
  3639. m.put(""+monsterid[b], _minf);
  3640. }
  3641. }
  3642. ct.put("m", m);
  3643. }
  3644. return ct;
  3645. /* Skill Packet for v1.4 by Zeroskull (JSON Modified) */
  3646. } catch (Exception e) {
  3647. traceError("Error in formulating skill JSON: " + e.getMessage());
  3648. }
  3649. return new JSONObject();
  3650. }
  3651.  
  3652. private void autoRest() {
  3653. if(state == 1 && !(hp >= hpmax && mp >= mpmax)){
  3654. int rand = _gen.nextInt(50);
  3655. while(rand < 35){
  3656. rand = _gen.nextInt(50);
  3657. }
  3658. hp += hpmax / rand;
  3659. hp = (hp > hpmax) ? hpmax : hp;
  3660. mp += mpmax / rand;
  3661. mp = (mp > mpmax) ? mpmax : mp;
  3662. try {
  3663. JSONObject _i = new JSONObject();
  3664.  
  3665. _i.put("intMP", mp);
  3666. _i.put("intHP", hp);
  3667.  
  3668. JSONObject ct = new JSONObject().put("cmd", "ct").put("p", new JSONObject().put(username, _i));
  3669. sendData(ct);
  3670. autoRestTimer();
  3671. } catch (JSONException e) {
  3672. }
  3673. }
  3674. }
  3675.  
  3676. private void restPlayer() {
  3677. if(state == 1 && !(hp >= hpmax && mp >= mpmax)){
  3678. hp += hpmax / 20;
  3679. hp = (hp > hpmax) ? hpmax : hp;
  3680. mp += mpmax / 20;
  3681. mp = (mp > mpmax) ? mpmax : mp;
  3682. sendUotls(true, false, true, false, false, false);
  3683. }
  3684. }
  3685.  
  3686. private void autoRestTimer(){
  3687. Timer timer = new Timer();
  3688. timer.schedule(new TimerTask() {
  3689. @Override
  3690. public void run() {
  3691. if(state == 1 && (hp < hpmax || mp < mpmax)){
  3692. autoRest();
  3693. }
  3694. }
  3695. }, 2500);
  3696. }
  3697.  
  3698. private void sendUotls(boolean addhp, boolean addhpmax, boolean addmp, boolean addmpmax, boolean addlevel, boolean addstate) {
  3699. try {
  3700. JSONObject uotls = new JSONObject();
  3701. uotls.put("cmd", "uotls");
  3702. JSONObject o = new JSONObject();
  3703. if(addhp)
  3704. o.put("intHP", hp);
  3705. if(addhpmax)
  3706. o.put("intHPMax", hpmax);
  3707. if(addmp)
  3708. o.put("intMP", mp);
  3709. if(addmpmax)
  3710. o.put("intMPMax", mpmax);
  3711. if(addlevel)
  3712. o.put("intLevel", level);
  3713. if(addstate)
  3714. o.put("intState", state);
  3715. uotls.put("o", o);
  3716. uotls.put("unm", username);
  3717. lobby.sendDataToPlayerMap(username, uotls, false);
  3718. } catch (JSONException e) {
  3719.  
  3720. }
  3721. }
  3722.  
  3723. private void buyItem(int itemid, int shopid) {
  3724. try {
  3725. JSONObject buy = new JSONObject();
  3726. buy.put("cmd", "buyItem");
  3727. ResultSet ch = _sql.query("SELECT id FROM etl_users_items WHERE sES='"+lobby._items.get(itemid).sES+"' AND item_id="+itemid+" AND user_id="+uID);
  3728. if (ch.next()) {
  3729. if(!(lobby._items.get(itemid).iStk > 1) && !(lobby._items.get(itemid).sType.equals("Enhancement"))) {
  3730. buy.put("bitSuccess", 0);
  3731. buy.put("strMessage", "Item already exist!");
  3732. buy.put("CharItemID", -1);
  3733. sendData(buy);
  3734. return;
  3735. }
  3736. }
  3737. if (lobby._items.containsKey(itemid)) {
  3738. if (lobby._items.get(itemid).bUpg > upgrade) {
  3739. buy.put("bitSuccess", 0);
  3740. buy.put("strMessage", "This item is member only!");
  3741. buy.put("CharItemID", -1);
  3742. sendData(buy);
  3743. } else if (lobby._items.get(itemid).isFounder > isFounder) {
  3744. buy.put("bitSuccess", 0);
  3745. buy.put("strMessage", "This item is founder only!");
  3746. buy.put("CharItemID", -1);
  3747. sendData(buy);
  3748. } else if (lobby._items.get(itemid).isSpeciall > 0) {
  3749. buy.put("bitSuccess", 0);
  3750. buy.put("strMessage", "This is a special item, you can't buy it!");
  3751. buy.put("CharItemID", -1);
  3752. sendData(buy);
  3753. } else if(lobby._shops.get(shopid).bLimited > 0 && lobby._items.get(itemid).iQtyRemain <= 0) {
  3754. buy.put("bitSuccess", 0);
  3755. buy.put("strMessage", "Item already sold out!");
  3756. buy.put("CharItemID", -1);
  3757. sendData(buy);
  3758. } else if (lobby._items.get(itemid).iLvl > level) {
  3759. buy.put("bitSuccess", 0);
  3760. buy.put("strMessage", "Level requirement not met!");
  3761. buy.put("CharItemID", -1);
  3762. sendData(buy);
  3763. } else {
  3764. int iGold = 0;
  3765. int iCoins = 0;
  3766. ResultSet is = _sql.query("SELECT iGold,iCoins FROM etl_users WHERE id="+uID);
  3767. if (is.next()) {
  3768. iGold = is.getInt("iGold");
  3769. iCoins = is.getInt("iCoins");
  3770. }
  3771. is.close();
  3772. if ((iGold - lobby._items.get(itemid).iCost) >= 0 || (lobby._items.get(itemid).bCoins == 1 && (iCoins - lobby._items.get(itemid).iCost) >= 0)) {
  3773. if (lobby._items.get(itemid).sES.equals("ar") && !lobby._items.get(itemid).sType.equals("Enhancement")) {
  3774. _sql.update("INSERT INTO etl_users_items (item_id, user_id, sES, iCP , iLvl, enh_id) VALUES (" + itemid + ", " + uID + ", 'ar', '0', '" + lobby._items.get(itemid).iLvl + "','" + lobby._items.get(itemid).EnhPatternID + "')");
  3775. } else if (lobby._items.get(itemid).sType.equals("Item") || lobby._items.get(itemid).sType.equals("Quest Item")) {
  3776. ResultSet es = _sql.query("SELECT id FROM etl_users_items WHERE item_id="+itemid+" AND user_id="+uID);
  3777. if (es.next()) {
  3778. _sql.update("UPDATE etl_users_items SET iQty=iQty+" + lobby._items.get(itemid).iQty + " WHERE item_id=" + itemid + " AND user_id=" + uID);
  3779. } else {
  3780. _sql.update("INSERT INTO etl_users_items (iQty ,item_id, user_id, sES, iLvl, enh_id) VALUES (" + lobby._items.get(itemid).iQty + ", " + itemid + ", " + uID + ", '" + lobby._items.get(itemid).sES + "', '" + lobby._items.get(itemid).iLvl + "', '" + lobby._items.get(itemid).EnhPatternID + "')");
  3781. }
  3782. es.close();
  3783. } else {
  3784. _sql.update("INSERT INTO etl_users_items (item_id, user_id, sES, iLvl, enh_id) VALUES (" + itemid + ", " + uID + ", '" + lobby._items.get(itemid).sES + "', '" + lobby._items.get(itemid).iLvl + "', '" + lobby._items.get(itemid).EnhPatternID + "')");
  3785. }
  3786. if (lobby._items.get(itemid).bCoins != 1) {
  3787. if((iGold - lobby._items.get(itemid).iCost) >= 0) {
  3788. _sql.update("UPDATE etl_users SET iGold=" + (iGold - lobby._items.get(itemid).iCost) + " WHERE id=" + uID);
  3789. if(lobby._shops.get(shopid).bLimited > 0) {
  3790. if((lobby._items.get(itemid).iQtyRemain - lobby._items.get(itemid).iQty) >= 0) {
  3791. lobby._items.get(itemid).iQtyRemain -= lobby._items.get(itemid).iQty;
  3792. _sql.update("UPDATE etl_items SET iQtyRemain=" + lobby._items.get(itemid).iQtyRemain + " WHERE item_id=" + itemid);
  3793. } else {
  3794. lobby.kickPlayer(username, "for hacking/and or using trainers. (limited shops exploit)");
  3795. }
  3796. }
  3797. } else
  3798. lobby.kickPlayer(username, "for hacking/and or using trainers. (gold exploit)");
  3799. } else {
  3800. if((iCoins - lobby._items.get(itemid).iCost) >= 0)
  3801. _sql.update("UPDATE etl_users SET iCoins=iCoins-" + lobby._items.get(itemid).iCost + " WHERE id=" + uID);
  3802. else
  3803. lobby.kickPlayer(username, "for hacking/and or using trainers. (ac coins exploit)");
  3804. }
  3805. ResultSet rs = _sql.query("SELECT id FROM etl_users_items WHERE sES='"+lobby._items.get(itemid).sES+"' AND item_id="+itemid+" AND user_id="+uID);
  3806. if (rs.next()) {
  3807. buy.put("bitSuccess", 1);
  3808. if(lobby._items.get(itemid).bHouse <= 0)
  3809. buy.put("iQty", ""+lobby._items.get(itemid).iQty);
  3810. buy.put("CharItemID", rs.getInt("id"));
  3811. sendData(buy);
  3812. }
  3813. rs.close();
  3814.  
  3815. if(lobby._items.get(itemid).sES.equals("ho")) {
  3816. if(!doUserHaveHouse(username)) {
  3817. _sql.update("UPDATE etl_users_items SET bEquip=1 WHERE sES='ho' AND item_id="+ itemid +" AND user_id=" + uID);
  3818. }
  3819. }
  3820. } else {
  3821. buy.put("bitSuccess", 0);
  3822. buy.put("strMessage", "Not Enough Gold!");
  3823. buy.put("CharItemID", -1);
  3824. sendData(buy);
  3825. }
  3826. }
  3827. } else {
  3828. buy.put("bitSuccess", 0);
  3829. buy.put("strMessage", "Item Does Not Exist");
  3830. buy.put("CharItemID", -1);
  3831. sendData(buy);
  3832. }
  3833. } catch (Exception e) {
  3834. traceError("Error in buying item: " + e.getMessage());
  3835. }
  3836. }
  3837.  
  3838. private void loadHairShop(int shopID) {
  3839. try {
  3840. JSONObject _hs = new JSONObject();
  3841. _hs.put("HairShopID", shopID);
  3842. _hs.put("cmd", "loadHairShop");
  3843. JSONArray _hair = new JSONArray();
  3844. ResultSet rs = _sql.query("SELECT hairsM,hairsF FROM etl_hairshop WHERE id="+shopID);
  3845. if (rs.next()) {
  3846. String[] items = rs.getString("hairs" + gender).split(",");
  3847. int i = items.length;
  3848. int e = 0;
  3849. rs.close();
  3850. while (e < i) {
  3851. ResultSet is = _sql.query("SELECT * FROM etl_hairs WHERE hairID="+Integer.parseInt(items[e]));
  3852. if (is.next()) {
  3853. JSONObject _h = new JSONObject();
  3854. _h.put("sFile", is.getString("sFile"));
  3855. _h.put("HairID", is.getInt("hairID"));
  3856. _h.put("sName", is.getString("sName"));
  3857. _h.put("sGen", is.getString("sGen"));
  3858. _hair.put(_h);
  3859. }
  3860. is.close();
  3861. e++;
  3862. }
  3863. }
  3864. _hs.put("hair", _hair);
  3865. sendData(_hs);
  3866. } catch (Exception e) {
  3867. traceError("Error in loading hair shop: " + e.getMessage());
  3868. }
  3869. }
  3870.  
  3871. private void changeColor(int skincolor, int haircolor, int eyecolor, int hairid) {
  3872. _sql.update("UPDATE etl_users SET intColorSkin=" + skincolor + ",intColorHair=" + haircolor + ",intColorEye=" + eyecolor + " WHERE id=" + uID);
  3873. try {
  3874. JSONObject cc = new JSONObject();
  3875. ResultSet rs = _sql.query("SELECT sName,sFile FROM etl_hairs WHERE hairID="+hairid);
  3876. cc.put("uid", pID);
  3877. cc.put("cmd", "changeColor");
  3878. if (rs.next()) {
  3879. String name = rs.getString("sName");
  3880. String file = rs.getString("sFile");
  3881. rs.close();
  3882. cc.put("HairID", hairid);
  3883. cc.put("strHairName", name);
  3884. cc.put("strHairFilename", file);
  3885. _sql.update("UPDATE etl_users SET HairID=" + hairid + ",strHairName='" + name + "',strHairFilename='" + file + "' WHERE id=" + uID);
  3886. }
  3887. rs.close();
  3888. cc.put("intColorSkin", skincolor);
  3889. cc.put("intColorHair", haircolor);
  3890. cc.put("intColorEye", eyecolor);
  3891. lobby.sendDataToPlayerMap(username, cc, false);
  3892. } catch (Exception e) {
  3893. traceError("Error in changing hair style and colors: " + e.getMessage());
  3894. }
  3895. }
  3896.  
  3897. private void changeArmorColor(int base, int trim, int accessory) {
  3898. _sql.update("UPDATE etl_users SET intColorBase=" + base + ", intColorAccessory=" + accessory + ", intColorTrim=" + trim + " WHERE id=" + uID);
  3899. try {
  3900. JSONObject cac = new JSONObject();
  3901. cac.put("uid", pID);
  3902. cac.put("cmd", "changeArmorColor");
  3903. cac.put("intColorBase", base);
  3904. cac.put("intColorTrim", trim);
  3905. cac.put("intColorAccessory", accessory);
  3906. lobby.sendDataToPlayerMap(username, cac, false);
  3907. } catch (JSONException e) {
  3908. }
  3909. }
  3910.  
  3911. private boolean turnInItem(int[] itemid, int qty[]) {
  3912. boolean doContinue = false;
  3913. int itemsfound = 0;
  3914. int total = 0;
  3915. try {
  3916. for (int i = 0; i < itemid.length; i++) {
  3917. trace("Total Quantity: " + _tempItems.get(itemid[i]) + " Needed Quantity: " + qty[i]);
  3918. ResultSet rs = _sql.query("SELECT iQty FROM etl_users_items WHERE item_id="+itemid[i]+" AND iQty>="+qty[i]+" AND user_id="+uID);
  3919. if (rs.next()) {
  3920. int iQty = rs.getInt("iQty");
  3921. int ccqty = iQty - qty[i];
  3922. rs.close();
  3923. if (ccqty <= 0) {
  3924. _sql.update("DELETE FROM etl_users_items WHERE item_id=" + itemid[i] + " AND user_id=" + uID);
  3925. } else {
  3926. _sql.update("UPDATE etl_users_items SET iQty=" + ccqty + " WHERE item_id=" + itemid[i] + " AND user_id=" + uID);
  3927. }
  3928.  
  3929. itemsfound += iQty;
  3930. total += qty[i];
  3931. } else if (_tempItems.get(itemid[i]) >= qty[i]) {
  3932. itemsfound += _tempItems.get(itemid[i]);
  3933. total += qty[i];
  3934. } else {
  3935. return false;
  3936. }
  3937. }
  3938.  
  3939. trace("Items Valid: " + itemsfound + " Total: " + total);
  3940. if (itemsfound >= total) {
  3941. doContinue = true;
  3942. }
  3943.  
  3944. if (doContinue) {
  3945. JSONObject _ti = new JSONObject();
  3946. _ti.put("cmd", "turnIn");
  3947. String _items = "";
  3948. for (int a = 0; a < itemid.length; a++) {
  3949. if (a != 0) {
  3950. _items += ",";
  3951. }
  3952. _items += itemid[a] + ":" + qty[a];
  3953.  
  3954. if(_tempItems.containsKey(itemid[a])) {
  3955. int what = _tempItems.get(itemid[a]);
  3956. _tempItems.put(itemid[a], (what -= qty[a]));
  3957. }
  3958. }
  3959. _ti.put("sItems", _items);
  3960.  
  3961. sendData(_ti);
  3962. return true;
  3963. }
  3964. } catch (Exception e) {
  3965. traceError("Error in turning in item:" + e.getMessage());
  3966. }
  3967. return false;
  3968. }
  3969.  
  3970. private void ping() {
  3971. final String msg = lobby.getRandomNotice();
  3972. Timer timer = new Timer();
  3973. timer.schedule(new TimerTask() {
  3974. @Override
  3975. public void run() {
  3976. sendData("%xt%hi%-1%");
  3977. sendData("{\"t\":\"xt\",\"b\":{\"r\":-1,\"o\":{\"cmd\":\"umsg\",\"s\":\""+msg+"\"}}}");
  3978. pkSend = 0;
  3979. ping();
  3980. }
  3981. }, 30000);
  3982. }
  3983.  
  3984. private void enhanceItem(int itemid, int enhanceid, boolean islocal) {
  3985. try {
  3986. JSONObject _enh = new JSONObject();
  3987. int iCost = lobby._items.get(enhanceid).iCost;
  3988. int EnhLvl = lobby._items.get(enhanceid).iLvl;
  3989. int EnhPID = lobby._items.get(enhanceid).EnhPatternID;
  3990. _enh.put("ItemID", itemid);
  3991. _enh.put("EnhID", enhanceid);
  3992. _enh.put("EnhLvl", EnhLvl);
  3993. _enh.put("EnhDPS", lobby._items.get(enhanceid).iDPS);
  3994. _enh.put("EnhRty", lobby._items.get(enhanceid).iRty);
  3995. _enh.put("EnhRng", lobby._items.get(enhanceid).iRng);
  3996. _enh.put("EnhName", lobby._items.get(enhanceid).sName);
  3997. _enh.put("EnhPID", EnhPID);
  3998. _enh.put("iCost", iCost);
  3999. _enh.put("bSuccess", 1);
  4000. if (!islocal) {
  4001. _enh.put("cmd", "enhanceItemShop");
  4002. _sql.update("UPDATE etl_users SET iGold=iGold-" + iCost + " WHERE id=" + uID);
  4003. sendData(_enh);
  4004. } else {
  4005. _enh.put("cmd", "enhanceItemLocal");
  4006. ResultSet rs = _sql.query("SELECT id FROM etl_users_items WHERE item_id="+enhanceid+" AND user_id=" + uID);
  4007. if (rs.next()) {
  4008. rs.close();
  4009. int eid[] = {enhanceid};
  4010. int qty[] = {1};
  4011. _tempItems.put(enhanceid, lobby._items.get(enhanceid).iQty);
  4012. turnInItem(eid, qty);
  4013. sendData(_enh);
  4014. }
  4015. }
  4016.  
  4017. if(lobby._items.get(itemid).sES.equals("Weapon")) {
  4018. wepLvl = lobby._items.get(enhanceid).iLvl;
  4019. }
  4020. _sql.update("UPDATE etl_users_items SET iLvl=" + EnhLvl + ",Enh_ID=" + EnhPID + " WHERE user_id=" + uID + " AND item_id=" + itemid);
  4021.  
  4022.  
  4023. } catch (Exception e) {
  4024. traceError("Error in enhance item: " + e.getMessage() + ", itemid: " + itemid + ", enhanceid: " + enhanceid);
  4025. }
  4026. }
  4027.  
  4028. }
Add Comment
Please, Sign In to add comment