mirror of
https://github.com/diamante0018/ServerList.git
synced 2025-04-19 19:12:54 +00:00
maint: 2023 update (it still works)
This commit is contained in:
parent
bcde93dc07
commit
11befb154e
@ -65,6 +65,7 @@ public class Main {
|
||||
|
||||
var master = new Option("master", "master server mode");
|
||||
var emulator = new Option("emulator", "client emulator mode");
|
||||
var magicOverride = new Option("magic_override", "master server will send all servers to the client");
|
||||
|
||||
var ping = Option.builder("ping")
|
||||
.argName("IP:Port")
|
||||
@ -74,6 +75,7 @@ public class Main {
|
||||
|
||||
options.addOption(master);
|
||||
options.addOption(emulator);
|
||||
options.addOption(magicOverride);
|
||||
options.addOption(ping);
|
||||
|
||||
return options;
|
||||
@ -90,6 +92,7 @@ public class Main {
|
||||
|
||||
var main = new Main();
|
||||
var options = main.createOptions();
|
||||
var magicOverride = false;
|
||||
var ip = new String();
|
||||
|
||||
var parser = new DefaultParser();
|
||||
@ -101,6 +104,10 @@ public class Main {
|
||||
main.setMode(Mode.Emulator);
|
||||
}
|
||||
|
||||
if (line.hasOption("magic_override")) {
|
||||
magicOverride = true;
|
||||
}
|
||||
|
||||
if (line.hasOption("ping")) {
|
||||
ip = line.getOptionValue("ping");
|
||||
}
|
||||
@ -111,6 +118,8 @@ public class Main {
|
||||
|
||||
if (main.getMode() == Mode.Master) {
|
||||
main.createMasterServer();
|
||||
main.getServer().setMagicOverride(magicOverride);
|
||||
System.out.println("Master Server startup");
|
||||
while (running.get() && main.getServer().isValid()) {
|
||||
main.getServer().await();
|
||||
}
|
||||
|
@ -37,6 +37,8 @@ public class MasterServer {
|
||||
|
||||
private ServerSocket socket;
|
||||
|
||||
private boolean magicOverride;
|
||||
|
||||
private boolean valid;
|
||||
|
||||
private final ServerList serverList;
|
||||
@ -68,7 +70,27 @@ public class MasterServer {
|
||||
var versionLE = Arrays.copyOfRange(blob, 4, 8);
|
||||
var versionBE = Utils.longSwap(versionLE);
|
||||
|
||||
if (Utils.isServerMagic(magicBE)) {
|
||||
if (Utils.isClientMagic(magicBE)) {
|
||||
System.out.println("handlePacket: magic is of type client");
|
||||
|
||||
serverList.removeInactive();
|
||||
|
||||
if (this.magicOverride) {
|
||||
versionBE = 0; // Handled in serverList.createResponse
|
||||
}
|
||||
|
||||
var toSend = serverList.createResponse(versionBE);
|
||||
|
||||
try {
|
||||
var out = new DataOutputStream(from.getOutputStream());
|
||||
out.write(toSend);
|
||||
|
||||
// Clean things up
|
||||
out.close();
|
||||
} catch (IOException ex) {
|
||||
System.err.println("handlePacket: IOException in DataOutputStream(from.getOutputStream())");
|
||||
}
|
||||
} else if (Utils.isServerMagic(magicBE)) {
|
||||
System.out.println("handlePacket: magic is of type server");
|
||||
|
||||
if (packetData.size() < 10) {
|
||||
@ -82,26 +104,10 @@ public class MasterServer {
|
||||
|
||||
var server = new Server(from.getInetAddress(), portBE, versionBE);
|
||||
serverList.addServer(server);
|
||||
|
||||
} else if (Utils.isClientMagic(magicBE)) {
|
||||
System.out.println("handlePacket: magic is of type client");
|
||||
|
||||
serverList.removeInactive();
|
||||
var toSend = serverList.createResponse(versionBE);
|
||||
|
||||
try {
|
||||
var out = new DataOutputStream(from.getOutputStream());
|
||||
out.write(toSend);
|
||||
|
||||
// Clean things up
|
||||
out.close();
|
||||
} catch (IOException ex) {
|
||||
System.err.println("handlePacket: IOException in DataOutputStream(from.getOutputStream())");
|
||||
}
|
||||
} else {
|
||||
System.out.println("handlePacket: magic is not recognized");
|
||||
}
|
||||
|
||||
|
||||
serverList.dumpOnlineServers();
|
||||
}
|
||||
|
||||
@ -158,6 +164,10 @@ public class MasterServer {
|
||||
}
|
||||
}
|
||||
|
||||
public void setMagicOverride(boolean magicOverride) {
|
||||
this.magicOverride = magicOverride;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
// Can happen if multiple instances are launched
|
||||
if (socket == null || socket.isClosed()) {
|
||||
|
@ -103,7 +103,8 @@ public class ServerList {
|
||||
while (it.hasNext()) {
|
||||
var server = it.next();
|
||||
// Let's make sure we send the client only servers on the same version
|
||||
if (server.getVersion() == version) {
|
||||
// 2023 Update: They changed the magic so add option to disable this check
|
||||
if (server.getVersion() == version || version == 0) {
|
||||
try {
|
||||
// Let's flip the bytes of this one too
|
||||
var ipBE = server.getAddress().getAddress();
|
||||
|
@ -38,17 +38,19 @@ public class Utils {
|
||||
public static final int PACKET_SERVERT_LEN = 10;
|
||||
|
||||
// (Warning: Remember to take into account endianness)
|
||||
// 'HELP'
|
||||
public static final int SERVER_MAGIC = 1212501072;
|
||||
// 'THEM'
|
||||
public static final int CLIENT_MAGIC = 1414022477;
|
||||
// 2023 Update: They magic was changed, client and server were switched (HELP & THEM)
|
||||
public static final int OLD_SERVER_MAGIC = 1212501072;
|
||||
public static final int NEW_SERVER_MAGIC = 1414022477;
|
||||
|
||||
public static final int OLD_CLIENT_MAGIC = 1414022477;
|
||||
public static final int NEW_CLIENT_MAGIC = 1212501072;
|
||||
|
||||
public static boolean isServerMagic(int magic) {
|
||||
return magic == SERVER_MAGIC;
|
||||
return magic == OLD_SERVER_MAGIC;
|
||||
}
|
||||
|
||||
public static boolean isClientMagic(int magic) {
|
||||
return magic == CLIENT_MAGIC;
|
||||
return magic == OLD_CLIENT_MAGIC;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user