Package marauroa.server.game
Class GameServerManager
java.lang.Object
java.lang.Thread
marauroa.server.game.GameServerManager
- All Implemented Interfaces:
Runnable
,IDisconnectedListener
The GameServerManager is a active entity of the marauroa.game package, it is
in charge of processing all the messages and modify PlayerEntry Container
accordingly.
The logic is similar to this:
GameManager { NetworkManager read Message switch(Message type) { case ...; } }So let's define the reply to each message. First, let's clarify that the best way of modelling this system is using finite automates, (a finite state machine) where, based on the input, we change the state we are currently in and produce an output.
Login
Process C2S Login ( STATE_BEGIN_LOGIN ) Precondition: The state MUST be NULL Test if there is room for more players. if there is no more room { reply S2C Login NACK( SERVER_FULL ) state = NULL } if check username, password in database is correct { create clientid add PlayerEntry notify database reply S2C Login ACK get characters list of the player reply S2C CharacterList state = STATE_LOGIN_COMPLETE } else { notify database reply S2C Login NACK( LOGIN_INCORRECT ) state = NULL } Postcondition: The state MUST be NULL or STATE_LOGIN_COMPLETE and a we have created a PlayerEntry for this player with a unique clientid.Choose Character
Process C2S ChooseCharacter ( STATE_LOGIN_COMPLETE ) Precondition: The state MUST be STATE_LOGIN_COMPLETE if character exists in database { add character to Player's PlayerEntry add character to game reply S2C Choose Character ACK state = STATE_GAME_BEGIN } else { reply S2C Choose Character NACK state = STATE_LOGIN_COMPLETE } Postcondition: The state MUST be STATE_GAME_BEGIN and the PlayerStructure should be completely filled or if the character choise was wrong the state is STATE_LOGIN_COMPLETELogout stage
Process C2S Logout ( STATE_GAME_END ) Precondition: The state can be anything but STATE_LOGIN_BEGIN if( rpEngine allows player to logout ) { reply S2C Logout ACK state = NULL store character in database remove character from game delete PlayerEntry } else { reply S2C Logout NACK } Postcondition: Either the same as the input state or the state currently in
- Author:
- miguel
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
ConstructorDescriptionGameServerManager(RSAKey key, INetworkServerManager netMan, RPServerManager rpMan)
Constructor that initialize also the RPManager -
Method Summary
Modifier and TypeMethodDescriptionvoid
finish()
This method request the active object to finish its execution and store all the players back to database.void
onDisconnect(Channel channel)
This method is called by network manager when a client connection is lost or even when the client logout correctly.void
run()
Runs the game glue logic.void
start()
Starting this thread makes it to start the thread that disconnect players.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, suspend, toString, yield
-
Constructor Details
-
GameServerManager
public GameServerManager(RSAKey key, INetworkServerManager netMan, RPServerManager rpMan) throws ExceptionConstructor that initialize also the RPManager- Parameters:
key
- the server private keynetMan
- a NetworkServerManager instance.rpMan
- a RPServerManager instance.- Throws:
Exception
- is there is any problem.
-
-
Method Details
-
start
public void start()Starting this thread makes it to start the thread that disconnect players. -
finish
public void finish()This method request the active object to finish its execution and store all the players back to database. -
run
public void run()Runs the game glue logic. This class is responsible of receiving messages from clients and instruct RP about actions clients did. -
onDisconnect
This method is called by network manager when a client connection is lost or even when the client logout correctly.- Specified by:
onDisconnect
in interfaceIDisconnectedListener
- Parameters:
channel
- the channel that was closed.
-