{1.1} Fixed crash and other issues with the shared world relay

This commit is contained in:
lax1dude 2024-11-08 19:37:23 -08:00
parent bcd575e87e
commit 59aee1b42f
6 changed files with 51 additions and 51 deletions

View File

@ -55,7 +55,7 @@ If you would like to invite other players to join your singleplayer world and pl
Once you press "Start Shared World", EaglercraftX 1.8 will give you a "join code" (usually 5 letters) to share with your friends. On a different device, go the "Multiplayer" screen and press "Direct Connect" and press "Join Shared World", enter the join code given to you when you started the shared world and press "Join World". Given a few seconds, the client should successfully be able to join your shared world from any other device on the internet that also has unrestricted internet access. If it does not work, check the "Network Settings" screen and make sure you and your friends all have the same set of shared world relay URLs configured or your clients will not be able to find each other. Once you press "Start Shared World", EaglercraftX 1.8 will give you a "join code" (usually 5 letters) to share with your friends. On a different device, go the "Multiplayer" screen and press "Direct Connect" and press "Join Shared World", enter the join code given to you when you started the shared world and press "Join World". Given a few seconds, the client should successfully be able to join your shared world from any other device on the internet that also has unrestricted internet access. If it does not work, check the "Network Settings" screen and make sure you and your friends all have the same set of shared world relay URLs configured or your clients will not be able to find each other.
If you would like to host your own relay, the JAR file and instructions can be downloaded from the "Network Settings" screen in the client. EaglercraftX 1.8 uses the same "LAN world" relay server that is used by Eaglercraft 1.5.2, if you would like the relay source code find a random copy of the Eaglercraft 1.5.2 source code and it should be located in the "sp-relay" folder. The relay has not been updated since then, it has only been renamed from "LAN world relay" to "Shared world relay". If you would like to host your own relay, the JAR file and instructions can be downloaded from the "Network Settings" screen in the client. EaglercraftX 1.8 uses the same "LAN world" relay server that is used by Eaglercraft 1.5.2, however there have been several bug fixes. The current version is available in the `sp-relay/SharedWorldRelay` folder.
## PBR Shaders ## PBR Shaders

View File

