Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*package com.Solid.core.network.mysql;
- import java.sql.ResultSet;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Executors;
- import com.Solid.core.util.GameDefinitionLoader;
- import com.Solid.core.util.Utility;
- import com.Solid.core.util.logger.PlayerLogger;
- import com.Solid.rs2.content.dialogue.DialogueManager;
- import com.Solid.rs2.content.dialogue.Emotion;
- import com.Solid.rs2.entity.player.Player;
- */
- package com.Solid.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.Solid.rs2.entity.player.net.Client;
- import com.Solid.rs2.entity.player.net.out.impl.SendMessage;
- import com.Solid.rs2.entity.player.Player;
- /**
- * Using this class:
- * To call this class, it's best to make a new thread. You can do it below like so:
- * new Thread(new Donation(player)).start();
- */
- public class MembershipRewards implements Runnable {
- public static final String HOST = "162.218.48.144"; // website ip address
- public static final String USER = "solidpsc_store";
- public static final String PASS = "caroline";
- public static final String DATABASE = "solidpsc_store";
- private Player player;
- private Connection conn;
- private Statement stmt;
- /**
- * The constructor
- * @param player
- */
- public MembershipRewards(Player player) {
- this.player = player;
- }
- @SuppressWarnings("all")
- @Override
- public void run() {
- try {
- if (!connect(HOST, DATABASE, USER, PASS)) {
- return;
- }
- String name = player.getUsername().replace("_", " ");
- ResultSet rs = executeQuery("SELECT * FROM payments WHERE player_name='"+name+"' AND status='Completed' AND claimed=0");
- boolean success = false;
- while (rs.next()) {
- int item_number = rs.getInt("item_number");
- double paid = rs.getDouble("amount");
- int quantity = rs.getInt("quantity");
- switch (item_number) {// add products according to their ID in the ACP
- case 20:
- player.getInventory().add(13190, quantity);
- success = true;
- break;
- case 21:
- player.getInventory().add(13191, quantity);
- success = true;
- break;
- case 22:
- player.getInventory().add(13192, quantity);
- success = true;
- break;
- case 23:
- player.getInventory().add(13193, quantity);
- success = true;
- break;
- case 24:
- player.getInventory().add(13194, quantity);
- success = true;
- break;
- case 25:
- player.getInventory().add(13195, quantity);
- success = true;
- break;
- case 26:
- player.getInventory().add(13196, quantity);
- success = true;
- break;
- case 27:
- player.getInventory().add(13197, quantity);
- success = true;
- break;
- case 28:
- player.getInventory().add(13198, quantity);
- success = true;
- break;
- }
- rs.updateInt("claimed", 1); // do not delete otherwise they can reclaim!
- rs.updateRow();
- }
- /*
- * We done?
- */
- if (success) {
- player.send(new SendMessage("Success, you have claimed your purchase."));
- } else {
- player.send(new SendMessage("Failed to find an unclaimed purchase for you."));
- }
- destroy();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- *
- * @param host the host ip address or url
- * @param database the name of the database
- * @param user the user attached to the database
- * @param pass the users password
- * @return true if connected
- */
- 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;
- }
- }
- /**
- * Disconnects from the MySQL server and destroy the connection
- * and statement instances
- */
- public void destroy() {
- try {
- conn.close();
- conn = null;
- if (stmt != null) {
- stmt.close();
- stmt = null;
- }
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * Executes an update query on the database
- * @param query
- * @see {@link Statement#executeUpdate}
- */
- 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;
- }
- /**
- * Executres a query on the database
- * @param query
- * @see {@link Statement#executeQuery(String)}
- * @return the results, never null
- */
- 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;
- }
- public static void collectReward(Player player2) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement