Advertisement
Guest User

Untitled

a guest
Feb 21st, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. package server.util.sql;
  2. import java.sql.ResultSet;
  3. import java.sql.SQLException;
  4.  
  5. import server.game.player.Player;
  6. import server.game.player.Rights;
  7.  
  8. public class Donation implements Runnable {
  9.  
  10. public static void main(String[] args) {
  11. }
  12.  
  13. public Donation(String username) {
  14. }
  15.  
  16. public static final String HOST_ADDRESS = "107.180.51.240";
  17. public static final String USERNAME = "User";
  18. public static final String PASSWORD = "Pass";
  19. public static final String DATABASE = "Db";
  20.  
  21. private Player player;
  22.  
  23. @Override
  24. public void run() {
  25. try {
  26. Database db = new Database(HOST_ADDRESS, USERNAME, PASSWORD, DATABASE);
  27.  
  28. if (!db.init()) {
  29. System.err.println("[Donation] Failed to connect to database!");
  30. return;
  31. }
  32.  
  33.  
  34. String name = player.getUsername().replace("_", " ");
  35. ResultSet rs = db.executeQuery("SELECT * FROM payments WHERE player_name='"+name+"' AND claimed=0");
  36.  
  37. while(rs.next()) {
  38. String item_name = rs.getString("item_name");
  39. int item_number = rs.getInt("item_number");
  40. double amount = rs.getDouble("amount");
  41. int quantity = rs.getInt("quantity");
  42.  
  43. ResultSet result = db.executeQuery("SELECT * FROM products WHERE item_id="+item_number+" LIMIT 1");
  44.  
  45. while(result.next()) {
  46.  
  47. double item_price = result.getDouble("item_price");
  48.  
  49. if (result == null
  50. || !result.getString("item_name").equalsIgnoreCase(item_name)
  51. || amount/item_price != quantity
  52. || quantity < 1 || quantity > Integer.MAX_VALUE) {
  53. System.out.println("[Donation] Invalid purchase for "+name+" (item: "+item_name+", id: "+item_number+")");
  54. continue;
  55. }
  56. }
  57.  
  58. handleItems(item_number);
  59. rs.updateInt("claimed", 1);
  60. rs.updateRow();
  61. }
  62.  
  63. db.destroyAll();
  64. } catch (Exception e) {
  65. e.printStackTrace();
  66. }
  67. }
  68.  
  69. public void handleItems(int productId) throws SQLException {
  70. Database db = new Database(HOST_ADDRESS, USERNAME, PASSWORD, DATABASE);
  71.  
  72. if (!db.init()) {
  73. System.err.println("[Donation] Failed to connect to database!");
  74. return;
  75. }
  76.  
  77.  
  78. String name = player.getUsername().replace("_", " ");
  79. ResultSet rs = db.executeQuery("SELECT * FROM payments WHERE player_name='"+name+"' AND claimed=0");
  80.  
  81. while(rs.next()) {
  82. int quantity = rs.getInt("quantity");
  83. switch(productId) {
  84. case 12:
  85. player.sendGameMessage("<shad=cc0ff><img=1>You Have Recieved Your donation! Thank you for your support!<img=1>");
  86. player.setRights(Rights.ELITE);
  87. break;
  88. case 13:
  89. player.sendGameMessage("<shad=cc0ff><img=1>You Have Recieved Your donation! Thank you for your support!<img=1>");
  90. player.setRights(Rights.MEGA);
  91. break;
  92. case 14:
  93. player.sendGameMessage("<shad=cc0ff><img=1>You Have Recieved Your donation! Thank you for your support!<img=1>");
  94. player.setRights(Rights.ULTRA);
  95. break;
  96. case 15:
  97. player.sendGameMessage("<shad=cc0ff><img=1>You Have Recieved Your donation! Thank you for your support!<img=1>");
  98. player.setRights(Rights.SPONSOR);
  99. break;
  100. case 16:
  101. player.sendGameMessage("<shad=cc0ff><img=1>You Have Recieved Your donation! Thank you for your support!<img=1>");
  102. player.getItems().addItem(4067, 1*quantity);
  103. break;
  104. case 17:
  105. player.sendGameMessage("<shad=cc0ff><img=1>You Have Recieved Your donation! Thank you for your support!<img=1>");
  106. player.getItems().addItem(995, 5000000*quantity);
  107. break;
  108. case 18:
  109. player.sendGameMessage("<shad=cc0ff><img=1>You Have Recieved Your donation! Thank you for your support!<img=1>");
  110. player.setRights(Rights.DONATOR);
  111. break;
  112. }
  113. }
  114. }
  115.  
  116. public Donation(Player player) {
  117. this.player = player;
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement