Class RPServerManager

java.lang.Object
java.lang.Thread
marauroa.server.game.rp.RPServerManager
All Implemented Interfaces:
Runnable

public class RPServerManager extends Thread
This class is responsible for adding actions to scheduler, and to build and sent perceptions.

The goal of the RP Manager is to handle the RP of the game. This means:

  • run RPActions from clients
  • manage RPWorld
  • control triggers for events
  • control AI

This is a HUGE task that is very complex.
Hence we split that behaviour in different class:

  • IRuleProcessor will handle al the RP logic and run actions from client. This class will also implement AI, triggers, events, rules, etc...
  • RPWorld will handle all the world storage and management logic.
Author:
miguel
  • Constructor Details

    • RPServerManager

      public RPServerManager(INetworkServerManager netMan) throws Exception
      Constructor
      Parameters:
      netMan - the NetworkServerManager so that we can send message
      Throws:
      Exception - in case of an unexpected error
  • Method Details

    • initializeExtensions

      This method loads the extensions: IRPRuleProcessor and IRPWorld that are going to be used to implement your game. This method loads these class from the class names passed as arguments in Configuration
      Parameters:
      conf - the Configuration class
      Throws:
      ClassNotFoundException
      NoSuchMethodException
      InvocationTargetException
      IllegalAccessException
      SecurityException
      IllegalArgumentException
    • getTurn

      public int getTurn()
      This method returns the actual turn number.
      Returns:
      actual turn number
    • getTurnDuration

      public long getTurnDuration()
      gets the duration of a turn
      Returns:
      duration
    • finish

      public void finish()
      This method finishes the thread that runs the RPServerManager. It calls the RPWorld.onFinish() method.
    • addRPAction

      public void addRPAction(RPObject object, RPAction action) throws ActionInvalidException
      Adds an action for the next turn
      Parameters:
      object - the object that casted the action
      action - the action itself
      Throws:
      ActionInvalidException
    • checkGameVersion

      public boolean checkGameVersion(String game, String version)
      This method decide if an client runs a compatible version of the game
      Parameters:
      game - the game name
      version - the game version as a string
      Returns:
      true if it is compatible.
    • createAccount

      public AccountResult createAccount(String username, String password, String email, String address)
      Creates an account for a player in the game.
      Parameters:
      username - player's username
      password - player's password
      email - player's email
      address - ip address of client
      Returns:
      a Result indicating if account creation was done successfully or not.
    • createAccountWithToken

      public AccountResult createAccountWithToken(String username, String tokenType, String token, String address)
      Create an account for a player in game. Uses token instead of password for cases like 3rd party authentication (e.g. google sign-in).
      Parameters:
      username - username for a new account
      tokenType - token type
      token - token obtained from 3rd party to verify
      address - ip address of client
      Returns:
      a Result indicating if account creation was done successfully or not.
    • createCharacter

      public CharacterResult createCharacter(String username, String character, RPObject template, String address)
      Creates a character for a account of a player
      Parameters:
      username - player's username
      character -
      template - the template we are going to use to create the object.
      address - ip address of client
      Returns:
      a Result indicating if account creation was done successfully or if it is not the cause.
    • onInit

      public boolean onInit(RPObject object) throws RPObjectInvalidException
      This method is called when a player is added to the game
      Parameters:
      object - player object
      Returns:
      true, to continue, false to cause an error
      Throws:
      RPObjectInvalidException - if the object was invalid
    • onExit

      public boolean onExit(RPObject object) throws RPObjectNotFoundException
      This method is called when a player leaves the game
      Parameters:
      object - player object
      Returns:
      true, to continue, false to prevent logout
      Throws:
      RPObjectNotFoundException - if the object does not exist
    • onTimeout

      public void onTimeout(RPObject object) throws RPObjectNotFoundException
      This method is called when connection to client is closed
      Parameters:
      object - player object
      Throws:
      RPObjectNotFoundException - if the object does not exist
    • transferContent

      public void transferContent(RPObject target, List<TransferContent> content)
      This method is triggered to send content to the clients
      Parameters:
      target - player
      content - content to transfer
    • transferContent

      public void transferContent(RPObject target, TransferContent content)
      This method is triggered to send content to the clients
      Parameters:
      target - player
      content - content to transfer
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • disconnectPlayer

      public void disconnectPlayer(RPObject object)
      This method disconnects a player from the server.
      Parameters:
      object - the player object that we want to disconnect from world
    • getValidator

      public ConnectionValidator getValidator()
      This method exposes network layer connection validator so game logic can handle it.
      Returns:
      the connection validator
    • getMimeTypeForResource

      public String getMimeTypeForResource(String resource)
      gets the content type for the requested resource
      Parameters:
      resource - name of resource
      Returns:
      mime content/type or null
    • getResource

      public InputStream getResource(String resource)
      gets an input stream to the requested resource
      Parameters:
      resource - name of resource
      Returns:
      InputStream or null