Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mayhem.core.network.mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import com.mayhem.core.util.Utility;
- import com.mayhem.rs2.content.membership.RankHandler;
- import com.mayhem.rs2.entity.World;
- import com.mayhem.rs2.entity.item.Item;
- import com.mayhem.rs2.entity.player.Player;
- import com.mayhem.rs2.entity.player.net.out.impl.SendMessage;
- public class Voting implements Runnable {
- public static final String HOST = "107.180.10.40";
- public static final String USER = "valorps_admin";
- public static final String PASS = "7GUZgAfcw6Ed3BQA";
- public static final String DATABASE = "valorps_vote4654";
- private Player player;
- private Connection conn;
- private Statement stmt;
- public Voting(Player player) {
- this.player = player;
- }
- @Override
- public void run() {
- try {
- if (!connect(HOST, DATABASE, USER, PASS)) {
- return;
- }
- String name = player.getUsername().replace(" ", "_");
- ResultSet rs = executeQuery("SELECT * FROM fx_votes WHERE username='"+name+"' AND claimed=0 AND callback_date IS NOT NULL");
- while (rs.next()) {
- String timestamp = rs.getTimestamp("callback_date").toString();
- String ipAddress = rs.getString("ip_address");
- int siteId = rs.getInt("site_id");
- player.setVotePoints(player.getVotePoints() + 1);
- System.out.println("Vote claimed by "+name+". (sid: "+siteId+", ip: "+ipAddress+", time: "+timestamp+")");
- player.send(new SendMessage("Thank you for voting!"));
- rs.updateInt("claimed", 1); // do not delete otherwise they can reclaim!
- rs.updateRow();
- }
- destroy();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public boolean connect(String host, String database, String user, String pass) {
- try {
- this.conn = DriverManager.getConnection("jdbc:mysql://"+host+":3306/"+database, user, pass);
- return true;
- } catch (SQLException e) {
- System.out.println("Failing connecting to database!");
- return false;
- }
- }
- public void destroy() {
- try {
- conn.close();
- conn = null;
- if (stmt != null) {
- stmt.close();
- stmt = null;
- }
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
- public int executeUpdate(String query) {
- try {
- this.stmt = this.conn.createStatement(1005, 1008);
- int results = stmt.executeUpdate(query);
- return results;
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- return -1;
- }
- public ResultSet executeQuery(String query) {
- try {
- this.stmt = this.conn.createStatement(1005, 1008);
- ResultSet results = stmt.executeQuery(query);
- return results;
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement