Advertisement
Guest User

Untitled

a guest
Oct 10th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. commands-
  2.  
  3. if (cmd.equals("auth") && input.length() > 0) {
  4.  
  5. boolean b = SQL.hasVoted(c, input,
  6. c.connectedFrom);
  7. if (b || c.voted) {
  8.  
  9. c.lastVoted = System.currentTimeMillis();
  10. c.voted = true;
  11. c.getDH().sendDialogues(525, 251);
  12.  
  13. } else {
  14. c.sendMessage("Auth code not valid.");
  15. return;
  16. }
  17. return;
  18.  
  19. }
  20.  
  21.  
  22. Anywhere - I used a SQL.java class
  23.  
  24. public static boolean hasVoted(Client c, String auth, String ip) {
  25. PreparedStatement ps = null;
  26. try {
  27. Class.forName("com.mysql.jdbc.Driver").newInstance();
  28. con = DriverManager.getConnection("jdbc:mysql://localhost/vote",
  29. "root", "");
  30. ps = con.prepareStatement("SELECT * FROM votes WHERE authcode = ? AND used = '0' LIMIT 1");
  31. ps.setString(1, auth);
  32. ResultSet results = ps.executeQuery();
  33. if (results.next()) {
  34. ps.close();
  35. ps = con.prepareStatement("UPDATE votes SET used = '1' WHERE authcode = ?");
  36. ps.setString(1, auth);
  37. ps.executeUpdate();
  38. return true;
  39. } else {
  40. return false;
  41. }
  42. } catch (Exception e) {
  43. e.printStackTrace();
  44. } finally {
  45. try {
  46. ps.cancel();
  47. con.close();
  48. } catch (SQLException e) {
  49. e.printStackTrace();
  50. }
  51. }
  52. return false;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement