Guest User

Untitled

a guest
Mar 12th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 97.29 KB | None | 0 0
  1. package server.dao.database;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8. import java.util.ArrayList;
  9. import java.util.Date;
  10. import java.util.HashMap;
  11. import java.util.HashSet;
  12. import java.util.logging.Level;
  13. import org.apache.mina.common.IoSession;
  14. import server.BanReason;
  15. import server.Config;
  16. import server.XLogger;
  17. import server.ecoscanner.PlayerWealth;
  18. import server.model.items.ItemList;
  19. import server.model.players.Player;
  20. import server.model.players.PlayerHandler;
  21. import server.model.players.PlayerRights;
  22. import server.util.MyHashSet;
  23. import server.world.Clan;
  24. import server.world.GrandExchangeOffer;
  25. import server.world.Lottery;
  26. import server.world.ShopHandler;
  27.  
  28. public final class Database {
  29.  
  30. private Database() {}
  31.  
  32. private static final ConnectionPoolManager cpm;
  33. private static final HashMap<String, PlayerWrapper> savingPlayers = new HashMap<String, PlayerWrapper>();
  34.  
  35. static {
  36. cpm = new ConnectionPoolManager("jdbc:mysql://pkhdatabase/pkhonor",
  37. "pkhonor", "pkhonorsqlp4ss");
  38. }
  39.  
  40. public static void addSavePlayer(String name, PlayerWrapper pw)
  41. {
  42. savingPlayers.put(name, pw);
  43. }
  44.  
  45. public static void removeSavePlayer(String name)
  46. {
  47. savingPlayers.remove(name);
  48. }
  49.  
  50. public static void logCommand(long millis, int playerid, String command, String arguments) {
  51. Connection conn = cpm.getConnectionFromPool();
  52. PreparedStatement ps = null;
  53. try {
  54. ps = conn.prepareStatement("INSERT INTO log_commands (timestamp, playerid, command, arguments) VALUES (?,?,?,?)");
  55. ps.setString(1, millisToTimestamp(millis));
  56. ps.setInt(2, playerid);
  57. ps.setString(3, command);
  58. ps.setString(4, arguments);
  59. ps.executeUpdate();
  60. } catch (SQLException ex) {
  61. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  62. } finally {
  63. try {
  64. if (ps != null) {
  65. ps.close();
  66. conn.commit();
  67. }
  68. } catch (Exception e) {
  69. } finally {
  70. cpm.returnConnectionToPool(conn);
  71. }
  72. }
  73. }
  74.  
  75. public static void logConnection(long millis, int playerid, String ip) {
  76. Connection conn = cpm.getConnectionFromPool();
  77. PreparedStatement ps = null;
  78. try {
  79. ps = conn.prepareStatement("INSERT INTO log_connections (timestamp, playerid, ip) VALUES (?,?,INET_ATON(?))");
  80. ps.setString(1, millisToTimestamp(millis));
  81. ps.setInt(2, playerid);
  82. ps.setString(3, ip);
  83. ps.executeUpdate();
  84. } catch (SQLException ex) {
  85. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  86. } finally {
  87. try {
  88. if (ps != null) {
  89. ps.close();
  90. conn.commit();
  91. }
  92. } catch (Exception e) {
  93. } finally {
  94. cpm.returnConnectionToPool(conn);
  95. }
  96. }
  97. }
  98.  
  99. public static void logDrop(long droptime, int dropplayerid, long pickuptime, int pickupplayerid, int itemid, int amount) {
  100. Connection conn = cpm.getConnectionFromPool();
  101. PreparedStatement ps = null;
  102. try {
  103. ps = conn.prepareStatement("INSERT INTO log_drops (droptime, from_playerid, pickuptime, to_playerid, itemid, amount) VALUES (?,?,?,?,?,?)");
  104. ps.setString(1, millisToTimestamp(droptime));
  105. ps.setInt(2, dropplayerid);
  106. ps.setString(3, millisToTimestamp(pickuptime));
  107. ps.setInt(4, pickupplayerid);
  108. ps.setInt(5, itemid);
  109. ps.setInt(6, amount);
  110. ps.executeUpdate();
  111. } catch (SQLException ex) {
  112. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  113. } finally {
  114. try {
  115. if (ps != null) {
  116. ps.close();
  117. conn.commit();
  118. }
  119. } catch (Exception e) {
  120. } finally {
  121. cpm.returnConnectionToPool(conn);
  122. }
  123. }
  124. }
  125.  
  126. public static void logTrade(long millis, int from_playerid, int to_playerid, int itemid[], int amount[]) {
  127. if(itemid.length != amount.length || itemid.length < 1)
  128. return;
  129. Connection conn = cpm.getConnectionFromPool();
  130. PreparedStatement ps = null;
  131. try {
  132. ps = conn.prepareStatement("INSERT INTO log_trades (timestamp, from_playerid, to_playerid, itemid, amount) VALUES (?,?,?,?,?)");
  133. ps.setString(1, millisToTimestamp(millis));
  134. ps.setInt(2, from_playerid);
  135. ps.setInt(3, to_playerid);
  136. for (int i = 0; i < itemid.length; i++) {
  137. if(itemid[i] > 0)
  138. {
  139. ps.setInt(4, itemid[i]);
  140. ps.setInt(5, amount[i]);
  141. ps.addBatch();
  142. }
  143. }
  144. ps.executeBatch();
  145. } catch (SQLException ex) {
  146. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  147. } finally {
  148. try {
  149. if (ps != null) {
  150. ps.close();
  151. conn.commit();
  152. }
  153. } catch (Exception e) {
  154. } finally {
  155. cpm.returnConnectionToPool(conn);
  156. }
  157. }
  158. }
  159.  
  160. public static void logStake(long millis, int from_playerid, int to_playerid, int[] itemid, int[] amount) {
  161. if(itemid.length != amount.length || itemid.length < 1)
  162. return;
  163. Connection conn = cpm.getConnectionFromPool();
  164. PreparedStatement ps = null;
  165. try {
  166. ps = conn.prepareStatement("INSERT INTO log_stakes_unfinished (timestamp, from_playerid, to_playerid, itemid, amount) VALUES (?,?,?,?,?)");
  167. ps.setString(1, millisToTimestamp(millis));
  168. ps.setInt(2, from_playerid);
  169. ps.setInt(3, to_playerid);
  170. for (int i = 0; i < itemid.length; i++) {
  171. if(itemid[i] > 0)
  172. {
  173. ps.setInt(4, itemid[i]);
  174. ps.setInt(5, amount[i]);
  175. ps.addBatch();
  176. }
  177. }
  178. ps.executeBatch();
  179. } catch (SQLException ex) {
  180. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  181. } finally {
  182. try {
  183. if (ps != null) {
  184. ps.close();
  185. conn.commit();
  186. }
  187. } catch (Exception e) {
  188. } finally {
  189. cpm.returnConnectionToPool(conn);
  190. }
  191. }
  192. }
  193.  
  194. public static void logStakeDone(long stakeid, int winnerid) {
  195. Connection conn = cpm.getConnectionFromPool();
  196. Statement s = null;
  197. try {
  198. s = conn.createStatement();
  199. s.executeUpdate("INSERT INTO log_stakes (timestamp, from_playerid, to_playerid, itemid, amount, winnerid) SELECT timestamp, from_playerid, to_playerid, itemid, amount, "+winnerid+" AS winnerid FROM log_stakes_unfinished WHERE timestamp="+millisToTimestamp(stakeid));
  200. s.executeUpdate("DELETE FROM log_stakes_unfinished WHERE timestamp="+millisToTimestamp(stakeid));
  201. } catch (SQLException ex) {
  202. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  203. } finally {
  204. try {
  205. if (s != null) {
  206. s.close();
  207. conn.commit();
  208. }
  209. } catch (Exception e) {
  210. } finally {
  211. cpm.returnConnectionToPool(conn);
  212. }
  213. }
  214. }
  215.  
  216. public static void logMBox(long millis, int playerid, int itemid, int amount) {
  217. Connection conn = cpm.getConnectionFromPool();
  218. PreparedStatement ps = null;
  219. try {
  220. ps = conn.prepareStatement("INSERT INTO log_mboxes (timestamp, playerid, itemid, amount) VALUES (?,?,?,?)");
  221. ps.setString(1, millisToTimestamp(millis));
  222. ps.setInt(2, playerid);
  223. ps.setInt(3, itemid);
  224. ps.setInt(4, amount);
  225. ps.executeUpdate();
  226. } catch (SQLException ex) {
  227. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  228. } finally {
  229. try {
  230. if (ps != null) {
  231. ps.close();
  232. conn.commit();
  233. }
  234. } catch (Exception e) {
  235. } finally {
  236. cpm.returnConnectionToPool(conn);
  237. }
  238. }
  239. }
  240.  
  241. public static void logExchange(long millis, int from_playerid, int to_playerid, int itemid, long amount) {
  242. Connection conn = cpm.getConnectionFromPool();
  243. PreparedStatement ps = null;
  244. try {
  245. ps = conn.prepareStatement("INSERT INTO log_grand_exchange (timestamp, from_playerid, to_playerid, itemid, amount) VALUES (?,?,?,?,?)");
  246. ps.setString(1, millisToTimestamp(millis));
  247. ps.setInt(2, from_playerid);
  248. ps.setInt(3, to_playerid);
  249. ps.setInt(4, itemid);
  250. ps.setLong(5, amount);
  251. ps.executeUpdate();
  252. } catch (SQLException ex) {
  253. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  254. } finally {
  255. try {
  256. if (ps != null) {
  257. ps.close();
  258. conn.commit();
  259. }
  260. } catch (Exception e) {
  261. } finally {
  262. cpm.returnConnectionToPool(conn);
  263. }
  264. }
  265. }
  266.  
  267. public static HashMap<Integer, PlayerWealth> getPlayerWealth() {
  268. Connection conn = cpm.getConnectionFromPool();
  269. HashMap<Integer, PlayerWealth> players = new HashMap<Integer, PlayerWealth>();
  270. Statement s = null;
  271. try {
  272. s = conn.createStatement();
  273. ResultSet res = s.executeQuery("SELECT playerid, timestamp FROM log_connections ORDER BY timestamp");
  274. HashMap<Integer, Long> connections = new HashMap<Integer, Long>();
  275. while(res.next())
  276. connections.put(res.getInt(1), timestampToMillis(res.getString(2)));
  277. System.out.println("Done loading all connections");
  278. res = s.executeQuery("SELECT username, playerid, rights, banned, rights FROM players");
  279. int index = 0;
  280. while(res.next())
  281. {
  282. if(!res.getBoolean(4))
  283. {
  284. int rights = res.getInt(3);
  285. String name = res.getString(1);
  286. if(rights != PlayerRights.HONOR && rights < PlayerRights.ADMIN
  287. && !PlayerRights.superUsers.contains(name))
  288. {
  289. index++;
  290. int playerId = res.getInt(2);
  291. players.put(playerId, new PlayerWealth(name, playerId, connections.containsKey(playerId) ? connections.get(playerId) : 0));
  292. }
  293. }
  294. }
  295. System.out.println("Done loading players");
  296. res = s.executeQuery("SELECT playerid, itemid, amount FROM player_banks");
  297. while(res.next())
  298. {
  299. int playerId = res.getInt(1);
  300. if(players.containsKey(playerId))
  301. players.get(playerId).addItem(res.getInt(2), res.getInt(3));
  302. }
  303. System.out.println("Done loading banks");
  304. res = s.executeQuery("SELECT playerid, e0, n0, e1, n1, e2, n2, e3, n3, e4, n4, e5, n5, e6, n6, e7, n7, e8, n8, e9, n9, e10, n10, e11, n11, e12, n12, e13, n13 FROM player_equipment");
  305. while(res.next())
  306. {
  307. int playerId = res.getInt(1);
  308. if(players.containsKey(playerId))
  309. {
  310. PlayerWealth pw = players.get(playerId);
  311. for(int i = 0; i < 14; i++)
  312. pw.addItem(res.getInt(2 + i*2), res.getInt(3 + i*2));
  313. }
  314. }
  315. System.out.println("Done loading equipment");
  316. res = s.executeQuery("SELECT playerid, i0, a0, i1, a1, i2, a2, i3, a3, i4, a4, i5, a5, i6, a6, i7, a7, i8, a8, i9, a9, i10, a10, i11, a11, i12, a12, i13, a13, i14, a14, i15, a15, i16, a16, i17, a17, i18, a18, i19, a19, i20, a20, i21, a21, i22, a22, i23, a23, i24, a24, i25, a25, i26, a26, i27, a27 FROM player_inventories");
  317. while(res.next())
  318. {
  319. int playerId = res.getInt(1);
  320. if(players.containsKey(playerId))
  321. {
  322. PlayerWealth pw = players.get(playerId);
  323. for(int i = 0; i < 28; i++)
  324. pw.addItem(res.getInt(2 + i*2), res.getInt(3 + i*2));
  325. }
  326. }
  327. System.out.println("Done loading inventories");
  328. res = s.executeQuery("SELECT playerid, itemid, amount, amountdone, priceeach, coins, items, sell FROM grand_exchange");
  329. while(res.next())
  330. {
  331. int playerId = res.getInt(1);
  332. if(players.containsKey(playerId))
  333. {
  334. PlayerWealth pw = players.get(playerId);
  335. int itemId = res.getInt(2);
  336. int amount = res.getInt(3);
  337. int amountDone = res.getInt(4);
  338. long priceEach = res.getLong(5);
  339. long coins = res.getLong(6);
  340. int items = res.getInt(7);
  341. boolean sell = res.getBoolean(8);
  342. if(sell)
  343. {
  344. if(items > 0)
  345. pw.addItem(itemId, items);
  346. if(coins >= 1000000000)
  347. pw.addItem(5020, (int)(coins/new Long(1000000000)));
  348. if(coins > 0)
  349. pw.addItem(995, (int)(coins % new Long(1000000000)));
  350. }
  351. else
  352. {
  353. coins += new Long(amount - amountDone)*priceEach;
  354. if(items > 0)
  355. pw.addItem(itemId, items);
  356. if(coins >= 1000000000)
  357. pw.addItem(5020, (int)(coins/new Long(1000000000)));
  358. if(coins > 0)
  359. pw.addItem(995, (int)(coins % new Long(1000000000)));
  360. }
  361. }
  362. }
  363. System.out.println("Done loading grand exchange");
  364. } catch (Exception ex) {
  365. ex.printStackTrace();
  366. } finally {
  367. try {
  368. if (s != null) {
  369. s.close();
  370. conn.commit();
  371. }
  372. } catch (Exception e) {
  373. } finally {
  374. cpm.returnConnectionToPool(conn);
  375. }
  376. }
  377. return players;
  378. }
  379.  
  380. public static Player getPlayer(String name, IoSession session) {
  381. Connection conn = cpm.getConnectionFromPool();
  382. PreparedStatement ps = null;
  383. Player p = null;
  384. try
  385. {
  386. if(savingPlayers.containsKey(name))
  387. {
  388. PlayerWrapper pw = savingPlayers.get(name);
  389. p = new Player(name);
  390. p.initialize(session);
  391. p.addCreditsToRemove(pw.creditsToRemove);
  392. p.playerLevel = pw.playerLevel.clone();
  393. p.playerXP = pw.playerXP.clone();
  394. p.playerId = pw.playerId;
  395. p.playerIndex = pw.playerIndex;
  396. p.playerName = pw.playerName;
  397. p.playerPass = pw.playerPass;
  398. p.heightLevel = pw.heightLevel;
  399. p.teleportToX = pw.absX;
  400. p.teleportToY = pw.absY;
  401. p.playerRights = pw.playerRights;
  402. p.bankPin = pw.bankPin.clone();
  403. p.lotteryPrize = pw.lotteryPrize;
  404. p.clan = pw.clan;
  405. p.setDonated(pw.donated);
  406. p.autoRet = pw.autoRet;
  407. p.fightMode = pw.fightMode;
  408. p.pkHonorPoints = pw.pkHonorPoints;
  409. p.splitChat = pw.splitChat;
  410. p.privateChat = pw.privateChat;
  411. p.specAmount = pw.specAmount;
  412. p.isRunningToggledOn = pw.isRunningToggledOn;
  413. p.energy = pw.energy;
  414. p.timePlayed = pw.timePlayed;
  415. p.kills = pw.kills;
  416. p.deaths = pw.deaths;
  417. p.dropPartyBalloons = pw.dropPartyBalloons;
  418. p.lastBalloonPurchase = pw.lastBalloonPurchase;
  419. p.crystalBowArrowCount = pw.crystalBowArrowCount;
  420. p.crystalShieldLeft = pw.crystalShieldLeft;
  421. p.skullTimer = pw.skullTimer;
  422. p.playerMagicBook = pw.playerMagicBook;
  423. p.prayerBookTime = pw.prayerBookTime;
  424. p.QH().pestInvasion = pw.pestInvasion;
  425. p.randomCoffin = pw.randomCoffin;
  426. p.barrowsNpcs[1] = pw.barrowsNpcs.clone();
  427. p.dfsCharges = pw.dfsCharges;
  428. p.tzWave = pw.tzWave;
  429. p.clanChannel = pw.clanChannel;
  430. p.lootSharePoints = pw.lootSharePoints;
  431. p.poisonDamage = pw.poisonDamage;
  432. p.autoHeal = pw.autoHeal;
  433. p.cannonStage = pw.cannonStage;
  434. p.cannonBalls = pw.cannonBalls;
  435. p.teleBlockLength = pw.teleBlockLength;
  436. p.teleBlockDelay = System.currentTimeMillis();
  437. p.pcPoints = pw.pcPoints;
  438. p.slayerTask = pw.slayerTask;
  439. p.taskAmount = pw.taskAmount;
  440. p.starter = pw.starter;
  441. p.pureOne = pw.pureOne;
  442. p.expLock = pw.expLock;
  443. p.maxDef = pw.maxDef;
  444. p.maxAtt = pw.maxAtt;
  445. p.armaKills = pw.armaKills;
  446. p.bandosKills = pw.bandosKills;
  447. p.saraKills = pw.saraKills;
  448. p.zammyKills = pw.zammyKills;
  449. p.lastGodwarsPray = pw.lastGodwarsPray;
  450. p.jailOreLeft = pw.jailOreLeft;
  451. p.jailType = pw.jailType;
  452. p.banned = pw.banned;
  453. p.banDuel = pw.banDuel;
  454. p.muteTimer = pw.muteTimer;
  455. p.yellMuteTimer = pw.yellMuteTimer;
  456. p.degrades = pw.degrades.clone();
  457. p.ACH().wiseOldMan = pw.wiseOldMan.clone();
  458. p.farmingBush = pw.farmingBush.clone();
  459. p.farmingCactus = pw.farmingCactus;
  460. p.farmingCompost = pw.farmingCompost.clone();
  461. p.farmingHerb = pw.farmingHerb.clone();
  462. p.farmingStages = pw.farmingStages.clone();
  463. p.farmingTime = pw.farmingTime.clone();
  464. p.farmingTimes = pw.farmingTimes.clone();
  465. p.farmingTypes = pw.farmingTypes.clone();
  466. p.playerAppearance = pw.playerAppearance;
  467. p.playerConnectCheck = pw.connectedFrom;
  468.  
  469. p.playerItems = pw.playerItems.clone();
  470. p.playerItemsN = pw.playerItemsN.clone();
  471. p.playerEquipment = pw.playerEquipment.clone();
  472. p.playerEquipmentN = pw.playerEquipmentN.clone();
  473. p.bankItems = pw.bankItems.clone();
  474. p.bankItemsN = pw.bankItemsN.clone();
  475.  
  476. p.friends = pw.friends;
  477. p.friendRanks = pw.friendRanks;
  478. p.ignores = pw.ignores;
  479.  
  480. p.geOffers = pw.geOffers.clone();
  481. pw.loaded = true;
  482. }
  483. else
  484. {
  485. ps = conn.prepareStatement("CALL GetPlayerInfo(?);");
  486. ps.setString(1, name);
  487. ResultSet res = ps.executeQuery();
  488. if(res.next()) {
  489. p = new Player(name);
  490. p.initialize(session);
  491. p.playerId = res.getInt(1);
  492. //p.username = res.getString(2); //No need, already set
  493. p.playerPass = res.getString(3);
  494. p.heightLevel = res.getInt(4);
  495. p.teleportToX = res.getInt(5);
  496. p.teleportToY = res.getInt(6);
  497. p.playerRights = res.getInt(7);
  498. p.bankPin = res.getString(8).equals("----") ? new int[]{-1,-1,-1,-1} : new int[]{Integer.parseInt(""+res.getString(8).charAt(0)),Integer.parseInt(""+res.getString(8).charAt(1)),Integer.parseInt(""+res.getString(8).charAt(2)),Integer.parseInt(""+res.getString(8).charAt(3))};
  499. p.setDonated(res.getInt(9));
  500. // p.credits = res.getInt(10); Fetched at runtime when needed
  501. p.fightMode = res.getInt(11);
  502. if(p.fightMode > 9) {
  503. p.fightMode -= 10;
  504. p.autoRet = true;
  505. }
  506. p.pkHonorPoints = res.getInt(12);
  507. p.privateChat = res.getInt(13);
  508. if(p.privateChat > 9) {
  509. p.privateChat -= 10;
  510. p.splitChat = true;
  511. }
  512. p.specAmount = res.getInt(14);
  513. p.energy = res.getInt(15);
  514. if(p.energy < 0) {
  515. p.energy = -p.energy;
  516. p.isRunningToggledOn = false;
  517. }
  518. p.timePlayed = res.getInt(16);
  519. p.kills = res.getInt(17);
  520. p.deaths = res.getInt(18);
  521. p.dropPartyBalloons = res.getInt(19);
  522. p.lastBalloonPurchase = res.getLong(20);
  523. p.crystalBowArrowCount = (int)res.getInt(21)/1000;
  524. p.crystalShieldLeft = res.getInt(21)%1000;
  525. p.skullTimer = res.getInt(22);
  526. p.playerMagicBook = res.getInt(23);
  527. p.prayerBookTime = res.getInt(24);
  528. p.QH().pestInvasion = res.getInt(25);
  529. int barrows = res.getInt(26);
  530. p.randomCoffin = (int)barrows/1000000;
  531. for (int i = 0; i < 6; i++)
  532. p.barrowsNpcs[i][1] = ((int)barrows/(int)Math.pow(10,i))%10;
  533. p.dfsCharges = res.getInt(27);
  534. p.tzWave = res.getInt(28);
  535. p.clanChannel = res.getInt(29);
  536. p.lootSharePoints = res.getInt(30);
  537. p.poisonDamage = res.getInt(31);
  538. p.autoHeal = res.getBoolean(32);
  539. p.cannonStage = res.getInt(33);
  540. if(p.cannonStage > 4) {
  541. p.cannonBalls = p.cannonStage - 4;
  542. p.cannonStage = 4;
  543. }
  544. p.teleBlockLength = res.getInt(34);
  545. p.teleBlockDelay = System.currentTimeMillis();
  546. p.pcPoints = res.getInt(35);
  547. p.slayerTask = (int)res.getInt(36)/1000;
  548. p.taskAmount = res.getInt(36)%1000;
  549. p.starter = res.getInt(37);
  550. p.pureOne = res.getInt(38);
  551. p.expLock = res.getBoolean(39);
  552. p.maxDef = res.getInt(40);
  553. String[] ar = res.getString(41).split(";");
  554. p.armaKills = Integer.parseInt(ar[0]);
  555. p.bandosKills = Integer.parseInt(ar[1]);
  556. p.saraKills = Integer.parseInt(ar[2]);
  557. p.zammyKills = Integer.parseInt(ar[3]);
  558. p.lastGodwarsPray = Long.parseLong(ar[4]);
  559. p.jailType = res.getInt(42)%10;
  560. p.jailOreLeft = (int)res.getInt(42)/10;
  561. p.banned = res.getBoolean(43);
  562. p.banDuel = res.getBoolean(44);
  563. p.muteTimer = res.getLong(45);
  564. p.yellMuteTimer = res.getLong(46);
  565. ar = res.getString(47).split(";");
  566. for(int i = 0; i < ar.length; i++)
  567. p.degrades[i] = Integer.parseInt(ar[i]);
  568. ar = res.getString(48).split(";");
  569. for(int i = 0; i < ar.length; i++)
  570. p.ACH().wiseOldMan[i] = Integer.parseInt(ar[i]);
  571. p.lotteryPrize = res.getInt(49);
  572. ar = res.getString(51).split(";");
  573. for(int i = 0; i < ar.length; i++)
  574. p.farmingBush[i] = Long.parseLong(ar[i]);
  575. p.farmingCactus = res.getLong(52);
  576. ar = res.getString(53).split(";");
  577. for(int i = 0; i < ar.length; i++)
  578. p.farmingCompost[i] = ar[i].equals("1");
  579. ar = res.getString(54).split(";");
  580. for(int i = 0; i < ar.length; i++)
  581. p.farmingHerb[i] = Integer.parseInt(ar[i]);
  582. ar = res.getString(55).split(";");
  583. for(int i = 0; i < ar.length; i++)
  584. p.farmingStages[i] = Integer.parseInt(ar[i]);
  585. ar = res.getString(56).split(";");
  586. for(int i = 0; i < ar.length; i++)
  587. p.farmingTime[i] = Integer.parseInt(ar[i]);
  588. ar = res.getString(57).split(";");
  589. for(int i = 0; i < ar.length; i++)
  590. p.farmingTimes[i] = Long.parseLong(ar[i]);
  591. ar = res.getString(58).split(";");
  592. for(int i = 0; i < ar.length; i++)
  593. p.farmingTypes[i] = Integer.parseInt(ar[i]);
  594.  
  595. for(int i = 0; i < 13; i++)
  596. p.playerAppearance[i] = res.getInt(i+60);
  597. for(int i = 0; i < 23; i++) {
  598. p.playerLevel[i] = res.getInt(2*i+74);
  599. p.playerXP[i] = res.getInt(2*i+75);
  600. }
  601. for(int i = 0; i < 14; i++) {
  602. p.playerEquipment[i] = res.getInt(2*i+121);
  603. p.playerEquipmentN[i] = res.getInt(2*i+122);
  604. }
  605. for(int i = 0; i < 28; i++) {
  606. p.playerItems[i] = res.getInt(2*i+150) + 1;
  607. p.playerItemsN[i] = res.getInt(2*i+151);
  608. }
  609. p.playerConnectCheck = res.getString(209);
  610. if(p.playerConnectCheck == null)
  611. p.playerConnectCheck = "";
  612. /*for(int i = 1; i <= res.getMetaData().getColumnCount(); i++)
  613. System.out.println(i+"\t"+res.getMetaData().getColumnName(i)+"\t"+res.getString(i));*/
  614. ps.close();
  615. ps = conn.prepareStatement("SELECT position, itemid, amount FROM player_banks WHERE playerid = ?");
  616. ps.setInt(1, p.playerId);
  617. res = ps.executeQuery();
  618. int i;
  619. while(res.next()) {
  620. i = res.getInt(1);
  621. p.bankItems[i] = res.getInt(2) + 1;
  622. p.bankItemsN[i] = res.getInt(3);
  623. }
  624. ps.close();
  625. ps = conn.prepareStatement("SELECT friendid, clanrank FROM player_friends WHERE playerid = ?");
  626. ps.setInt(1, p.playerId);
  627. res = ps.executeQuery();
  628. i = 0;
  629. while(res.next()) {
  630. p.friends[i] = res.getLong(1);
  631. p.friendRanks[i] = res.getInt(2);
  632. i++;
  633. }
  634. ps.close();
  635. ps = conn.prepareStatement("SELECT ignoreid FROM player_ignore WHERE playerid = ?");
  636. ps.setInt(1, p.playerId);
  637. res = ps.executeQuery();
  638. i = 0;
  639. while(res.next()) {
  640. p.ignores[i] = res.getLong(1);
  641. i++;
  642. }
  643. ps.close();
  644. ps = conn.prepareStatement("INSERT INTO online_players (timestamp, username) VALUES (?,?)");
  645. ps.setString(1, millisToTimestamp(System.currentTimeMillis()));
  646. ps.setString(2, p.playerName);
  647. ps.executeUpdate();
  648. }
  649. }
  650. } catch (SQLException ex) {
  651. // XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  652. } finally {
  653. try {
  654. if (ps != null) {
  655. ps.close();
  656. conn.commit();
  657. }
  658. } catch (Exception e) {
  659. } finally {
  660. cpm.returnConnectionToPool(conn);
  661. }
  662. }
  663. return p;
  664. }
  665.  
  666. public static void addNewPlayer(Player p) {
  667. Connection conn = cpm.getConnectionFromPool();
  668. PreparedStatement ps = null;
  669. try {
  670. ps = conn.prepareStatement("INSERT INTO players (playerid, username, password, height, posx, posy, rights, pin, donated, credits, fightmode, pkpoints, privatechat, specialenergy, runenergy, timeplayed, kills, deaths, droppartyballoons, lastballoonpurchase, crystal, skulltimer, magicbook, prayerbook, q1, barrowsbrothers, dfscharges, tzwave, clanchannel, lootsharepoints, poisondamage, heal, cannon, teleblock, pcpoints, slayertask, starter, pureone, xplock, maxdef, godwars, jailstatus, banned, duelbanned, mutetimer, yellmutetimer, degrades, wom, lottery) VALUES (NULL,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS);
  671. ps.setString(1, p.playerName);
  672. ps.setString(2, p.playerPass);
  673. ps.setInt(3, p.heightLevel);
  674. ps.setInt(4, p.absX);
  675. ps.setInt(5, p.absY);
  676. ps.setInt(6, p.playerRights);
  677. if(p.bankPin[0] == -1)
  678. ps.setString(7, "----");
  679. else
  680. ps.setString(7, ""+p.bankPin[0]+p.bankPin[1]+p.bankPin[2]+p.bankPin[3]);
  681. ps.setInt(8, p.getDonated());
  682. ps.setInt(9, 0);
  683. if(p.autoRet)
  684. ps.setInt(10, p.fightMode+10);
  685. else
  686. ps.setInt(10, p.fightMode);
  687. ps.setInt(11, p.pkHonorPoints);
  688. if(p.splitChat)
  689. ps.setInt(12, p.privateChat+10);
  690. else
  691. ps.setInt(12, p.privateChat);
  692. ps.setInt(13, p.specAmount);
  693. if(p.isRunningToggledOn)
  694. ps.setInt(14, p.energy);
  695. else
  696. ps.setInt(14, -p.energy);
  697. ps.setInt(15, p.timePlayed);
  698. ps.setInt(16, p.kills);
  699. ps.setInt(17, p.deaths);
  700. ps.setInt(18, p.dropPartyBalloons);
  701. ps.setLong(19, p.lastBalloonPurchase);
  702. ps.setInt(20, p.crystalBowArrowCount*1000+p.crystalShieldLeft);
  703. ps.setInt(21, p.skullTimer);
  704. ps.setInt(22, p.playerMagicBook);
  705. ps.setInt(23, p.prayerBookTime);
  706. ps.setInt(24, p.QH().pestInvasion);
  707. int barrowsbrothers = 1000000*p.randomCoffin;
  708. for (int i = 0; i < 6; i++)
  709. barrowsbrothers += Math.pow(10,i) * p.barrowsNpcs[i][1];
  710. ps.setInt(25, barrowsbrothers);
  711. ps.setInt(26, p.dfsCharges);
  712. ps.setInt(27, p.tzWave);
  713. ps.setInt(28, p.clanChannel);
  714. ps.setLong(29, p.lootSharePoints);
  715. ps.setInt(30, p.poisonDamage);
  716. ps.setBoolean(31, p.autoHeal);
  717. ps.setInt(32, p.cannonStage+p.cannonBalls);
  718. ps.setInt(33, p.teleBlockLength);
  719. ps.setInt(34, p.pcPoints);
  720. ps.setInt(35, 1000*p.slayerTask+p.taskAmount);
  721. ps.setInt(36, p.starter);
  722. ps.setInt(37, p.pureOne);
  723. ps.setBoolean(38, p.expLock);
  724. ps.setInt(39, p.maxDef);
  725. ps.setString(40, p.armaKills+";"+p.bandosKills+";"+p.saraKills+";"+p.zammyKills+";"+p.lastGodwarsPray);
  726. ps.setInt(41, 10*p.jailOreLeft+p.jailType);
  727. ps.setBoolean(42, p.banned);
  728. ps.setBoolean(43, p.banDuel);
  729. ps.setLong(44, p.muteTimer);
  730. ps.setLong(45, p.yellMuteTimer);
  731. ps.setString(46, arrayToString(p.degrades, ";"));
  732. ps.setString(47, arrayToString(p.ACH().wiseOldMan, ";"));
  733. ps.setInt(48, p.lotteryPrize);
  734. ps.executeUpdate();
  735. ResultSet rskey = ps.getGeneratedKeys();
  736. if (rskey != null && rskey.next())
  737. p.playerId = rskey.getInt(1);
  738. ps.close();
  739. if (p.playerId > 0) {
  740. ps = conn.prepareStatement("INSERT INTO player_looks (playerid, lk0, lk1, lk2, lk3, lk4, lk5, lk6, lk7, lk8, lk9, lk10, lk11, lk12) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
  741. ps.setInt(1, p.playerId);
  742. for (int i = 0; i < p.playerAppearance.length; i++)
  743. ps.setInt(i+2, p.playerAppearance[i]);
  744. ps.executeUpdate();
  745. ps.close();
  746.  
  747. ps = conn.prepareStatement("INSERT INTO player_stats (playerid, l0, x0, l1, x1, l2, x2, l3, x3, l4, x4, l5, x5, l6, x6, l7, x7, l8, x8, l9, x9, l10, x10, l11, x11, l12, x12, l13, x13, l14, x14, l15, x15, l16, x16, l17, x17, l18, x18, l19, x19, l20, x20, l21, x21, l22, x22) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
  748. ps.setInt(1, p.playerId);
  749. for (int i = 0; i < 23; i++) {
  750. ps.setInt((2*(i+1)), p.playerLevel[i]);
  751. ps.setInt((2*(i+1)+1), p.playerXP[i]);
  752. }
  753. ps.executeUpdate();
  754. ps.close();
  755.  
  756. ps = conn.prepareStatement("INSERT INTO player_inventories (playerid, i0, a0, i1, a1, i2, a2, i3, a3, i4, a4, i5, a5, i6, a6, i7, a7, i8, a8, i9, a9, i10, a10, i11, a11, i12, a12, i13, a13, i14, a14, i15, a15, i16, a16, i17, a17, i18, a18, i19, a19, i20, a20, i21, a21, i22, a22, i23, a23, i24, a24, i25, a25, i26, a26, i27, a27) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
  757. ps.setInt(1, p.playerId);
  758. for (int i = 0; i < p.playerItems.length; i++) {
  759. ps.setInt((2*(i+1)), p.playerItems[i] - 1);
  760. ps.setInt((2*(i+1)+1), p.playerItemsN[i]);
  761. }
  762. ps.executeUpdate();
  763. ps.close();
  764.  
  765. ps = conn.prepareStatement("INSERT INTO player_equipment (playerid, e0, n0, e1, n1, e2, n2, e3, n3, e4, n4, e5, n5, e6, n6, e7, n7, e8, n8, e9, n9, e10, n10, e11, n11, e12, n12, e13, n13) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
  766. ps.setInt(1, p.playerId);
  767. for (int i = 0; i < p.playerEquipment.length; i++) {
  768. ps.setInt((2*(i+1)), p.playerEquipment[i]);
  769. ps.setInt((2*(i+1)+1), p.playerEquipmentN[i]);
  770. }
  771. ps.executeUpdate();
  772. ps.close();
  773.  
  774. /* For later: if we decide to save only those who are actually farming */
  775. //if(!(p.farmingCactus == 0 && arrayIsEmpty(p.farmingBush)
  776. // && arrayIsEmpty(p.farmingCompost) && arrayIsEmpty(p.farmingHerb)
  777. // && arrayIsEmpty(p.farmingStages) && arrayIsEmpty(p.farmingTime)
  778. // && arrayIsEmpty(p.farmingTimes) && arrayIsEmpty(p.farmingTypes))) {
  779. ps = conn.prepareStatement("INSERT INTO player_farm (playerid, bush, cactus, compost, herb, stages, time, times, types) VALUES (?,?,?,?,?,?,?,?,?)");
  780. ps.setInt(1, p.playerId);
  781. ps.setString(2, arrayToString(p.farmingBush, ";"));
  782. ps.setLong(3, p.farmingCactus);
  783. ps.setString(4, arrayToString(p.farmingCompost, ";"));
  784. ps.setString(5, arrayToString(p.farmingHerb, ";"));
  785. ps.setString(6, arrayToString(p.farmingStages, ";"));
  786. ps.setString(7, arrayToString(p.farmingTime, ";"));
  787. ps.setString(8, arrayToString(p.farmingTimes, ";"));
  788. ps.setString(9, arrayToString(p.farmingTypes, ";"));
  789. ps.executeUpdate();
  790. ps.close();
  791. //}
  792. }
  793. ps.close();
  794. ps = conn.prepareStatement("INSERT INTO online_players (timestamp, username) VALUES (?,?)");
  795. ps.setString(1, millisToTimestamp(System.currentTimeMillis()));
  796. ps.setString(2, p.playerName);
  797. ps.executeUpdate();
  798. conn.commit();
  799. } catch (SQLException ex) {
  800. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  801. try {
  802. conn.rollback();
  803. } catch (SQLException ex1) {}
  804. } finally {
  805. try {
  806. if (ps != null) {
  807. ps.close();
  808. }
  809. } catch (Exception e) {
  810. } finally {
  811. cpm.returnConnectionToPool(conn);
  812. }
  813. }
  814. }
  815.  
  816. public static void savePlayer(PlayerWrapper p, boolean logout) {
  817. Connection conn = cpm.getConnectionFromPool();
  818. PreparedStatement ps = null;
  819. String name = p.playerName;
  820. try {
  821. if(server.Server.shuttingDown)
  822. conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
  823. ps = conn.prepareStatement("UPDATE players SET username=?, password=?, height=?, posx=?, posy=?, rights=?, pin=?, donated=?, credits=credits-?, fightmode=?, pkpoints=?, privatechat=?, specialenergy=?, runenergy=?, timeplayed=?, kills=?, deaths=?, droppartyballoons=?, lastballoonpurchase=?, crystal=?, skulltimer=?, magicbook=?, prayerbook=?, q1=?, barrowsbrothers=?, dfscharges=?, tzwave=?, clanchannel=?, lootsharepoints=?, poisondamage=?, heal=?, cannon=?, teleblock=?, pcpoints=?, slayertask=?, starter=?, pureone=?, xplock=?, maxdef=?, godwars=?, jailstatus=?, banned=?, duelbanned=?, mutetimer=?, yellmutetimer=?, degrades=?, wom=?, lottery=? WHERE playerid=?", Statement.RETURN_GENERATED_KEYS);
  824. ps.setString(1, p.playerName);
  825. ps.setString(2, p.playerPass);
  826. ps.setInt(3, p.heightLevel);
  827. ps.setInt(4, p.absX);
  828. ps.setInt(5, p.absY);
  829. ps.setInt(6, p.playerRights);
  830. if(p.bankPin[0] == -1)
  831. ps.setString(7, "----");
  832. else
  833. ps.setString(7, ""+p.bankPin[0]+p.bankPin[1]+p.bankPin[2]+p.bankPin[3]);
  834. ps.setInt(8, p.donated);
  835. ps.setInt(9, p.creditsToRemove);
  836. if(p.autoRet)
  837. ps.setInt(10, p.fightMode+10);
  838. else
  839. ps.setInt(10, p.fightMode);
  840. ps.setInt(11, p.pkHonorPoints);
  841. if(p.splitChat)
  842. ps.setInt(12, p.privateChat+10);
  843. else
  844. ps.setInt(12, p.privateChat);
  845. ps.setInt(13, p.specAmount);
  846. if(p.isRunningToggledOn)
  847. ps.setInt(14, p.energy);
  848. else
  849. ps.setInt(14, -p.energy);
  850. ps.setInt(15, p.timePlayed);
  851. ps.setInt(16, p.kills);
  852. ps.setInt(17, p.deaths);
  853. ps.setInt(18, p.dropPartyBalloons);
  854. ps.setLong(19, p.lastBalloonPurchase);
  855. ps.setInt(20, p.crystalBowArrowCount*1000+p.crystalShieldLeft);
  856. ps.setInt(21, p.skullTimer);
  857. ps.setInt(22, p.playerMagicBook);
  858. ps.setInt(23, p.prayerBookTime);
  859. ps.setInt(24, p.pestInvasion);
  860. int barrowsbrothers = 1000000*p.randomCoffin;
  861. for (int i = 0; i < 6; i++)
  862. barrowsbrothers += Math.pow(10,i) * p.barrowsNpcs[1];
  863. ps.setInt(25, barrowsbrothers);
  864. ps.setInt(26, p.dfsCharges);
  865. ps.setInt(27, p.tzWave);
  866. ps.setInt(28, p.clanChannel);
  867. ps.setLong(29, p.lootSharePoints);
  868. ps.setInt(30, p.poisonDamage);
  869. ps.setBoolean(31, p.autoHeal);
  870. ps.setInt(32, p.cannonStage+p.cannonBalls);
  871. ps.setInt(33, p.teleBlockLength);
  872. ps.setInt(34, p.pcPoints);
  873. ps.setInt(35, 1000*p.slayerTask+p.taskAmount);
  874. ps.setInt(36, p.starter);
  875. ps.setInt(37, p.pureOne);
  876. ps.setBoolean(38, p.expLock);
  877. ps.setInt(39, p.maxDef);
  878. ps.setString(40, p.armaKills+";"+p.bandosKills+";"+p.saraKills+";"+p.zammyKills+";"+p.lastGodwarsPray);
  879. ps.setInt(41, 10*p.jailOreLeft+p.jailType);
  880. ps.setBoolean(42, p.banned);
  881. ps.setBoolean(43, p.banDuel);
  882. ps.setLong(44, p.muteTimer);
  883. ps.setLong(45, p.yellMuteTimer);
  884. ps.setString(46, arrayToString(p.degrades, ";"));
  885. ps.setString(47, arrayToString(p.wiseOldMan, ";"));
  886. ps.setInt(48, p.lotteryPrize);
  887. ps.setInt(49, p.playerId);
  888. ps.executeUpdate();
  889. if((logout && !server.Server.shuttingDown) || p.updatedStats) {
  890. ps.close();
  891. ps = conn.prepareStatement("UPDATE player_stats SET l0=?, x0=?, l1=?, x1=?, l2=?, x2=?, l3=?, x3=?, l4=?, x4=?, l5=?, x5=?, l6=?, x6=?, l7=?, x7=?, l8=?, x8=?, l9=?, x9=?, l10=?, x10=?, l11=?, x11=?, l12=?, x12=?, l13=?, x13=?, l14=?, x14=?, l15=?, x15=?, l16=?, x16=?, l17=?, x17=?, l18=?, x18=?, l19=?, x19=?, l20=?, x20=?, l21=?, x21=?, l22=?, x22=? WHERE playerid=?");
  892. for (int i = 0; i < 23; i++) {
  893. ps.setInt((2*i+1), p.playerLevel[i]);
  894. ps.setInt((2*i+2), p.playerXP[i]);
  895. }
  896. ps.setInt(47, p.playerId);
  897. ps.executeUpdate();
  898. }
  899. if(p.updatedFriends.size() > 0) {
  900. ps.close();
  901. ps = conn.prepareStatement("CALL UpdateFriend(?,?,?);");
  902. ps.setInt(1, p.playerId);
  903. for(long id : p.updatedFriends.keySet()) {
  904. ps.setLong(2, id);
  905. ps.setInt(3, p.updatedFriends.get(id));
  906. ps.addBatch();
  907. }
  908. ps.executeBatch();
  909. }
  910. if(p.updatedIgnores.size() > 0) {
  911. ps.close();
  912. ps = conn.prepareStatement("CALL UpdateIgnore(?,?);");
  913. ps.setInt(1, p.playerId);
  914. for(long id : p.updatedIgnores) {
  915. ps.setLong(2, id);
  916. ps.addBatch();
  917. }
  918. ps.executeBatch();
  919. }
  920. if((logout && !server.Server.shuttingDown) || p.updatedFarming) {
  921. ps.close();
  922. ps = conn.prepareStatement("UPDATE player_farm SET bush=?, cactus=?, compost=?, herb=?, stages=?, time=?, times=?, types=? WHERE playerid=?");
  923. ps.setString(1, arrayToString(p.farmingBush, ";"));
  924. ps.setLong(2, p.farmingCactus);
  925. ps.setString(3, arrayToString(p.farmingCompost, ";"));
  926. ps.setString(4, arrayToString(p.farmingHerb, ";"));
  927. ps.setString(5, arrayToString(p.farmingStages, ";"));
  928. ps.setString(6, arrayToString(p.farmingTime, ";"));
  929. ps.setString(7, arrayToString(p.farmingTimes, ";"));
  930. ps.setString(8, arrayToString(p.farmingTypes, ";"));
  931. ps.setInt(9, p.playerId);
  932. ps.executeUpdate();
  933. }
  934. if(logout || p.updatedInventory) {
  935. ps.close();
  936. ps = conn.prepareStatement("UPDATE player_inventories SET i0=?, a0=?, i1=?, a1=?, i2=?, a2=?, i3=?, a3=?, i4=?, a4=?, i5=?, a5=?, i6=?, a6=?, i7=?, a7=?, i8=?, a8=?, i9=?, a9=?, i10=?, a10=?, i11=?, a11=?, i12=?, a12=?, i13=?, a13=?, i14=?, a14=?, i15=?, a15=?, i16=?, a16=?, i17=?, a17=?, i18=?, a18=?, i19=?, a19=?, i20=?, a20=?, i21=?, a21=?, i22=?, a22=?, i23=?, a23=?, i24=?, a24=?, i25=?, a25=?, i26=?, a26=?, i27=?, a27=? WHERE playerid=?");
  937. for (int i = 0; i < p.playerItems.length; i++) {
  938. ps.setInt(2*i+1, p.playerItems[i] - 1);
  939. ps.setInt(2*i+2, p.playerItemsN[i]);
  940. }
  941. ps.setInt(57, p.playerId);
  942. ps.executeUpdate();
  943. }
  944. if(logout || p.updatedEquipment) {
  945. ps.close();
  946. ps = conn.prepareStatement("UPDATE player_equipment SET e0=?, n0=?, e1=?, n1=?, e2=?, n2=?, e3=?, n3=?, e4=?, n4=?, e5=?, n5=?, e6=?, n6=?, e7=?, n7=?, e8=?, n8=?, e9=?, n9=?, e10=?, n10=?, e11=?, n11=?, e12=?, n12=?, e13=?, n13=? WHERE playerid=?");
  947. for (int i = 0; i < p.playerEquipment.length; i++) {
  948. ps.setInt(2*i+1, p.playerEquipment[i]);
  949. ps.setInt(2*i+2, p.playerEquipmentN[i]);
  950. }
  951. ps.setInt(29, p.playerId);
  952. ps.executeUpdate();
  953. }
  954. if(logout) {
  955. ps.close();
  956. ps = conn.prepareStatement("CALL UpdateBankItem(?,?,?,?);");
  957. ps.setInt(1, p.playerId);
  958. for(int i = 0; i < p.bankItems.length; i++) {
  959. ps.setInt(2, i);
  960. ps.setInt(3, p.bankItems[i] - 1);
  961. ps.setInt(4, p.bankItemsN[i]);
  962. ps.addBatch();
  963. }
  964. ps.executeBatch();
  965. if(!p.loaded)
  966. {
  967. ps.close();
  968. ps = conn.prepareStatement("DELETE FROM online_players WHERE username = ?");
  969. ps.setString(1, p.playerName);
  970. ps.executeUpdate();
  971. }
  972. } else if(p.updatedBankSpots[p.updatedBankSpots.length-1]) {
  973. ps.close();
  974. ps = conn.prepareStatement("CALL UpdateBankItem(?,?,?,?);");
  975. ps.setInt(1, p.playerId);
  976. for(int i = 0; i < p.updatedBankSpots.length - 1; i++) {
  977. if(p.updatedBankSpots[i]) {
  978. ps.setInt(2, i);
  979. ps.setInt(3, p.bankItems[i] - 1);
  980. ps.setInt(4, p.bankItemsN[i]);
  981. ps.addBatch();
  982. }
  983. }
  984. ps.executeBatch();
  985. }
  986. if(!server.Server.shuttingDown) {
  987. ps.close();
  988. ps = conn.prepareStatement("CALL UpdateHighscores(?);");
  989. ps.setInt(1, p.playerId);
  990. ps.executeUpdate();
  991. }
  992. conn.commit();
  993. int playerIndex = PlayerHandler.getPlayerIndex(p.playerId);
  994. if(playerIndex > -1)
  995. PlayerHandler.players[playerIndex].addCreditsToRemove(-p.creditsToRemove);
  996. } catch (SQLException ex) {
  997. XLogger.getInstance().log(Level.SEVERE, "Exception in saving player " + p.playerName + "(id " + p.playerId + ")", ex);
  998. try {
  999. conn.rollback();
  1000. } catch (SQLException ex1) {}
  1001. } finally {
  1002. removeSavePlayer(name);
  1003. try {
  1004. if (ps != null) {
  1005. ps.close();
  1006. }
  1007. if(server.Server.shuttingDown)
  1008. conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
  1009. } catch (Exception e) {
  1010. } finally {
  1011. cpm.returnConnectionToPool(conn);
  1012. }
  1013. }
  1014. }
  1015.  
  1016. public static void saveLooks(PlayerWrapper p) {
  1017. Connection conn = cpm.getConnectionFromPool();
  1018. PreparedStatement ps = null;
  1019. try {
  1020. ps = conn.prepareStatement("UPDATE player_looks SET lk0=?, lk1=?, lk2=?, lk3=?, lk4=?, lk5=?, lk6=?, lk7=?, lk8=?, lk9=?, lk10=?, lk11=?, lk12=? WHERE playerid=?");
  1021. for (int i = 0; i < p.playerAppearance.length; i++)
  1022. ps.setInt(i+1, p.playerAppearance[i]);
  1023. ps.setInt(14, p.playerId);
  1024. ps.executeUpdate();
  1025. } catch (SQLException ex) {
  1026. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1027. } finally {
  1028. try {
  1029. if (ps != null) {
  1030. ps.close();
  1031. conn.commit();
  1032. }
  1033. } catch (Exception e) {
  1034. } finally {
  1035. cpm.returnConnectionToPool(conn);
  1036. }
  1037. }
  1038. }
  1039.  
  1040. public static void removeOnlinePlayer(String name) {
  1041. Connection conn = cpm.getConnectionFromPool();
  1042. PreparedStatement ps = null;
  1043. try {
  1044. ps = conn.prepareStatement("DELETE FROM online_players WHERE username=?");
  1045. ps.setString(1, name);
  1046. ps.executeUpdate();
  1047. } catch (SQLException ex) {
  1048. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1049. } finally {
  1050. try {
  1051. if (ps != null) {
  1052. ps.close();
  1053. conn.commit();
  1054. }
  1055. } catch (Exception e) {
  1056. } finally {
  1057. cpm.returnConnectionToPool(conn);
  1058. }
  1059. }
  1060. }
  1061.  
  1062. public static void resetOnlinePlayers() {
  1063. Connection conn = cpm.getConnectionFromPool();
  1064. Statement s = null;
  1065. try {
  1066. s = conn.createStatement();
  1067. s.executeUpdate("DELETE FROM online_players");
  1068. } catch (SQLException ex) {
  1069. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1070. } finally {
  1071. try {
  1072. if (s != null) {
  1073. s.close();
  1074. conn.commit();
  1075. }
  1076. } catch (Exception e) {
  1077. } finally {
  1078. cpm.returnConnectionToPool(conn);
  1079. }
  1080. }
  1081. }
  1082.  
  1083. public static int getCredits(Player p) {
  1084. Connection conn = cpm.getConnectionFromPool();
  1085. PreparedStatement ps = null;
  1086. try {
  1087. conn.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
  1088. ps = conn.prepareStatement("SELECT credits FROM players WHERE playerid = ?");
  1089. ps.setInt(1, p.playerId);
  1090. ResultSet res = ps.executeQuery();
  1091. if(res.next())
  1092. return res.getInt(1) - p.getCreditsToRemove();
  1093. } catch (SQLException ex) {
  1094. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1095. } finally {
  1096. try {
  1097. if (ps != null) {
  1098. ps.close();
  1099. conn.commit();
  1100. }
  1101. conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
  1102. } catch (Exception e) {
  1103. } finally {
  1104. cpm.returnConnectionToPool(conn);
  1105. }
  1106. }
  1107. return 0;
  1108. }
  1109.  
  1110. public static String[] getPassAndPin(String name) {
  1111. Connection conn = cpm.getConnectionFromPool();
  1112. PreparedStatement ps = null;
  1113. try {
  1114. ps = conn.prepareStatement("SELECT password, pin FROM players WHERE username = ?");
  1115. ps.setString(1, name);
  1116. ResultSet res = ps.executeQuery();
  1117. if(res.next())
  1118. return new String[]{res.getString(1), res.getString(2)};
  1119. } catch (SQLException ex) {
  1120. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1121. } finally {
  1122. try {
  1123. if (ps != null) {
  1124. ps.close();
  1125. conn.commit();
  1126. }
  1127. } catch (Exception e) {
  1128. } finally {
  1129. cpm.returnConnectionToPool(conn);
  1130. }
  1131. }
  1132. return null;
  1133. }
  1134.  
  1135. public static int[] getIDAndRights(String name) {
  1136. Connection conn = cpm.getConnectionFromPool();
  1137. PreparedStatement ps = null;
  1138. try {
  1139. ps = conn.prepareStatement("SELECT playerid, rights FROM players WHERE username=?");
  1140. ps.setString(1, name);
  1141. ResultSet res = ps.executeQuery();
  1142. if(res.next())
  1143. return new int[]{res.getInt(1), res.getInt(2)};
  1144. } catch (SQLException ex) {
  1145. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1146. } finally {
  1147. try {
  1148. if (ps != null) {
  1149. ps.close();
  1150. conn.commit();
  1151. }
  1152. } catch (Exception e) {
  1153. } finally {
  1154. cpm.returnConnectionToPool(conn);
  1155. }
  1156. }
  1157. return null;
  1158. }
  1159.  
  1160. public static void setPassword(int playerid, String password) {
  1161. Connection conn = cpm.getConnectionFromPool();
  1162. PreparedStatement ps = null;
  1163. try {
  1164. ps = conn.prepareStatement("UPDATE players SET password=? WHERE playerid=?");
  1165. ps.setString(1, password);
  1166. ps.setInt(2, playerid);
  1167. ps.executeUpdate();
  1168. } catch (SQLException ex) {
  1169. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1170. } finally {
  1171. try {
  1172. if (ps != null) {
  1173. ps.close();
  1174. conn.commit();
  1175. }
  1176. } catch (Exception e) {
  1177. } finally {
  1178. cpm.returnConnectionToPool(conn);
  1179. }
  1180. }
  1181. }
  1182.  
  1183. public static void banPlayer(long millis, int playerid, int byplayerid, String reason, boolean connection) {
  1184. Connection conn = cpm.getConnectionFromPool();
  1185. PreparedStatement ps = null;
  1186. try {
  1187. ps = conn.prepareStatement("INSERT INTO log_bans (timestamp, playerid, by_playerid, reason) VALUES (?,?,?,?)");
  1188. ps.setString(1, millisToTimestamp(millis));
  1189. ps.setInt(2, playerid);
  1190. ps.setInt(3, byplayerid);
  1191. ps.setString(4, reason);
  1192. ps.executeUpdate();
  1193. ps.close();
  1194. ps = conn.prepareStatement("UPDATE players SET banned=1 WHERE playerid=?");
  1195. ps.setInt(1, playerid);
  1196. ps.executeUpdate();
  1197. if(connection) {
  1198. ps.close();
  1199. ps = conn.prepareStatement("INSERT INTO connection_bans (playerid, ip) VALUES (?,(SELECT ip FROM log_connections WHERE playerid=? ORDER BY timestamp DESC LIMIT 1))");
  1200. ps.setInt(1, playerid);
  1201. ps.setInt(2, playerid);
  1202. ps.executeUpdate();
  1203. }
  1204. } catch (SQLException ex) {
  1205. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1206. } finally {
  1207. try {
  1208. if (ps != null) {
  1209. ps.close();
  1210. conn.commit();
  1211. }
  1212. } catch (Exception e) {
  1213. } finally {
  1214. cpm.returnConnectionToPool(conn);
  1215. }
  1216. }
  1217. }
  1218.  
  1219. public static String unbanPlayer(int playerid) {
  1220. Connection conn = cpm.getConnectionFromPool();
  1221. PreparedStatement ps = null;
  1222. try {
  1223. ps = conn.prepareStatement("UPDATE players SET banned=0 WHERE playerid=?");
  1224. ps.setInt(1, playerid);
  1225. ps.executeUpdate();
  1226. ps.close();
  1227. ps = conn.prepareStatement("DELETE FROM connection_bans WHERE playerid=?");
  1228. ps.setInt(1, playerid);
  1229. ps.executeUpdate();
  1230. ps.close();
  1231. ps = conn.prepareStatement("SELECT username FROM connection_bans INNER JOIN players ON players.playerid = connection_bans.playerid WHERE ip = (SELECT ip FROM log_connections WHERE playerid=? ORDER BY timestamp DESC LIMIT 1)");
  1232. ps.setInt(1, playerid);
  1233. ResultSet res = ps.executeQuery();
  1234. String names;
  1235. if(!res.next())
  1236. return null;
  1237. else
  1238. names = res.getString(1);
  1239. while(res.next())
  1240. names = names + ", " + res.getString(1);
  1241. return names;
  1242. } catch (SQLException ex) {
  1243. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1244. } finally {
  1245. try {
  1246. if (ps != null) {
  1247. ps.close();
  1248. conn.commit();
  1249. }
  1250. } catch (Exception e) {
  1251. } finally {
  1252. cpm.returnConnectionToPool(conn);
  1253. }
  1254. }
  1255. return null;
  1256. }
  1257.  
  1258. public static void duelBanPlayer(int playerid) {
  1259. Connection conn = cpm.getConnectionFromPool();
  1260. PreparedStatement ps = null;
  1261. try {
  1262. ps = conn.prepareStatement("UPDATE players SET duelbanned=1 WHERE playerid=?");
  1263. ps.setInt(1, playerid);
  1264. ps.executeUpdate();
  1265. } catch (SQLException ex) {
  1266. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1267. } finally {
  1268. try {
  1269. if (ps != null) {
  1270. ps.close();
  1271. conn.commit();
  1272. }
  1273. } catch (Exception e) {
  1274. } finally {
  1275. cpm.returnConnectionToPool(conn);
  1276. }
  1277. }
  1278. }
  1279.  
  1280. public static void duelUnbanPlayer(int playerid) {
  1281. Connection conn = cpm.getConnectionFromPool();
  1282. PreparedStatement ps = null;
  1283. try {
  1284. ps = conn.prepareStatement("UPDATE players SET duelbanned=0 WHERE playerid=?");
  1285. ps.setInt(1, playerid);
  1286. ps.executeUpdate();
  1287. } catch (SQLException ex) {
  1288. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1289. } finally {
  1290. try {
  1291. if (ps != null) {
  1292. ps.close();
  1293. conn.commit();
  1294. }
  1295. } catch (Exception e) {
  1296. } finally {
  1297. cpm.returnConnectionToPool(conn);
  1298. }
  1299. }
  1300. }
  1301.  
  1302. public static void mutePlayer(int playerid, long time, boolean connection) {
  1303. Connection conn = cpm.getConnectionFromPool();
  1304. PreparedStatement ps = null;
  1305. try {
  1306. ps = conn.prepareStatement("UPDATE players SET mutetimer=? WHERE playerid=?");
  1307. ps.setLong(1, time);
  1308. ps.setInt(2, playerid);
  1309. ps.executeUpdate();
  1310. if(connection) {
  1311. ps.close();
  1312. ps = conn.prepareStatement("INSERT INTO connection_mutes (playerid, ip) VALUES (?,(SELECT ip FROM log_connections WHERE playerid=? ORDER BY timestamp DESC LIMIT 1))");
  1313. ps.setInt(1, playerid);
  1314. ps.setInt(2, playerid);
  1315. ps.executeUpdate();
  1316. }
  1317. } catch (SQLException ex) {
  1318. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1319. } finally {
  1320. try {
  1321. if (ps != null) {
  1322. ps.close();
  1323. conn.commit();
  1324. }
  1325. } catch (Exception e) {
  1326. } finally {
  1327. cpm.returnConnectionToPool(conn);
  1328. }
  1329. }
  1330. }
  1331.  
  1332. public static String unmutePlayer(int playerid) {
  1333. Connection conn = cpm.getConnectionFromPool();
  1334. PreparedStatement ps = null;
  1335. try {
  1336. ps = conn.prepareStatement("UPDATE players SET mutetimer=0 WHERE playerid=?");
  1337. ps.setInt(1, playerid);
  1338. ps.executeUpdate();
  1339. ps.close();
  1340. ps = conn.prepareStatement("DELETE FROM connection_mutes WHERE playerid=?");
  1341. ps.setInt(1, playerid);
  1342. ps.executeUpdate();
  1343. ps.close();
  1344. ps = conn.prepareStatement("SELECT username FROM connection_mutes INNER JOIN players ON players.playerid = connection_mutes.playerid WHERE ip = (SELECT ip FROM log_connections WHERE playerid=? ORDER BY timestamp DESC LIMIT 1)");
  1345. ps.setInt(1, playerid);
  1346. ResultSet res = ps.executeQuery();
  1347. String names;
  1348. if(!res.next())
  1349. return null;
  1350. else
  1351. names = res.getString(1);
  1352. while(res.next())
  1353. names = names + ", " + res.getString(1);
  1354. return names;
  1355. } catch (SQLException ex) {
  1356. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1357. } finally {
  1358. try {
  1359. if (ps != null) {
  1360. ps.close();
  1361. conn.commit();
  1362. }
  1363. } catch (Exception e) {
  1364. } finally {
  1365. cpm.returnConnectionToPool(conn);
  1366. }
  1367. }
  1368. return null;
  1369. }
  1370.  
  1371. public static void yellmutePlayer(int playerid, long time) {
  1372. Connection conn = cpm.getConnectionFromPool();
  1373. PreparedStatement ps = null;
  1374. try {
  1375. ps = conn.prepareStatement("UPDATE players SET yellmutetimer=? WHERE playerid=?");
  1376. ps.setLong(1, time);
  1377. ps.setInt(2, playerid);
  1378. ps.executeUpdate();
  1379. } catch (SQLException ex) {
  1380. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1381. } finally {
  1382. try {
  1383. if (ps != null) {
  1384. ps.close();
  1385. conn.commit();
  1386. }
  1387. } catch (Exception e) {
  1388. } finally {
  1389. cpm.returnConnectionToPool(conn);
  1390. }
  1391. }
  1392. }
  1393.  
  1394. public static void unyellmutePlayer(int playerid) {
  1395. Connection conn = cpm.getConnectionFromPool();
  1396. PreparedStatement ps = null;
  1397. try {
  1398. ps = conn.prepareStatement("UPDATE players SET yellmutetimer=0 WHERE playerid=?");
  1399. ps.setInt(1, playerid);
  1400. ps.executeUpdate();
  1401. } catch (SQLException ex) {
  1402. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1403. } finally {
  1404. try {
  1405. if (ps != null) {
  1406. ps.close();
  1407. conn.commit();
  1408. }
  1409. } catch (Exception e) {
  1410. } finally {
  1411. cpm.returnConnectionToPool(conn);
  1412. }
  1413. }
  1414. }
  1415.  
  1416. public static void saveMac(int playerid, String mac) {
  1417. Connection conn = cpm.getConnectionFromPool();
  1418. PreparedStatement ps = null;
  1419. try {
  1420. ps = conn.prepareStatement("CALL addMac(?,?);");
  1421. ps.setInt(1, playerid);
  1422. ps.setString(2, mac);
  1423. ps.executeUpdate();
  1424. } catch (SQLException ex) {
  1425. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1426. } finally {
  1427. try {
  1428. if (ps != null) {
  1429. ps.close();
  1430. conn.commit();
  1431. }
  1432. } catch (Exception e) {
  1433. } finally {
  1434. cpm.returnConnectionToPool(conn);
  1435. }
  1436. }
  1437. }
  1438.  
  1439. /**
  1440. * @return A BanReason containing 4 things:
  1441. * -> Rank of the banner
  1442. * -> Name of the banner
  1443. * -> Reason why this person was banned
  1444. * -> Date of ban
  1445. */
  1446. public static BanReason getReason(String username) {
  1447. Connection conn = cpm.getConnectionFromPool();
  1448. PreparedStatement ps = null;
  1449. try {
  1450. conn.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
  1451. ps = conn.prepareStatement("SELECT p2.rights, p2.username, reason, timestamp FROM log_bans INNER JOIN players AS p1 ON p1.playerid = log_bans.playerid LEFT JOIN players AS p2 ON p2.playerid = log_bans.by_playerid WHERE p1.username = ? ORDER BY timestamp DESC LIMIT 1");
  1452. ps.setString(1, username);
  1453. ResultSet res = ps.executeQuery();
  1454. if(res.next())
  1455. return new BanReason(res.getInt(1), res.getString(2), res.getString(3), timestampToMillis(res.getString(4)));
  1456. } catch (SQLException ex) {
  1457. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1458. } finally {
  1459. try {
  1460. if (ps != null) {
  1461. ps.close();
  1462. conn.commit();
  1463. }
  1464. conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
  1465. } catch (Exception e) {
  1466. } finally {
  1467. cpm.returnConnectionToPool(conn);
  1468. }
  1469. }
  1470. return null;
  1471. }
  1472.  
  1473. /**
  1474. * @return the latest IP of this person
  1475. */
  1476. public static String getIp(String username) {
  1477. Connection conn = cpm.getConnectionFromPool();
  1478. PreparedStatement ps = null;
  1479. try {
  1480. conn.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
  1481. ps = conn.prepareStatement("SELECT INET_NTOA(ip) FROM log_connections INNER JOIN players ON players.playerid = log_connections.playerid WHERE username = ? ORDER BY timestamp DESC LIMIT 1");
  1482. ps.setString(1, username);
  1483. ResultSet res = ps.executeQuery();
  1484. if(res.next())
  1485. return res.getString(1);
  1486. } catch (SQLException ex) {
  1487. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1488. } finally {
  1489. try {
  1490. if (ps != null) {
  1491. ps.close();
  1492. conn.commit();
  1493. }
  1494. conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
  1495. } catch (Exception e) {
  1496. } finally {
  1497. cpm.returnConnectionToPool(conn);
  1498. }
  1499. }
  1500. return null;
  1501. }
  1502.  
  1503. public static String[] getMacs(String username) {
  1504. ArrayList<String> macs = null;
  1505. Connection conn = cpm.getConnectionFromPool();
  1506. PreparedStatement ps = null;
  1507. try {
  1508. ps = conn.prepareStatement("SELECT mac FROM player_macs AS pm INNER JOIN players ON players.playerid = pm.playerid INNER JOIN (SELECT playerid, MAX(count) AS max FROM player_macs GROUP BY playerid) AS j ON pm.playerid = j.playerid WHERE username=? AND count*10 >= max");
  1509. ps.setString(1, username);
  1510. ResultSet res = ps.executeQuery();
  1511. macs = new ArrayList<String>();
  1512. while(res.next())
  1513. macs.add(res.getString(1));
  1514. } catch (SQLException ex) {
  1515. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1516. } finally {
  1517. try {
  1518. if (ps != null) {
  1519. ps.close();
  1520. conn.commit();
  1521. }
  1522. } catch (Exception e) {
  1523. } finally {
  1524. cpm.returnConnectionToPool(conn);
  1525. }
  1526. }
  1527. return macs.toArray(new String[0]);
  1528. }
  1529.  
  1530. public static String getPlayerName(int playerid) {
  1531. Connection conn = cpm.getConnectionFromPool();
  1532. PreparedStatement ps = null;
  1533. try {
  1534. ps = conn.prepareStatement("SELECT username FROM players WHERE playerid = ?");
  1535. ps.setInt(1, playerid);
  1536. ResultSet res = ps.executeQuery();
  1537. if(res.next())
  1538. return res.getString(1);
  1539. } catch (SQLException ex) {
  1540. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1541. } finally {
  1542. try {
  1543. if (ps != null) {
  1544. ps.close();
  1545. conn.commit();
  1546. }
  1547. } catch (Exception e) {
  1548. } finally {
  1549. cpm.returnConnectionToPool(conn);
  1550. }
  1551. }
  1552. return null;
  1553. }
  1554.  
  1555. public static int getTimePlayed(String name) {
  1556. Connection conn = cpm.getConnectionFromPool();
  1557. PreparedStatement ps = null;
  1558. try {
  1559. ps = conn.prepareStatement("SELECT timeplayed FROM players WHERE username = ?");
  1560. ps.setString(1, name);
  1561. ResultSet res = ps.executeQuery();
  1562. if(res.next())
  1563. return res.getInt(1);
  1564. } catch (SQLException ex) {
  1565. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1566. } finally {
  1567. try {
  1568. if (ps != null) {
  1569. ps.close();
  1570. conn.commit();
  1571. }
  1572. } catch (Exception e) {
  1573. } finally {
  1574. cpm.returnConnectionToPool(conn);
  1575. }
  1576. }
  1577. return -1;
  1578. }
  1579.  
  1580. public static boolean isBanned(String username) {
  1581. Connection conn = cpm.getConnectionFromPool();
  1582. PreparedStatement ps = null;
  1583. try {
  1584. ps = conn.prepareStatement("SELECT banned FROM players WHERE username = ?");
  1585. ps.setString(1, username);
  1586. ResultSet res = ps.executeQuery();
  1587. if(res.next())
  1588. return res.getBoolean(1);
  1589. } catch (SQLException ex) {
  1590. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1591. } finally {
  1592. try {
  1593. if (ps != null) {
  1594. ps.close();
  1595. conn.commit();
  1596. }
  1597. } catch (Exception e) {
  1598. } finally {
  1599. cpm.returnConnectionToPool(conn);
  1600. }
  1601. }
  1602. return false;
  1603. }
  1604.  
  1605. public static boolean isDuelBanned(String username) {
  1606. Connection conn = cpm.getConnectionFromPool();
  1607. PreparedStatement ps = null;
  1608. try {
  1609. ps = conn.prepareStatement("SELECT duelbanned FROM players WHERE username = ?");
  1610. ps.setString(1, username);
  1611. ResultSet res = ps.executeQuery();
  1612. if(res.next())
  1613. return res.getBoolean(1);
  1614. } catch (SQLException ex) {
  1615. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1616. } finally {
  1617. try {
  1618. if (ps != null) {
  1619. ps.close();
  1620. conn.commit();
  1621. }
  1622. } catch (Exception e) {
  1623. } finally {
  1624. cpm.returnConnectionToPool(conn);
  1625. }
  1626. }
  1627. return false;
  1628. }
  1629.  
  1630. public static long getMuteTimer(String username) {
  1631. Connection conn = cpm.getConnectionFromPool();
  1632. PreparedStatement ps = null;
  1633. try {
  1634. ps = conn.prepareStatement("SELECT mutetimer FROM players WHERE username = ?");
  1635. ps.setString(1, username);
  1636. ResultSet res = ps.executeQuery();
  1637. if(res.next())
  1638. return res.getLong(1);
  1639. } catch (SQLException ex) {
  1640. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1641. } finally {
  1642. try {
  1643. if (ps != null) {
  1644. ps.close();
  1645. conn.commit();
  1646. }
  1647. } catch (Exception e) {
  1648. } finally {
  1649. cpm.returnConnectionToPool(conn);
  1650. }
  1651. }
  1652. return 0;
  1653. }
  1654.  
  1655. public static long getYellMuteTimer(String username) {
  1656. Connection conn = cpm.getConnectionFromPool();
  1657. PreparedStatement ps = null;
  1658. try {
  1659. ps = conn.prepareStatement("SELECT yellmutetimer FROM players WHERE username = ?");
  1660. ps.setString(1, username);
  1661. ResultSet res = ps.executeQuery();
  1662. if(res.next())
  1663. return res.getLong(1);
  1664. } catch (SQLException ex) {
  1665. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1666. } finally {
  1667. try {
  1668. if (ps != null) {
  1669. ps.close();
  1670. conn.commit();
  1671. }
  1672. } catch (Exception e) {
  1673. } finally {
  1674. cpm.returnConnectionToPool(conn);
  1675. }
  1676. }
  1677. return 0;
  1678. }
  1679.  
  1680. public static void setRights(String username, int rights) {
  1681. Connection conn = cpm.getConnectionFromPool();
  1682. PreparedStatement ps = null;
  1683. try {
  1684. ps = conn.prepareStatement("UPDATE players SET rights=? WHERE username=?");
  1685. ps.setInt(1, rights);
  1686. ps.setString(2, username);
  1687. ps.executeUpdate();
  1688. } catch (SQLException ex) {
  1689. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1690. } finally {
  1691. try {
  1692. if (ps != null) {
  1693. ps.close();
  1694. conn.commit();
  1695. }
  1696. } catch (Exception e) {
  1697. } finally {
  1698. cpm.returnConnectionToPool(conn);
  1699. }
  1700. }
  1701. }
  1702.  
  1703. public static void setItemPrice(int itemid, long newLowPrice, long newHighPrice) {
  1704. Connection conn = cpm.getConnectionFromPool();
  1705. PreparedStatement ps = null;
  1706. try {
  1707. ps = conn.prepareStatement("UPDATE items SET lowvalue=?, highvalue=? WHERE itemid=?");
  1708. ps.setLong(1, newLowPrice);
  1709. ps.setLong(2, newHighPrice);
  1710. ps.setInt(3, itemid);
  1711. ps.executeUpdate();
  1712. } catch (SQLException ex) {
  1713. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1714. } finally {
  1715. try {
  1716. if (ps != null) {
  1717. ps.close();
  1718. conn.commit();
  1719. }
  1720. } catch (Exception e) {
  1721. } finally {
  1722. cpm.returnConnectionToPool(conn);
  1723. }
  1724. }
  1725. }
  1726.  
  1727. public static void cleanHighscores() {
  1728. Connection conn = cpm.getConnectionFromPool();
  1729. Statement s = null;
  1730. try {
  1731. s = conn.createStatement();
  1732. s.executeUpdate("DELETE FROM highscores, highscores_overall USING highscores INNER JOIN highscores_overall ON highscores.playerName = highscores_overall.playerName WHERE highscores.playerName IN (SELECT username FROM players WHERE banned=1 OR rights=2 OR rights>5)");
  1733. } catch (SQLException ex) {
  1734. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1735. } finally {
  1736. try {
  1737. if (s != null) {
  1738. s.close();
  1739. conn.commit();
  1740. }
  1741. } catch (Exception e) {
  1742. } finally {
  1743. cpm.returnConnectionToPool(conn);
  1744. }
  1745. }
  1746. }
  1747.  
  1748. public static void loadShops() {
  1749. Connection conn = cpm.getConnectionFromPool();
  1750. Statement s = null;
  1751. try {
  1752. s = conn.createStatement();
  1753. ResultSet res = s.executeQuery("SELECT shops.shopid, name, buysall, itemid, amount FROM shops LEFT JOIN shop_contents ON shops.shopid = shop_contents.shopid");
  1754. int shopid = 0;
  1755. res.next();
  1756. while(!res.isAfterLast()) {
  1757. shopid = res.getInt(1);
  1758. ShopHandler.shopName[shopid] = res.getString(2);
  1759. ShopHandler.buysAll[shopid] = res.getBoolean(3);
  1760. int i = 0;
  1761. do {
  1762. int itemid = res.getInt(4) + 1;
  1763. if(!res.wasNull())
  1764. {
  1765. ShopHandler.shopItems[shopid][i] = itemid;
  1766. ShopHandler.shopItemsN[shopid][i] = res.getInt(5);
  1767. ShopHandler.shopItemsSN[shopid][i] = res.getInt(5);
  1768. ShopHandler.shopItemsStandard[shopid]++;
  1769. }
  1770. i++;
  1771. } while(res.next() && res.getInt(1) == shopid);
  1772. }
  1773. ShopHandler.totalShops = shopid + 1;
  1774. } catch (SQLException ex) {
  1775. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1776. } finally {
  1777. try {
  1778. if (s != null) {
  1779. s.close();
  1780. conn.commit();
  1781. }
  1782. } catch (Exception e) {
  1783. } finally {
  1784. cpm.returnConnectionToPool(conn);
  1785. }
  1786. }
  1787. }
  1788.  
  1789. public static void loadVotes(HashMap<String, Long> ips, HashMap<String, ArrayList<Long>> macs) {
  1790. Connection conn = cpm.getConnectionFromPool();
  1791. Statement s = null;
  1792. PreparedStatement ps = null;
  1793. try {
  1794. s = conn.createStatement();
  1795. ResultSet res = s.executeQuery("SELECT timestamp, INET_NTOA(ip), mac FROM votes ORDER BY timestamp ASC");
  1796. HashSet<String> delete = new HashSet<String>();
  1797. long time, now = System.currentTimeMillis();
  1798. while(res.next()) {
  1799. time = timestampToMillis(res.getString(1));
  1800. if (now - time < Config.votingHours * 60 * 60 * 1000) {
  1801. ips.put(res.getString(2), time);
  1802. String mac = res.getString(3);
  1803. if(macs.containsKey(mac))
  1804. macs.get(mac).add(time);
  1805. else {
  1806. ArrayList<Long> times = new ArrayList<Long>();
  1807. times.add(time);
  1808. macs.put(mac, times);
  1809. }
  1810. } else
  1811. delete.add(res.getString(2));
  1812. }
  1813. s.close();
  1814. ps = conn.prepareStatement("DELETE FROM votes WHERE INET_NTOA(ip) = ?");
  1815. for(String ip : delete) {
  1816. ps.setString(1, ip);
  1817. ps.addBatch();
  1818. }
  1819. ps.executeBatch();
  1820. } catch (SQLException ex) {
  1821. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1822. } finally {
  1823. try {
  1824. if (s != null) {
  1825. s.close();
  1826. ps.close();
  1827. conn.commit();
  1828. }
  1829. } catch (Exception e) {
  1830. } finally {
  1831. cpm.returnConnectionToPool(conn);
  1832. }
  1833. }
  1834. }
  1835.  
  1836. public static void saveVote(String ip, String mac, long millis) {
  1837. Connection conn = cpm.getConnectionFromPool();
  1838. PreparedStatement ps = null;
  1839. try {
  1840. ps = conn.prepareStatement("INSERT INTO votes (timestamp,ip,mac) VALUES (?,INET_ATON(?),?)");
  1841. ps.setString(1, millisToTimestamp(millis));
  1842. ps.setString(2, ip);
  1843. ps.setString(3, mac);
  1844. ps.executeUpdate();
  1845. } catch (SQLException ex) {
  1846. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1847. } finally {
  1848. try {
  1849. if (ps != null) {
  1850. ps.close();
  1851. conn.commit();
  1852. }
  1853. } catch (Exception e) {
  1854. } finally {
  1855. cpm.returnConnectionToPool(conn);
  1856. }
  1857. }
  1858. }
  1859.  
  1860. public static int loadLottery(int[] players) {
  1861. Connection conn = cpm.getConnectionFromPool();
  1862. Statement s = null;
  1863. int i = 0;
  1864. try {
  1865. s = conn.createStatement();
  1866. ResultSet res = s.executeQuery("SELECT playerid FROM lottery");
  1867. while(res.next() && i < Lottery.MAX_TICKETS)
  1868. players[i++] = res.getInt(1);
  1869. } catch (SQLException ex) {
  1870. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1871. } finally {
  1872. try {
  1873. if (s != null) {
  1874. s.close();
  1875. conn.commit();
  1876. }
  1877. } catch (Exception e) {
  1878. } finally {
  1879. cpm.returnConnectionToPool(conn);
  1880. }
  1881. }
  1882. return i;
  1883. }
  1884.  
  1885. public static void addToLottery(int playerid, int tickets) {
  1886. Connection conn = cpm.getConnectionFromPool();
  1887. PreparedStatement ps = null;
  1888. try {
  1889. ps = conn.prepareStatement("INSERT INTO lottery (playerid) VALUES (?)");
  1890. ps.setInt(1, playerid);
  1891. for(int i = 0; i < tickets; i++)
  1892. ps.addBatch();
  1893. ps.executeBatch();
  1894. } catch (SQLException ex) {
  1895. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1896. } finally {
  1897. try {
  1898. if (ps != null) {
  1899. ps.close();
  1900. conn.commit();
  1901. }
  1902. } catch (Exception e) {
  1903. } finally {
  1904. cpm.returnConnectionToPool(conn);
  1905. }
  1906. }
  1907. }
  1908.  
  1909. public static void clearLottery() {
  1910. Connection conn = cpm.getConnectionFromPool();
  1911. Statement s = null;
  1912. try {
  1913. s = conn.createStatement();
  1914. s.executeUpdate("DELETE FROM lottery");
  1915. } catch (SQLException ex) {
  1916. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1917. } finally {
  1918. try {
  1919. if (s != null) {
  1920. s.close();
  1921. conn.commit();
  1922. }
  1923. } catch (Exception e) {
  1924. } finally {
  1925. cpm.returnConnectionToPool(conn);
  1926. }
  1927. }
  1928. }
  1929.  
  1930. public static void saveLotteryWinner(int playerid, int place) {
  1931. Connection conn = cpm.getConnectionFromPool();
  1932. PreparedStatement ps = null;
  1933. try {
  1934. ps = conn.prepareStatement("UPDATE players SET lottery=? WHERE playerid=?");
  1935. ps.setInt(1, place);
  1936. ps.setInt(2, playerid);
  1937. ps.executeUpdate();
  1938. } catch (SQLException ex) {
  1939. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1940. } finally {
  1941. try {
  1942. if (ps != null) {
  1943. ps.close();
  1944. conn.commit();
  1945. }
  1946. } catch (Exception e) {
  1947. } finally {
  1948. cpm.returnConnectionToPool(conn);
  1949. }
  1950. }
  1951. }
  1952.  
  1953. public static void loadClans(HashMap<String, Integer> playerIds, HashMap<Integer, Clan> clans) {
  1954. Connection conn = cpm.getConnectionFromPool();
  1955. Statement s = null;
  1956. PreparedStatement psf = null, psi = null;
  1957. try {
  1958. s = conn.createStatement();
  1959. psf = conn.prepareStatement("SELECT friendid, clanrank FROM player_friends WHERE playerid=?");
  1960. psi = conn.prepareStatement("SELECT ignoreid FROM player_ignore WHERE playerid=?");
  1961. ResultSet res = s.executeQuery("SELECT clans.playerid, clanname, username, settings FROM clans INNER JOIN players ON players.playerid = clans.playerid");
  1962. while(res.next()) {
  1963. int id = res.getInt(1), set = res.getInt(4);
  1964.  
  1965. long[] friends = new long[200];
  1966. int[] friendRanks = new int[200];
  1967. psf.setInt(1, id);
  1968. ResultSet r = psf.executeQuery();
  1969. int i = 0;
  1970. while(r.next() && i < 200) {
  1971. friends[i] = r.getLong(1);
  1972. friendRanks[i] = r.getInt(2);
  1973. i++;
  1974. }
  1975. r.close();
  1976. long[] ignores = new long[200];
  1977. psi.setInt(1, id);
  1978. r = psi.executeQuery();
  1979. i = 0;
  1980. while(r.next() && i < 200)
  1981. ignores[i++] = r.getLong(1);
  1982. r.close();
  1983.  
  1984. Clan clan = new Clan(id, res.getString(2), res.getString(3), set%10, set/10%10,
  1985. set/1000%10, set/100%10, set/10000%10, friends, friendRanks, ignores);
  1986.  
  1987. clans.put(id, clan);
  1988. playerIds.put(clan.ownerName, id);
  1989. }
  1990. } catch (SQLException ex) {
  1991. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  1992. } finally {
  1993. try {
  1994. if (s != null) {
  1995. s.close();
  1996. psf.close();
  1997. psi.close();
  1998. conn.commit();
  1999. }
  2000. } catch (Exception e) {
  2001. } finally {
  2002. cpm.returnConnectionToPool(conn);
  2003. }
  2004. }
  2005. }
  2006.  
  2007. public static void saveClan(Clan c) {
  2008. Connection conn = cpm.getConnectionFromPool();
  2009. PreparedStatement ps = null;
  2010. try {
  2011. ps = conn.prepareStatement("CALL addClan(?,?,?);");
  2012. ps.setInt(1, c.owner);
  2013. ps.setString(2, c.name);
  2014. ps.setInt(3, 10000*c.lootShare+1000*c.canKick+100*c.canShareLoot+10*c.canTalk+c.canJoin);
  2015. ps.executeUpdate();
  2016. } catch (SQLException ex) {
  2017. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  2018. } finally {
  2019. try {
  2020. if (ps != null) {
  2021. ps.close();
  2022. conn.commit();
  2023. }
  2024. } catch (Exception e) {
  2025. } finally {
  2026. cpm.returnConnectionToPool(conn);
  2027. }
  2028. }
  2029. }
  2030.  
  2031. public static void deleteClan(int playerid) {
  2032. Connection conn = cpm.getConnectionFromPool();
  2033. PreparedStatement ps = null;
  2034. try {
  2035. ps = conn.prepareStatement("DELETE FROM clans WHERE playerid=?");
  2036. ps.setInt(1, playerid);
  2037. ps.executeUpdate();
  2038. } catch (SQLException ex) {
  2039. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  2040. } finally {
  2041. try {
  2042. if (ps != null) {
  2043. ps.close();
  2044. conn.commit();
  2045. }
  2046. } catch (Exception e) {
  2047. } finally {
  2048. cpm.returnConnectionToPool(conn);
  2049. }
  2050. }
  2051. }
  2052.  
  2053. public static void updateGEOffer(long millis, int playerid, int itemid, int amount, int amountdone, long priceeach, long coins, int items, boolean sell, boolean cancelled) {
  2054. Connection conn = cpm.getConnectionFromPool();
  2055. PreparedStatement ps = null;
  2056. try {
  2057. ps = conn.prepareStatement("CALL UpdateGEOffer(?,?,?,?,?,?,?,?,?,?);");
  2058. ps.setString(1, millisToTimestamp(millis));
  2059. ps.setInt(2, playerid);
  2060. ps.setInt(3, itemid);
  2061. ps.setInt(4, amount);
  2062. ps.setInt(5, amountdone);
  2063. ps.setLong(6, priceeach);
  2064. ps.setLong(7, coins);
  2065. ps.setInt(8, items);
  2066. ps.setBoolean(9, sell);
  2067. ps.setBoolean(10, cancelled);
  2068. ps.executeUpdate();
  2069. } catch (SQLException ex) {
  2070. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  2071. } finally {
  2072. try {
  2073. if (ps != null) {
  2074. ps.close();
  2075. conn.commit();
  2076. }
  2077. } catch (Exception e) {
  2078. } finally {
  2079. cpm.returnConnectionToPool(conn);
  2080. }
  2081. }
  2082. }
  2083.  
  2084. public static void deleteGEOffer(long millis) {
  2085. Connection conn = cpm.getConnectionFromPool();
  2086. Statement s = null;
  2087. try {
  2088. s = conn.createStatement();
  2089. s.executeUpdate("DELETE FROM grand_exchange WHERE timestamp="+millisToTimestamp(millis));
  2090. } catch (SQLException ex) {
  2091. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  2092. } finally {
  2093. try {
  2094. if (s != null) {
  2095. s.close();
  2096. conn.commit();
  2097. }
  2098. } catch (Exception e) {
  2099. } finally {
  2100. cpm.returnConnectionToPool(conn);
  2101. }
  2102. }
  2103. }
  2104.  
  2105. public static void loadAllGEOffers(HashMap<Long, GrandExchangeOffer> offers,
  2106. HashMap<Integer, HashSet<GrandExchangeOffer>> buyOffers,
  2107. HashMap<Integer, HashSet<GrandExchangeOffer>> sellOffers) {
  2108. Connection conn = cpm.getConnectionFromPool();
  2109. Statement s = null;
  2110. try {
  2111. s = conn.createStatement();
  2112. ResultSet res = s.executeQuery("SELECT timestamp, playerid, itemid, amount, amountdone, priceeach, coins, items, sell, cancelled FROM grand_exchange");
  2113. while(res.next()) {
  2114. long id = timestampToMillis(res.getString(1));
  2115. int playerId = res.getInt(2);
  2116. int itemId = res.getInt(3);
  2117. int amount = res.getInt(4);
  2118. int itemsDone = res.getInt(5);
  2119. long priceEach = res.getLong(6);
  2120. long coins = res.getLong(7);
  2121. int items = res.getInt(8);
  2122. boolean sell = res.getBoolean(9);
  2123. boolean cancelled = res.getBoolean(10);
  2124.  
  2125. GrandExchangeOffer offer = new GrandExchangeOffer(id, playerId, itemId, amount, itemsDone, items, priceEach, coins, sell, cancelled);
  2126. offers.put(id, offer);
  2127. //Check if the one-week period has expired
  2128. if(System.currentTimeMillis() - id > 7*24*3600*1000 && !offer.isDone() && !offer.isCancelled())
  2129. offer.cancel();
  2130. else {
  2131. HashMap<Integer, HashSet<GrandExchangeOffer>> map = sell ? sellOffers : buyOffers;
  2132. if(!map.containsKey(itemId))
  2133. map.put(itemId, new HashSet<GrandExchangeOffer>());
  2134. map.get(itemId).add(offer);
  2135. }
  2136. }
  2137. } catch (SQLException ex) {
  2138. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  2139. } finally {
  2140. try {
  2141. if (s != null) {
  2142. s.close();
  2143. conn.commit();
  2144. }
  2145. } catch (Exception e) {
  2146. } finally {
  2147. cpm.returnConnectionToPool(conn);
  2148. }
  2149. }
  2150. }
  2151.  
  2152. public static void loadItems(HashMap<Integer,ItemList> items) {
  2153. Connection conn = cpm.getConnectionFromPool();
  2154. Statement s = null;
  2155. try {
  2156. s = conn.createStatement();
  2157. ResultSet res = s.executeQuery("SELECT items.itemid, name, noted, lowvalue, highvalue, stackable, equipable, att_stab, att_slash, att_crush, att_magic, att_ranged, def_stab, def_slash, def_crush, def_magic, def_ranged, strength, prayer, COALESCE(speed,3000) AS speed FROM items LEFT JOIN items_equipment ON items.itemid = items_equipment.itemid");
  2158. while(res.next())
  2159. items.put(res.getInt(1),
  2160. new ItemList(res.getInt(1),
  2161. res.getString(2),
  2162. res.getBoolean(3),
  2163. res.getLong(4),
  2164. res.getLong(5),
  2165. res.getBoolean(6),
  2166. res.getBoolean(7),
  2167. res.getInt(20),
  2168. res.getBoolean(7) ? new int[]{res.getInt(8),
  2169. res.getInt(9),
  2170. res.getInt(10),
  2171. res.getInt(11),
  2172. res.getInt(12),
  2173. res.getInt(13),
  2174. res.getInt(14),
  2175. res.getInt(15),
  2176. res.getInt(16),
  2177. res.getInt(17),
  2178. res.getInt(18),
  2179. res.getInt(19)}
  2180. : new int[12]));
  2181. } catch (SQLException ex) {
  2182. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  2183. } finally {
  2184. try {
  2185. if (s != null) {
  2186. s.close();
  2187. conn.commit();
  2188. }
  2189. } catch (Exception e) {
  2190. } finally {
  2191. cpm.returnConnectionToPool(conn);
  2192. }
  2193. }
  2194. }
  2195.  
  2196. public static void loadConnectionBansAndMutes(MyHashSet<String> ipbans,
  2197. MyHashSet<String> macbans,
  2198. MyHashSet<String> ipmutes,
  2199. MyHashSet<String> macmutes) {
  2200. Connection conn = cpm.getConnectionFromPool();
  2201. Statement s = null;
  2202. try {
  2203. s = conn.createStatement();
  2204. ResultSet res = s.executeQuery("SELECT DISTINCT INET_NTOA(ip) FROM connection_bans");
  2205. while(res.next())
  2206. ipbans.add(res.getString(1));
  2207. res = s.executeQuery("SELECT DISTINCT INET_NTOA(ip) FROM connection_mutes");
  2208. while(res.next())
  2209. ipmutes.add(res.getString(1));
  2210. res = s.executeQuery("SELECT DISTINCT mac FROM player_macs AS pm INNER JOIN connection_bans ON connection_bans.playerid = pm.playerid INNER JOIN (SELECT playerid, MAX(count) AS max FROM player_macs GROUP BY playerid) AS j ON pm.playerid = j.playerid WHERE count*10 >= max");
  2211. while(res.next())
  2212. {
  2213. if(!res.getString(1).equals("000000000000"))
  2214. macbans.add(res.getString(1));
  2215. }
  2216. res = s.executeQuery("SELECT DISTINCT mac FROM player_macs AS pm INNER JOIN connection_mutes ON connection_mutes.playerid = pm.playerid INNER JOIN (SELECT playerid, MAX(count) AS max FROM player_macs GROUP BY playerid) AS j ON pm.playerid = j.playerid WHERE count*10 >= max");
  2217. while(res.next())
  2218. {
  2219. if(!res.getString(1).equals("000000000000"))
  2220. macmutes.add(res.getString(1));
  2221. }
  2222. } catch (SQLException ex) {
  2223. XLogger.getInstance().log(Level.SEVERE, "Exception", ex);
  2224. } finally {
  2225. try {
  2226. if (s != null) {
  2227. s.close();
  2228. conn.commit();
  2229. }
  2230. } catch (Exception e) {
  2231. } finally {
  2232. cpm.returnConnectionToPool(conn);
  2233. }
  2234. }
  2235. }
  2236.  
  2237. public static String millisToTimestamp(long millis) {
  2238. Date d = new Date(millis);
  2239. return (d.getYear()+1900)+
  2240. (d.getMonth() < 9? "0"+(d.getMonth()+1) : ""+(d.getMonth()+1))+
  2241. (d.getDate() < 10? "0"+d.getDate() : ""+d.getDate())+
  2242. (d.getHours() < 10? "0"+d.getHours() : ""+d.getHours())+
  2243. (d.getMinutes() < 10? "0"+d.getMinutes() : ""+d.getMinutes())+
  2244. (d.getSeconds() < 10? "0"+d.getSeconds() : ""+d.getSeconds())+
  2245. "."+(millis%1000);
  2246. }
  2247.  
  2248. public static long timestampToMillis(String t) {
  2249. return new Date(Integer.parseInt(t.substring(0,4))-1900,
  2250. Integer.parseInt(t.substring(4,6))-1,
  2251. Integer.parseInt(t.substring(6,8)),
  2252. Integer.parseInt(t.substring(8,10)),
  2253. Integer.parseInt(t.substring(10,12)),
  2254. Integer.parseInt(t.substring(12,14)))
  2255. .getTime()+Integer.parseInt(t.substring(15));
  2256. }
  2257.  
  2258. public static String arrayToString(int[] ar, String separator) {
  2259. StringBuilder result = new StringBuilder();
  2260. if (ar.length > 0) {
  2261. result.append(ar[0]);
  2262. for (int i = 1; i < ar.length; i++) {
  2263. result.append(separator);
  2264. result.append(ar[i]);
  2265. }
  2266. }
  2267. return result.toString();
  2268. }
  2269.  
  2270. public static String arrayToString(long[] ar, String separator) {
  2271. StringBuilder result = new StringBuilder();
  2272. if (ar.length > 0) {
  2273. result.append(ar[0]);
  2274. for (int i = 1; i < ar.length; i++) {
  2275. result.append(separator);
  2276. result.append(ar[i]);
  2277. }
  2278. }
  2279. return result.toString();
  2280. }
  2281.  
  2282. public static String arrayToString(boolean[] ar, String separator) {
  2283. StringBuilder result = new StringBuilder();
  2284. if (ar.length > 0) {
  2285. result.append(ar[0]?"1":"0");
  2286. for (int i = 1; i < ar.length; i++) {
  2287. result.append(separator);
  2288. result.append(ar[i]?"1":"0");
  2289. }
  2290. }
  2291. return result.toString();
  2292. }
  2293.  
  2294. /* Unused, maybe later if we stop saving farm info for people who don't use it */
  2295. public static boolean arrayIsEmpty(int[] ar) {
  2296. for(int i : ar)
  2297. if(i != 0)
  2298. return false;
  2299. return true;
  2300. }
  2301.  
  2302. public static boolean arrayIsEmpty(long[] ar) {
  2303. for(long i : ar)
  2304. if(i != 0)
  2305. return false;
  2306. return true;
  2307. }
  2308.  
  2309. public static boolean arrayIsEmpty(boolean[] ar) {
  2310. for(boolean i : ar)
  2311. if(i)
  2312. return false;
  2313. return true;
  2314. }
  2315. }
Add Comment
Please, Sign In to add comment