Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- commands-
- if (cmd.equals("auth") && input.length() > 0) {
- boolean b = SQL.hasVoted(c, input,
- c.connectedFrom);
- if (b || c.voted) {
- c.lastVoted = System.currentTimeMillis();
- c.voted = true;
- c.getDH().sendDialogues(525, 251);
- } else {
- c.sendMessage("Auth code not valid.");
- return;
- }
- return;
- }
- Anywhere - I used a SQL.java class
- public static boolean hasVoted(Client c, String auth, String ip) {
- PreparedStatement ps = null;
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- con = DriverManager.getConnection("jdbc:mysql://localhost/vote",
- "root", "");
- ps = con.prepareStatement("SELECT * FROM votes WHERE authcode = ? AND used = '0' LIMIT 1");
- ps.setString(1, auth);
- ResultSet results = ps.executeQuery();
- if (results.next()) {
- ps.close();
- ps = con.prepareStatement("UPDATE votes SET used = '1' WHERE authcode = ?");
- ps.setString(1, auth);
- ps.executeUpdate();
- return true;
- } else {
- return false;
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- ps.cancel();
- con.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement