netbattle.database.registry
Class AccountRegistry

java.lang.Object
  extended by netbattle.database.registry.AccountRegistry
Direct Known Subclasses:
DatabaseImpl, FileImpl

public abstract class AccountRegistry
extends java.lang.Object

This class represents an account registry on the server. The class itself does not implement the registry; this is left to a subclass so that a user without a database may rely on flat files instead.

The general contract of the methods of this class is that passwords are always SHA-1 hashes; the AccountRegistry class does not preform any hashing itself.

See Also:
DatabaseImpl, FileImpl

Field Summary
static int LEVEL_ADMIN
           
static int LEVEL_MOD
           
static int LEVEL_USER
          User level constants.
 
Constructor Summary
AccountRegistry()
           
 
Method Summary
abstract  boolean addNewUser(java.lang.String user, java.lang.String password)
          Add a new user to the registry.
abstract  boolean banUser(java.lang.String user, long date)
          Set the date upon which a user becomes unbanned.
abstract  boolean banUser(java.lang.String user, java.lang.String ip, long date)
           
abstract  void close()
          Close this AccountRegistry.
protected  void finalize()
          In case close() is not otherwise called, this finialiser ensures that the account registry is properly closed.
static AccountRegistry getInstance()
          Return the single instance of this class.
abstract  java.lang.String getIpAddress(java.lang.String user)
          Get the IP Address of a particular user.
abstract  long getIpUnbanDate(java.lang.String ip)
          Return the date upon which an IP address becomes unbanned.
abstract  java.lang.String getPassword(java.lang.String user)
          Get the SHA-1 hash of a user's password.
abstract  int getUserLevel(java.lang.String user)
          Get the level of a user.
abstract  UserTableMessage getUserList()
          Get a list of all users in this registry.
abstract  java.util.List getUsersByIp(java.lang.String ip)
          Get a List of users with a given IP Address.
abstract  long getUserUnbanDate(java.lang.String user)
          Determine when a user becomes unbanned.
static void setInstance(AccountRegistry reg)
          Set the single instance of this class.
abstract  boolean setUserLevel(java.lang.String user, int level)
          Set the level of a user.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEVEL_USER

public static final int LEVEL_USER
User level constants.

See Also:
Constant Field Values

LEVEL_MOD

public static final int LEVEL_MOD
See Also:
Constant Field Values

LEVEL_ADMIN

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

AccountRegistry

public AccountRegistry()
Method Detail

setInstance

public static void setInstance(AccountRegistry reg)
Set the single instance of this class.


getInstance

public static AccountRegistry getInstance()
Return the single instance of this class.


finalize

protected void finalize()
                 throws java.lang.Throwable
In case close() is not otherwise called, this finialiser ensures that the account registry is properly closed.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

close

public abstract void close()
Close this AccountRegistry.


getPassword

public abstract java.lang.String getPassword(java.lang.String user)
Get the SHA-1 hash of a user's password.

Returns:
the hash or null if the user does not exist

addNewUser

public abstract boolean addNewUser(java.lang.String user,
                                   java.lang.String password)
Add a new user to the registry.

Parameters:
user - the user name of the user
password - an SHA-1 hash of the user's password
Returns:
whether the user was added successfully

banUser

public abstract boolean banUser(java.lang.String user,
                                long date)
Set the date upon which a user becomes unbanned.


banUser

public abstract boolean banUser(java.lang.String user,
                                java.lang.String ip,
                                long date)

getUserUnbanDate

public abstract long getUserUnbanDate(java.lang.String user)
Determine when a user becomes unbanned.

Returns:
a UNIX timestamp of the unban date

getIpUnbanDate

public abstract long getIpUnbanDate(java.lang.String ip)
Return the date upon which an IP address becomes unbanned.


getUserLevel

public abstract int getUserLevel(java.lang.String user)
Get the level of a user.


setUserLevel

public abstract boolean setUserLevel(java.lang.String user,
                                     int level)
Set the level of a user.


getUserList

public abstract UserTableMessage getUserList()
Get a list of all users in this registry.


getIpAddress

public abstract java.lang.String getIpAddress(java.lang.String user)
Get the IP Address of a particular user.


getUsersByIp

public abstract java.util.List getUsersByIp(java.lang.String ip)
Get a List of users with a given IP Address.