diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroGameMediator.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroGameMediator.java index 707b2e500..97deacdf7 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroGameMediator.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroGameMediator.java @@ -30,6 +30,7 @@ public class LotroGameMediator { private Map _decisionQuerySentTimes = new HashMap(); private Set _playersPlaying = new HashSet(); + private String _gameId; private int _maxSecondsForGamePerPlayer = 60 * 80; // 80 minutes private boolean _allowSpectators; private boolean _cancellable; @@ -40,9 +41,11 @@ public class LotroGameMediator { private ReentrantReadWriteLock.ReadLock _readLock = _lock.readLock(); private ReentrantReadWriteLock.WriteLock _writeLock = _lock.writeLock(); private int _channelNextIndex = 0; + private volatile boolean _destroyed; - public LotroGameMediator(LotroFormat lotroFormat, LotroGameParticipant[] participants, LotroCardBlueprintLibrary library, int maxSecondsForGamePerPlayer, + public LotroGameMediator(String gameId, LotroFormat lotroFormat, LotroGameParticipant[] participants, LotroCardBlueprintLibrary library, int maxSecondsForGamePerPlayer, boolean allowSpectators, boolean cancellable) { + _gameId = gameId; _maxSecondsForGamePerPlayer = maxSecondsForGamePerPlayer; _allowSpectators = allowSpectators; _cancellable = cancellable; @@ -63,6 +66,18 @@ public class LotroGameMediator { _userFeedback.setGame(_lotroGame); } + public boolean isDestroyed() { + return _destroyed; + } + + public void destroy() { + _destroyed = true; + } + + public String getGameId() { + return _gameId; + } + public boolean isAllowSpectators() { return _allowSpectators; } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroServer.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroServer.java index 74885e2da..18d5ef80d 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroServer.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroServer.java @@ -59,6 +59,7 @@ public class LotroServer extends AbstractServer { _gameDeathWarningsSent.add(gameId); } if (currentTime > finishedGame.getValue().getTime() + _timeToGameDeath) { + _runningGames.get(gameId).destroy(); _gameDeathWarningsSent.remove(gameId); _runningGames.remove(gameId); _chatServer.destroyChatRoom(getChatRoomName(gameId)); @@ -79,7 +80,7 @@ public class LotroServer extends AbstractServer { return "Game" + gameId; } - public String createNewGame(LotroFormat lotroFormat, String tournamentName, final LotroGameParticipant[] participants, boolean allowSpectators, boolean allowCancelling, boolean allowChatAccess, boolean competitiveTime) { + public LotroGameMediator createNewGame(LotroFormat lotroFormat, String tournamentName, final LotroGameParticipant[] participants, boolean allowSpectators, boolean allowCancelling, boolean allowChatAccess, boolean competitiveTime) { _lock.writeLock().lock(); try { if (participants.length < 2) @@ -94,7 +95,7 @@ public class LotroServer extends AbstractServer { } else _chatServer.createChatRoom(getChatRoomName(gameId), false, 30); - LotroGameMediator lotroGameMediator = new LotroGameMediator(lotroFormat, participants, _lotroCardBlueprintLibrary, + LotroGameMediator lotroGameMediator = new LotroGameMediator(gameId, lotroFormat, participants, _lotroCardBlueprintLibrary, competitiveTime ? 60 * 40 : 60 * 80, allowSpectators, allowCancelling); lotroGameMediator.addGameResultListener( new GameResultListener() { @@ -140,7 +141,7 @@ public class LotroServer extends AbstractServer { _runningGames.put(gameId, lotroGameMediator); _nextGameId++; - return gameId; + return lotroGameMediator; } finally { _lock.writeLock().unlock(); } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java index d1c3bf086..0331e0e6b 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/HallServer.java @@ -221,8 +221,7 @@ public class HallServer extends AbstractServer { for (RunningTable runningTable : _runningTables.values()) { if (runningTable.getLeague() == league) { - String gameId = runningTable.getGameId(); - LotroGameMediator game = _lotroServer.getGameById(gameId); + LotroGameMediator game = runningTable.getLotroGameMediator(); if (game != null && !game.isFinished() && game.getPlayersPlaying().contains(player.getName())) throw new HallException("You can't play in multiple league games at the same time"); } @@ -467,23 +466,23 @@ public class HallServer extends AbstractServer { for (Map.Entry runningGame : _runningTables.entrySet()) { final RunningTable runningTable = runningGame.getValue(); - LotroGameMediator lotroGameMediator = _lotroServer.getGameById(runningTable.getGameId()); + LotroGameMediator lotroGameMediator = runningTable.getLotroGameMediator(); if (lotroGameMediator != null) { if (!lotroGameMediator.isFinished()) - visitor.visitTable(runningGame.getKey(), runningTable.getGameId(), player.getType().contains("a") || lotroGameMediator.isAllowSpectators(), HallInfoVisitor.TableStatus.PLAYING, lotroGameMediator.getGameStatus(), runningTable.getFormatName(), runningTable.getTournamentName(), lotroGameMediator.getPlayersPlaying(), lotroGameMediator.getPlayersPlaying().contains(player.getName()), lotroGameMediator.getWinner()); + visitor.visitTable(runningGame.getKey(), lotroGameMediator.getGameId(), player.getType().contains("a") || lotroGameMediator.isAllowSpectators(), HallInfoVisitor.TableStatus.PLAYING, lotroGameMediator.getGameStatus(), runningTable.getFormatName(), runningTable.getTournamentName(), lotroGameMediator.getPlayersPlaying(), lotroGameMediator.getPlayersPlaying().contains(player.getName()), lotroGameMediator.getWinner()); else finishedTables.put(runningGame.getKey(), runningTable); if (lotroGameMediator != null && !lotroGameMediator.isFinished() && lotroGameMediator.getPlayersPlaying().contains(player.getName())) - visitor.runningPlayerGame(runningTable.getGameId()); + visitor.runningPlayerGame(lotroGameMediator.getGameId()); } } // Then rest for (Map.Entry nonPlayingGame : finishedTables.entrySet()) { final RunningTable runningTable = nonPlayingGame.getValue(); - LotroGameMediator lotroGameMediator = _lotroServer.getGameById(runningTable.getGameId()); + LotroGameMediator lotroGameMediator = runningTable.getLotroGameMediator(); if (lotroGameMediator != null) - visitor.visitTable(nonPlayingGame.getKey(), runningTable.getGameId(), false, HallInfoVisitor.TableStatus.FINISHED, lotroGameMediator.getGameStatus(), runningTable.getFormatName(), runningTable.getTournamentName(), lotroGameMediator.getPlayersPlaying(), lotroGameMediator.getPlayersPlaying().contains(player.getName()), lotroGameMediator.getWinner()); + visitor.visitTable(nonPlayingGame.getKey(), lotroGameMediator.getGameId(), false, HallInfoVisitor.TableStatus.FINISHED, lotroGameMediator.getGameStatus(), runningTable.getFormatName(), runningTable.getTournamentName(), lotroGameMediator.getPlayersPlaying(), lotroGameMediator.getPlayersPlaying().contains(player.getName()), lotroGameMediator.getWinner()); } for (Map.Entry tournamentQueueEntry : _tournamentQueues.entrySet()) { @@ -613,13 +612,12 @@ public class HallServer extends AbstractServer { } private void createGame(League league, LeagueSerieData leagueSerie, String tableId, LotroGameParticipant[] participants, GameResultListener listener, LotroFormat lotroFormat, String tournamentName, boolean allowSpectators, boolean allowCancelling, boolean allowChatAccess, boolean competitiveTime) { - String gameId = _lotroServer.createNewGame(lotroFormat, tournamentName, participants, allowSpectators, allowCancelling, allowChatAccess, competitiveTime); - LotroGameMediator lotroGameMediator = _lotroServer.getGameById(gameId); + LotroGameMediator lotroGameMediator = _lotroServer.createNewGame(lotroFormat, tournamentName, participants, allowSpectators, allowCancelling, allowChatAccess, competitiveTime); if (listener != null) lotroGameMediator.addGameResultListener(listener); lotroGameMediator.startGame(); lotroGameMediator.addGameResultListener(_notifyHallListeners); - _runningTables.put(tableId, new RunningTable(gameId, lotroFormat.getName(), tournamentName, league, leagueSerie)); + _runningTables.put(tableId, new RunningTable(lotroGameMediator, lotroFormat.getName(), tournamentName, league, leagueSerie)); } private class NotifyHallListenersGameResultListener implements GameResultListener { @@ -657,7 +655,8 @@ public class HallServer extends AbstractServer { // Remove finished games HashMap copy = new HashMap(_runningTables); for (Map.Entry runningTable : copy.entrySet()) { - if (_lotroServer.getGameById(runningTable.getValue().getGameId()) == null) { + LotroGameMediator lotroGameMediator = runningTable.getValue().getLotroGameMediator(); + if (lotroGameMediator.isDestroyed()) { _runningTables.remove(runningTable.getKey()); hallChanged(); } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/RunningTable.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/RunningTable.java index 50fb8ae4a..464d63be4 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/RunningTable.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/RunningTable.java @@ -1,17 +1,18 @@ package com.gempukku.lotro.hall; import com.gempukku.lotro.db.vo.League; +import com.gempukku.lotro.game.LotroGameMediator; import com.gempukku.lotro.league.LeagueSerieData; public class RunningTable { - private String _gameId; + private LotroGameMediator _lotroGameMediator; private String _formatName; private String _tournamentName; private League _league; private LeagueSerieData _leagueSerie; - public RunningTable(String gameId, String formatName, String tournamentName, League league, LeagueSerieData leagueSerie) { - _gameId = gameId; + public RunningTable(LotroGameMediator lotroGameMediator, String formatName, String tournamentName, League league, LeagueSerieData leagueSerie) { + _lotroGameMediator = lotroGameMediator; _formatName = formatName; _tournamentName = tournamentName; _league = league; @@ -22,8 +23,8 @@ public class RunningTable { return _formatName; } - public String getGameId() { - return _gameId; + public LotroGameMediator getLotroGameMediator() { + return _lotroGameMediator; } public String getTournamentName() {