This commit is contained in:
6arelyFuture 2025-01-11 14:39:45 +01:00
parent 13ed5f0d77
commit 9a57cc938e
Signed by: Future
GPG Key ID: F2000F181A4F7C85
2 changed files with 14 additions and 2 deletions

View File

@ -117,13 +117,13 @@ public class MasterServerPinger {
byte[] ipBytesLE = new byte[4];
System.arraycopy(bytes, i, ipBytesLE, 0, 4);
var ipBytesBE = Utils.longSwap(ipBytesLE);
var ipBytesBE = Utils.bytesToInt(ipBytesLE);
var ipAddress = Utils.bytesToIP(ipBytesBE);
var portBytesLE = new byte[2];
System.arraycopy(bytes, i + 4, portBytesLE, 0, 2);
var port = ((portBytesLE[1] & 0xFF) << 8) | (portBytesLE[0] & 0xFF);
var port = Utils.shortSwap(portBytesLE);
System.out.println(String.format("Server: %s:%d", ipAddress, port));

View File

@ -58,6 +58,18 @@ public class Utils {
return magic == OLD_CLIENT_MAGIC;
}
public static int bytesToInt(byte[] bytes) {
if (bytes.length != 4) {
throw new IllegalArgumentException("Array must contain exactly 4 bytes.");
}
// Combine the bytes into an int (assuming the bytes are in Big-Endian order)
int result = ((bytes[0] & 0xFF) << 24) | ((bytes[1] & 0xFF) << 16)
| ((bytes[2] & 0xFF) << 8) | (bytes[3] & 0xFF);
return result;
}
/**
* Flips the array around
*