Guest User

Untitled

a guest
Jun 1st, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.80 KB | None | 0 0
  1. package server.util;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.util.Properties;
  8.  
  9. import server.model.players.Client;
  10.  
  11. /**
  12. *
  13. * @author fuck Randon
  14. *
  15. *
  16. */
  17.  
  18. public class VoteHandler {
  19. public static boolean Vote = true;
  20.  
  21. final static int[][] itemData = {{995, 5000000}, {1040, 1}}; // {{itemID, amount}, {itemID, amount}}
  22.  
  23. private static final String DB = "forgotte_vote";
  24. private static final String URL = "forgottenx.com";
  25. private static final String USER = "forgotte_vote";
  26. private static final String PASS = "yeye123";
  27. private static final Properties prop;
  28. static {
  29. prop = new Properties();
  30. prop.put("user", USER);
  31. prop.put("password", PASS);
  32. //prop.put("autoReconnect", "true");
  33. //prop.put("maxReconnects", "4");
  34. }
  35.  
  36. public static Connection conn = null;
  37.  
  38. /**
  39. * Connects to the database
  40. */
  41. public static synchronized void connect() {
  42. try {
  43. Class.forName("com.mysql.jdbc.Driver");
  44. conn = DriverManager.getConnection("jdbc:mysql://159.253.5.162/" + DB, prop);
  45. System.out.println("Vote Handler: Success");
  46. } catch (Exception e) {
  47. System.out.println("Vote Handler Error: "+ e);
  48. System.out.println("Setting vote to false to help not cause anymore errors.");
  49. Vote = false;
  50. }
  51. }
  52.  
  53. public static synchronized Connection getConnection() {
  54. try {
  55. if (conn == null || conn.isClosed()) {
  56. conn = DriverManager.getConnection("jdbc:mysql://159.253.5.162/"+ DB, prop);
  57. }
  58. } catch (SQLException e) {
  59. System.out.println(e);
  60. e.printStackTrace();
  61. Vote = false;
  62. }
  63. return conn;
  64. }
  65.  
  66.  
  67. /**
  68. * giveItems, does a loop to give the player all of the items in the array
  69. */
  70. public static synchronized void giveItems(Client c) {
  71. if(c.getItems().freeSlots() > itemData.length - 1) {
  72. for (int i = 0; i < itemData.length; i++) {
  73. c.getItems().addItem(itemData[i][0], itemData[i][1]);
  74. }
  75. c.sendMessage("Thanks for voting!");
  76. } else {
  77. c.sendMessage("You must have "+ itemData.length +" item slots to get your reward.");
  78. }
  79. }
  80.  
  81. /**
  82. * checkVote, will return true or false depending if the player has voted
  83. */
  84. public static synchronized boolean checkVote(String auth) {
  85. try {
  86. ResultSet res = getConnection().createStatement().executeQuery("SELECT `authcode` FROM `authcodes` WHERE `authcode`= '"+ auth + "' AND `recieved` = 0");
  87. if (res.next())
  88. return true;
  89. else
  90. return false;
  91. } catch (SQLException e) {
  92. e.printStackTrace();
  93. return false;
  94. }
  95. }
  96.  
  97. /**
  98. * Updates the users vote in the database
  99. */
  100. public static synchronized void updateVote(String auth) {
  101. try {
  102. getConnection().createStatement().execute("UPDATE `authcodes` SET `recieved` = 1 WHERE `authcode` = '"+ auth + "'");
  103. } catch (Exception e) {
  104. System.out.println(e);
  105. e.printStackTrace();
  106. }
  107. }
  108. }package server.util;
  109.  
  110. import java.sql.Connection;
  111. import java.sql.DriverManager;
  112. import java.sql.ResultSet;
  113. import java.sql.SQLException;
  114. import java.util.Properties;
  115.  
  116. import server.model.players.Client;
  117.  
  118. /**
  119. *
  120. * @author fuck Randon
  121. *
  122. *
  123. */
  124.  
  125. public class VoteHandler {
  126. public static boolean Vote = true;
  127.  
  128. final static int[][] itemData = {{995, 5000000}, {1040, 1}}; // {{itemID, amount}, {itemID, amount}}
  129.  
  130. private static final String DB = "forgotte_vote";
  131. private static final String URL = "forgottenx.com";
  132. private static final String USER = "forgotte_vote";
  133. private static final String PASS = "yeye123";
  134. private static final Properties prop;
  135. static {
  136. prop = new Properties();
  137. prop.put("user", USER);
  138. prop.put("password", PASS);
  139. //prop.put("autoReconnect", "true");
  140. //prop.put("maxReconnects", "4");
  141. }
  142.  
  143. public static Connection conn = null;
  144.  
  145. /**
  146. * Connects to the database
  147. */
  148. public static synchronized void connect() {
  149. try {
  150. Class.forName("com.mysql.jdbc.Driver");
  151. conn = DriverManager.getConnection("jdbc:mysql://159.253.5.162/" + DB, prop);
  152. System.out.println("Vote Handler: Success");
  153. } catch (Exception e) {
  154. System.out.println("Vote Handler Error: "+ e);
  155. System.out.println("Setting vote to false to help not cause anymore errors.");
  156. Vote = false;
  157. }
  158. }
  159.  
  160. public static synchronized Connection getConnection() {
  161. try {
  162. if (conn == null || conn.isClosed()) {
  163. conn = DriverManager.getConnection("jdbc:mysql://159.253.5.162/"+ DB, prop);
  164. }
  165. } catch (SQLException e) {
  166. System.out.println(e);
  167. e.printStackTrace();
  168. Vote = false;
  169. }
  170. return conn;
  171. }
  172.  
  173.  
  174. /**
  175. * giveItems, does a loop to give the player all of the items in the array
  176. */
  177. public static synchronized void giveItems(Client c) {
  178. if(c.getItems().freeSlots() > itemData.length - 1) {
  179. for (int i = 0; i < itemData.length; i++) {
  180. c.getItems().addItem(itemData[i][0], itemData[i][1]);
  181. }
  182. c.sendMessage("Thanks for voting!");
  183. } else {
  184. c.sendMessage("You must have "+ itemData.length +" item slots to get your reward.");
  185. }
  186. }
  187.  
  188. /**
  189. * checkVote, will return true or false depending if the player has voted
  190. */
  191. public static synchronized boolean checkVote(String auth) {
  192. try {
  193. ResultSet res = getConnection().createStatement().executeQuery("SELECT `authcode` FROM `authcodes` WHERE `authcode`= '"+ auth + "' AND `recieved` = 0");
  194. if (res.next())
  195. return true;
  196. else
  197. return false;
  198. } catch (SQLException e) {
  199. e.printStackTrace();
  200. return false;
  201. }
  202. }
  203.  
  204. /**
  205. * Updates the users vote in the database
  206. */
  207. public static synchronized void updateVote(String auth) {
  208. try {
  209. getConnection().createStatement().execute("UPDATE `authcodes` SET `recieved` = 1 WHERE `authcode` = '"+ auth + "'");
  210. } catch (Exception e) {
  211. System.out.println(e);
  212. e.printStackTrace();
  213. }
  214. }
  215. }
Add Comment
Please, Sign In to add comment