diff --git a/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/EaglerSPClient.java b/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/EaglerSPClient.java index f31b8e7..b913b41 100644 --- a/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/EaglerSPClient.java +++ b/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/EaglerSPClient.java @@ -35,13 +35,13 @@ public class EaglerSPClient { try { this.socket.send(IPacket.writePacket(packet)); }catch(IOException ex) { - EaglerSPRelay.logger.debug("Error sending data to {}", this.socket.getAttachment()); + EaglerSPRelay.logger.debug("Error sending data to {}", (String) this.socket.getAttachment()); EaglerSPRelay.logger.debug(ex); disconnect(IPacketFEDisconnectClient.TYPE_INTERNAL_ERROR, "Internal Server Error"); this.socket.close(); } }else { - EaglerSPRelay.logger.debug("WARNING: Tried to send data to {} after the connection closed.", this.socket.getAttachment()); + EaglerSPRelay.logger.debug("WARNING: Tried to send data to {} after the connection closed.", (String) this.socket.getAttachment()); } } @@ -50,21 +50,21 @@ public class EaglerSPClient { if(LoginState.assertEquals(this, LoginState.INIT)) { state = LoginState.SENT_ICE_CANDIDATE; server.handleClientICECandidate(this, (IPacket03ICECandidate)packet); - EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x03: ICECandidate", socket.getAttachment()); + EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x03: ICECandidate", (String) socket.getAttachment()); } return true; }else if(packet instanceof IPacket04Description) { if(LoginState.assertEquals(this, LoginState.RECIEVED_ICE_CANIDATE)) { state = LoginState.SENT_DESCRIPTION; server.handleClientDescription(this, (IPacket04Description)packet); - EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x04: Description", socket.getAttachment()); + EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x04: Description", (String) socket.getAttachment()); } return true; }else if(packet instanceof IPacket05ClientSuccess) { if(LoginState.assertEquals(this, LoginState.RECIEVED_DESCRIPTION)) { state = LoginState.FINISHED; server.handleClientSuccess(this, (IPacket05ClientSuccess)packet); - EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x05: ClientSuccess", socket.getAttachment()); + EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x05: ClientSuccess", (String) socket.getAttachment()); disconnect(IPacketFEDisconnectClient.TYPE_FINISHED_SUCCESS, "Successful connection"); } return true; @@ -72,7 +72,7 @@ public class EaglerSPClient { if(LoginState.assertEquals(this, LoginState.RECIEVED_DESCRIPTION)) { state = LoginState.FINISHED; server.handleClientFailure(this, (IPacket06ClientFailure)packet); - EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x05: ClientFailure", socket.getAttachment()); + EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x05: ClientFailure", (String) socket.getAttachment()); disconnect(IPacketFEDisconnectClient.TYPE_FINISHED_FAILED, "Failed connection"); } return true; @@ -103,7 +103,7 @@ public class EaglerSPClient { send(pkt); socket.close(); } - EaglerSPRelay.logger.debug("[{}][Relay -> Client] PKT 0xFE: #{} {}", socket.getAttachment(), code, reason); + EaglerSPRelay.logger.debug("[{}][Relay -> Client] PKT 0xFE: #{} {}", (String) socket.getAttachment(), code, reason); } public static final int clientCodeLength = 16; diff --git a/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/EaglerSPRelay.java b/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/EaglerSPRelay.java index 16f8b3b..45d2ba4 100644 --- a/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/EaglerSPRelay.java +++ b/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/EaglerSPRelay.java @@ -179,7 +179,7 @@ public class EaglerSPRelay extends WebSocketServer { } if(totalCons >= config.getConnectionsPerIP()) { - logger.debug("[{}]: Too many connections are open on this address", arg0.getAttachment()); + logger.debug("[{}]: Too many connections are open on this address", (String) arg0.getAttachment()); arg0.send(IPacketFEDisconnectClient.ratelimitPacketTooMany); arg0.close(); return; @@ -208,7 +208,7 @@ public class EaglerSPRelay extends WebSocketServer { IPacket00Handshake ipkt = (IPacket00Handshake)pkt; if(ipkt.connectionVersion != Constants.protocolVersion) { logger.debug("[{}]: Connected with unsupported protocol version: {} (supported " - + "version: {})", arg0.getAttachment(), ipkt.connectionVersion, Constants.protocolVersion); + + "version: {})", (String) arg0.getAttachment(), ipkt.connectionVersion, Constants.protocolVersion); if(ipkt.connectionVersion < Constants.protocolVersion) { arg0.send(IPacket.writePacket(new IPacketFFErrorCode(IPacketFFErrorCode.TYPE_PROTOCOL_VERSION, "Outdated Client! (v" + Constants.protocolVersion + " req)"))); @@ -221,21 +221,21 @@ public class EaglerSPRelay extends WebSocketServer { } if(ipkt.connectionType == 0x01) { if(!rateLimit(worldRateLimiter, arg0, waiting.address)) { - logger.debug("[{}]: Got world ratelimited", arg0.getAttachment()); + logger.debug("[{}]: Got world ratelimited", (String) arg0.getAttachment()); return; } synchronized(serverAddressSets) { List lst = serverAddressSets.get(waiting.address); if(lst != null) { if(lst.size() >= config.getWorldsPerIP()) { - logger.debug("[{}]: Too many worlds are open on this address", arg0.getAttachment()); + logger.debug("[{}]: Too many worlds are open on this address", (String) arg0.getAttachment()); arg0.send(IPacketFEDisconnectClient.ratelimitPacketTooMany); arg0.close(); return; } } } - logger.debug("[{}]: Connected as a server", arg0.getAttachment()); + logger.debug("[{}]: Connected as a server", (String) arg0.getAttachment()); EaglerSPServer srv; synchronized(serverCodes) { int j = 0; @@ -243,7 +243,7 @@ public class EaglerSPRelay extends WebSocketServer { do { if(++j > 100) { logger.error("Error: relay is running out of codes!"); - logger.error("Closing connection to {}", arg0.getAttachment()); + logger.error("Closing connection to {}", (String) arg0.getAttachment()); arg0.send(IPacket.writePacket(new IPacketFFErrorCode(IPacketFFErrorCode.TYPE_INTERNAL_ERROR, "Internal Server Error"))); arg0.close(); @@ -255,7 +255,7 @@ public class EaglerSPRelay extends WebSocketServer { serverCodes.put(code, srv); ipkt.connectionCode = code; arg0.send(IPacket.writePacket(ipkt)); - logger.debug("[{}][Relay -> Server] PKT 0x00: Assign join code: {}", arg0.getAttachment(), code); + logger.debug("[{}][Relay -> Server] PKT 0x00: Assign join code: {}", (String) arg0.getAttachment(), code); } synchronized(serverConnections) { serverConnections.put(arg0, srv); @@ -269,15 +269,15 @@ public class EaglerSPRelay extends WebSocketServer { lst.add(srv); } srv.send(new IPacket01ICEServers(EaglerSPRelayConfigRelayList.relayServers)); - logger.debug("[{}][Relay -> Server] PKT 0x01: Send ICE server list to server", arg0.getAttachment()); + logger.debug("[{}][Relay -> Server] PKT 0x01: Send ICE server list to server", (String) arg0.getAttachment()); }else { if(!rateLimit(pingRateLimiter, arg0, waiting.address)) { - logger.debug("[{}]: Got ping ratelimited", arg0.getAttachment()); + logger.debug("[{}]: Got ping ratelimited", (String) arg0.getAttachment()); return; } if(ipkt.connectionType == 0x02) { String code = ipkt.connectionCode; - logger.debug("[{}]: Connected as a client, requested server code: {}", arg0.getAttachment(), code); + logger.debug("[{}]: Connected as a client, requested server code: {}", (String) arg0.getAttachment(), code); if(code.length() != config.getCodeLength()) { logger.debug("The code '{}' is invalid because it's the wrong length, disconnecting"); arg0.send(IPacket.writePacket(new IPacketFFErrorCode(IPacketFFErrorCode.TYPE_CODE_LENGTH, @@ -319,18 +319,18 @@ public class EaglerSPRelay extends WebSocketServer { lst.add(cl); } cl.send(new IPacket01ICEServers(EaglerSPRelayConfigRelayList.relayServers)); - logger.debug("[{}][Relay -> Client] PKT 0x01: Send ICE server list to client", arg0.getAttachment()); + logger.debug("[{}][Relay -> Client] PKT 0x01: Send ICE server list to client", (String) arg0.getAttachment()); } }else if(ipkt.connectionType == 0x03) { - logger.debug("[{}]: Pinging the server", arg0.getAttachment()); + logger.debug("[{}]: Pinging the server", (String) arg0.getAttachment()); arg0.send(IPacket.writePacket(new IPacket69Pong(Constants.protocolVersion, config.getComment(), Constants.versionBrand))); arg0.close(); }else if(ipkt.connectionType == 0x04) { - logger.debug("[{}]: Polling the server for other worlds", arg0.getAttachment()); + logger.debug("[{}]: Polling the server for other worlds", (String) arg0.getAttachment()); arg0.send(IPacket.writePacket(new IPacket07LocalWorlds(getLocalWorlds(waiting.address)))); arg0.close(); }else { - logger.debug("[{}]: Unknown connection type: {}", arg0.getAttachment(), ipkt.connectionType); + logger.debug("[{}]: Unknown connection type: {}", (String) arg0.getAttachment(), ipkt.connectionType); arg0.send(IPacket.writePacket(new IPacketFFErrorCode(IPacketFFErrorCode.TYPE_ILLEGAL_OPERATION, "Unexpected Init Packet"))); arg0.close(); @@ -338,7 +338,7 @@ public class EaglerSPRelay extends WebSocketServer { } }else { logger.debug("[{}]: Pending connection did not send a 0x00 packet to identify " - + "as a client or server", arg0.getAttachment()); + + "as a client or server", (String) arg0.getAttachment()); arg0.send(IPacket.writePacket(new IPacketFFErrorCode(IPacketFFErrorCode.TYPE_ILLEGAL_OPERATION, "Unexpected Init Packet"))); arg0.close(); @@ -350,7 +350,7 @@ public class EaglerSPRelay extends WebSocketServer { } if(srv != null) { if(!srv.handle(pkt)) { - logger.debug("[{}]: Server sent invalid packet: {}", arg0.getAttachment(), pkt.getClass().getSimpleName()); + logger.debug("[{}]: Server sent invalid packet: {}", (String) arg0.getAttachment(), pkt.getClass().getSimpleName()); arg0.send(IPacket.writePacket(new IPacketFFErrorCode(IPacketFFErrorCode.TYPE_INVALID_PACKET, "Invalid Packet Recieved"))); arg0.close(); @@ -362,13 +362,13 @@ public class EaglerSPRelay extends WebSocketServer { } if(cl != null) { if(cl.handle(pkt)) { - logger.debug("[{}]: Client sent invalid packet: {}", arg0.getAttachment(), pkt.getClass().getSimpleName()); + logger.debug("[{}]: Client sent invalid packet: {}", (String) arg0.getAttachment(), pkt.getClass().getSimpleName()); arg0.send(IPacket.writePacket(new IPacketFFErrorCode(IPacketFFErrorCode.TYPE_INVALID_PACKET, "Invalid Packet Recieved"))); arg0.close(); } }else { - logger.debug("[{}]: Connection has no client/server attached to it!", arg0.getAttachment()); + logger.debug("[{}]: Connection has no client/server attached to it!", (String) arg0.getAttachment()); arg0.send(IPacket.writePacket(new IPacketFFErrorCode(IPacketFFErrorCode.TYPE_ILLEGAL_OPERATION, "Internal Server Error"))); arg0.close(); @@ -376,14 +376,14 @@ public class EaglerSPRelay extends WebSocketServer { } } }catch(Throwable t) { - logger.error("[{}]: Failed to handle binary frame: {}", arg0.getAttachment(), t); + logger.error("[{}]: Failed to handle binary frame: {}", (String) arg0.getAttachment(), t); arg0.close(); } } @Override public void onMessage(WebSocket arg0, String arg1) { - logger.debug("[{}]: Sent a text frame, disconnecting", arg0.getAttachment()); + logger.debug("[{}]: Sent a text frame, disconnecting", (String) arg0.getAttachment()); arg0.close(); } @@ -394,7 +394,7 @@ public class EaglerSPRelay extends WebSocketServer { srv = serverConnections.remove(arg0); } if(srv != null) { - logger.debug("[{}]: Server closed, code: {}", arg0.getAttachment(), srv.code); + logger.debug("[{}]: Server closed, code: {}", (String) arg0.getAttachment(), srv.code); synchronized(serverCodes) { serverCodes.remove(srv.code); } @@ -415,7 +415,7 @@ public class EaglerSPRelay extends WebSocketServer { while(itr.hasNext()) { EaglerSPClient cl = itr.next(); if(cl.server == srv) { - logger.debug("[{}]: Disconnecting client: {} (id: ", cl.socket.getAttachment(), cl.id); + logger.debug("[{}]: Disconnecting client: {} (id: ", (String) cl.socket.getAttachment(), cl.id); cl.socket.close(); } } @@ -434,20 +434,20 @@ public class EaglerSPRelay extends WebSocketServer { } } if(cl != null) { - logger.debug("[{}]: Client closed, id: {}", arg0.getAttachment(), cl.id); + logger.debug("[{}]: Client closed, id: {}", (String) arg0.getAttachment(), cl.id); synchronized(clientIds) { clientIds.remove(cl.id); } cl.server.handleClientDisconnect(cl); }else { - logger.debug("[{}]: Connection Closed: {} ", arg0.getAttachment()); + logger.debug("[{}]: Connection Closed: {} ", (String) arg0.getAttachment()); } } } @Override public void onError(WebSocket arg0, Exception arg1) { - logger.error("[{}]: Exception thrown: {}", arg0.getAttachment(), arg1.toString()); + logger.error("[{}]: Exception thrown: {}", (String) arg0.getAttachment(), arg1.toString()); logger.debug(arg1); arg0.close(); } diff --git a/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/EaglerSPServer.java b/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/EaglerSPServer.java index 108a47d..8bc8bde 100644 --- a/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/EaglerSPServer.java +++ b/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/EaglerSPServer.java @@ -70,7 +70,7 @@ public class EaglerSPServer { if(LoginState.assertEquals(cl, LoginState.SENT_ICE_CANDIDATE)) { cl.state = LoginState.RECIEVED_ICE_CANIDATE; cl.handleServerICECandidate(packet); - EaglerSPRelay.logger.debug("[{}][Server -> Relay -> Client] PKT 0x03: ICECandidate", cl.socket.getAttachment()); + EaglerSPRelay.logger.debug("[{}][Server -> Relay -> Client] PKT 0x03: ICECandidate", (String) cl.socket.getAttachment()); } }else { this.socket.send(IPacket.writePacket(new IPacketFFErrorCode(IPacketFFErrorCode.TYPE_UNKNOWN_CLIENT, @@ -84,7 +84,7 @@ public class EaglerSPServer { if(LoginState.assertEquals(cl, LoginState.SENT_DESCRIPTION)) { cl.state = LoginState.RECIEVED_DESCRIPTION; cl.handleServerDescription(packet); - EaglerSPRelay.logger.debug("[{}][Server -> Relay -> Client] PKT 0x04: Description", cl.socket.getAttachment()); + EaglerSPRelay.logger.debug("[{}][Server -> Relay -> Client] PKT 0x04: Description", (String) cl.socket.getAttachment()); } }else { this.socket.send(IPacket.writePacket(new IPacketFFErrorCode(IPacketFFErrorCode.TYPE_UNKNOWN_CLIENT, @@ -96,7 +96,7 @@ public class EaglerSPServer { EaglerSPClient cl = clients.get(packet.clientId); if(cl != null) { cl.handleServerDisconnectClient(packet); - EaglerSPRelay.logger.debug("[{}][Server -> Relay -> Client] PKT 0xFE: Disconnect: {}: {}", cl.socket.getAttachment(), + EaglerSPRelay.logger.debug("[{}][Server -> Relay -> Client] PKT 0xFE: Disconnect: {}: {}", (String) cl.socket.getAttachment(), packet.code, packet.reason); }else { this.socket.send(IPacket.writePacket(new IPacketFFErrorCode(IPacketFFErrorCode.TYPE_UNKNOWN_CLIENT, diff --git a/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/LoginState.java b/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/LoginState.java index e8b186f..c494689 100644 --- a/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/LoginState.java +++ b/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/LoginState.java @@ -14,7 +14,7 @@ public enum LoginState { if(client.state != state) { String msg = "client is in state " + client.state.name() + " when it was supposed to be " + state.name(); client.disconnect(IPacketFEDisconnectClient.TYPE_INVALID_OPERATION, msg); - EaglerSPRelay.logger.debug("[{}][Relay -> Client] PKT 0xFE: TYPE_INVALID_OPERATION: {}", client.socket.getAttachment(), msg); + EaglerSPRelay.logger.debug("[{}][Relay -> Client] PKT 0xFE: TYPE_INVALID_OPERATION: {}", (String) client.socket.getAttachment(), msg); return false; }else { return true; diff --git a/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket00Handshake.java b/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket00Handshake.java index 609d9bc..268c7f9 100644 --- a/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket00Handshake.java +++ b/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket00Handshake.java @@ -30,12 +30,13 @@ public class IPacket00Handshake extends IPacket { @Override public void write(DataOutputStream output) throws IOException { output.write(connectionType); + output.write(connectionVersion); IPacket.writeASCII8(output, connectionCode); } @Override public int packetLength() { - return 1 + (connectionCode != null ? 1 + connectionCode.length() : 0); + return 1 + 1 + (connectionCode != null ? 1 + connectionCode.length() : 0); } } diff --git a/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket02NewClient.java b/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket02NewClient.java index d875cb6..4fa91cf 100644 --- a/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket02NewClient.java +++ b/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket02NewClient.java @@ -11,6 +11,9 @@ public class IPacket02NewClient extends IPacket { this.clientId = clientId; } + public IPacket02NewClient() { + } + public void write(DataOutputStream output) throws IOException { writeASCII8(output, clientId); } diff --git a/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket69Pong.java b/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket69Pong.java index 948183c..20848e2 100644 --- a/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket69Pong.java +++ b/sp-relay/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket69Pong.java @@ -17,6 +17,9 @@ public class IPacket69Pong extends IPacket { this.comment = comment; this.brand = brand; } + + public IPacket69Pong() { + } public void write(DataOutputStream output) throws IOException { output.write(protcolVersion); diff --git a/src/main/java/net/lax1dude/eaglercraft/RelayServer.java b/src/main/java/net/lax1dude/eaglercraft/RelayServer.java index b7ada2b..50cdc30 100644 --- a/src/main/java/net/lax1dude/eaglercraft/RelayServer.java +++ b/src/main/java/net/lax1dude/eaglercraft/RelayServer.java @@ -48,11 +48,11 @@ public class RelayServer { } public String getPingComment() { - return queriedComment; + return queriedComment == null ? "" : queriedComment; } public String getPingVendor() { - return queriedVendor; + return queriedVendor == null ? "" : queriedVendor; } public VersionMismatch getPingCompatible() { diff --git a/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket00Handshake.java b/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket00Handshake.java index 609d9bc..62a6b27 100644 --- a/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket00Handshake.java +++ b/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket00Handshake.java @@ -30,6 +30,7 @@ public class IPacket00Handshake extends IPacket { @Override public void write(DataOutputStream output) throws IOException { output.write(connectionType); + output.write(connectionVersion); IPacket.writeASCII8(output, connectionCode); } diff --git a/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket02NewClient.java b/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket02NewClient.java index 4fa2763..b6d2d05 100644 --- a/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket02NewClient.java +++ b/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket02NewClient.java @@ -8,6 +8,10 @@ public class IPacket02NewClient extends IPacket { public String clientId; public IPacket02NewClient(String clientId) { + this.clientId = clientId; + } + + public IPacket02NewClient() { } public void read(DataInputStream input) throws IOException { diff --git a/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket69Pong.java b/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket69Pong.java index bdb2cd7..8f6cb56 100644 --- a/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket69Pong.java +++ b/src/main/java/net/lax1dude/eaglercraft/sp/relay/pkt/IPacket69Pong.java @@ -17,6 +17,9 @@ public class IPacket69Pong extends IPacket { this.comment = comment; this.brand = brand; } + + public IPacket69Pong() { + } public void read(DataInputStream output) throws IOException { protcolVersion = output.read();