Package marauroa.server.game.rp
Class RPServerManager
java.lang.Object
java.lang.Thread
marauroa.server.game.rp.RPServerManager
- All Implemented Interfaces:
Runnable
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
-
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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addRPAction(RPObject object, RPAction action)
Adds an action for the next turnboolean
checkGameVersion(String game, String version)
This method decide if an client runs a compatible version of the gamecreateAccount(String username, String password, String email, String address)
Creates an account for a player in the game.createAccountWithToken(String username, String tokenType, String token, String address)
Create an account for a player in game.createCharacter(String username, String character, RPObject template, String address)
Creates a character for a account of a playervoid
disconnectPlayer(RPObject object)
This method disconnects a player from the server.void
finish()
This method finishes the thread that runs the RPServerManager.getMimeTypeForResource(String resource)
gets the content type for the requested resourcegetResource(String resource)
gets an input stream to the requested resourceint
getTurn()
This method returns the actual turn number.long
gets the duration of a turnThis method exposes network layer connection validator so game logic can handle it.protected void
This method loads the extensions: IRPRuleProcessor and IRPWorld that are going to be used to implement your game.boolean
This method is called when a player leaves the gameboolean
This method is called when a player is added to the gamevoid
This method is called when connection to client is closedvoid
run()
void
transferContent(RPObject target, List<TransferContent> content)
This method is triggered to send content to the clientsvoid
transferContent(RPObject target, TransferContent content)
This method is triggered to send content to the clientsMethods 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, start, stop, suspend, toString, yield
-
Constructor Details
-
RPServerManager
Constructor- Parameters:
netMan
- the NetworkServerManager so that we can send message- Throws:
Exception
- in case of an unexpected error
-
-
Method Details
-
initializeExtensions
protected void initializeExtensions(Configuration conf) throws ClassNotFoundException, IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchMethodExceptionThis 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
Adds an action for the next turn- Parameters:
object
- the object that casted the actionaction
- the action itself- Throws:
ActionInvalidException
-
checkGameVersion
This method decide if an client runs a compatible version of the game- Parameters:
game
- the game nameversion
- the game version as a string- Returns:
- true if it is compatible.
-
createAccount
Creates an account for a player in the game.- Parameters:
username
- player's usernamepassword
- player's passwordemail
- player's emailaddress
- 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 accounttokenType
- token typetoken
- token obtained from 3rd party to verifyaddress
- 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 usernamecharacter
-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
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
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
This method is called when connection to client is closed- Parameters:
object
- player object- Throws:
RPObjectNotFoundException
- if the object does not exist
-
transferContent
This method is triggered to send content to the clients- Parameters:
target
- playercontent
- content to transfer
-
transferContent
This method is triggered to send content to the clients- Parameters:
target
- playercontent
- content to transfer
-
run
public void run() -
disconnectPlayer
This method disconnects a player from the server.- Parameters:
object
- the player object that we want to disconnect from world
-
getValidator
This method exposes network layer connection validator so game logic can handle it.- Returns:
- the connection validator
-
getMimeTypeForResource
gets the content type for the requested resource- Parameters:
resource
- name of resource- Returns:
- mime content/type or
null
-
getResource
gets an input stream to the requested resource- Parameters:
resource
- name of resource- Returns:
- InputStream or
null
-