So a few people have been asking me to release this:
UUID Banning [Very Secure Ban] so here it is!
Difficulty: 3/10 (just copy and paste, brain needed!)
THIS CURRENTLY ONLY WORKS ON WINDOWS. JUST FINISHING IT UP TO WORK ON MAC!
Lets start off with the client stuff!
****Client****
Ok so first add this java class:
CreateUID.java
Once you got that open up client.java and look for
Code:
private void login(String s, String s1, boolean flag)
now in that method look for:
Code:
stream.writeDWord(signlink.uid);
or if you don't have that look for:
Code:
stream.writeDWord(/*signlink.uid*/999999);
now under that add:
Code:
stream.writeString(CreateUID.generateUID());
now look for:
Code:
if(k == 21)
{
for(int k1 = socketStream.read(); k1 >= 0; k1--)
{
loginMessage1 = "You have only just left another world";
loginMessage2 = "Your profile will be transferred in: " + k1 + " seconds";
drawLoginScreen(true);
try
{
Thread.sleep(1000L);
}
catch(Exception _ex) { }
}
login(s, s1, flag);
return;
}
and under that add:
Code:
if(k == 22) {
loginMessage1 = "Your computer has been UUID banned.";
loginMessage2 = "Please appeal on the forums.";
return;
}
Great now you're done with the client sided part.
Onto server.
****Server****
Open up Connection.java
and near the top you should see:
Code:
public static Collection<String> bannedIps = new ArrayList<String> ();
or something similar. Under those add this:
Code:
public static Collection<String> bannedUid = new ArrayList<String> ();
A few lines under you should see:
Code:
public static void initialize() {
somewhere in that method add:
Then add this:
Code:
public static void unUidBanUser(String name) {
bannedUid.remove(name);
deleteFromFile("./Data/bans/UUIDBans.txt", name);
}
add this method too:
Code:
static String uidForUser = null;
public static void getUidForUser(Client c, String name) {
File file = new File("./Data/characters/" + name + ".txt");
StringBuffer contents = new StringBuffer();
BufferedReader reader = null;
boolean error = false;
try {
reader = new BufferedReader(new FileReader(file));
String text = null;
int line = 0;
int done = 0;
// repeat until all lines is read
while ((text = reader.readLine()) != null && done == 0) {
text = text.trim();
line += 1;
if(line >= 6) {
text = text.trim();
int spot = text.indexOf("=");
String token = text.substring(0, spot);
token = token.trim();
String token2 = text.substring(spot + 1);
token2 = token2.trim();
if(token.equalsIgnoreCase("UUID")) {
uidForUser = token2;
done = 1;
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
error = true;
c.sendMessage("Could not find the character file "+name+".txt");
} catch (IOException e) {
e.printStackTrace();
error = true;
c.sendMessage("A problem occured while trying to read the character file for "+name+".");
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
//System.out.println(macForUser);
if(!error) {
bannedUid.remove(uidForUser);
deleteFromFile("./Data/bans/UUIDBans.txt", uidForUser);
c.sendMessage("@red@Un-UUID banned user "+name+" with the UUID address of "+uidForUser+".");
}
}
Then this:
Code:
public static void addUidToBanList(String UUID) {
bannedUid.add(UUID);
}
then this:
Code:
public static boolean isUidBanned(String UUID) {
return bannedUid.contains(UUID);
}
then this:
Code:
public static void removeUidFromBanList(String UUID) {
bannedUid.remove(UUID);
deleteFromFile("./Data/bans/UUIDBans.txt", UUID);
}
next add this method (it reads all the banned UUIDS on server startup):
Code:
public static void banUid() {
try {
BufferedReader in = new BufferedReader(new FileReader("./Data/bans/UUIDBans.txt"));
String data;
try {
while ((data = in.readLine()) != null) {
addUidToBanList(data);
System.out.println(data);
}
} finally {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
after add this (writes uuids to text file):
Code:
public static void addUidToFile(String UUID) {
try {
BufferedWriter out = new BufferedWriter(new FileWriter("./Data/bans/UUIDBans.txt", true));
try {
out.newLine();
out.write(UUID);
} finally {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
Great now save and close.
Now open up RS2LoginProtocolDecoder.java.
Once in there add this:
Code:
public static String UUID;
next search for:
or something similar. Then under that if statement you should add:
Code:
UUID = readRS2String(rsaBuffer);
if you don't use RSA encryption then add:
Code:
UUID = readRS2String(in);
next search for:
Code:
load(session, uid, name, pass, inC, outC, version);
and change that to:
Code:
load(session, uid, name, pass, inC, outC, version, UUID);
After that look for:
Code:
private synchronized void load(final IoSession session, final int uid, String name, String pass, final ISAACRandomGen inC, ISAACRandomGen outC, int version) {
and change that to:
Code:
private synchronized void load(final IoSession session, final int uid, String name, String pass, final ISAACRandomGen inC, ISAACRandomGen outC, int version, String UUID) {
now in that same method (synchronized void load) look for:
Code:
if(Connection.isNamedBanned(cl.playerName)) {
under that if statement add this:
Code:
if(Connection.isUidBanned(UUID)) {
returnCode = 22;
}
Good now you're done with that.
Now lets open commands.java!
add this command:
Code:
if (playerCommand.startsWith("uidban")) {
try {
String playerToBan = playerCommand.substring(7);
for (int i = 0; i < PlayerHandler.players.length; i++) {
if (PlayerHandler.players[i] != null) {
if (PlayerHandler.players[i].playerName.equalsIgnoreCase(playerToBan) && PlayerHandler.players[i].playerRights != 3) {
Connection.addUidToBanList(PlayerHandler.players[i].UUID);
Connection.addUidToFile(PlayerHandler.players[i].UUID);
if (c.playerRights == 3) {
c.sendMessage("@red@[" + PlayerHandler.players[i].playerName + "] has been UUID Banned with the UUID: " + PlayerHandler.players[i].UUID);
} else {
c.sendMessage("@red@[" + PlayerHandler.players[i].playerName + "] has been UUID Banned.");
}
PlayerHandler.players[i].disconnected = true;
}
}
}
} catch (Exception ignored) {
}
}
and then add this one to unban:
Code:
if(playerCommand.startsWith("unuidban")) {
String player = playerCommand.substring(9);
Connection.getUidForUser(c, player);
}
you also might have to add this import:
Code:
import server.Connection;
Thats all!
If you use this please thank me! Have a nice day
.