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
|
|