Class GameServerManager

java.lang.Object
java.lang.Thread
marauroa.server.game.GameServerManager
All Implemented Interfaces:
Runnable, IDisconnectedListener

public final class GameServerManager extends Thread implements 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_COMPLETE
 
Logout 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
  • Constructor Details

    • GameServerManager

      public GameServerManager(RSAKey key, INetworkServerManager netMan, RPServerManager rpMan) throws Exception
      Constructor that initialize also the RPManager
      Parameters:
      key - the server private key
      netMan - 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.
      Overrides:
      start in class Thread
    • 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.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • onDisconnect

      public void onDisconnect(Channel channel)
      This method is called by network manager when a client connection is lost or even when the client logout correctly.
      Specified by:
      onDisconnect in interface IDisconnectedListener
      Parameters:
      channel - the channel that was closed.