Caching of handshake data should work

This commit is contained in:
Adrian Bergqvist 2022-06-05 21:34:39 +02:00
parent 4e4cead245
commit c095c04756
2 changed files with 17 additions and 2 deletions

View File

@ -0,0 +1,9 @@
package org.adde0109.ambassador;
public class ForgeConnectionHandler {
}

View File

@ -28,7 +28,7 @@ public class ForgeHandshakeDataHandler {
public byte[] recivedClientACK;
public byte[] recivedClientModlist;
private static final int PACKET_LENGTH_INDEX = 14;
private static final int PACKET_LENGTH_INDEX = 14; //length of "fml:handshake"+1
private final Logger logger;
private RegisteredServer handshakeServer;
@ -40,14 +40,20 @@ public class ForgeHandshakeDataHandler {
@Subscribe(order = PostOrder.EARLY)
public void onPreLogin(PreLoginEvent event, Continuation continuation) {
if (cachedServerHandshake == null) {
if(handshakeServer.getPlayersConnected().isEmpty()) {
handshakeReceiver receiver = new handshakeReceiver(handshakeServer, logger);
receiver.downloadHandshake().thenAccept((p) -> {
cachedServerHandshake = p;
sendModlist(p.modListPacket,(LoginPhaseConnection) event.getConnection());
sendOther(p.otherPackets,(LoginPhaseConnection) event.getConnection());
continuation.resume();
});
}
else if(cachedServerHandshake != null) {
sendModlist(cachedServerHandshake.modListPacket, (LoginPhaseConnection) event.getConnection());
sendOther(cachedServerHandshake.otherPackets,(LoginPhaseConnection) event.getConnection());
continuation.resume();
}
}
@Subscribe