Advertisement
Guest User

dffqsdqsd

a guest
Oct 18th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.69 KB | None | 0 0
  1. package database.client;
  2.  
  3. import game.GameServer;
  4.  
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. import world.World;
  9. import world.client.Account;
  10.  
  11. import com.mysql.jdbc.PreparedStatement;
  12.  
  13. import database.ConnectionManager;
  14. import database.ConnectionManager.Database;
  15.  
  16. public class Accounts {
  17.  
  18. private static final String TableName = "accounts";
  19.  
  20. /*********************
  21. * UPDATES *
  22. *********************/
  23. public static void update(Account acc)
  24. {
  25. try
  26. {
  27. String baseQuery = "UPDATE `"+TableName+"` SET " +
  28. "`bankKamas` = ?,"+
  29. "`bank` = ?,"+
  30. "`level` = ?,"+
  31. "`points` = ?,"+
  32. "`pseudo` = ?,"+
  33. "`banned` = ?,"+
  34. "`banned_time` = ?,"+
  35. "`friends` = ?,"+
  36. "`enemy` = ?,"+
  37. "`mute_time` = ?,"+
  38. "`mute_raison` = ?,"+
  39. "`mute_pseudo` = ?,"+
  40. "`warnings` = ?,"+
  41. "`lastWarningDate` = ?,"+
  42. "`points` = ?"+
  43. " WHERE `guid` = ?;";
  44. PreparedStatement p = ConnectionManager.newTransact(baseQuery, ConnectionManager.Get(Database.REALM));
  45.  
  46. p.setLong( 1, acc.bank.getKamas());
  47. p.setString(2, acc.bank.toString());
  48. p.setInt( 3, acc.getGmLevel());
  49. p.setString(4, acc.getPseudo());
  50. p.setInt( 5, (acc.isBanned()?1:0));
  51. p.setLong( 6, acc.getBannedTime());
  52. p.setString(7, acc.parseFriendListToDB());
  53. p.setString(8, acc.parseEnemyListToDB());
  54. p.setLong( 9, acc.getMuteTime());
  55. p.setString(10, acc.getMuteRaison());
  56. p.setString(11, acc.getMutePseudo());
  57. p.setInt( 12, acc.getWarning());
  58. p.setLong( 13, acc.getLastWarningDate());
  59. p.setInt( 14, acc.getPoints());
  60. p.setInt( 15, acc.getGuid());
  61.  
  62. p.executeUpdate();
  63. ConnectionManager.closePreparedStatement(p);
  64. }catch(SQLException e)
  65. {
  66. GameServer.addToLog("SQL ERROR: "+e.getMessage());
  67. e.printStackTrace();
  68. }
  69. }
  70.  
  71. public static void update_points(Account account)
  72. {
  73. String baseQuery = "UPDATE `"+TableName+"` SET `points` = ? WHERE `guid` = ?;";
  74.  
  75. try
  76. {
  77. PreparedStatement p = ConnectionManager.newTransact(baseQuery, ConnectionManager.Get(Database.REALM));
  78.  
  79. p.setInt(1, account.getPoints());
  80. p.setInt(2, account.getGuid());
  81.  
  82. p.executeUpdate();
  83. ConnectionManager.closePreparedStatement(p);
  84. }catch(SQLException e)
  85. {
  86. e.printStackTrace();
  87. }
  88. }
  89.  
  90. public static void update_lastconnection(Account account)
  91. {
  92. String baseQuery = "UPDATE `"+TableName+"` SET " +
  93. "`lastIP` = ?," +
  94. "`lastConnectionDate` = ?" +
  95. " WHERE `guid` = ?;";
  96.  
  97. try
  98. {
  99. PreparedStatement p = ConnectionManager.newTransact(baseQuery, ConnectionManager.Get(Database.REALM));
  100.  
  101. p.setString(1, account.getCurIp());
  102. p.setString(2, account.getLastConnectionDate());
  103. p.setInt(3, account.getGuid());
  104. p.executeUpdate();
  105. ConnectionManager.closePreparedStatement(p);
  106. }catch(SQLException e)
  107. {
  108. e.printStackTrace();
  109. }
  110. }
  111.  
  112. public static void update_vip(Account compte)
  113. {
  114. String baseQuery = "UPDATE `"+TableName+"` SET `vip` = ? WHERE `guid` = ?;";
  115.  
  116. try
  117. {
  118. PreparedStatement p = ConnectionManager.newTransact(baseQuery, ConnectionManager.Get(Database.REALM));
  119.  
  120. p.setInt(1, compte.getVip());
  121. p.setInt(2, compte.getGuid());
  122.  
  123. p.executeUpdate();
  124. ConnectionManager.closePreparedStatement(p);
  125. }catch(SQLException e)
  126. {
  127. e.printStackTrace();
  128. }
  129. }
  130.  
  131. public static void update_logged(int accID, boolean logged)
  132. {
  133. PreparedStatement p;
  134. String query = "UPDATE `"+TableName+"` SET logged=? WHERE `guid`=?;";
  135. try {
  136. p = ConnectionManager.newTransact(query, ConnectionManager.Get(Database.REALM));
  137. p.setInt(1, logged ? 1 : 0);
  138. p.setInt(2, accID);
  139.  
  140. p.execute();
  141. ConnectionManager.closePreparedStatement(p);
  142. } catch (SQLException e) {
  143. e.printStackTrace();
  144. }
  145. }
  146. public static void set_online(int accID) {
  147. update_logged(accID, true);
  148. }
  149. public static void set_offline(int accID) {
  150. update_logged(accID, false);
  151. }
  152.  
  153. public static void reset_logged()
  154. {
  155. PreparedStatement p;
  156. String query = "UPDATE `"+TableName+"` SET logged=0;";
  157. try {
  158. p = ConnectionManager.newTransact(query, ConnectionManager.Get(Database.REALM));
  159.  
  160. p.execute();
  161. ConnectionManager.closePreparedStatement(p);
  162. } catch (SQLException e) {
  163. e.printStackTrace();
  164. }
  165.  
  166. }
  167.  
  168. public static void update_gifts(Account account) {
  169. String baseQuery = "UPDATE `"+TableName+"` SET `cadeau` = 0 WHERE `guid` = ?;";
  170. try {
  171.  
  172. PreparedStatement p = ConnectionManager.newTransact(baseQuery, ConnectionManager.Get(Database.REALM));
  173. p.setInt(1, account.getGuid());
  174. p.executeUpdate();
  175. ConnectionManager.closePreparedStatement(p);
  176.  
  177. } catch (SQLException e) {
  178. e.printStackTrace();
  179. }
  180. }
  181.  
  182.  
  183. /*********************
  184. * SELECT *
  185. *********************/
  186.  
  187. public static Account get(int guid) {
  188.  
  189. Account account = null;
  190.  
  191. try {
  192. ResultSet RS = ConnectionManager.executeQuery("SELECT * FROM "+TableName+" WHERE guid = '"+guid+"';", Database.REALM);
  193. while(RS.next()){
  194. account = new Account(
  195. RS.getInt("guid"),
  196. RS.getString("account").toLowerCase(),
  197. RS.getString("pass"),
  198. RS.getString("pseudo"),
  199. RS.getString("question"),
  200. RS.getString("reponse"),
  201. RS.getInt("level"),
  202. RS.getInt("vip"),
  203. RS.getInt("points"),
  204. (RS.getInt("banned") == 1),
  205. RS.getLong("banned_time"),
  206. RS.getString("lastIP"),
  207. RS.getString("lastConnectionDate"),
  208. RS.getString("bank"),
  209. RS.getInt("bankKamas"),
  210. RS.getString("friends"),
  211. RS.getString("enemy"),
  212. RS.getInt("cadeau"),
  213. RS.getLong("mute_time"),
  214. RS.getString("mute_raison"),
  215. RS.getString("mute_pseudo"),
  216. RS.getInt("warnings"),
  217. RS.getLong("lastWarningDate"),
  218. RS.getInt("last_vote")
  219. );
  220. World.addAccount(account);
  221. World.ReassignAccountToChar(account);
  222. }
  223. RS.getStatement().close();
  224. RS.close();
  225. } catch (Exception e){e.printStackTrace();}
  226.  
  227. return account;
  228. }
  229.  
  230. public static String getLastIP(int guid) {
  231.  
  232. String LastIP = "";
  233.  
  234. try {
  235. ResultSet RS = ConnectionManager.executeQuery("SELECT `lastIP` FROM `"+TableName+"` WHERE `guid` = '"+guid+"';", Database.REALM);
  236. if(RS.first())
  237. LastIP = RS.getString("lastIP");
  238. RS.getStatement().close();
  239. RS.close();
  240. } catch (Exception e){e.printStackTrace();}
  241.  
  242. return LastIP;
  243. }
  244.  
  245. public static boolean isVIP(Account compte)
  246. {
  247. try {
  248. java.sql.PreparedStatement p = ConnectionManager.Get(Database.REALM).prepareStatement("SELECT * FROM `"+TableName+"` WHERE guid = ?;");
  249. p.setInt(1, compte.getGuid());
  250. ResultSet RS = p.executeQuery();
  251.  
  252. while(RS.next())
  253. {
  254. return (RS.getInt("vip") == 1);
  255. }
  256.  
  257. } catch (SQLException e) {
  258. e.printStackTrace();
  259. }
  260. return false;
  261. }
  262.  
  263. public static void load_ByIP(String ip)
  264. {
  265. try
  266. {
  267. ResultSet RS = ConnectionManager.executeQuery("SELECT * from `"+TableName+"` WHERE `lastIP` = '"+ip+"';", Database.REALM);
  268.  
  269. String baseQuery = "UPDATE `"+TableName+"` SET `reload_needed` = 0 WHERE guid = ?;";
  270. PreparedStatement p = ConnectionManager.newTransact(baseQuery, ConnectionManager.Get(Database.REALM));
  271.  
  272. while(RS.next())
  273. {
  274. //Si le compte est deja connecte, on zap
  275. if(World.getCompte(RS.getInt("guid")) != null)
  276. if(World.getCompte(RS.getInt("guid")).isOnline())
  277. continue;
  278.  
  279. Account C = new Account(
  280. RS.getInt("guid"),
  281. RS.getString("account").toLowerCase(),
  282. RS.getString("pass"),
  283. RS.getString("pseudo"),
  284. RS.getString("question"),
  285. RS.getString("reponse"),
  286. RS.getInt("level"),
  287. RS.getInt("vip"),
  288. RS.getInt("points"),
  289. (RS.getInt("banned") == 1),
  290. RS.getLong("banned_time"),
  291. RS.getString("lastIP"),
  292. RS.getString("lastConnectionDate"),
  293. RS.getString("bank"),
  294. RS.getInt("bankKamas"),
  295. RS.getString("friends"),
  296. RS.getString("enemy"),
  297. RS.getInt("cadeau"),
  298. RS.getLong("mute_time"),
  299. RS.getString("mute_raison"),
  300. RS.getString("mute_pseudo"),
  301. RS.getInt("warnings"),
  302. RS.getLong("lastWarningDate"),
  303. RS.getInt("last_vote")
  304. );
  305. World.addAccount(C);
  306. World.ReassignAccountToChar(C);
  307.  
  308. p.setInt(1, RS.getInt("guid"));
  309. p.executeUpdate();
  310. }
  311.  
  312. ConnectionManager.closePreparedStatement(p);
  313. ConnectionManager.closeResultSet(RS);
  314.  
  315. } catch(SQLException e) {
  316. GameServer.addToLog("SQL ERROR: "+e.getMessage());
  317. e.printStackTrace();
  318. }
  319. }
  320.  
  321.  
  322. public static int get_lastvote(int guid) {
  323.  
  324. int lastvote = 0;
  325.  
  326. try {
  327. ResultSet RS = ConnectionManager.executeQuery("SELECT `guid`, `last_vote` FROM `"+TableName+"` WHERE `guid` = '"+guid+"';", Database.REALM);
  328. while(RS.next())
  329. lastvote = RS.getInt("last_vote");
  330. RS.getStatement().close();
  331. RS.close();
  332. } catch (Exception e){e.printStackTrace();}
  333.  
  334. return lastvote;
  335. }
  336.  
  337. public static int getPoints(Account account)
  338. {
  339. try {
  340. java.sql.PreparedStatement p = ConnectionManager.Get(Database.REALM).prepareStatement("SELECT * FROM `"+TableName+"` WHERE guid = ?;");
  341. p.setInt(1, account.getGuid());
  342. ResultSet RS = p.executeQuery();
  343.  
  344. while(RS.next())
  345. {
  346. return (RS.getInt("points"));
  347. }
  348.  
  349. } catch (SQLException e) {
  350. e.printStackTrace();
  351. }
  352. return -1;
  353. }
  354. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement