Jump to content
Sign in to follow this  
arrowzflame

[PI] Timed bans

Recommended Posts

First declare in player.java

[CODE]public long banStart;
public long banEnd;[/CODE]

Add this to playerSave:

[CODE] } else if(token.equals("ban-start")) {
p.banStart = Long.parseLong(token2);
} else if(token.equals("ban-end")) {
p.banEnd = Long.parseLong(token2);[/CODE]

[CODE] characterfile.write("ban-start = ", 0, 12);
characterfile.write(Long.toString(p.banStart), 0, Long.toString(p.banStart).length());
characterfile.newLine();


characterfile.write("ban-end = ", 0, 10);
characterfile.write(Long.toString(p.banEnd), 0, Long.toString(p.banEnd).length());
characterfile.newLine();[/CODE]


Go to commands.java add
[CODE] if (playerCommand.startsWith("timedban") && c.playerRights >= 1 && c.playerRights <= 3) { // use as ::ban name

try {
String[] args = playerCommand.split("-");
if(args.length < 2) {

c.sendMessage("Correct usage: ::ban-playername-time");
return;

}

String playerToBan = args[1];
int secondsToBan = Integer.parseInt(args[2])*1000;

for(int i = 0; i < Config.MAX_PLAYERS; i++) {
if(Server.playerHandler.players[i] != null) {
if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
Player o = Server.playerHandler.players[i];
o.banStart = System.currentTimeMillis();
o.banEnd = System.currentTimeMillis()+ secondsToBan;
o.disconnected = true;
Connection.addNameToBanList(playerToBan);
Connection.addNameToFile(playerToBan);
break;
}
}
}

c.sendMessage("You banned the player: "+playerToBan+" for "+secondsToBan/1000+" seconds");
} catch(Exception e) {
c.sendMessage("Player Must Be Offline.");
}
}[/CODE]

Go to RS2LoginProtocolDecoder find:

[CODE] if(Connection.isNamedBanned(cl.playerName)) {
returnCode = 23;
}[/CODE]

Replace with:

[CODE]
if(Connection.isNamedBanned(cl.playerName)) {
PlayerSave.loadGame(cl, cl.playerName, cl.playerPass);
if(System.currentTimeMillis() < cl.banEnd) {
returnCode = 23;
} else {
cl.banEnd = 0;
Connection.removeNameFromBanList(cl.playerName);
}
}[/CODE]

Go to command.java again find the normal ban command find disconnected = true under it add:

[CODE] Server.playerHandler.players[i].banStart = System.currentTimeMillis();
Server.playerHandler.players[i].banEnd = Long.MAX_VALUE;[/CODE]

::timedban-playername-time No process used.

EDIT: banStart is not used but its just a way of looking when the person was banned.

Share this post


Link to post
Share on other sites
For 1 hour would I do like 1h or 3600 for 1 hour in seconds or what

Share this post


Link to post
Share on other sites
Sign in to follow this  

×