Class GameServerSide

  • Direct Known Subclasses:
    GameServerSideTestAccess

    public class GameServerSide
    extends Game
    Class Game gets and holds high-level data about a Titan game. This is the old design with the game information in the server. Some of the functionality here is supposed to be moved into the Game class which then can be shared between server and clients (the class, not the instances). Other parts should be moved into the Server class or elsewhere.
    Author:
    David Ripton, Bruce Sherrod, Romain Dolbeau
    • Field Detail

      • LOGGER

        private static final java.util.logging.Logger LOGGER
      • activePlayerNum

        private int activePlayerNum
      • lastRecruitTurnNumber

        private int lastRecruitTurnNumber
      • battleInProgress

        private boolean battleInProgress
      • summoning

        private boolean summoning
      • reinforcing

        private boolean reinforcing
      • acquiring

        private boolean acquiring
      • pointsScored

        private int pointsScored
      • turnCombatFinished

        private int turnCombatFinished
      • winner

        private Legion winner
      • engagementResult

        private java.lang.String engagementResult
      • pendingAdvancePhase

        private boolean pendingAdvancePhase
      • loadingGame

        private boolean loadingGame
      • replayOngoing

        private boolean replayOngoing
      • server

        private Server server
      • attackerProposals

        private final java.util.Set<Proposal> attackerProposals
      • defenderProposals

        private final java.util.Set<Proposal> defenderProposals
      • colorPickOrder

        private final java.util.LinkedList<Player> colorPickOrder
      • colorsLeft

        private java.util.List<PlayerColor> colorsLeft
      • options

        private final Options options
      • hostingPlayerName

        private java.lang.String hostingPlayerName
      • flagFilename

        private java.lang.String flagFilename
      • startingWebClient

        private WebClient startingWebClient
      • gameSaver

        private final GameSaving gameSaver
        The object that handles the Game Saving procedure
      • isFirstAutoSave

        private boolean isFirstAutoSave
        From the very first autosave file name, we derive the file where to store all the messages that are sent to the internal spectator client.
      • iscMessages

        private java.io.PrintWriter iscMessages
        The file where to send the spectator messages. Might/will be null when autosave disabled.
      • gameCounter

        private static int gameCounter
      • gameId

        private final java.lang.String gameId
      • hotSeatMode

        private boolean hotSeatMode
      • cvbPlayer

        private Player cvbPlayer
      • waitForClientsMutex

        java.lang.Object waitForClientsMutex
      • serverGotAll

        boolean serverGotAll
    • Constructor Detail

      • GameServerSide

        public GameServerSide​(WhatNextManager whatNextMgr,
                              Options serverOptions,
                              Variant variant)
        The normal constructor to be used everywhere
        Parameters:
        whatNextMgr - A WhatNextManager object which manages the main control flow which thing to do 'next' when this game is over.
        serverOptions - The server side options, initialized from the GetPlayers dialog and/or command line options.
        variant - Variant of this game
    • Method Detail

      • makeNewGameServerSide

        static GameServerSide makeNewGameServerSide​(Variant variant)
        Shortcut for UnitTests, to create a Game with dummy input objects on the fly.
      • newGameServerSide

        public static GameServerSide newGameServerSide​(WhatNextManager whatNextMgr,
                                                       Options serverOptions,
                                                       Variant variant)
        For more complicated functional tests
        Parameters:
        whatNextMgr -
        serverOptions -
        variant -
        Returns:
      • setFlagFilename

        public void setFlagFilename​(java.lang.String flagFilename)
      • getHostingPlayer

        public java.lang.String getHostingPlayer()
      • getPort

        private int getPort()
      • initServer

        private void initServer()
      • actOnWaitForClientsCompleted

        public void actOnWaitForClientsCompleted​(boolean gotAll)
      • startServerAndWaitUntilNotifiedThatWaitForClientsCompleted

        private boolean startServerAndWaitUntilNotifiedThatWaitForClientsCompleted()
      • createLocalClients

        public void createLocalClients()
      • createLocalClient

        private void createLocalClient​(PlayerServerSide player,
                                       boolean createGUI,
                                       java.lang.String type)
      • createInternalDummyClient

        private void createInternalDummyClient()
      • storeLocalClient

        protected void storeLocalClient​(java.lang.String playerName,
                                        Client c)
      • updateCaretakerDisplaysFor

        private void updateCaretakerDisplaysFor​(CreatureType type)
        Update the dead and available counts for a creature type on all clients.
      • updateCaretakerDisplays

        public void updateCaretakerDisplays()
        Update the dead and available counts for all creature types on all clients.
      • waitUntilGameFinishes

        protected void waitUntilGameFinishes()
      • cleanupWhenGameOver

        private void cleanupWhenGameOver()
      • clearFlags

        private void clearFlags()
      • addPlayersFromOptions

        private void addPlayersFromOptions()
      • startNewGameAndWaitUntilOver

        public boolean startNewGameAndWaitUntilOver​(java.lang.String hostingPlayer)
      • newGame

        boolean newGame​(java.lang.String hostingPlayer)
        Start a new game.
      • newGame2

        void newGame2()
      • sortPlayersDescendingTower

        private void sortPlayersDescendingTower()
        Temporary solution ... I do not know a better way how to do the sorting on players (type List) itself. I don't want to pull up the Comparator predicate, because ClientSide might have totally different idea of the right "order"...
      • nameIsTaken

        private boolean nameIsTaken​(java.lang.String name,
                                    Player checkedPlayer)
      • getUniqueName

        java.lang.String getUniqueName​(java.lang.String name,
                                       Player player)
        If the name is taken, add random digits to the end.
      • findNetworkPlayer

        Player findNetworkPlayer​(java.lang.String playerName)
        Find a Player for a new remote client. If loading a game, this is the network player with a matching player name. If a new game, it's the first network player whose name is still set to
      • syncOptions

        private void syncOptions()
        Send all current game option values to all clients.
      • assignColors

        private void assignColors()
      • nextPickColor

        void nextPickColor()
      • makeNameByType

        private java.lang.String makeNameByType​(java.lang.String templateName,
                                                java.lang.String type)
      • getNextColorPicker

        Player getNextColorPicker()
      • newGame3

        private void newGame3()
        Done picking player colors; proceed to start game.
      • assignTowers

        private void assignTowers()
        Randomize towers by rolling dice and rerolling ties.
      • getBalancedTowers

        static java.util.List<MasterHex> getBalancedTowers​(int numPlayers,
                                                           java.util.List<MasterHex> towerList)
        Return a list with a balanced order of numPlayer towers chosen from towerList, which must hold numeric strings.
      • getServer

        Server getServer()
      • createAndAddPlayer

        PlayerServerSide createAndAddPlayer​(java.lang.String name,
                                            java.lang.String shortTypeName)
      • getActivePlayerNum

        int getActivePlayerNum()
      • getActivePlayer

        Player getActivePlayer()
      • makeMovementRoll

        private void makeMovementRoll()
      • getPlayerByNameIgnoreNull

        Player getPlayerByNameIgnoreNull​(java.lang.String playerName)
        Resolve playerName into Player object. Name might be null, then returns null.
        Parameters:
        playerName -
        Returns:
        The player object for given player name, null if name was null
      • getPlayerByName

        Player getPlayerByName​(java.lang.String playerName)
        Resolve playerName into Player object. Name must not be null. If no player for given name found, it would throw IllegalArgumentException (well, did earlier, at the moment (03/2012) replace with SEVERE error; exception would totally throw server thread out of the orbit...)
        Parameters:
        playerName -
        Returns:
        Player object for given name.
      • getPlayerByShortColor

        Player getPlayerByShortColor​(java.lang.String shortColor)
        NOTE: to be used only during loading a Game! Client side has a more sophisticated version that takes slain players and their inherited markers into account.
      • handlePlayerWithdrawal

        void handlePlayerWithdrawal​(Player player)
        A player requested he wants to withdraw (or connection was lost, and server socket handling does withdraw then).
        Parameters:
        player - The player that wishes to withdraw from the game TODO Notify all players.
      • getWinner

        private Player getWinner()
      • checkForVictory

        void checkForVictory()
      • announceGameOver

        private void announceGameOver​(boolean disposeFollows)
      • isLoadingGame

        boolean isLoadingGame()
      • isReplayOngoing

        boolean isReplayOngoing()
      • stopAllDueToFunctionalTestCompleted

        public void stopAllDueToFunctionalTestCompleted()
      • kickstartGame

        public void kickstartGame()
      • notifyTestCaseGameIsUpNow

        protected void notifyTestCaseGameIsUpNow()
      • advancePhase

        void advancePhase​(Phase oldPhase,
                          Player player)
        Advance to the next phase, only if the passed oldPhase and playerName are current.
      • setGameOver

        public void setGameOver​(boolean gameOver,
                                java.lang.String message)
        Overrides:
        setGameOver in class Game
      • setupPhase

        private void setupPhase()
      • setupSplit

        private void setupSplit()
      • hotSeatModeChangeBoards

        private void hotSeatModeChangeBoards()
      • setupMove

        private void setupMove()
      • setupFight

        private void setupFight()
      • setupMuster

        private void setupMuster()
      • isAutoSavePoint

        private boolean isAutoSavePoint()
        So far, we do autosave only at begin of each players turn, i.e. when a split phase was just set up.
        Returns:
        Whether now is a time when autosave is due.
      • autoSave

        void autoSave()
      • getIscMessageFile

        public java.io.PrintWriter getIscMessageFile()
      • saveGameWithErrorHandling

        void saveGameWithErrorHandling​(java.lang.String filename,
                                       boolean autoSave)
      • loadGameAndWaitUntilOver

        public boolean loadGameAndWaitUntilOver​(org.jdom.Element root)
      • loadGame

        public boolean loadGame​(org.jdom.Element root)
      • readLegion

        private void readLegion​(org.jdom.Element leg,
                                PlayerServerSide player)
                         throws org.jdom.DataConversionException
        Throws:
        org.jdom.DataConversionException
      • loadGame2

        boolean loadGame2()
      • resyncBackupData

        private boolean resyncBackupData()
      • findEligibleRecruits

        java.util.List<CreatureType> findEligibleRecruits​(Legion legion,
                                                          MasterHex hex)
        Return a list of eligible recruits, as Creatures. TODO second parameter is probably superfluous
      • findEligibleRecruiters

        private java.util.List<CreatureType> findEligibleRecruiters​(Legion legion,
                                                                    java.lang.String recruitName)
        Return a list of eligible recruiter creatures.
      • anonymousRecruitLegal

        private boolean anonymousRecruitLegal​(Legion legion,
                                              CreatureType recruit)
        Return true if this legion can recruit this recruit without disclosing a recruiter.
      • editModeAddCreature

        public void editModeAddCreature​(java.lang.String markerId,
                                        java.lang.String creatureName)
      • editModeRemoveCreature

        public void editModeRemoveCreature​(java.lang.String markerId,
                                           java.lang.String creatureName)
      • editModeRelocateLegion

        public void editModeRelocateLegion​(java.lang.String markerId,
                                           java.lang.String hexLabel)
      • acquireMaybe

        public void acquireMaybe​(LegionServerSide legion,
                                 int scoreBeforeAdd,
                                 int pointsToAdd)
        If the legion can acquire (height < 7), find out which acquirable it might get for the pointsToAdd, and fire off the askAcquirable messages.
        Parameters:
        legion - Legion which earned the points and thus is entitled to get the acqirable
        scoreBeforeAdd - Score from which to start
        pointsToAdd - How many points were earned
      • dispose

        void dispose()
      • placeInitialLegion

        private void placeInitialLegion​(PlayerServerSide player,
                                        java.lang.String markerId)
      • hasConventionalMove

        public boolean hasConventionalMove​(LegionServerSide legion,
                                           MasterHex hex,
                                           int roll,
                                           boolean ignoreFriends)
      • createSummonAngel

        void createSummonAngel​(Legion attacker)
      • reinforce

        void reinforce​(Legion legion)
        Called locally and from Battle.
      • doneReinforcing

        void doneReinforcing()
      • doSummon

        void doSummon​(Summoning event)
        Handles summoning of a creature.
        Parameters:
        event - The summoning event (or null if summoning is to be skipped) TODO get rid of downcasts
      • isBattleInProgress

        boolean isBattleInProgress()
      • finishBattle

        void finishBattle​(MasterHex masterHex,
                          boolean attackerEntered,
                          int points,
                          int turnDone)
      • doSplit

        boolean doSplit​(Legion parent,
                        java.lang.String childId,
                        java.util.List<CreatureType> creaturesToSplit)
        Return true and call Server.didSplit() if the split succeeded. Return false if it failed.
      • doMove

        java.lang.String doMove​(Legion legion,
                                MasterHex hex,
                                EntrySide entrySide,
                                boolean teleport,
                                CreatureType teleportingLord)
        Move the legion to the hex if legal. Return a string telling the reason why it is illegal, or null if ok and move was done.
      • undoMove

        void undoMove​(Legion legion)
      • engage2

        private void engage2​(MasterHex hex)
      • engage3

        private void engage3​(MasterHex hex)
      • flee

        void flee​(Legion legion)
      • concede

        void concede​(Legion attacker)
      • doNotFlee

        void doNotFlee​(Legion legion)
      • doNotConcede

        void doNotConcede​(Legion legion)
        Used only for pre-battle attacker concession.
      • makeProposal

        void makeProposal​(java.lang.String playerName,
                          java.lang.String proposalString)
        playerName offers proposal.
      • handleConcession

        private void handleConcession​(Legion loser,
                                      Legion winner,
                                      boolean fled)
      • handleNegotiation

        private void handleNegotiation​(Proposal results)
      • doneAcquiringAngels

        void doneAcquiringAngels()
      • setEngagementResult

        private void setEngagementResult​(java.lang.String aResult,
                                         Legion winner,
                                         int aPoints,
                                         int aTurn)
      • checkEngagementDone

        private void checkEngagementDone()
      • gameShouldContinue

        public boolean gameShouldContinue()
      • getPlayerByMarkerId

        public Player getPlayerByMarkerId​(java.lang.String markerId)
      • getPlayerUsingColor

        private Player getPlayerUsingColor​(java.lang.String shortColor)
      • mulligan

        int mulligan()
      • getOption

        boolean getOption​(java.lang.String optname)
      • getIntOption

        int getIntOption​(java.lang.String optname)
      • addCreatureEvent

        void addCreatureEvent​(AddCreatureAction event,
                              java.lang.String reason)
      • removeCreatureEvent

        void removeCreatureEvent​(Legion legion,
                                 CreatureType creature,
                                 java.lang.String reason)
      • mergeEvent

        void mergeEvent​(java.lang.String splitoffId,
                        java.lang.String survivorId)
      • revealEvent

        void revealEvent​(boolean allPlayers,
                         java.util.List<Player> players,
                         Legion legion,
                         java.util.List<CreatureType> creatureNames,
                         java.lang.String reason)
      • playerElimEvent

        void playerElimEvent​(Player player,
                             Player slayer)
      • movementRollEvent

        void movementRollEvent​(Player player,
                               int roll)
      • legionUndoMoveEvent

        void legionUndoMoveEvent​(Legion legion)
      • undoRecruitEvent

        void undoRecruitEvent​(Legion legion)