@ -17,7 +17,7 @@ package net.lax1dude.eaglercraft.v1_8.sp.relay.server;
*/ */
public class Constants { public class Constants {
public static final String versionName = "1.0"; public static final String versionName = "1.1";
public static final String versionBrand = "lax1dude"; public static final String versionBrand = "lax1dude";
public static final int protocolVersion = 1; public static final int protocolVersion = 1;

View File

@ -41,17 +41,17 @@ public class EaglerSPClient {
} }
public void send(RelayPacket packet) { public void send(RelayPacket packet) {
if(this.socket.isOpen()) { if(socket.isOpen()) {
try { try {
this.socket.send(RelayPacket.writePacket(packet, EaglerSPRelay.logger)); socket.send(RelayPacket.writePacket(packet, EaglerSPRelay.logger));
}catch(IOException ex) { }catch(IOException ex) {
EaglerSPRelay.logger.debug("Error sending data to {}", (String) this.socket.getAttachment()); EaglerSPRelay.logger.debug("Error sending data to {}", socket.getAttachment());
EaglerSPRelay.logger.debug(ex); EaglerSPRelay.logger.debug(ex);
disconnect(RelayPacketFEDisconnectClient.TYPE_INTERNAL_ERROR, "Internal Server Error"); disconnect(RelayPacketFEDisconnectClient.TYPE_INTERNAL_ERROR, "Internal Server Error");
this.socket.close(); socket.close();
} }
}else { }else {
EaglerSPRelay.logger.debug("WARNING: Tried to send data to {} after the connection closed.", (String) this.socket.getAttachment()); EaglerSPRelay.logger.debug("WARNING: Tried to send data to {} after the connection closed.", socket.getAttachment());
} }
} }
@ -60,21 +60,21 @@ public class EaglerSPClient {
if(LoginState.assertEquals(this, LoginState.RECIEVED_DESCRIPTION)) { if(LoginState.assertEquals(this, LoginState.RECIEVED_DESCRIPTION)) {
state = LoginState.SENT_ICE_CANDIDATE; state = LoginState.SENT_ICE_CANDIDATE;
server.handleClientICECandidate(this, (RelayPacket03ICECandidate)packet); server.handleClientICECandidate(this, (RelayPacket03ICECandidate)packet);
EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x03: ICECandidate", (String) socket.getAttachment()); EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x03: ICECandidate", socket.getAttachment());
} }
return true; return true;
}else if(packet instanceof RelayPacket04Description) { }else if(packet instanceof RelayPacket04Description) {
if(LoginState.assertEquals(this, LoginState.INIT)) { if(LoginState.assertEquals(this, LoginState.INIT)) {
state = LoginState.SENT_DESCRIPTION; state = LoginState.SENT_DESCRIPTION;
server.handleClientDescription(this, (RelayPacket04Description)packet); server.handleClientDescription(this, (RelayPacket04Description)packet);
EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x04: Description", (String) socket.getAttachment()); EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x04: Description", socket.getAttachment());
} }
return true; return true;
}else if(packet instanceof RelayPacket05ClientSuccess) { }else if(packet instanceof RelayPacket05ClientSuccess) {
if(LoginState.assertEquals(this, LoginState.RECIEVED_ICE_CANIDATE)) { if(LoginState.assertEquals(this, LoginState.RECIEVED_ICE_CANIDATE)) {
state = LoginState.FINISHED; state = LoginState.FINISHED;
server.handleClientSuccess(this, (RelayPacket05ClientSuccess)packet); server.handleClientSuccess(this, (RelayPacket05ClientSuccess)packet);
EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x05: ClientSuccess", (String) socket.getAttachment()); EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x05: ClientSuccess", socket.getAttachment());
disconnect(RelayPacketFEDisconnectClient.TYPE_FINISHED_SUCCESS, "Successful connection"); disconnect(RelayPacketFEDisconnectClient.TYPE_FINISHED_SUCCESS, "Successful connection");
} }
return true; return true;
@ -82,7 +82,7 @@ public class EaglerSPClient {
if(LoginState.assertEquals(this, LoginState.RECIEVED_ICE_CANIDATE)) { if(LoginState.assertEquals(this, LoginState.RECIEVED_ICE_CANIDATE)) {
state = LoginState.FINISHED; state = LoginState.FINISHED;
server.handleClientFailure(this, (RelayPacket06ClientFailure)packet); server.handleClientFailure(this, (RelayPacket06ClientFailure)packet);
EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x05: ClientFailure", (String) socket.getAttachment()); EaglerSPRelay.logger.debug("[{}][Client -> Relay -> Server] PKT 0x05: ClientFailure", socket.getAttachment());
disconnect(RelayPacketFEDisconnectClient.TYPE_FINISHED_FAILED, "Failed connection"); disconnect(RelayPacketFEDisconnectClient.TYPE_FINISHED_FAILED, "Failed connection");
} }
return true; return true;
@ -109,11 +109,11 @@ public class EaglerSPClient {
if (code != RelayPacketFEDisconnectClient.TYPE_FINISHED_SUCCESS) server.send(pkt); if (code != RelayPacketFEDisconnectClient.TYPE_FINISHED_SUCCESS) server.send(pkt);
serverNotifiedOfClose = true; serverNotifiedOfClose = true;
} }
if(this.socket.isOpen()) { if(socket.isOpen()) {
send(pkt); send(pkt);
socket.close(); socket.close();
} }
EaglerSPRelay.logger.debug("[{}][Relay -> Client] PKT 0xFE: #{} {}", (String) socket.getAttachment(), code, reason); EaglerSPRelay.logger.debug("[{}][Relay -> Client] PKT 0xFE: #{} {}", socket.getAttachment(), code, reason);
} }
public static final int clientCodeLength = 16; public static final int clientCodeLength = 16;

