mirror of
https://github.com/2006-Scape/Parabot-Randoms.git
synced 2026-07-04 08:39:24 +00:00
[BUGFIX] Generating random UUID
Also reformatted the code
This commit is contained in:
@@ -2,10 +2,12 @@ package org.parabot.randoms.locopk;
|
||||
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.asm.ASMClassLoader;
|
||||
import org.parabot.environment.OperatingSystem;
|
||||
import org.parabot.environment.randoms.Random;
|
||||
import org.parabot.environment.randoms.RandomType;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author EmmaStone
|
||||
@@ -26,13 +28,15 @@ public class MacAddressFix implements Random {
|
||||
|
||||
Class<?> createUID = classLoader.loadClass("com.locopk.client.rs.CreateUID");
|
||||
|
||||
Field mac = createUID.getDeclaredField("mac");
|
||||
if (OperatingSystem.getOS().equals(OperatingSystem.MAC)) {
|
||||
|
||||
String randomMac = randomMacAddress();
|
||||
Field mac = createUID.getDeclaredField("mac");
|
||||
mac.set(null, randomMacAddress());
|
||||
} else {
|
||||
Field firstID = createUID.getDeclaredField("firstId");
|
||||
|
||||
System.out.println(randomMac);
|
||||
|
||||
mac.set(null, randomMac);
|
||||
firstID.set(null, UUID.randomUUID().toString());
|
||||
}
|
||||
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -55,23 +59,23 @@ public class MacAddressFix implements Random {
|
||||
return RandomType.ON_SERVER_START;
|
||||
}
|
||||
|
||||
private String randomMacAddress(){
|
||||
private String randomMacAddress() {
|
||||
java.util.Random rand = new java.util.Random();
|
||||
byte[] macAddr = new byte[6];
|
||||
rand.nextBytes(macAddr);
|
||||
|
||||
macAddr[0] = (byte)(macAddr[0] & (byte)254); //zeroing last 2 bytes to make it unicast and locally adminstrated
|
||||
macAddr[0] = (byte) (macAddr[0] & (byte) 254); //zeroing last 2 bytes to make it unicast and locally adminstrated
|
||||
|
||||
StringBuilder sb = new StringBuilder(18);
|
||||
for(byte b : macAddr){
|
||||
for (byte b : macAddr) {
|
||||
|
||||
if(sb.length() > 0)
|
||||
if (sb.length() > 0) {
|
||||
sb.append("");
|
||||
}
|
||||
|
||||
sb.append(String.format("%02x", b));
|
||||
}
|
||||
|
||||
|
||||
return sb.toString().toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user