wyvern.kernel.player
Class PlayerManager

java.lang.Object
  extended bywyvern.kernel.player.PlayerManager

public final class PlayerManager
extends java.lang.Object

This class implements an extremely simple persistence mechanism. It acts as a sort of player database, using the filesystem to store "player files". Player files have identical syntax to game archetypes - they're stored as a list of properties.

The PlayerManager class is reponsible for creating new players, as well as retrieving and saving existing players. Eventually it may serve as a gateway to a real database.

Version:
1.0, Mar 19, 1998
Author:
Steve Yegge

Nested Class Summary
static interface PlayerManager.OfflineProperties
          Constants for return values from setOfflineProperties
 
Field Summary
static int MAX_CHARACTERS
           
static int MAX_PLAYER_NAME_LENGTH
           
static int MIN_PLAYER_NAME_LENGTH
           
 
Constructor Summary
PlayerManager()
           
 
Method Summary
static Player createGuestPlayer()
          Creates a new guest player for a guest visitor.
static java.util.List getAltsForPlayer(java.lang.String email)
          Returns a list of the names of all the players associated with a given email address.
static java.lang.Object[] getOfflineProperties(java.lang.String player, java.lang.String[] names)
          Returns a list of properties from an offline player.
static java.lang.String getPathToPlayer(java.lang.String name)
          Returns the absolute path to the player file, given the name of the player.
static Player loadPlayer(java.lang.String name)
          Loads saved player data into a Player object.
static boolean playerExists(java.lang.String name)
          Returns true if the specified player file exists.
static java.lang.String readPlayerFile(Player p)
          Returns the contents of the player's save-file as a string.
static boolean savePlayer(Player p)
          Saves the specified player.
static void saveVisitor(java.lang.String name, java.lang.String domain, java.lang.String contents)
          Saves a visitor from another server.
static void setAsynchronousSaves()
          Turns saves back to async-mode, using a thread pool.
static void setFileCache(boolean cache)
          Turns disk-file caching on and off.
static int setOfflineProperties(java.lang.String player, java.lang.String[] propnames, java.lang.Object[] props)
          Sets properties on an offline player.
static void setSynchronousSaves()
          Tells the PlayerManager to save players on the current thread, rather than using a thread pool.
static void throwExceptions(boolean x)
          Wizards: Don't call this under pain of death.
static java.lang.String toXML(Player p)
          Returns serialized XML for a player.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_PLAYER_NAME_LENGTH

public static final int MIN_PLAYER_NAME_LENGTH
See Also:
Constant Field Values

MAX_PLAYER_NAME_LENGTH

public static final int MAX_PLAYER_NAME_LENGTH
See Also:
Constant Field Values

MAX_CHARACTERS

public static final int MAX_CHARACTERS
See Also:
Constant Field Values
Constructor Detail

PlayerManager

public PlayerManager()
Method Detail

getPathToPlayer

public static java.lang.String getPathToPlayer(java.lang.String name)
Returns the absolute path to the player file, given the name of the player. Necessary because player files are not all stored in a single directory anymore.

Parameters:
name - the player name. case doesn't matter.
Returns:
the absolute path to where the player file would be stored, not including the player name itself (just the directory.) NOTE: doesn't actually check if the player file exists; it just returns a directory based on the name that's passed in. Use playerExists() to see if a player file has been created.

playerExists

public static boolean playerExists(java.lang.String name)
Returns true if the specified player file exists.

Parameters:
name - the name of the player to check on

loadPlayer

public static Player loadPlayer(java.lang.String name)
                         throws java.lang.Exception
Loads saved player data into a Player object.

Parameters:
name - the name of the saved player to load
Returns:
a Player implementation to use for this session
Throws:
any - Exception with a detail message for the client
java.lang.Exception

savePlayer

public static boolean savePlayer(Player p)
Saves the specified player.

Returns:
true if successful, false if it failed for some reason.

readPlayerFile

public static java.lang.String readPlayerFile(Player p)
                                       throws java.io.IOException
Returns the contents of the player's save-file as a string. Used when transferring a player to another server.

Parameters:
p - the name of the player whose save-file is wanted
Returns:
the contents of the most recently-saved player file
Throws:
java.io.IOException

saveVisitor

public static void saveVisitor(java.lang.String name,
                               java.lang.String domain,
                               java.lang.String contents)
                        throws java.lang.Exception
Saves a visitor from another server.

Parameters:
name - the name of the player
domain - the domain/machine name of the player's home server
contents - the contents of the player's save file
Throws:
any - Exception if the directory for that server couldn't be created, or any of the arguments are invalid, or anything else went wrong.
java.lang.Exception

createGuestPlayer

public static Player createGuestPlayer()
                                throws java.lang.Exception
Creates a new guest player for a guest visitor.

Throws:
java.lang.Exception

toXML

public static java.lang.String toXML(Player p)
                              throws java.lang.Exception
Returns serialized XML for a player.

Parameters:
p - the player to serialize
Returns:
the player serialized out to XML.
Throws:
any - Exception if we couldn't do it for some reason (error message in the exception).
java.lang.Exception

setSynchronousSaves

public static void setSynchronousSaves()
Tells the PlayerManager to save players on the current thread, rather than using a thread pool. This should ONLY be used for tools, and never in the game. Just don't even call this method.


setAsynchronousSaves

public static void setAsynchronousSaves()
Turns saves back to async-mode, using a thread pool.


setFileCache

public static void setFileCache(boolean cache)
Turns disk-file caching on and off. Don't use this under penalty of torture and death. It's only for the backfill tool.

Parameters:
cache - true to write the player file into the filesystem after saving them into the database, false to just write the database. By default, the file cache is on, and the backfill tool passes false for this parameter to turn it off.

setOfflineProperties

public static int setOfflineProperties(java.lang.String player,
                                       java.lang.String[] propnames,
                                       java.lang.Object[] props)
Sets properties on an offline player.

For boolean properties, the value should be a java.lang.Boolean.
For int properties, the value should be a java.lang.Integer.
For long properties, the value should be a java.lang.Long.
For double properties, the value should be a java.lang.Double.

Parameters:
player - the name of the player to modify
propnames - an array of property nams you'll be modifying
props - an array of props corresponding to the property names
Returns:
a PlayerManager.OfflineProperties constant
Throws:
java.lang.IllegalArgumentException - if any of the params are null, or if the array lengths aren't the same, or if any of the array values are null.

getOfflineProperties

public static java.lang.Object[] getOfflineProperties(java.lang.String player,
                                                      java.lang.String[] names)
Returns a list of properties from an offline player.

Parameters:
player - the player to query
names - an array of property names to look up
Returns:
an array of values corresponding to the passed names, or null if there was an error loading the player, or the player was online, or something else went wrong.
Throws:
java.lang.IllegalArgumentException - if any param is null

getAltsForPlayer

public static java.util.List getAltsForPlayer(java.lang.String email)
Returns a list of the names of all the players associated with a given email address.

Parameters:
email - the email to look up
Returns:
a list of the character names for that email, or an empty list if the email didn't exist or the lookup failed.

throwExceptions

public static void throwExceptions(boolean x)
Wizards: Don't call this under pain of death.