Class GameSession
- java.lang.Object
-
- de.extio.spacecraft.shared.model.game_server.instance.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 Summary
Constructors Constructor Description GameSession()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AchievementsManager
getAchievementsManager()
The achievements managerList<Area2>
getActiveExtViewPorts()
Returns all extended viewports (viewport + sensor map) players can seeList<Module>
getActiveServerModules()
Returns all active server modules<T> T
getBusinessObject(Class<? extends T> clazz)
Business objects implement game mechanicsBlockingQueue<Object>
getDeferredDatagrams()
List<org.apache.commons.lang3.tuple.Pair<GameActionMessage,Set<UUID>>>
getDeferredGameActionMessages()
EntityDefManager
getEntityDefManager()
The entity definition managerint
getExceptions()
GameModeDef
getGameMode()
Returns the definition of the current game modeShipClass
getGameModeGlobalShipClass()
Map<String,Object>
getGameModeOptions()
Game mode options are a shared state for this game session.GameRunMode
getGameRunMode()
The game run modeUUID
getGameSessionId()
Returns the game session identifierGameSessionState
getGameSessionState()
Returns whether the game session is still in lobby or already startedUUID
getHost()
Returns the player who is currently hostUUID
getInstanceId()
Returns the id of the instance the game session is running.OffsetDateTime
getLastMaintenanceWarning()
long
getLastServerListing()
DirectoryRecord
getListServerRecord()
LocalizationManager
getLocalizationManager()
The localization managerModManager
getModManager()
The mod managerlong
getNextRunHigh()
long
getNextRunHighPrediction()
long
getNextRunLow()
long
getNextRunLowPrediction()
long
getNoPlayersSince()
Runnable
getOffloadTask()
String
getPassword()
Map<UUID,Player>
getPendingPlayers()
com.google.common.collect.ImmutableMap<UUID,Player>
getPlayers()
Returns all players of a game sessionMap<UUID,GameSessionReconnectTicket>
getReconnectTickets()
Random
getReproducibleSessionRng()
Similar to the session rng, but you may only use it for certain actions that require reproducible behavior after loading a checkpoint.int
getRunIntervalMsHigh()
int
getRunIntervalMsLow()
SceneRegistry
getSceneRegistry()
The scene registryScriptingManager
getScriptingManager()
The scripting managerServerModuleManager
getServerModuleManager()
The module managerServerWorldManager
getServerWorldManager()
The server WorldManager, representing the game worldRandom
getSessionRng()
If you need a random number, you usually want to use session random number generator.Map<UUID,UUID>
getShipByPlayer()
Returns a lookup map for ships by player idShipClassManager
getShipClassManager()
The ship class managerMap<UUID,Integer>
getShipSlotByPlayer()
Lookup map for the ship slot index by player idList<GameSessionShipSlot>
getShipSlots()
Returns all ship slots players can joinMap<String,Object>
getState()
A shared state for this game session.int
getTurn()
Returns the turn numberRandom
getZeroRng()
Zero random number generator always returns 0.boolean
isEditorMode()
Returns whether game session is in editor mode, e.g.boolean
isFirstGameTurn()
boolean
isGameModeOptionsDirty()
boolean
isOfficialServerGenuineSession()
boolean
isOffloadTaskPrivileged()
boolean
isOffloadTaskRunning()
boolean
isPauseable()
boolean
isTerminate()
boolean
isTurnWasPaused()
void
setAchievementsManager(AchievementsManager achievementsManager)
void
setEditorMode(boolean editorMode)
void
setEntityDefManager(EntityDefManager entityDefManager)
void
setExceptions(int exceptions)
void
setFirstGameTurn(boolean firstGameTurn)
void
setGameMode(GameModeDef gameMode)
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.void
setGameModeOptionsDirty(boolean gameModeOptionsDirty)
Flags game mode options dirty to transfer it to the clientvoid
setGameRunMode(GameRunMode gameRunMode)
void
setGameSessionState(GameSessionState gameSessionState)
void
setHost(UUID host)
void
setInstanceId(UUID instanceId)
void
setLastMaintenanceWarning(OffsetDateTime lastMaintenanceWarning)
void
setLastServerListing(long lastServerListing)
void
setListServerRecord(DirectoryRecord listServerRecord)
void
setLocalizationManager(LocalizationManager localizationManager)
void
setModManager(ModManager modManager)
void
setNextRunHigh(long nextRunHigh)
void
setNextRunHighPrediction(long nextRunHighPrediction)
void
setNextRunLow(long nextRunLow)
void
setNextRunLowPrediction(long nextRunLowPrediction)
void
setNoPlayersSince(long noPlayersSince)
void
setOfficialServerGenuineSession(boolean officialServerGenuineSession)
void
setOffloadTask(boolean offloadTaskPrivileged, Runnable offloadTask)
Offload tasks are running in separate threads after the game session run (turn) has been processed.void
setOffloadTaskRunning(boolean offloadTaskRunning)
void
setPassword(String password)
void
setPauseable(boolean pauseable)
void
setPlayers(com.google.common.collect.ImmutableMap<UUID,Player> players)
void
setReproducibleSessionRng(Random reproducibleSessionRng)
void
setRunIntervalMsHigh(int runIntervalMsHigh)
void
setRunIntervalMsLow(int runIntervalMsLow)
void
setSceneRegistry(SceneRegistry sceneRegistry)
void
setScriptingManager(ScriptingManager scriptingManager)
void
setServerModuleManager(ServerModuleManager serverModuleManager)
void
setServerWorldManager(ServerWorldManager serverWorldManager)
void
setSessionRng(Random sessionRng)
void
setShipClassManager(ShipClassManager shipClassManager)
void
setTerminate(boolean terminate)
Terminate the game sessionvoid
setTurn(int turn)
void
setTurnWasPaused(boolean turnWasPaused)
void
setZeroRng(Random zeroRng)
-
-
-
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
-
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()
-
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)
-
getListServerRecord
public DirectoryRecord getListServerRecord()
-
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)
-
getShipSlots
public List<GameSessionShipSlot> getShipSlots()
Returns all ship slots players can join
-
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()
-
getDeferredDatagrams
public BlockingQueue<Object> getDeferredDatagrams()
-
isOfficialServerGenuineSession
public boolean isOfficialServerGenuineSession()
-
setOfficialServerGenuineSession
public void setOfficialServerGenuineSession(boolean officialServerGenuineSession)
-
getReconnectTickets
public Map<UUID,GameSessionReconnectTicket> getReconnectTickets()
-
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)
-
-