View File

@ -202,7 +202,7 @@ public class EaglerSPRelay extends WebSocketServer {
} }
if(totalCons >= config.getConnectionsPerIP()) { if(totalCons >= config.getConnectionsPerIP()) {
logger.debug("[{}]: Too many connections are open on this address", (String) arg0.getAttachment()); logger.debug("[{}]: Too many connections are open on this address", arg0.getAttachment());
arg0.send(RelayPacketFEDisconnectClient.ratelimitPacketTooMany); arg0.send(RelayPacketFEDisconnectClient.ratelimitPacketTooMany);
arg0.close(); arg0.close();
return; return;
@ -231,7 +231,7 @@ public class EaglerSPRelay extends WebSocketServer {
RelayPacket00Handshake ipkt = (RelayPacket00Handshake)pkt; RelayPacket00Handshake ipkt = (RelayPacket00Handshake)pkt;
if(ipkt.connectionVersion != Constants.protocolVersion) { if(ipkt.connectionVersion != Constants.protocolVersion) {
logger.debug("[{}]: Connected with unsupported protocol version: {} (supported " logger.debug("[{}]: Connected with unsupported protocol version: {} (supported "
+ "version: {})", (String) arg0.getAttachment(), ipkt.connectionVersion, Constants.protocolVersion); + "version: {})", arg0.getAttachment(), ipkt.connectionVersion, Constants.protocolVersion);
if(ipkt.connectionVersion < Constants.protocolVersion) { if(ipkt.connectionVersion < Constants.protocolVersion) {
arg0.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_PROTOCOL_VERSION, arg0.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_PROTOCOL_VERSION,
"Outdated Client! (v" + Constants.protocolVersion + " req)"), EaglerSPRelay.logger)); "Outdated Client! (v" + Constants.protocolVersion + " req)"), EaglerSPRelay.logger));
@ -244,21 +244,21 @@ public class EaglerSPRelay extends WebSocketServer {
} }
if(ipkt.connectionType == 0x01) { if(ipkt.connectionType == 0x01) {
if(!rateLimit(worldRateLimiter, arg0, waiting.address)) { if(!rateLimit(worldRateLimiter, arg0, waiting.address)) {
logger.debug("[{}]: Got world ratelimited", (String) arg0.getAttachment()); logger.debug("[{}]: Got world ratelimited", arg0.getAttachment());
return; return;
} }
synchronized(serverAddressSets) { synchronized(serverAddressSets) {
List<EaglerSPServer> lst = serverAddressSets.get(waiting.address); List<EaglerSPServer> lst = serverAddressSets.get(waiting.address);
if(lst != null) { if(lst != null) {
if(lst.size() >= config.getWorldsPerIP()) { if(lst.size() >= config.getWorldsPerIP()) {
logger.debug("[{}]: Too many worlds are open on this address", (String) arg0.getAttachment()); logger.debug("[{}]: Too many worlds are open on this address", arg0.getAttachment());
arg0.send(RelayPacketFEDisconnectClient.ratelimitPacketTooMany); arg0.send(RelayPacketFEDisconnectClient.ratelimitPacketTooMany);
arg0.close(); arg0.close();
return; return;
} }
} }
} }
logger.debug("[{}]: Connected as a server", (String) arg0.getAttachment()); logger.debug("[{}]: Connected as a server", arg0.getAttachment());
EaglerSPServer srv; EaglerSPServer srv;
synchronized(serverCodes) { synchronized(serverCodes) {
int j = 0; int j = 0;
@ -266,7 +266,7 @@ public class EaglerSPRelay extends WebSocketServer {
do { do {
if(++j > 100) { if(++j > 100) {
logger.error("Error: relay is running out of codes!"); logger.error("Error: relay is running out of codes!");
logger.error("Closing connection to {}", (String) arg0.getAttachment()); logger.error("Closing connection to {}", arg0.getAttachment());
arg0.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_INTERNAL_ERROR, arg0.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_INTERNAL_ERROR,
"Internal Server Error"), EaglerSPRelay.logger)); "Internal Server Error"), EaglerSPRelay.logger));
arg0.close(); arg0.close();
@ -278,7 +278,7 @@ public class EaglerSPRelay extends WebSocketServer {
serverCodes.put(code, srv); serverCodes.put(code, srv);
ipkt.connectionCode = code; ipkt.connectionCode = code;
arg0.send(RelayPacket.writePacket(ipkt, EaglerSPRelay.logger)); arg0.send(RelayPacket.writePacket(ipkt, EaglerSPRelay.logger));
logger.debug("[{}][Relay -> Server] PKT 0x00: Assign join code: {}", (String) arg0.getAttachment(), code); logger.debug("[{}][Relay -> Server] PKT 0x00: Assign join code: {}", arg0.getAttachment(), code);
} }
synchronized(serverConnections) { synchronized(serverConnections) {
serverConnections.put(arg0, srv); serverConnections.put(arg0, srv);
@ -292,15 +292,15 @@ public class EaglerSPRelay extends WebSocketServer {
lst.add(srv); lst.add(srv);
} }
srv.send(new RelayPacket01ICEServers(EaglerSPRelayConfigRelayList.relayServers)); srv.send(new RelayPacket01ICEServers(EaglerSPRelayConfigRelayList.relayServers));
logger.debug("[{}][Relay -> Server] PKT 0x01: Send ICE server list to server", (String) arg0.getAttachment()); logger.debug("[{}][Relay -> Server] PKT 0x01: Send ICE server list to server", arg0.getAttachment());
}else { }else {
if(!rateLimit(pingRateLimiter, arg0, waiting.address)) { if(!rateLimit(pingRateLimiter, arg0, waiting.address)) {
logger.debug("[{}]: Got ping ratelimited", (String) arg0.getAttachment()); logger.debug("[{}]: Got ping ratelimited", arg0.getAttachment());
return; return;
} }
if(ipkt.connectionType == 0x02) { if(ipkt.connectionType == 0x02) {
String code = ipkt.connectionCode; String code = ipkt.connectionCode;
logger.debug("[{}]: Connected as a client, requested server code: {}", (String) arg0.getAttachment(), code); logger.debug("[{}]: Connected as a client, requested server code: {}", arg0.getAttachment(), code);
if(code.length() != config.getCodeLength()) { if(code.length() != config.getCodeLength()) {
logger.debug("The code '{}' is invalid because it's the wrong length, disconnecting", code); logger.debug("The code '{}' is invalid because it's the wrong length, disconnecting", code);
arg0.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_CODE_LENGTH, arg0.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_CODE_LENGTH,
@ -345,14 +345,14 @@ public class EaglerSPRelay extends WebSocketServer {
lst.add(cl); lst.add(cl);
} }
cl.send(new RelayPacket01ICEServers(EaglerSPRelayConfigRelayList.relayServers)); cl.send(new RelayPacket01ICEServers(EaglerSPRelayConfigRelayList.relayServers));
logger.debug("[{}][Relay -> Client] PKT 0x01: Send ICE server list to client", (String) arg0.getAttachment()); logger.debug("[{}][Relay -> Client] PKT 0x01: Send ICE server list to client", arg0.getAttachment());
} }
}else if(ipkt.connectionType == 0x03) { }else if(ipkt.connectionType == 0x03) {
logger.debug("[{}]: Pinging the server", (String) arg0.getAttachment()); logger.debug("[{}]: Pinging the server", arg0.getAttachment());
arg0.send(RelayPacket.writePacket(new RelayPacket69Pong(Constants.protocolVersion, config.getComment(), Constants.versionBrand), EaglerSPRelay.logger)); arg0.send(RelayPacket.writePacket(new RelayPacket69Pong(Constants.protocolVersion, config.getComment(), Constants.versionBrand), EaglerSPRelay.logger));
arg0.close(); arg0.close();
}else if(ipkt.connectionType == 0x04) { }else if(ipkt.connectionType == 0x04) {
logger.debug("[{}]: Polling the server for other worlds", (String) arg0.getAttachment()); logger.debug("[{}]: Polling the server for other worlds", arg0.getAttachment());
if(config.isEnableShowLocals()) { if(config.isEnableShowLocals()) {
arg0.send(RelayPacket.writePacket(new RelayPacket07LocalWorlds(getLocalWorlds(waiting.address)), EaglerSPRelay.logger)); arg0.send(RelayPacket.writePacket(new RelayPacket07LocalWorlds(getLocalWorlds(waiting.address)), EaglerSPRelay.logger));
}else { }else {
@ -360,7 +360,7 @@ public class EaglerSPRelay extends WebSocketServer {
} }
arg0.close(); arg0.close();
}else { }else {
logger.debug("[{}]: Unknown connection type: {}", (String) arg0.getAttachment(), ipkt.connectionType); logger.debug("[{}]: Unknown connection type: {}", arg0.getAttachment(), ipkt.connectionType);
arg0.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_ILLEGAL_OPERATION, arg0.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_ILLEGAL_OPERATION,
"Unexpected Init Packet"), EaglerSPRelay.logger)); "Unexpected Init Packet"), EaglerSPRelay.logger));
arg0.close(); arg0.close();
@ -368,7 +368,7 @@ public class EaglerSPRelay extends WebSocketServer {
} }
}else { }else {
logger.debug("[{}]: Pending connection did not send a 0x00 packet to identify " logger.debug("[{}]: Pending connection did not send a 0x00 packet to identify "
+ "as a client or server", (String) arg0.getAttachment()); + "as a client or server", arg0.getAttachment());
arg0.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_ILLEGAL_OPERATION, arg0.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_ILLEGAL_OPERATION,
"Unexpected Init Packet"), EaglerSPRelay.logger)); "Unexpected Init Packet"), EaglerSPRelay.logger));
arg0.close(); arg0.close();
@ -380,7 +380,7 @@ public class EaglerSPRelay extends WebSocketServer {
} }
if(srv != null) { if(srv != null) {
if(!srv.handle(pkt)) { if(!srv.handle(pkt)) {
logger.debug("[{}]: Server sent invalid packet: {}", (String) arg0.getAttachment(), pkt.getClass().getSimpleName()); logger.debug("[{}]: Server sent invalid packet: {}", arg0.getAttachment(), pkt.getClass().getSimpleName());
arg0.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_INVALID_PACKET, arg0.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_INVALID_PACKET,
"Invalid Packet Recieved"), EaglerSPRelay.logger)); "Invalid Packet Recieved"), EaglerSPRelay.logger));
arg0.close(); arg0.close();
@ -392,13 +392,13 @@ public class EaglerSPRelay extends WebSocketServer {
} }
if(cl != null) { if(cl != null) {
if(!cl.handle(pkt)) { if(!cl.handle(pkt)) {
logger.debug("[{}]: Client sent invalid packet: {}", (String) arg0.getAttachment(), pkt.getClass().getSimpleName()); logger.debug("[{}]: Client sent invalid packet: {}", arg0.getAttachment(), pkt.getClass().getSimpleName());
arg0.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_INVALID_PACKET, arg0.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_INVALID_PACKET,
"Invalid Packet Recieved"), EaglerSPRelay.logger)); "Invalid Packet Recieved"), EaglerSPRelay.logger));
arg0.close(); arg0.close();
} }
}else { }else {
logger.debug("[{}]: Connection has no client/server attached to it!", (String) arg0.getAttachment()); logger.debug("[{}]: Connection has no client/server attached to it!", arg0.getAttachment());
arg0.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_ILLEGAL_OPERATION, arg0.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_ILLEGAL_OPERATION,
"Internal Server Error"), EaglerSPRelay.logger)); "Internal Server Error"), EaglerSPRelay.logger));
arg0.close(); arg0.close();
@ -406,14 +406,14 @@ public class EaglerSPRelay extends WebSocketServer {
} }
} }
}catch(Throwable t) { }catch(Throwable t) {
logger.error("[{}]: Failed to handle binary frame: {}", (String) arg0.getAttachment(), t); logger.error("[{}]: Failed to handle binary frame: {}", arg0.getAttachment(), t);
arg0.close(); arg0.close();
} }
} }
@Override @Override
public void onMessage(WebSocket arg0, String arg1) { public void onMessage(WebSocket arg0, String arg1) {
logger.debug("[{}]: Sent a text frame, disconnecting", (String) arg0.getAttachment()); logger.debug("[{}]: Sent a text frame, disconnecting", arg0.getAttachment());
arg0.close(); arg0.close();
} }
@ -424,7 +424,7 @@ public class EaglerSPRelay extends WebSocketServer {
srv = serverConnections.remove(arg0); srv = serverConnections.remove(arg0);
} }
if(srv != null) { if(srv != null) {
logger.debug("[{}]: Server closed, code: {}", (String) arg0.getAttachment(), srv.code); logger.debug("[{}]: Server closed, code: {}", arg0.getAttachment(), srv.code);
synchronized(serverCodes) { synchronized(serverCodes) {
serverCodes.remove(srv.code); serverCodes.remove(srv.code);
} }
@ -445,7 +445,7 @@ public class EaglerSPRelay extends WebSocketServer {
while(itr.hasNext()) { while(itr.hasNext()) {
EaglerSPClient cl = itr.next(); EaglerSPClient cl = itr.next();
if(cl.server == srv) { if(cl.server == srv) {
logger.debug("[{}]: Disconnecting client: {} (id: ", (String) cl.socket.getAttachment(), cl.id); logger.debug("[{}]: Disconnecting client: {} (id: {})", cl.socket.getAttachment(), cl.id);
cl.socket.close(); cl.socket.close();
} }
} }
@ -464,22 +464,22 @@ public class EaglerSPRelay extends WebSocketServer {
} }
} }
} }
logger.debug("[{}]: Client closed, id: {}", (String) arg0.getAttachment(), cl.id); logger.debug("[{}]: Client closed, id: {}", arg0.getAttachment(), cl.id);
synchronized(clientIds) { synchronized(clientIds) {
clientIds.remove(cl.id); clientIds.remove(cl.id);
} }
cl.server.handleClientDisconnect(cl); cl.server.handleClientDisconnect(cl);
}else { }else {
logger.debug("[{}]: Connection Closed", (String) arg0.getAttachment()); logger.debug("[{}]: Connection Closed", arg0.getAttachment());
} }
} }
} }
@Override @Override
public void onError(WebSocket arg0, Exception arg1) { public void onError(WebSocket arg0, Exception arg1) {
logger.error("[{}]: Exception thrown: {}", (arg0 == null ? "SERVER" : (String) arg0.getAttachment()), arg1.toString()); logger.error("[{}]: Exception thrown: {}", (arg0 == null ? "SERVER" : arg0.getAttachment()), arg1.toString());
logger.debug(arg1); logger.debug(arg1);
arg0.close(); if(arg0 != null) arg0.close();
} }
private List<RelayPacket07LocalWorlds.LocalWorld> getLocalWorlds(String addr) { private List<RelayPacket07LocalWorlds.LocalWorld> getLocalWorlds(String addr) {

View File

@ -52,21 +52,21 @@ public class EaglerSPServer {
} }
public void send(RelayPacket packet) { public void send(RelayPacket packet) {
if(this.socket.isOpen()) { if(socket.isOpen()) {
try { try {
this.socket.send(RelayPacket.writePacket(packet, EaglerSPRelay.logger)); socket.send(RelayPacket.writePacket(packet, EaglerSPRelay.logger));
}catch(IOException ex) { }catch(IOException ex) {
EaglerSPRelay.logger.debug("Error sending data to {}", this.serverAddress); EaglerSPRelay.logger.debug("Error sending data to {}", serverAddress);
EaglerSPRelay.logger.debug(ex); EaglerSPRelay.logger.debug(ex);
try { try {
this.socket.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_INTERNAL_ERROR, socket.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_INTERNAL_ERROR,
"Internal Server Error"), EaglerSPRelay.logger)); "Internal Server Error"), EaglerSPRelay.logger));
}catch(IOException ex2) { }catch(IOException ex2) {
} }
this.socket.close(); socket.close();
} }
}else { }else {
EaglerSPRelay.logger.debug("WARNING: Tried to send data to {} after the connection closed.", this.serverAddress); EaglerSPRelay.logger.debug("WARNING: Tried to send data to {} after the connection closed.", serverAddress);
} }
} }
@ -78,10 +78,10 @@ public class EaglerSPServer {
if(LoginState.assertEquals(cl, LoginState.SENT_ICE_CANDIDATE)) { if(LoginState.assertEquals(cl, LoginState.SENT_ICE_CANDIDATE)) {
cl.state = LoginState.RECIEVED_ICE_CANIDATE; cl.state = LoginState.RECIEVED_ICE_CANIDATE;
cl.handleServerICECandidate(packet); cl.handleServerICECandidate(packet);
EaglerSPRelay.logger.debug("[{}][Server -> Relay -> Client] PKT 0x03: ICECandidate", (String) cl.socket.getAttachment()); EaglerSPRelay.logger.debug("[{}][Server -> Relay -> Client] PKT 0x03: ICECandidate", cl.socket.getAttachment());
} }
}else { }else {
this.socket.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_UNKNOWN_CLIENT, socket.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_UNKNOWN_CLIENT,
"Unknown Client ID: " + packet.peerId), EaglerSPRelay.logger)); "Unknown Client ID: " + packet.peerId), EaglerSPRelay.logger));
} }
return true; return true;
@ -92,10 +92,10 @@ public class EaglerSPServer {
if(LoginState.assertEquals(cl, LoginState.SENT_DESCRIPTION)) { if(LoginState.assertEquals(cl, LoginState.SENT_DESCRIPTION)) {
cl.state = LoginState.RECIEVED_DESCRIPTION; cl.state = LoginState.RECIEVED_DESCRIPTION;
cl.handleServerDescription(packet); cl.handleServerDescription(packet);
EaglerSPRelay.logger.debug("[{}][Server -> Relay -> Client] PKT 0x04: Description", (String) cl.socket.getAttachment()); EaglerSPRelay.logger.debug("[{}][Server -> Relay -> Client] PKT 0x04: Description", cl.socket.getAttachment());
} }
}else { }else {
this.socket.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_UNKNOWN_CLIENT, socket.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_UNKNOWN_CLIENT,
"Unknown Client ID: " + packet.peerId), EaglerSPRelay.logger)); "Unknown Client ID: " + packet.peerId), EaglerSPRelay.logger));
} }
return true; return true;
@ -104,10 +104,10 @@ public class EaglerSPServer {
EaglerSPClient cl = clients.get(packet.clientId); EaglerSPClient cl = clients.get(packet.clientId);
if(cl != null) { if(cl != null) {
cl.handleServerDisconnectClient(packet); cl.handleServerDisconnectClient(packet);
EaglerSPRelay.logger.debug("[{}][Server -> Relay -> Client] PKT 0xFE: Disconnect: {}: {}", (String) cl.socket.getAttachment(), EaglerSPRelay.logger.debug("[{}][Server -> Relay -> Client] PKT 0xFE: Disconnect: {}: {}", cl.socket.getAttachment(),
packet.code, packet.reason); packet.code, packet.reason);
}else { }else {
this.socket.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_UNKNOWN_CLIENT, socket.send(RelayPacket.writePacket(new RelayPacketFFErrorCode(RelayPacketFFErrorCode.TYPE_UNKNOWN_CLIENT,
"Unknown Client ID: " + packet.clientId), EaglerSPRelay.logger)); "Unknown Client ID: " + packet.clientId), EaglerSPRelay.logger));
} }
return true; return true;