RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
VoteService.java
1package com.osroyale.game.service;
2
3import com.osroyale.content.achievement.AchievementHandler;
4import com.osroyale.content.achievement.AchievementKey;
5import com.osroyale.game.world.World;
6import com.osroyale.game.world.entity.mob.player.Player;
7import com.osroyale.game.world.items.Item;
8import org.apache.logging.log4j.LogManager;
9import org.apache.logging.log4j.Logger;
10
11import java.sql.*;
12import java.util.concurrent.TimeUnit;
13
37
38public final class VoteService {
39
40 private static final Logger logger = LogManager.getLogger(VoteService.class);
41 private static final String CONNECTION_STRING = "jdbc:mysql://173.82.152.23:3306/osroyjs_vote";
42 private static final String USER = "osroyjs_exo1";
43 private static final String PASS = "3AXbU=W7IfzX";
44 private static final Item REWARD = new Item(7478, 1);
45
46 public static void claimReward(Player player) {
47 if (!player.databaseRequest.elapsed(1, TimeUnit.MINUTES)) {
48 player.dialogueFactory.sendStatement("You can only check our database once every 1 minute!").execute();
49 return;
50 }
51
52 if (!player.inventory.hasCapacityFor(REWARD)) {
53 player.dialogueFactory.sendStatement("Please clear up some inventory spaces before doing this!").execute();
54 return;
55 }
56
57 boolean found = false;
58 player.dialogueFactory.sendStatement("Checking request...").execute();
59 player.databaseRequest.reset();
60
61 try (Connection connection = DriverManager.getConnection(CONNECTION_STRING, USER, PASS);
62 PreparedStatement sta = connection.prepareStatement("SELECT * FROM fx_votes WHERE username = ? AND claimed=0 AND callback_date IS NOT NULL", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)) {
63
64 sta.setString(1, player.getName().replace(" ", "_"));
65
66 try (ResultSet rs = sta.executeQuery()) {
67 while (rs.next()) {
68 String timestamp = rs.getTimestamp("callback_date").toString();
69 String ipAddress = rs.getString("ip_address");
70 int siteId = rs.getInt("site_id");
71
72 found = true;
73 player.inventory.add(REWARD);
74 player.totalVotes += 1;
75 logger.info(String.format("[Vote] Vote claimed by %s. (sid: %d, ip: %s, time: %s)", player.getName(), siteId, ipAddress, timestamp));
76 rs.updateInt("claimed", 1); // do not delete otherwise they can reclaim!
77 rs.updateRow();
78 }
79 }
80
81 if (!found) {
82 player.dialogueFactory.sendStatement("There is no vote reward for you to claim!").execute();
83 } else {
85 player.dialogueFactory.sendStatement("Thank-you for your support, " + player.getName() + "!").execute();
86 World.sendMessage("<col=CF2192>Tarnish: <col=" + player.right.getColor() + ">" + player.getName() + " </col>has just voted! They have voted a total of <col=CF2192>" + player.totalVotes + " </col>times.");
87 }
88 } catch (SQLException ex) {
89 logger.error(String.format("Error claiming vote for player=%s", player.getName()), ex);
90 }
91 }
92
93}
static void activate(Player player, AchievementKey achievement)
final DialogueFactory sendStatement(String... lines)
static void sendMessage(String... messages)
Definition World.java:433