mirror of
https://github.com/diamante0018/ServerList.git
synced 2025-02-08 20:59:02 +00:00
fix bugs
This commit is contained in:
parent
13ed5f0d77
commit
9a57cc938e
@ -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));
|
||||
|
||||
|
@ -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
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user