Class PlayerEntryContainer

java.lang.Object
marauroa.server.game.container.PlayerEntryContainer
All Implemented Interfaces:
Iterable<PlayerEntry>

public class PlayerEntryContainer extends Object implements 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

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    add​(Channel channel)
    Add a new Player entry to the container.
    void
    dumps the statistics
    get​(int clientid)
    This method returns the PlayerEntry whose client id is clientid or null otherwise.
    get​(String username)
    This method returns the first entry that has been associated to this player or null if it does not exists.
    get​(RPObject object)
    This method returns the entry that has been associated to this player or null if it does not exists.
    get​(Channel channel)
    This method returns the entry that has been associated with this SocketChannel, or null if it does not exists.
    This method returns an instance of PlayerEntryContainer
    Obtains an idle player entry from the container.
    This method returns the lock so that you can control how the resource is used
    getOldEntry​(PlayerEntry oldEntry)
    This method returns the old entry that has been associated to this player or null if there is no old entry
    boolean
    has​(int clientid)
    This method returns true if there is any PlayerEntry which has client id as clientid.
    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
    This method returns the size of the container.
    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

      public static PlayerEntryContainer getContainer()
      This method returns an instance of PlayerEntryContainer
      Returns:
      A shared instance of PlayerEntryContainer
    • iterator

      public Iterator<PlayerEntry> iterator()
      This method returns an iterator over tha available player entry objects.
      Specified by:
      iterator in interface Iterable<PlayerEntry>
      Returns:
      the iterator
    • getLock

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

      public PlayerEntry get(int clientid)
      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

      public PlayerEntry get(Channel channel)
      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

      public PlayerEntry get(String username)
      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

      public PlayerEntry getOldEntry(PlayerEntry oldEntry)
      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

      public PlayerEntry get(RPObject object)
      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

      public PlayerEntry remove(int clientid)
      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

      public PlayerEntry add(Channel channel)
      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

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

      public String toString()
      a string representation useful for debugging.
      Overrides:
      toString in class Object
      Returns:
      String