Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. /*package com.Solid.core.network.mysql;
  2.  
  3. import java.sql.ResultSet;
  4. import java.util.concurrent.ExecutorService;
  5. import java.util.concurrent.Executors;
  6.  
  7. import com.Solid.core.util.GameDefinitionLoader;
  8. import com.Solid.core.util.Utility;
  9. import com.Solid.core.util.logger.PlayerLogger;
  10. import com.Solid.rs2.content.dialogue.DialogueManager;
  11. import com.Solid.rs2.content.dialogue.Emotion;
  12. import com.Solid.rs2.entity.player.Player;
  13. */
  14. package com.Solid.core.network.mysql;
  15.  
  16. import java.sql.Connection;
  17. import java.sql.DriverManager;
  18. import java.sql.ResultSet;
  19. import java.sql.SQLException;
  20. import java.sql.Statement;
  21.  
  22. import com.Solid.rs2.entity.player.net.Client;
  23. import com.Solid.rs2.entity.player.net.out.impl.SendMessage;
  24. import com.Solid.rs2.entity.player.Player;
  25.  
  26. /**
  27. * Using this class:
  28. * To call this class, it's best to make a new thread. You can do it below like so:
  29. * new Thread(new Donation(player)).start();
  30. */
  31. public class MembershipRewards implements Runnable {
  32.  
  33. public static final String HOST = "162.218.48.144"; // website ip address
  34. public static final String USER = "solidpsc_store";
  35. public static final String PASS = "caroline";
  36. public static final String DATABASE = "solidpsc_store";
  37.  
  38. private Player player;
  39. private Connection conn;
  40. private Statement stmt;
  41.  
  42. /**
  43. * The constructor
  44. * @param player
  45. */
  46. public MembershipRewards(Player player) {
  47. this.player = player;
  48. }
  49.  
  50. @SuppressWarnings("all")
  51. @Override
  52. public void run() {
  53. try {
  54. if (!connect(HOST, DATABASE, USER, PASS)) {
  55. return;
  56. }
  57.  
  58. String name = player.getUsername().replace("_", " ");
  59. ResultSet rs = executeQuery("SELECT * FROM payments WHERE player_name='"+name+"' AND status='Completed' AND claimed=0");
  60. boolean success = false;
  61.  
  62. while (rs.next()) {
  63. int item_number = rs.getInt("item_number");
  64. double paid = rs.getDouble("amount");
  65. int quantity = rs.getInt("quantity");
  66.  
  67. switch (item_number) {// add products according to their ID in the ACP
  68.  
  69. case 20:
  70. player.getInventory().add(13190, quantity);
  71. success = true;
  72. break;
  73. case 21:
  74. player.getInventory().add(13191, quantity);
  75. success = true;
  76. break;
  77. case 22:
  78. player.getInventory().add(13192, quantity);
  79. success = true;
  80. break;
  81. case 23:
  82. player.getInventory().add(13193, quantity);
  83. success = true;
  84. break;
  85. case 24:
  86. player.getInventory().add(13194, quantity);
  87. success = true;
  88. break;
  89. case 25:
  90. player.getInventory().add(13195, quantity);
  91. success = true;
  92. break;
  93. case 26:
  94. player.getInventory().add(13196, quantity);
  95. success = true;
  96. break;
  97. case 27:
  98. player.getInventory().add(13197, quantity);
  99. success = true;
  100. break;
  101. case 28:
  102. player.getInventory().add(13198, quantity);
  103. success = true;
  104. break;
  105.  
  106. }
  107.  
  108. rs.updateInt("claimed", 1); // do not delete otherwise they can reclaim!
  109. rs.updateRow();
  110. }
  111. /*
  112. * We done?
  113. */
  114. if (success) {
  115. player.send(new SendMessage("Success, you have claimed your purchase."));
  116. } else {
  117. player.send(new SendMessage("Failed to find an unclaimed purchase for you."));
  118. }
  119.  
  120. destroy();
  121. } catch (Exception e) {
  122. e.printStackTrace();
  123. }
  124. }
  125.  
  126. /**
  127. *
  128. * @param host the host ip address or url
  129. * @param database the name of the database
  130. * @param user the user attached to the database
  131. * @param pass the users password
  132. * @return true if connected
  133. */
  134. public boolean connect(String host, String database, String user, String pass) {
  135. try {
  136. this.conn = DriverManager.getConnection("jdbc:mysql://"+host+":3306/"+database, user, pass);
  137. return true;
  138. } catch (SQLException e) {
  139. System.out.println("Failing connecting to database!");
  140. return false;
  141. }
  142. }
  143.  
  144. /**
  145. * Disconnects from the MySQL server and destroy the connection
  146. * and statement instances
  147. */
  148. public void destroy() {
  149. try {
  150. conn.close();
  151. conn = null;
  152. if (stmt != null) {
  153. stmt.close();
  154. stmt = null;
  155. }
  156. } catch(Exception e) {
  157. e.printStackTrace();
  158. }
  159. }
  160.  
  161. /**
  162. * Executes an update query on the database
  163. * @param query
  164. * @see {@link Statement#executeUpdate}
  165. */
  166. public int executeUpdate(String query) {
  167. try {
  168. this.stmt = this.conn.createStatement(1005, 1008);
  169. int results = stmt.executeUpdate(query);
  170. return results;
  171. } catch (SQLException ex) {
  172. ex.printStackTrace();
  173. }
  174. return -1;
  175. }
  176.  
  177. /**
  178. * Executres a query on the database
  179. * @param query
  180. * @see {@link Statement#executeQuery(String)}
  181. * @return the results, never null
  182. */
  183. public ResultSet executeQuery(String query) {
  184. try {
  185. this.stmt = this.conn.createStatement(1005, 1008);
  186. ResultSet results = stmt.executeQuery(query);
  187. return results;
  188. } catch (SQLException ex) {
  189. ex.printStackTrace();
  190. }
  191. return null;
  192. }
  193.  
  194. public static void collectReward(Player player2) {
  195.  
  196. }
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement