fix: fix player living in room bug

This commit is contained in:
wzp 2024-12-23 12:58:01 +08:00
parent e560f071ad
commit 34930fc6ae
2 changed files with 14 additions and 0 deletions

View File

@ -263,5 +263,6 @@ public class ChessController {
.filter(e -> e.getValue().getLastStateChange().toInstant().isBefore(before10Min))
.map(Map.Entry::getKey)
.forEach(rooms::remove);
rooms.values().forEach(Room::tryClean);
}
}

View File

@ -196,6 +196,19 @@ public class Room {
return sessionId.equals(whiteSession.getId());
}
public void tryClean() {
if (whiteSession != null) {
if (!whiteSession.isOpen()) {
this.leave(whiteSession);
}
}
if (blackSession != null) {
if (!blackSession.isOpen()) {
this.leave(blackSession);
}
}
}
public enum RoomState {
CREATED,
WAITING,