So I'm writing my own voting system, because I was hacked with an exploit from motivote. It votes and rewards just fine, but the problem is, they can vote from the same IP on different accounts. I'm trying to fix this but to no use. My code is below, can anyone see what I'm doing wrong?
Commands.java
Code:
case "vote":
String ip = player.getLastIP();
boolean isInList = false;
for (int x = 0; x < Settings.voteips.size(); x++) {
if (Settings.voteips.get(x).equals(ip) && player.getVoted() == false) {
player.sm("You voted on a different account already, sorry.");
player.setVoted(true);
player.setVotedTime(12 * 60 * 1000 * 60);
return true;
}
}
for (int x = 0; x < Settings.voteips.size(); x++) {
if (Settings.voteips.get(x).equals(ip)) {
isInList = true;
}
}
if (player.getVoted() == true && isInList == true) {
if (player.getVotedTime() > Utils.currentTimeMillis()) {
player.sm("Please remember that you only vote once every 12 hours.");
return true;
} else {
for (int x = 0; x < Settings.voteips.size(); x++) {
if (Settings.voteips.get(x).equals(ip)) {
Settings.voteips.remove(x);
}
}
player.setVoted(false);
}
}
if (player.getVotedTime() < Utils.currentTimeMillis() && player.getVoted() == false) {
//vote stuff
player.setVotedRand(Utils.random(150000) + Utils.currentTimeMillis());
}
return true;
case "claimvote":
if (player.getVotedRand() > Utils.currentTimeMillis()) {
player.sm(
"If you have not voted at all sites, please do so, otherwise allow 1-2 minutes to process.");
return true;
}
if (player.getVoted() == false) {
player.getBank().addItem(995, 20000000, true);
player.getPackets().sendGameMessage("Thanks for voting. Your reward has been added to you bank.");
player.addToVoteTotal(1);
player.setSpins(5 + player.getSpins());
player.sm("You've been awarded 5 spins.");
World.sendWorldMessage("<col=6b00b3>" + player.getUsername().substring(0, 1).toUpperCase()
+ player.getUsername().substring(1, player.getUsername().length())
+ " has just voted for the server, and has voted " + player.getVoteTotal() + " times!",
false);
player.sm("You have voted " + player.getVoteTotal() + " times!");
int random1 = Utils.random(Settings.RandomItems.length);
int itemrandom = Settings.RandomItems[random1];
player.getBank().addItem(itemrandom, 1, true);
player.sm("A " + ItemDefinitions.getItemDefinitions(itemrandom).getName()
+ " has been added to your bank");
World.sendWorldMessage("<col=6b00b3>" + player.getUsername().substring(0, 1).toUpperCase()
+ player.getUsername().substring(1, player.getUsername().length()) + " has just gotten a: "
+ ItemDefinitions.getItemDefinitions(itemrandom).getName() + " for voting!", false);
Settings.voteips.add(player.getLastIP());
player.setVoted(true);
player.setVotedTime(Utils.currentTimeMillis() + (12 * 60 * 60 * 1000));
} else {
player.sm("You cannot claimvote yet.");
}
return true;
Settings.java
Code:
public static ArrayList<String> voteips = new ArrayList<String>();
If you see something like "getVoteRand" or "getVotedTime", these are just setters and getters of a long, and the timers work fine.
Maybe this is the fix?
Don't think so. Just had an idea that it might need to be synchronized
Code:
public static volatile ArrayList<String> voteips = new ArrayList<String>();
also yes I realize they don't actually need to vote, they could just ::vote and wait.