Post: [PI] UUID Banning
03-16-2015, 06:00 PM #1
Stunz
Former Staff
(adsbygoogle = window.adsbygoogle || []).push({});
Difficulty: 3/10 (just copy and paste, brain needed!)

Lets start off with the client stuff!

****Client****

Ok so first add this java class:
You must login or register to view this content.

Once you got that open up client.java and look for
    private void login(String s, String s1, boolean flag)


now in that method look for:

    stream.writeDWord(signlink.uid);


or if you don't have that look for:

    stream.writeDWord(/*signlink.uid*/999999);


now under that add:
    stream.writeString(CreateUID.generateUID());


now look for:

    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:

    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:
    public static Collection<String> bannedIps = new ArrayList<String> ();


or something similar. Under those add this:

    public static Collection<String> bannedUid = new ArrayList<String> ();


A few lines under you should see:
    public static void initialize() {


somewhere in that method add:
    banUid();


Then add this:

    public static void unUidBanUser(String name) {
bannedUid.remove(name);
deleteFromFile("./Data/bans/UUIDBans.txt", name);
}


add this method too:

    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:

    public static void addUidToBanList(String UUID) {
bannedUid.add(UUID);
}


then this:

    public static boolean isUidBanned(String UUID) {
return bannedUid.contains(UUID);
}


then this:

    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):

    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):
    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:

    public static String UUID;


next search for:

    if(uid != 


or something similar. Then under that if statement you should add:

    UUID = readRS2String(rsaBuffer);


if you don't use RSA encryption then add:

    UUID = readRS2String(in);


next search for:

    load(session, uid, name, pass, inC, outC, version);


and change that to:

    load(session, uid, name, pass, inC, outC, version, UUID);


After that look for:
    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:
    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:
    if(Connection.isNamedBanned(cl.playerName)) {


under that if statement add this:

    if(Connection.isUidBanned(UUID)) {
returnCode = 22;
}


Good now you're done with that.
Now lets open commands.java!

add this command:
     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 UUISad Awesome " + 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:

     if(playerCommand.startsWith("unuidban")) {
String player = playerCommand.substring(9);
Connection.getUidForUser(c, player);
}


you also might have to add this import:
    import server.Connection;


Ok now onto saving their UUID to their char file.
Open Player.java and add:

    public String UUID = "";


now open Playersave.java and look for:
    characterfile.write("character-rights = ", 0, 19);
characterfile.write(Integer.toString(p.playerRights), 0, Integer.toString(p.playerRights).length());
characterfile.newLine();


and right under that add:
    characterfile.write("UUID = ", 0, 7);
characterfile.write(p.UUID, 0, p.UUID.length());
characterfile.newLine();


Now for the last part. Open up client.java and look for "void initialize" then in that method add:
    UUID = RS2LoginProtocolDecoder.UUID;


Thats all!

If you use this please thank me! Have a nice day :P.

[spoiler=FIX!!]
If you get this error:
    unreported exception Exception; must be caught or dec
lared to be thrown

then search for (in the same method where that error is):
    catch(IOException _ex)
{
loginMessage1 = "";

and under that add:
    } catch (Exception e) {
System.out.println("Error while generating uid. Skipping step.");
e.printStackTrace();
}
(adsbygoogle = window.adsbygoogle || []).push({});

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo