diff --git a/.gitignore b/.gitignore index 9d459d7de..d988c1ea0 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ logs/* remote-sync replay !replay/.placeholder +logs/nohup.out +gemp-lotr/docker/docker-compose.yml diff --git a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/HallRequestHandler.java b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/HallRequestHandler.java index e7adfad83..e18083930 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/HallRequestHandler.java +++ b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/handler/HallRequestHandler.java @@ -11,10 +11,7 @@ import com.gempukku.lotro.db.vo.League; import com.gempukku.lotro.draft.DraftChannelVisitor; import com.gempukku.lotro.game.*; import com.gempukku.lotro.game.formats.LotroFormatLibrary; -import com.gempukku.lotro.hall.HallChannelVisitor; -import com.gempukku.lotro.hall.HallCommunicationChannel; -import com.gempukku.lotro.hall.HallException; -import com.gempukku.lotro.hall.HallServer; +import com.gempukku.lotro.hall.*; import com.gempukku.lotro.league.LeagueSerieData; import com.gempukku.lotro.league.LeagueService; import com.gempukku.lotro.logic.GameUtils; @@ -144,6 +141,9 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri boolean isPrivate = (isPrivateVal != null ? Boolean.valueOf(isPrivateVal) : false); String isInviteOnlyVal = getFormParameterSafely(postDecoder, "isInviteOnly"); boolean isInviteOnly = (isInviteOnlyVal != null ? Boolean.valueOf(isInviteOnlyVal) : false); + //To prevent annoyance, super long glacial games are hidden from everyone except + // the participants and admins. + boolean isHidden = timer.toLowerCase().equals(GameTimer.GLACIAL_TIMER.name()); Player resourceOwner = getResourceOwnerSafely(request, participantId); @@ -175,7 +175,7 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri try { - _hallServer.createNewTable(format, resourceOwner, deckName, timer, desc, isInviteOnly, isPrivate); + _hallServer.createNewTable(format, resourceOwner, deckName, timer, desc, isInviteOnly, isPrivate, isHidden); responseWriter.writeXmlResponse(null); } catch (HallException e) { @@ -183,7 +183,7 @@ public class HallRequestHandler extends LotroServerRequestHandler implements Uri { //try again assuming it's a new player with one of the default library decks selected Player librarian = _playerDao.getPlayer("Librarian"); - _hallServer.spoofNewTable(format, resourceOwner, librarian, deckName, timer, "(New Player) " + desc, isInviteOnly, isPrivate); + _hallServer.spoofNewTable(format, resourceOwner, librarian, deckName, timer, "(New Player) " + desc, isInviteOnly, isPrivate, isHidden); responseWriter.writeXmlResponse(null); return; } diff --git a/gemp-lotr/gemp-lotr-common/src/main/java/com/gempukku/lotro/common/DBDefs.java b/gemp-lotr/gemp-lotr-common/src/main/java/com/gempukku/lotro/common/DBDefs.java index 976430f72..977c0bb1f 100644 --- a/gemp-lotr/gemp-lotr-common/src/main/java/com/gempukku/lotro/common/DBDefs.java +++ b/gemp-lotr/gemp-lotr-common/src/main/java/com/gempukku/lotro/common/DBDefs.java @@ -9,6 +9,7 @@ public class DBDefs { public static class GameHistory { public int id; + public String gameId; public String winner; public int winnerId; @@ -31,6 +32,15 @@ public class DBDefs { public String tournament; + public int winner_site; + public int loser_site; + + public String game_length_type; + public int max_game_time; + public int game_timeout; + public int winner_clock_remaining; + public int loser_clock_remaining; + public int replay_version = -1; } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/DbGameHistoryDAO.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/DbGameHistoryDAO.java index 647f42477..1fec169e2 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/DbGameHistoryDAO.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/DbGameHistoryDAO.java @@ -24,7 +24,7 @@ public class DbGameHistoryDAO implements GameHistoryDAO { _dbAccess = dbAccess; } - public void addGameHistory(String winner, int winnerId, String loser, int loserId, String winReason, String loseReason, String winRecordingId, String loseRecordingId, + public int addGameHistory(String winner, int winnerId, String loser, int loserId, String winReason, String loseReason, String winRecordingId, String loseRecordingId, String formatName, String tournament, String winnerDeckName, String loserDeckName, ZonedDateTime startDate, ZonedDateTime endDate, int replayVersion) { try { Sql2o db = new Sql2o(_dbAccess.getDataSource()); @@ -54,8 +54,11 @@ public class DbGameHistoryDAO implements GameHistoryDAO { .addParameter("end_date", endDate.format(_dateTimeFormat)) .addParameter("version", replayVersion); - query.executeUpdate(); + int id = query.executeUpdate() + .getKey(Integer.class); conn.commit(); + + return id; } } catch (Exception ex) { throw new RuntimeException("Unable to insert game history", ex); diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/GameHistoryDAO.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/GameHistoryDAO.java index da077c2bb..4695f202d 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/GameHistoryDAO.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/GameHistoryDAO.java @@ -7,7 +7,7 @@ import java.time.ZonedDateTime; import java.util.List; public interface GameHistoryDAO { - public void addGameHistory(String winner, int winnerId, String loser, int loserId, String winReason, String loseReason, String winRecordingId, String loseRecordingId, String formatName, String tournament, String winnerDeckName, String loserDeckName, ZonedDateTime startDate, ZonedDateTime endDate, int version); + public int addGameHistory(String winner, int winnerId, String loser, int loserId, String winReason, String loseReason, String winRecordingId, String loseRecordingId, String formatName, String tournament, String winnerDeckName, String loserDeckName, ZonedDateTime startDate, ZonedDateTime endDate, int version); public DBDefs.GameHistory getGameHistory(String recordID); public boolean doesReplayIDExist(String id); public List getGameHistoryForPlayer(Player player, int start, int count); diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/GameHistoryService.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/GameHistoryService.java index 283146350..4161335df 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/GameHistoryService.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/GameHistoryService.java @@ -17,19 +17,21 @@ public class GameHistoryService { _gameHistoryDAO = gameHistoryDAO; } - public void addGameHistory(DBDefs.GameHistory gh) { - addGameHistory(gh.winner, gh.winnerId, gh.loser, gh.loserId, gh.win_reason, gh.lose_reason, gh.win_recording_id, gh.lose_recording_id, + public int addGameHistory(DBDefs.GameHistory gh) { + return addGameHistory(gh.winner, gh.winnerId, gh.loser, gh.loserId, gh.win_reason, gh.lose_reason, gh.win_recording_id, gh.lose_recording_id, gh.format_name, gh.tournament, gh.winner_deck_name, gh.loser_deck_name, gh.start_date, gh.end_date, gh.replay_version); } - public void addGameHistory(String winner, int winnerId, String loser, int loserId, String winReason, String loseReason, String winRecordingId, String loseRecordingId, String formatName, String tournament, String winnerDeckName, String loserDeckName, ZonedDateTime startDate, ZonedDateTime endDate, int version) { - _gameHistoryDAO.addGameHistory(winner, winnerId, loser, loserId, winReason, loseReason, winRecordingId, loseRecordingId, formatName, tournament, winnerDeckName, loserDeckName, startDate, endDate, version); + public int addGameHistory(String winner, int winnerId, String loser, int loserId, String winReason, String loseReason, String winRecordingId, String loseRecordingId, String formatName, String tournament, String winnerDeckName, String loserDeckName, ZonedDateTime startDate, ZonedDateTime endDate, int version) { + int id = _gameHistoryDAO.addGameHistory(winner, winnerId, loser, loserId, winReason, loseReason, winRecordingId, loseRecordingId, formatName, tournament, winnerDeckName, loserDeckName, startDate, endDate, version); Integer winnerCount = _playerGameCount.get(winner); Integer loserCount = _playerGameCount.get(loser); if (winnerCount != null) _playerGameCount.put(winner, winnerCount + 1); if (loserCount != null) _playerGameCount.put(loser, loserCount + 1); + + return id; } public boolean doesReplayIDExist(String id) { diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/GameRecorder.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/GameRecorder.java index eb975a41a..28a9f1e7b 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/GameRecorder.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/GameRecorder.java @@ -57,7 +57,11 @@ public class GameRecorder { return (winnerName, winReason, loserName, loseReason) -> { final ZonedDateTime endDate = ZonedDateTime.now(ZoneOffset.UTC); + var time = lotroGame.getTimeSettings(); + var clocks = lotroGame.getPlayerClocks(); var gameInfo = new DBDefs.GameHistory() {{ + gameId = lotroGame.getGameId(); + winner = winnerName; winnerId = _playerDAO.getPlayer(winnerName).getId(); loser = loserName; @@ -79,12 +83,21 @@ public class GameRecorder { tournament = tournamentName; - //Update this version as needed + winner_site = lotroGame.getGame().getGameState().getPlayerPosition(winner); + loser_site = lotroGame.getGame().getGameState().getPlayerPosition(winner); + + game_length_type = time.name(); + max_game_time = time.maxSecondsPerPlayer(); + game_timeout = time.maxSecondsPerDecision(); + winner_clock_remaining = clocks.getOrDefault(winnerName, -1); + loser_clock_remaining = clocks.getOrDefault(loserName, -1); + + //Update this version as needed; note that this is the REPLAY FORMAT, not the JSON summary replay_version = 1; }}; var playerRecordingId = saveRecordedChannels(recordingChannels, gameInfo, decks); - _gameHistoryService.addGameHistory(gameInfo); + gameInfo.id = _gameHistoryService.addGameHistory(gameInfo); if(format.isPlaytest()) { @@ -110,9 +123,9 @@ public class GameRecorder { private File getRecordingFileVersion1(String playerId, String gameId, ZonedDateTime startDate) { var gameReplayFolder = new File(AppConfig.getProperty("application.root"), "replay"); - //This dumbass formatting output is because anything that otherwise intersects with the + //This dumbass formatting output is because anything that otherwise interacts with the // year subfield appears to trigger a JVM segfault in the guts of the java ecosystem. - // Super-dumb. Don't touch. + // Super-dumb. Don't touch these two lines. var year = startDate.format(DateTimeFormatter.ofPattern("yyyy")); var month = startDate.format(DateTimeFormatter.ofPattern("MM")); 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 d09181441..f495c580f 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 @@ -8,6 +8,7 @@ import com.gempukku.lotro.communication.GameStateListener; import com.gempukku.lotro.filters.Filters; import com.gempukku.lotro.game.state.GameCommunicationChannel; import com.gempukku.lotro.game.state.GameEvent; +import com.gempukku.lotro.hall.GameTimer; import com.gempukku.lotro.logic.GameUtils; import com.gempukku.lotro.logic.decisions.AwaitingDecision; import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException; @@ -32,8 +33,8 @@ public class LotroGameMediator { private final Map _playerDecks = new HashMap<>(); private final String _gameId; - private final int _maxSecondsForGamePerPlayer; - private final int _maxSecondsPerDecision; + + private GameTimer _timeSettings; private final boolean _allowSpectators; private final boolean _cancellable; private final boolean _showInGameHall; @@ -44,11 +45,10 @@ public class LotroGameMediator { private int _channelNextIndex = 0; private volatile boolean _destroyed; - public LotroGameMediator(String gameId, LotroFormat lotroFormat, LotroGameParticipant[] participants, LotroCardBlueprintLibrary library, int maxSecondsForGamePerPlayer, - int maxSecondsPerDecision, boolean allowSpectators, boolean cancellable, boolean showInGameHall) { + public LotroGameMediator(String gameId, LotroFormat lotroFormat, LotroGameParticipant[] participants, LotroCardBlueprintLibrary library, + GameTimer gameTimer, boolean allowSpectators, boolean cancellable, boolean showInGameHall) { _gameId = gameId; - _maxSecondsForGamePerPlayer = maxSecondsForGamePerPlayer; - _maxSecondsPerDecision = maxSecondsPerDecision; + _timeSettings = gameTimer; _allowSpectators = allowSpectators; _cancellable = cancellable; this._showInGameHall = showInGameHall; @@ -83,6 +83,8 @@ public class LotroGameMediator { return _gameId; } + public DefaultLotroGame getGame() { return _lotroGame; } + public boolean isAllowSpectators() { return _allowSpectators; } @@ -257,7 +259,7 @@ public class LotroGameMediator { // Channel is stale (user no longer connected to game, to save memory, we remove the channel // User can always reconnect and establish a new channel GameCommunicationChannel channel = playerChannels.getValue(); - if (currentTime > channel.getLastAccessed() + _maxSecondsPerDecision*1000) { + if (currentTime > channel.getLastAccessed() + _timeSettings.maxSecondsPerDecision() * 1000L) { _lotroGame.removeGameStateListener(channel); _communicationChannels.remove(playerId); } @@ -267,7 +269,7 @@ public class LotroGameMediator { for (Map.Entry playerDecision : new HashMap<>(_decisionQuerySentTimes).entrySet()) { String playerId = playerDecision.getKey(); long decisionSent = playerDecision.getValue(); - if (currentTime > decisionSent + _maxSecondsPerDecision*1000) { + if (currentTime > decisionSent + _timeSettings.maxSecondsPerDecision() * 1000L) { addTimeSpentOnDecisionToUserClock(playerId); _lotroGame.playerLost(playerId, "Player decision timed-out"); } @@ -275,7 +277,7 @@ public class LotroGameMediator { for (Map.Entry playerClock : _playerClocks.entrySet()) { String player = playerClock.getKey(); - if (_maxSecondsForGamePerPlayer - playerClock.getValue() - getCurrentUserPendingTime(player) < 0) { + if (_timeSettings.maxSecondsPerPlayer() - playerClock.getValue() - getCurrentUserPendingTime(player) < 0) { addTimeSpentOnDecisionToUserClock(player); _lotroGame.playerLost(player, "Player run out of time"); } @@ -385,7 +387,7 @@ public class LotroGameMediator { Map secondsLeft = new HashMap<>(); for (Map.Entry playerClock : _playerClocks.entrySet()) { String playerClockName = playerClock.getKey(); - secondsLeft.put(playerClockName, _maxSecondsForGamePerPlayer - playerClock.getValue() - getCurrentUserPendingTime(playerClockName)); + secondsLeft.put(playerClockName, _timeSettings.maxSecondsPerPlayer() - playerClock.getValue() - getCurrentUserPendingTime(playerClockName)); } visitor.visitClock(secondsLeft); } finally { @@ -416,7 +418,7 @@ public class LotroGameMediator { Map secondsLeft = new HashMap<>(); for (Map.Entry playerClock : _playerClocks.entrySet()) { String playerId = playerClock.getKey(); - secondsLeft.put(playerId, _maxSecondsForGamePerPlayer - playerClock.getValue() - getCurrentUserPendingTime(playerId)); + secondsLeft.put(playerId, _timeSettings.maxSecondsPerPlayer() - playerClock.getValue() - getCurrentUserPendingTime(playerId)); } visitor.visitClock(secondsLeft); } finally { @@ -440,7 +442,7 @@ public class LotroGameMediator { } } - private int getCurrentUserPendingTime(String participantId) { + public int getCurrentUserPendingTime(String participantId) { if (!_decisionQuerySentTimes.containsKey(participantId)) return 0; long queryTime = _decisionQuerySentTimes.get(participantId); @@ -448,6 +450,12 @@ public class LotroGameMediator { return (int) ((currentTime - queryTime) / 1000); } + public GameTimer getTimeSettings() { + return _timeSettings; + } + + public Map getPlayerClocks() { return Collections.unmodifiableMap(_playerClocks); } + public String getPlayerPositions() { StringBuilder stringBuilder = new StringBuilder(); for (String player : _playersPlaying) { 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 0299031b3..ff562a9bc 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 @@ -100,18 +100,18 @@ public class LotroServer extends AbstractServer { _chatServer.createChatRoom(getChatRoomName(gameId), false, 30, false, null); // Allow spectators for leagues, but not tournaments + // Also: yes, yes, we're very proud that you found a way to assign this boolean in one line. + // The point of the code setting it like this is to make each case painfully explicit. boolean spectate = true; if(gameSettings.getLeague() != null) { spectate = true; } - else if(gameSettings.isCompetitive()) { - spectate = false; - } - if(gameSettings.isPrivateGame()) { + else if(gameSettings.isCompetitive() || gameSettings.isPrivateGame() || gameSettings.isHiddenGame()) { spectate = false; } + LotroGameMediator lotroGameMediator = new LotroGameMediator(gameId, gameSettings.getLotroFormat(), participants, _lotroCardBlueprintLibrary, - gameSettings.getMaxSecondsPerPlayer(), gameSettings.getMaxSecondsPerDecision(), + gameSettings.getTimeSettings(), spectate, !gameSettings.isCompetitive(), gameSettings.isHiddenGame()); lotroGameMediator.addGameResultListener( new GameResultListener() { diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/ReplayMetadata.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/ReplayMetadata.java index dac3154d1..52adaf80b 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/ReplayMetadata.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/ReplayMetadata.java @@ -23,7 +23,9 @@ public class ReplayMetadata { public List StartingFellowship = new ArrayList<>(); } - public Integer MetadataVersion = 1; + //Version 1: First tracked version; original version was completely different + //Version 2: Adding the highest achieved sites by player, game IDs, and game timer length information + public Integer MetadataVersion = 2; public DBDefs.GameHistory GameReplayInfo; diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/GameSettings.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/GameSettings.java index 27dd6bc06..4e474ab72 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/GameSettings.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/GameSettings.java @@ -13,15 +13,13 @@ public class GameSettings { private final boolean competitive; private final boolean privateGame; private final boolean hiddenGame; - private final String timerName; - private final int maxSecondsPerPlayer; - private final int maxSecondsPerDecision; + private final GameTimer timeSettings; private final String userDescription; private final boolean isInviteOnly; public GameSettings(CollectionType collectionType, LotroFormat lotroFormat, League league, LeagueSerieData leagueSerie, - boolean competitive, boolean privateGame, boolean hiddenGame, String timerName, int maxSecondsPerPlayer, int maxSecondsPerDecision, - String description, boolean isInviteOnly) { + boolean competitive, boolean privateGame, boolean isInviteOnly, boolean hiddenGame, + GameTimer timer, String description) { this.collectionType = collectionType; this.lotroFormat = lotroFormat; this.league = league; @@ -29,9 +27,7 @@ public class GameSettings { this.competitive = competitive; this.privateGame = privateGame; this.hiddenGame = hiddenGame; - this.timerName = timerName; - this.maxSecondsPerPlayer = maxSecondsPerPlayer; - this.maxSecondsPerDecision = maxSecondsPerDecision; + this.timeSettings = timer; this.userDescription = description; this.isInviteOnly = isInviteOnly; } @@ -64,17 +60,7 @@ public class GameSettings { return hiddenGame; } - public int getMaxSecondsPerPlayer() { - return maxSecondsPerPlayer; - } - - public int getMaxSecondsPerDecision() { - return maxSecondsPerDecision; - } - - public String getTimerName() { - return timerName; - } + public GameTimer getTimeSettings() { return timeSettings; } public String getUserDescription() { return userDescription; } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/GameTimer.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/GameTimer.java index dfb6d2bef..39b7e47fd 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/GameTimer.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/GameTimer.java @@ -1,31 +1,26 @@ package com.gempukku.lotro.hall; -public class GameTimer { - private final boolean longGame; - private final String name; - private final int maxSecondsPerPlayer; - private final int maxSecondsPerDecision; +public record GameTimer(boolean longGame, String name, int maxSecondsPerPlayer, int maxSecondsPerDecision) { - public GameTimer(boolean longGame, String name, int maxSecondsPerPlayer, int maxSecondsPerDecision) { - this.longGame = longGame; - this.name = name; - this.maxSecondsPerPlayer = maxSecondsPerPlayer; - this.maxSecondsPerDecision = maxSecondsPerDecision; - } + public static final GameTimer DEFAULT_TIMER = new GameTimer(false, "Default", 60 * 80, 60 * 5); + public static final GameTimer BLITZ_TIMER = new GameTimer(false, "Blitz!", 60 * 30, 60 * 5); + public static final GameTimer SLOW_TIMER = new GameTimer(false, "Slow", 60 * 120, 60 * 10); + public static final GameTimer GLACIAL_TIMER = new GameTimer(true, "Glacial", 60 * 60 * 24 * 3, 60 * 60 * 24); + // 5 minutes timeout, 40 minutes per game per player + public static final GameTimer COMPETITIVE_TIMER = new GameTimer(false, "Competitive", 60 * 40, 60 * 5); + public static final GameTimer TOURNAMENT_TIMER = new GameTimer(false, "Tournament", 60 * 40, 60 * 5); - public boolean isLongGame() { - return longGame; - } - - public String getName() { - return name; - } - - public int getMaxSecondsPerPlayer() { - return maxSecondsPerPlayer; - } - - public int getMaxSecondsPerDecision() { - return maxSecondsPerDecision; + public static GameTimer ResolveTimer(String timer) { + if (timer != null) { + switch (timer.toLowerCase()) { + case "blitz": + return GameTimer.BLITZ_TIMER; + case "slow": + return GameTimer.SLOW_TIMER; + case "glacial": + return GameTimer.GLACIAL_TIMER; + } + } + return GameTimer.DEFAULT_TIMER; } } 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 189ff7810..53fe00874 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 @@ -30,12 +30,7 @@ import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; public class HallServer extends AbstractServer { - private static final GameTimer DEFAULT_TIMER = new GameTimer(false, "Default", 60 * 80, 60 * 5); - private static final GameTimer BLITZ_TIMER = new GameTimer(false, "Blitz!", 60 * 30, 60 * 5); - private static final GameTimer SLOW_TIMER = new GameTimer(false, "Slow", 60 * 120, 60 * 10); - private static final GameTimer GLACIAL_TIMER = new GameTimer(true, "Glacial", 60 * 60 * 24 * 3, 60 * 60 * 24); - // 5 minutes timeout, 40 minutes per game per player - private static final GameTimer COMPETITIVE_TIMER = new GameTimer(false, "Competitive", 60 * 40, 60 * 5); + private static final int _playerTableInactivityPeriod = 1000 * 20 ; // 20 seconds @@ -344,11 +339,11 @@ public class HallServer extends AbstractServer { /** * @return If table created, otherwise false (if the user already is sitting at a table or playing). */ - public void createNewTable(String type, Player player, String deckName, String timer, String description, boolean isInviteOnly, boolean isPrivate) throws HallException { + public void createNewTable(String type, Player player, String deckName, String timer, String description, boolean isInviteOnly, boolean isPrivate, boolean isHidden) throws HallException { if (_shutdown) throw new HallException("Server is in shutdown mode. Server will be restarted after all running games are finished."); - GameSettings gameSettings = createGameSettings(type, timer, description, isInviteOnly, isPrivate); + GameSettings gameSettings = createGameSettings(type, timer, description, isInviteOnly, isPrivate, isHidden); LotroDeck lotroDeck = validateUserAndDeck(gameSettings.getLotroFormat(), player, deckName, gameSettings.getCollectionType()); @@ -364,11 +359,11 @@ public class HallServer extends AbstractServer { } } - public void spoofNewTable(String type, Player player, Player librarian, String deckName, String timer, String description, boolean isInviteOnly, boolean isPrivate) throws HallException { + public void spoofNewTable(String type, Player player, Player librarian, String deckName, String timer, String description, boolean isInviteOnly, boolean isPrivate, boolean isHidden) throws HallException { if (_shutdown) throw new HallException("Server is in shutdown mode. Server will be restarted after all running games are finished."); - GameSettings gameSettings = createGameSettings(type, timer, description, isInviteOnly, isPrivate); + GameSettings gameSettings = createGameSettings(type, timer, description, isInviteOnly, isPrivate, isHidden); LotroDeck lotroDeck = validateUserAndDeck(gameSettings.getLotroFormat(), librarian, deckName, gameSettings.getCollectionType()); @@ -384,12 +379,12 @@ public class HallServer extends AbstractServer { } } - private GameSettings createGameSettings(String type, String timer, String description, boolean isInviteOnly, boolean isPrivate) throws HallException { + private GameSettings createGameSettings(String type, String timer, String description, boolean isInviteOnly, boolean isPrivate, boolean isHidden) throws HallException { League league = null; LeagueSerieData leagueSerie = null; CollectionType collectionType = _defaultCollectionType; LotroFormat format = _formatLibrary.getHallFormats().get(type); - GameTimer gameTimer = resolveTimer(timer); + GameTimer gameTimer = GameTimer.ResolveTimer(timer); if (format == null) { // Maybe it's a league format? @@ -414,7 +409,7 @@ public class HallServer extends AbstractServer { format = leagueSerie.getFormat(); collectionType = leagueSerie.getCollectionType(); - gameTimer = COMPETITIVE_TIMER; + gameTimer = GameTimer.COMPETITIVE_TIMER; } } // It's not a normal format and also not a league one @@ -422,21 +417,7 @@ public class HallServer extends AbstractServer { throw new HallException("This format is not supported: " + type); return new GameSettings(collectionType, format, league, leagueSerie, - league != null, isPrivate, gameTimer.isLongGame(), gameTimer.getName(), gameTimer.getMaxSecondsPerPlayer(), gameTimer.getMaxSecondsPerDecision(), description, isInviteOnly); - } - - private GameTimer resolveTimer(String timer) { - if (timer != null) { - switch (timer) { - case "blitz": - return BLITZ_TIMER; - case "slow": - return SLOW_TIMER; - case "glacial": - return GLACIAL_TIMER; - } - } - return DEFAULT_TIMER; + league != null, isPrivate, isInviteOnly, isHidden, gameTimer, description); } public boolean joinQueue(String queueId, Player player, String deckName) throws HallException, SQLException, IOException { @@ -751,7 +732,7 @@ public class HallServer extends AbstractServer { if (league != null) return league.getName() + " - " + table.getGameSettings().getLeagueSerie().getName(); else - return "Casual - " + table.getGameSettings().getTimerName(); + return "Casual - " + table.getGameSettings().getTimeSettings().name(); } private void createGameFromTable(GameTable gameTable) { @@ -885,7 +866,7 @@ public class HallServer extends AbstractServer { private HallTournamentCallback(Tournament tournament) { _tournament = tournament; tournamentGameSettings = new GameSettings(null, _formatLibrary.getFormat(_tournament.getFormat()), - null, null, true, false, false, "Tournament", 60 * 40, 60 * 5, null, false); + null, null, true, false, false, false, GameTimer.TOURNAMENT_TIMER, null); } @Override diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/TableHolder.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/TableHolder.java index 2dda25d12..f3ff57302 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/TableHolder.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/hall/TableHolder.java @@ -251,6 +251,6 @@ public class TableHolder { if (league != null) return league.getName() + " - " + table.getGameSettings().getLeagueSerie().getName(); else - return "Casual - " + table.getGameSettings().getTimerName(); + return "Casual - " + table.getGameSettings().getTimeSettings().name(); } }