Prevent some exceptions

This commit is contained in:
方块君
2022-07-22 14:44:22 +08:00
parent 67f3eb180d
commit 8030ef8034
2 changed files with 73 additions and 61 deletions

View File

@@ -96,6 +96,7 @@ public class SocketClient {
public void run() {
//noinspection InfiniteLoopStatement
while (true) {
try {
String data = SocketUtils.readString(is);
Packet packet = Grasscutter.getGsonFactory().fromJson(data, Packet.class);
if (packet.token.equals(token)) {
@@ -140,6 +141,9 @@ public class SocketClient {
break;
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
}

View File

@@ -24,7 +24,6 @@ public class SocketServer {
private static final HashMap<String, ClientThread> clientList = new HashMap<>();
private static final HashMap<String, Integer> clientTimeout = new HashMap<>();
private static Logger mLogger;
public static void startServer() throws IOException {
@@ -145,6 +144,7 @@ public class SocketServer {
public void run() {
// noinspection InfiniteLoopStatement
while (true) {
try {
String data = SocketUtils.readString(is);
Packet packet = Grasscutter.getGsonFactory().fromJson(data, Packet.class);
if (packet.token.equals(token)) {
@@ -171,6 +171,14 @@ public class SocketServer {
}
}
}
} catch (Throwable e) {
e.printStackTrace();
mLogger.error("[OpenCommand] Client {} disconnect.", address);
clientList.remove(address);
clientTimeout.remove(address);
SocketData.playerList.remove(address);
break;
}
}
}
}