mirror of
https://github.com/jie65535/gc-opencommand-plugin.git
synced 2025-07-28 18:59:16 +08:00
Prevent some exceptions
This commit is contained in:
parent
67f3eb180d
commit
8030ef8034
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user