netbattle.database.registry
Class FileImpl

java.lang.Object
  extended by netbattle.database.registry.AccountRegistry
      extended by netbattle.database.registry.FileImpl

public class FileImpl
extends AccountRegistry

This is an implementation of the AccountRegistry that uses only flat files. The impl. works by internally storing the registry data as a HashMap. When an instance is created, the map is unseralised from a file. When the close method is called, the map is seralised to the same file. To reduce susceptibility to data loss, the data is also serialised periodically, as specified when the class is instantiated.


Field Summary
 
Fields inherited from class netbattle.database.registry.AccountRegistry
LEVEL_ADMIN, LEVEL_MOD, LEVEL_USER
 
Constructor Summary
FileImpl(java.lang.String file, long delta)
          Creates a new instance of FileImpl
 
Method Summary
 boolean addNewUser(java.lang.String user, java.lang.String password)
          Add a new user to the registry.
 boolean banUser(java.lang.String user, long date)
          Set the date upon which a user becomes unbanned.
 boolean banUser(java.lang.String user, java.lang.String ip, long date)
          Set the date upon which a user becomes unbanned.
 void close()
          Close this AccountRegistry.
 java.lang.String getIpAddress(java.lang.String user)
          Get the IP Address of a particular user.
 long getIpUnbanDate(java.lang.String ip)
          Return the date upon which an IP address becomes unbanned.
 java.lang.String getPassword(java.lang.String user)
          Get the SHA-1 hash of a user's password.
 int getUserLevel(java.lang.String user)
          Get the level of a user.
 UserTableMessage getUserList()
          Get a list of all users in this registry.
 java.util.List getUsersByIp(java.lang.String ip)
          Get a List of users with a given IP Address.
 long getUserUnbanDate(java.lang.String user)
          Determine when a user becomes unbanned.
 boolean setUserLevel(java.lang.String user, int level)
          Set the level of a user.
 
Methods inherited from class netbattle.database.registry.AccountRegistry
finalize, getInstance, setInstance
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileImpl

public FileImpl(java.lang.String file,
                long delta)
Creates a new instance of FileImpl

Parameters:
delta - the number of milliseconds between each backup of the map
Method Detail

close

public void close()
Close this AccountRegistry.

Specified by:
close in class AccountRegistry

getPassword

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

Specified by:
getPassword in class AccountRegistry
Returns:
the hash or null if the user does not exist

addNewUser

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

Specified by:
addNewUser in class AccountRegistry
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 boolean banUser(java.lang.String user,
                       long date)
Set the date upon which a user becomes unbanned.

Specified by:
banUser in class AccountRegistry

banUser

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

Specified by:
banUser in class AccountRegistry

getUserUnbanDate

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

Specified by:
getUserUnbanDate in class AccountRegistry
Returns:
a UNIX timestamp of the unban date

getIpUnbanDate

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

Specified by:
getIpUnbanDate in class AccountRegistry

getUserList

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

Specified by:
getUserList in class AccountRegistry

getIpAddress

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

Specified by:
getIpAddress in class AccountRegistry

getUsersByIp

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

Specified by:
getUsersByIp in class AccountRegistry

getUserLevel

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

Specified by:
getUserLevel in class AccountRegistry

setUserLevel

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

Specified by:
setUserLevel in class AccountRegistry