Fix - old draft chat rooms are now destroyed automatically by chat server during cleanup instead of manually by tournament

This commit is contained in:
jakub.salavec
2025-04-15 13:03:53 +02:00
parent 49f774f283
commit 62b8705172
4 changed files with 23 additions and 4 deletions

View File

@@ -66,6 +66,10 @@ public class ChatRoom {
}
}
public long getSecsSinceLastMessage() {
return (System.currentTimeMillis() - _lastMessages.getLast().getWhen().getTime()) / 1000;
}
private void shrinkLastMessages() {
while (_lastMessages.size() > MAX_MESSAGE_HISTORY_COUNT) {
_lastMessages.removeFirst();

View File

@@ -189,4 +189,8 @@ public class ChatRoomMediator {
_lock.readLock().unlock();
}
}
public long getSecsSinceLastMessage() {
return _chatRoom.getSecsSinceLastMessage();
}
}

View File

@@ -5,6 +5,7 @@ import com.gempukku.lotro.PrivateInformationException;
import com.gempukku.lotro.db.IgnoreDAO;
import com.gempukku.lotro.db.PlayerDAO;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -72,6 +73,20 @@ public class ChatServer extends AbstractServer {
}
protected void cleanup() {
// remove draft chat rooms if they are unused
Set<String> toRemove = new HashSet<>();
_chatRooms.forEach((roomName, chatRoomMediator) -> {
if (roomName.startsWith("Draft-")
&& chatRoomMediator.getUsersInRoom(true).size() == 0
&& chatRoomMediator.getSecsSinceLastMessage() > 5 * 60) {
// empty draft chat room without any messages sends in last 45 minutes
toRemove.add(roomName);
}
});
toRemove.forEach(this::destroyChatRoom);
for (ChatRoomMediator chatRoomMediator : _chatRooms.values())
chatRoomMediator.cleanup();
}

View File

@@ -199,10 +199,6 @@ public class TableDraftTournament extends BaseTournament implements Tournament {
_tournamentInfo.Stage = Stage.PLAYING_GAMES;
_tournamentService.recordTournamentStage(_tournamentId, getTournamentStage());
} else if (getTournamentStage() == Stage.PLAYING_GAMES) {
// Chat room no longer needed - kept alive during deck-building if people stayed longer
chatServer.destroyChatRoom("Draft-" + tableDraftInfo.tableDraftParams.tournamentId);
if (_currentlyPlayingPlayers.isEmpty()) {
if (_tournamentInfo.PairingMechanism.isFinished(getCurrentRound(), _players, _droppedPlayers)) {
result.add(finishTournament(collectionsManager));