Guest User

Untitled

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