Class GameSession


  • public final class GameSession
    extends Object
    The server game session object is the main way of accessing the state of a session and all managers related to a that session. It is usually passed to all methods that are part of a game session run (turn) and acts as a context object. For background, many game sessions share a server instance thread. See also ServerFacade
    • Constructor Detail

      • GameSession

        public GameSession()
    • Method Detail

      • getBusinessObject

        public <T> T getBusinessObject​(Class<? extends T> clazz)
        Business objects implement game mechanics
      • getPlayers

        public com.google.common.collect.ImmutableMap<UUID,​Player> getPlayers()
        Returns all players of a game session
      • setPlayers

        public void setPlayers​(com.google.common.collect.ImmutableMap<UUID,​Player> players)
      • getHost

        public UUID getHost()
        Returns the player who is currently host
      • setHost

        public void setHost​(UUID host)
      • getGameSessionId

        public UUID getGameSessionId()
        Returns the game session identifier
      • getNextRunLow

        public long getNextRunLow()
      • setNextRunLow

        public void setNextRunLow​(long nextRunLow)
      • getNextRunLowPrediction

        public long getNextRunLowPrediction()
      • setNextRunLowPrediction

        public void setNextRunLowPrediction​(long nextRunLowPrediction)
      • getNextRunHigh

        public long getNextRunHigh()
      • setNextRunHigh

        public void setNextRunHigh​(long nextRunHigh)
      • getNextRunHighPrediction

        public long getNextRunHighPrediction()
      • setNextRunHighPrediction

        public void setNextRunHighPrediction​(long nextRunHighPrediction)
      • getRunIntervalMsLow

        public int getRunIntervalMsLow()
      • setRunIntervalMsLow

        public void setRunIntervalMsLow​(int runIntervalMsLow)
      • getRunIntervalMsHigh

        public int getRunIntervalMsHigh()
      • setRunIntervalMsHigh

        public void setRunIntervalMsHigh​(int runIntervalMsHigh)
      • getGameSessionState

        public GameSessionState getGameSessionState()
        Returns whether the game session is still in lobby or already started
      • setGameSessionState

        public void setGameSessionState​(GameSessionState gameSessionState)
      • getPassword

        public String getPassword()
      • setPassword

        public void setPassword​(String password)
      • getShipByPlayer

        public Map<UUID,​UUID> getShipByPlayer()
        Returns a lookup map for ships by player id
      • isFirstGameTurn

        public boolean isFirstGameTurn()
      • setFirstGameTurn

        public void setFirstGameTurn​(boolean firstGameTurn)
      • getTurn

        public int getTurn()
        Returns the turn number
      • setTurn

        public void setTurn​(int turn)
      • getServerWorldManager

        public ServerWorldManager getServerWorldManager()
        The server WorldManager, representing the game world
      • setServerWorldManager

        public void setServerWorldManager​(ServerWorldManager serverWorldManager)
      • getDeferredGameActionMessages

        public List<org.apache.commons.lang3.tuple.Pair<GameActionMessage,​Set<UUID>>> getDeferredGameActionMessages()
      • getPendingPlayers

        public Map<UUID,​Player> getPendingPlayers()
      • getEntityDefManager

        public EntityDefManager getEntityDefManager()
        The entity definition manager
      • setEntityDefManager

        public void setEntityDefManager​(EntityDefManager entityDefManager)
      • getShipClassManager

        public ShipClassManager getShipClassManager()
        The ship class manager
      • setShipClassManager

        public void setShipClassManager​(ShipClassManager shipClassManager)
      • setListServerRecord

        public void setListServerRecord​(DirectoryRecord listServerRecord)
      • getLastServerListing

        public long getLastServerListing()
      • setLastServerListing

        public void setLastServerListing​(long lastServerListing)
      • getInstanceId

        public UUID getInstanceId()
        Returns the id of the instance the game session is running. Many game sessions share an instance thread.
      • setInstanceId

        public void setInstanceId​(UUID instanceId)
      • isEditorMode

        public boolean isEditorMode()
        Returns whether game session is in editor mode, e.g. running in ship or scene editor
      • setEditorMode

        public void setEditorMode​(boolean editorMode)
      • getActiveServerModules

        public List<Module> getActiveServerModules()
        Returns all active server modules
      • getModManager

        public ModManager getModManager()
        The mod manager
      • setModManager

        public void setModManager​(ModManager modManager)
      • getGameMode

        public GameModeDef getGameMode()
        Returns the definition of the current game mode
      • setGameMode

        public void setGameMode​(GameModeDef gameMode)
      • getShipSlotByPlayer

        public Map<UUID,​Integer> getShipSlotByPlayer()
        Lookup map for the ship slot index by player id
      • getExceptions

        public int getExceptions()
      • setExceptions

        public void setExceptions​(int exceptions)
      • isTerminate

        public boolean isTerminate()
      • setTerminate

        public void setTerminate​(boolean terminate)
        Terminate the game session
      • getServerModuleManager

        public ServerModuleManager getServerModuleManager()
        The module manager
      • setServerModuleManager

        public void setServerModuleManager​(ServerModuleManager serverModuleManager)
      • getState

        public Map<String,​Object> getState()
        A shared state for this game session. Will not be transferred to the client. Useful to store and share server side information between modules and entities.
      • getGameModeOptions

        public Map<String,​Object> getGameModeOptions()
        Game mode options are a shared state for this game session. Unlike #getState, game mode options are also transferred to the client. Set #isGameModeOptionsDirty after changing the state.
      • isGameModeOptionsDirty

        public boolean isGameModeOptionsDirty()
      • setGameModeOptionsDirty

        public void setGameModeOptionsDirty​(boolean gameModeOptionsDirty)
        Flags game mode options dirty to transfer it to the client
      • getScriptingManager

        public ScriptingManager getScriptingManager()
        The scripting manager
      • setScriptingManager

        public void setScriptingManager​(ScriptingManager scriptingManager)
      • getLocalizationManager

        public LocalizationManager getLocalizationManager()
        The localization manager
      • setLocalizationManager

        public void setLocalizationManager​(LocalizationManager localizationManager)
      • getSceneRegistry

        public SceneRegistry getSceneRegistry()
        The scene registry
      • setSceneRegistry

        public void setSceneRegistry​(SceneRegistry sceneRegistry)
      • getGameModeGlobalShipClass

        public ShipClass getGameModeGlobalShipClass()
      • setGameModeGlobalShipClass

        public void setGameModeGlobalShipClass​(ShipClass gameModeGlobalShipClass)
        When setting a global ship class, SpaceshipValidator will validate all ships against this class instead of the class that is stored in the ship. This makes it possible that game modes define a ship class as the common denominator for players loading their own ships and players don't need to set the same ship class in the editor - their ship just needs to be compatible.
      • getActiveExtViewPorts

        public List<Area2> getActiveExtViewPorts()
        Returns all extended viewports (viewport + sensor map) players can see
      • getGameRunMode

        public GameRunMode getGameRunMode()
        The game run mode
      • setGameRunMode

        public void setGameRunMode​(GameRunMode gameRunMode)
      • getZeroRng

        public Random getZeroRng()
        Zero random number generator always returns 0. Useful for example for speed runs that require predictable behavior
      • setZeroRng

        public void setZeroRng​(Random zeroRng)
      • getSessionRng

        public Random getSessionRng()
        If you need a random number, you usually want to use session random number generator. It's seed is also stored in checkpoints.
      • setSessionRng

        public void setSessionRng​(Random sessionRng)
      • getReproducibleSessionRng

        public Random getReproducibleSessionRng()
        Similar to the session rng, but you may only use it for certain actions that require reproducible behavior after loading a checkpoint. For example the last outpost stage controller uses the reproducible rng to ensure that the same scenes are loaded at the same locations again after loading a checkpoint.
      • setReproducibleSessionRng

        public void setReproducibleSessionRng​(Random reproducibleSessionRng)
      • getLastMaintenanceWarning

        public OffsetDateTime getLastMaintenanceWarning()
      • setLastMaintenanceWarning

        public void setLastMaintenanceWarning​(OffsetDateTime lastMaintenanceWarning)
      • isTurnWasPaused

        public boolean isTurnWasPaused()
      • setTurnWasPaused

        public void setTurnWasPaused​(boolean turnWasPaused)
      • isOffloadTaskRunning

        public boolean isOffloadTaskRunning()
      • setOffloadTaskRunning

        public void setOffloadTaskRunning​(boolean offloadTaskRunning)
      • getOffloadTask

        public Runnable getOffloadTask()
      • setOffloadTask

        public void setOffloadTask​(boolean offloadTaskPrivileged,
                                   Runnable offloadTask)
        Offload tasks are running in separate threads after the game session run (turn) has been processed. A new game session run (turn) will not start until the offload task has been finished. Use cases are to offload heavy actions like loading a bunch of scenes.
      • isOffloadTaskPrivileged

        public boolean isOffloadTaskPrivileged()
      • isOfficialServerGenuineSession

        public boolean isOfficialServerGenuineSession()
      • setOfficialServerGenuineSession

        public void setOfficialServerGenuineSession​(boolean officialServerGenuineSession)
      • getNoPlayersSince

        public long getNoPlayersSince()
      • setNoPlayersSince

        public void setNoPlayersSince​(long noPlayersSince)
      • isPauseable

        public boolean isPauseable()
      • setPauseable

        public void setPauseable​(boolean pauseable)
      • getAchievementsManager

        public AchievementsManager getAchievementsManager()
        The achievements manager
      • setAchievementsManager

        public void setAchievementsManager​(AchievementsManager achievementsManager)