Class ServerFacade
- java.lang.Object
-
- de.extio.spacecraft.shared.server.ServerFacade
-
public abstract class ServerFacade extends Object
Server facade is the main entry point to access all game session context independent functions of the game server. See also GameSession context object to access most managers and business objects.
It can only be accessed when in the context of a game server thread.
Example how to use the facade: ServerFacade.instance().getCurrentGameSession().getServerWorldManager().something();
-
-
Field Summary
Fields Modifier and Type Field Description protected static ThreadLocal<Boolean>
IN_SERVER_CONTEXT
protected static ServerFacade
INSTANCE
-
Constructor Summary
Constructors Modifier Constructor Description protected
ServerFacade()
ServerFacade is a singleton, use .instance()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
closeSession(UUID sessionId)
Disconnects a certain player (same as net session)abstract Random
createRandomGenerator(long seed)
Returns a new instance of a random number generator with a given seedabstract <T> T
getBusinessObject(Class<? extends T> clazz)
Business objects implementing various game mechanics.abstract GameSession
getCurrentGameSession()
Returns the game session context object that is currently active in the thread context.abstract UUID
getCurrentInstanceId()
Returns the game server instance id of the current thread contextabstract GameSession
getGameSessionById(UUID gameSessionId)
Returns the game session by idabstract GameSession
getGameSessionByPlayerId(UUID netSessionId)
Returns the game session a player is connected toabstract MetaserverClient
getMetaserverClient()
Api client for the metaserverabstract ObjectSerialization
getObjectSerialization()
The object de-/serializerabstract byte[]
getOfficialCheckpointSalt()
abstract String
getOfficialServerKey()
abstract SecurityFacade
getSecurityFacade()
The security facadeabstract StorageManager
getStorageManager()
The storage managerabstract VersionManager
getVersionManager()
The version managerabstract boolean
hasGameSessionById(UUID gameSessionId)
Checks whether the given game session id is validabstract void
initReproducibleSessionRng(GameSession gameSession, String state)
abstract void
initSessionRng(GameSession gameSession, String state)
static ServerFacade
instance()
ServerFacade is a singleton, use this method to access the facadestatic ServerFacade
instance(boolean checkContext)
ServerFacade is a singleton, use this method to access the facadeabstract boolean
isDedicatedServer()
Checks whether the server that is running is dedicatedstatic boolean
isInServerContext()
Checks whether the current thread is running in context of the game server (i.e.abstract boolean
isOfficialServer()
Checks whether the server that is running is an official serverabstract void
publishInternalMessage(GameSession gameSession, AbstractMessage message, boolean processImmediately)
Sends a Message internally, it remains on the game server and can be processed by any module / composite / entity subscribing to itabstract void
publishMessage(GameSession gameSession, Set<UUID> destinations, AbstractMessage message, boolean defer)
Sends a Message to a clientabstract void
publishMessageToAll(GameSession gameSession, AbstractMessage message, boolean defer)
Sends a Message to all clientsabstract void
reportError(String module, String message)
Reports an error
-
-
-
Field Detail
-
INSTANCE
protected static ServerFacade INSTANCE
-
IN_SERVER_CONTEXT
protected static ThreadLocal<Boolean> IN_SERVER_CONTEXT
-
-
Method Detail
-
instance
public static ServerFacade instance()
ServerFacade is a singleton, use this method to access the facade
-
instance
public static ServerFacade instance(boolean checkContext)
ServerFacade is a singleton, use this method to access the facade- Parameters:
checkContext
- Checks whether called in server context. This makes sure it is not accidently called from the game client, which will have undefined effects. Only bypass this check if you know what you are doing.
-
isInServerContext
public static boolean isInServerContext()
Checks whether the current thread is running in context of the game server (i.e. is not part of the game client).
-
getVersionManager
public abstract VersionManager getVersionManager()
The version manager
-
getStorageManager
public abstract StorageManager getStorageManager()
The storage manager
-
getSecurityFacade
public abstract SecurityFacade getSecurityFacade()
The security facade
-
getObjectSerialization
public abstract ObjectSerialization getObjectSerialization()
The object de-/serializer
-
getMetaserverClient
public abstract MetaserverClient getMetaserverClient()
Api client for the metaserver
-
getBusinessObject
public abstract <T> T getBusinessObject(Class<? extends T> clazz)
Business objects implementing various game mechanics. See .shared.bo package
-
getCurrentInstanceId
public abstract UUID getCurrentInstanceId()
Returns the game server instance id of the current thread context
-
getCurrentGameSession
public abstract GameSession getCurrentGameSession()
Returns the game session context object that is currently active in the thread context. Result may be null if there is no active game session context.
-
hasGameSessionById
public abstract boolean hasGameSessionById(UUID gameSessionId)
Checks whether the given game session id is valid
-
getGameSessionById
public abstract GameSession getGameSessionById(UUID gameSessionId)
Returns the game session by id
-
getGameSessionByPlayerId
public abstract GameSession getGameSessionByPlayerId(UUID netSessionId)
Returns the game session a player is connected to
-
publishMessage
public abstract void publishMessage(GameSession gameSession, Set<UUID> destinations, AbstractMessage message, boolean defer)
Sends a Message to a client- Parameters:
destinations
- A set of one or many player ids (same as net session ids)defer
- Defer sending out this message. This is an optimization to send out multiple message in one datagram at the end of a turn to reduce overhead. It is right now only implemented for GameActionMessage, for other message types it has no effect.
-
publishMessageToAll
public abstract void publishMessageToAll(GameSession gameSession, AbstractMessage message, boolean defer)
Sends a Message to all clients- Parameters:
defer
- Defer sending out this message. This is an optimization to send out multiple message in one datagram at the end of a turn to reduce overhead. It is right now only implemented for GameActionMessage, for other message types it has no effect.
-
publishInternalMessage
public abstract void publishInternalMessage(GameSession gameSession, AbstractMessage message, boolean processImmediately)
Sends a Message internally, it remains on the game server and can be processed by any module / composite / entity subscribing to it- Parameters:
processImmediately
- Processes the message synchronously, otherwise it will be added to the regular message queue and processed in the next turn. Requires elevated security permissions, therefore it will throw an exception when used by scripts.
-
closeSession
public abstract void closeSession(UUID sessionId)
Disconnects a certain player (same as net session)
-
initSessionRng
@RestrictedMethod public abstract void initSessionRng(GameSession gameSession, String state)
-
initReproducibleSessionRng
@RestrictedMethod public abstract void initReproducibleSessionRng(GameSession gameSession, String state)
-
createRandomGenerator
public abstract Random createRandomGenerator(long seed)
Returns a new instance of a random number generator with a given seed
-
isDedicatedServer
public abstract boolean isDedicatedServer()
Checks whether the server that is running is dedicated
-
isOfficialServer
public abstract boolean isOfficialServer()
Checks whether the server that is running is an official server
-
getOfficialServerKey
@RestrictedMethod public abstract String getOfficialServerKey()
-
getOfficialCheckpointSalt
@RestrictedMethod public abstract byte[] getOfficialCheckpointSalt()
-
-