Guest User

Untitled

a guest
Aug 7th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 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. import server.model.players.packets.Commands;
  9. import server.Config;
  10. import server.Server;
  11. import server.model.players.PlayerSave;
  12. import server.model.players.Player;
  13. import server.model.players.Client;
  14. import server.model.players.PacketType;
  15. import server.model.players.PlayerHandler;
  16. import server.util.Misc;
  17. import server.model.players.CombatAssistant;
  18. import server.model.players.skills.Slayer;
  19. import server.model.items.ItemAssistant;
  20. import server.util.VoteHandler;
  21.  
  22. import server.model.players.Client;
  23.  
  24. /**
  25. *
  26. * @author Rag3
  27. *
  28. *
  29. */
  30.  
  31. public class VoteHandler {
  32. public static boolean Vote = true;
  33.  
  34. final static int[][] itemData = {{995, 15000000}}; // {{itemID, amount}, {itemID, amount}}
  35.  
  36. private static final String DB = "leon_shawnvote";
  37. private static final String URL = "184.173.210.64";
  38. private static final String USER = "leon_shawnvote";
  39. private static final String PASS = "shawn123";
  40. private static final Properties prop;
  41. static {
  42. prop = new Properties();
  43. prop.put("user", USER);
  44. prop.put("password", PASS);
  45. //prop.put("autoReconnect", "true");
  46. //prop.put("maxReconnects", "4");
  47. }
  48.  
  49. public static Connection conn = null;
  50.  
  51. /**
  52. * Connects to the database
  53. */
  54. public static synchronized void connect() {
  55. try {
  56. Class.forName("com.mysql.jdbc.Driver");
  57. conn = DriverManager.getConnection("jdbc:mysql://184.173.210.64/" + DB, prop);
  58. System.out.println("Vote Handler: Success");
  59. } catch (Exception e) {
  60. System.out.println("Vote Handler Error: "+ e);
  61. System.out.println("Setting vote to false to help not cause anymore errors.");
  62. Vote = false;
  63. }
  64. }
  65.  
  66. public static synchronized Connection getConnection() {
  67. try {
  68. if (conn == null || conn.isClosed()) {
  69. conn = DriverManager.getConnection("jdbc:mysql://184.173.210.64/"+ DB, prop);
  70. }
  71. } catch (SQLException e) {
  72. System.out.println(e);
  73. e.printStackTrace();
  74. Vote = false;
  75. }
  76. return conn;
  77. }
  78.  
  79.  
  80. /**
  81. * giveItems, does a loop to give the player all of the items in the array
  82. */
  83. public static synchronized void giveItems(Client c) {
  84. c.votePoints += 1;
  85. if(c.getItems().freeSlots() > itemData.length - 1) {
  86. for (int i = 0; i < itemData.length; i++) {
  87. c.getItems().addItem(itemData[i][0], itemData[i][1]);
  88. }
  89. for (int j = 0; j < Server.playerHandler.players.length; j++) {
  90. if (Server.playerHandler.players[j] != null) {
  91. Client c2 = (Client)Server.playerHandler.players[j];
  92. c2.sendMessage("[<col=16711680>Vote Handler</col>]<col=0>" +c.playerName+" has just been rewarded for voting!</col>");
  93. }
  94. }
  95. c.sendMessage("Thanks for voting!");
  96. } else {
  97. c.sendMessage("You must have "+ itemData.length +" item slots to get your reward.");
  98. }
  99. }
  100.  
  101. /**
  102. * checkVote, will return true or false depending if the player has voted
  103. */
  104. public static synchronized boolean checkVote(String auth) {
  105. try {
  106. ResultSet res = getConnection().createStatement().executeQuery("SELECT `authcode` FROM `votes` WHERE `authcode`= '"+ Commands.authcode + "' AND `used` = 0");
  107. if (res.next())
  108. return true;
  109. else
  110. return false;
  111. } catch (SQLException e) {
  112. e.printStackTrace();
  113. return false;
  114. }
  115. }
  116.  
  117. /**
  118. * Updates the users vote in the database
  119. */
  120. public static synchronized void updateVote(String auth) {
  121. try {
  122. getConnection().createStatement().execute("UPDATE `votes` SET `used` = 1 WHERE `authcode` = '"+ Commands.authcode + "'");
  123. } catch (Exception e) {
  124. System.out.println(e);
  125. e.printStackTrace();
  126. }
  127. }
  128. }
Add Comment
Please, Sign In to add comment