fix: fix room cannot be clean's bug
This commit is contained in:
parent
2b3b8fa9e6
commit
a43196133e
@ -211,7 +211,7 @@ public class ChessController {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Room getRoomByPlayer(String id) {
|
||||
private static Room getRoomByPlayer(String id) {
|
||||
for (Room value : rooms.values()) {
|
||||
if (value.isIn(id)) return value;
|
||||
}
|
||||
@ -220,8 +220,12 @@ public class ChessController {
|
||||
|
||||
@OnClose
|
||||
public void onClose(Session session) {
|
||||
staticOnClose(session);
|
||||
}
|
||||
|
||||
public static void staticOnClose(Session session) {
|
||||
String sessionId = session.getId();
|
||||
Room roomByPlayer = this.getRoomByPlayer(sessionId);
|
||||
Room roomByPlayer = getRoomByPlayer(sessionId);
|
||||
if (roomByPlayer != null) {
|
||||
roomByPlayer.leave(session);
|
||||
roomByPlayer.broadcast(roomByPlayer.getRoomInfo(users));
|
||||
@ -238,7 +242,11 @@ public class ChessController {
|
||||
for (Session value : sessions.values()) {
|
||||
if (!pingPong.getOrDefault(value, true)) {
|
||||
log.info("closed by connectionManager");
|
||||
value.close(new CloseReason(CloseReason.CloseCodes.CLOSED_ABNORMALLY, "链接延迟过高"));
|
||||
if (value.isOpen()) {
|
||||
value.close(new CloseReason(CloseReason.CloseCodes.CLOSED_ABNORMALLY, "链接延迟过高"));
|
||||
continue;
|
||||
}
|
||||
staticOnClose(value);
|
||||
continue;
|
||||
}
|
||||
pingPong.put(value, false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user