Package marauroa.server.game.container
Class PlayerEntryContainer
java.lang.Object
marauroa.server.game.container.PlayerEntryContainer
- All Implemented Interfaces:
Iterable<PlayerEntry>
This is a helper class to sort and access PlayerEntry in a controlled way.
This class implements the singleton pattern. PlayerContainer is the data
structure that contains all of the information about the players while the
game is running.
It consists of a list of PlayerEntry objects and is heavily linked with the database, so we can hide its complexity to GameManager. By making PlayerDatabase hidden by PlayerContainer we achieve the illusion that managing the runtime behavior we modify automatically the permanent one.
- Author:
- miguel
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdd a new Player entry to the container.void
dumps the statisticsget(int clientid)
This method returns the PlayerEntry whose client id is clientid or null otherwise.This method returns the first entry that has been associated to this player or null if it does not exists.This method returns the entry that has been associated to this player or null if it does not exists.This method returns the entry that has been associated with this SocketChannel, or null if it does not exists.static PlayerEntryContainer
This method returns an instance of PlayerEntryContainerObtains an idle player entry from the container.getLock()
This method returns the lock so that you can control how the resource is usedgetOldEntry(PlayerEntry oldEntry)
This method returns the old entry that has been associated to this player or null if there is no old entryboolean
has(int clientid)
This method returns true if there is any PlayerEntry which has client id as clientid.iterator()
This method returns an iterator over tha available player entry objects.remove(int clientid)
This method removed a player entry from the container and return it or null if the entry does not exist.int
size()
This method returns the size of the container.toString()
a string representation useful for debugging.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
PlayerEntryContainer
protected PlayerEntryContainer()Constructor
-
-
Method Details
-
getContainer
This method returns an instance of PlayerEntryContainer- Returns:
- A shared instance of PlayerEntryContainer
-
iterator
This method returns an iterator over tha available player entry objects.- Specified by:
iterator
in interfaceIterable<PlayerEntry>
- Returns:
- the iterator
-
getLock
This method returns the lock so that you can control how the resource is used- Returns:
- the RWLock of the object
-
size
public int size()This method returns the size of the container.- Returns:
- Container's size.
-
has
public boolean has(int clientid)This method returns true if there is any PlayerEntry which has client id as clientid.- Parameters:
clientid
- the id of the PlayerEntry we are looking for- Returns:
- true if it is found or false otherwise.
-
get
This method returns the PlayerEntry whose client id is clientid or null otherwise.- Parameters:
clientid
- the id of the PlayerEntry we are looking for- Returns:
- the PlayerEntry if is it found or null otherwise
-
get
This method returns the entry that has been associated with this SocketChannel, or null if it does not exists.- Parameters:
channel
- the socket channel to check- Returns:
- the PlayerEntry or null if it is not found.
-
get
This method returns the first entry that has been associated to this player or null if it does not exists. Note: It is possible to login with the same account and different character multiple times.- Parameters:
username
- the username to look for- Returns:
- the PlayerEntry or null if it is not found
-
getOldEntry
This method returns the old entry that has been associated to this player or null if there is no old entry- Parameters:
oldEntry
- old entry with username and password- Returns:
- the PlayerEntry or null if there is none
-
get
This method returns the entry that has been associated to this player or null if it does not exists.- Parameters:
object
- the RPObject we have to look for- Returns:
- the PlayerEntry or null if it is not found
-
remove
This method removed a player entry from the container and return it or null if the entry does not exist.- Parameters:
clientid
- the clientid we want its Player entry to remove.- Returns:
- the player entry or null if it has not been found.
-
add
Add a new Player entry to the container. This method assigns automatically a random clientid to this player entry.- Parameters:
channel
- the socket channel associated with the client- Returns:
- client id resulting
-
getIdleEntry
Obtains an idle player entry from the container. We can define an idle player entry like a player that has connected to server and requested to login, but never actually completed login stage. This client is taking server resources but doing nothing useful at all.- Returns:
- an idle PlayerEntry or null if not found
-
dumpStatistics
public void dumpStatistics()dumps the statistics -
toString
a string representation useful for debugging.
-