Atavism Version 2018.1AGIS API

atavism.server.engine
Class MasterDatabase

java.lang.Object
  extended by atavism.server.engine.MasterDatabase

public class MasterDatabase
extends java.lang.Object

Access to Entities in database - default is MySQL All Entity access requires both an object oid and a Namespace.


Nested Class Summary
static class MasterDatabase.WorldInfo
          A class to represent a world - world name, world mgr server, hostname, port, mediaURL
 
Constructor Summary
MasterDatabase()
          Constructor starts the keepalive thread
MasterDatabase(java.lang.String sDriver)
          General database connection.
 
Method Summary
 int AOAcctPasswdCheck(java.lang.String username, java.lang.String password)
          Returns the atavism account id if the username and password match. otherwise, returns -1.
 boolean checkPlayerCanConnectToWorld(int worldID)
          Checks if the specified world is currently online and that there is sufficient population space for them to connect.
 void close()
          Close the database connection.
 void connect(java.lang.String url, java.lang.String username, java.lang.String password)
          Connect to the database at the host given by the url, using the given username and password
 int createAccount(java.lang.String username, java.lang.String password, java.lang.String emailAddress, boolean specificID, int accountID)
          Checks password, returns the user OID if matches, otherwise returns null
 boolean createUser(java.lang.String username, java.lang.String password, java.lang.String email, int status)
          Create a user - returns false if failed - usually because username is not unique.
 boolean databaseContainsTable(java.lang.String dbName, java.lang.String tableName)
          Tests to see if the table of the given name is present in a database.
 boolean databaseTableContainsColumn(java.lang.String dbName, java.lang.String tableName, java.lang.String columnName)
          Tests to see if the table of the given name contain the given row in the current database.
 void executeBatch(java.util.List<java.lang.String> statements)
          Run the series of SQL statements in the list argument.
 java.sql.ResultSet executeSelect(java.lang.String query)
           
 void executeUpdate(java.lang.String update)
          Run the update statement in the string arg.
static java.lang.String generateSaltedPassword(java.lang.String passwd)
           
 java.lang.Integer getAccountId(java.lang.String username)
           
 int getCurrentWorld(java.lang.String username)
          Reads in the id of the world the player was last connected to.
 java.lang.String getPassword(java.lang.String username)
           
 int getServerToConnectTo(java.lang.String username)
          Works out which server the player should connect to.
 int getServerWithLowestPopulation()
          Finds the server with the lowest population that the player can connect to.
 java.lang.String getUserName(long uid)
          Get user name.
 int getWorldWithPlayersCharacters(int accountID)
          Reads in the servers the player has characters on and returns the one with the most players characters on that they can connect to.
static void main(java.lang.String[] args)
          A main program that exercises database functionality.
 OID passwordCheck(java.lang.String username, java.lang.String password)
          Checks password, returns the user OID if matches, otherwise returns null
 void ping()
          Runs a select statement to make sure we can still talk to the database.
 MasterDatabase.WorldInfo resolveWorldID(int worldID)
          Resolves the passed-in world ID to a servername and port.
 int statusCheck(java.lang.String username)
          Checks account status, returns the user OID if matches, otherwise returns null
 void updateUser(java.lang.String username, java.lang.String password, int status)
          Create a user - returns false if failed - usually because username is not unique.
 void updateUserWorld(java.lang.String username, int worldID)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MasterDatabase

public MasterDatabase()
Constructor starts the keepalive thread


MasterDatabase

public MasterDatabase(java.lang.String sDriver)
General database connection. Create JDBC database for with the supplied string representing the driver class, e.g. "com.mysql.jdbc.Driver". Also starts the keepalive thread.

Method Detail

connect

public void connect(java.lang.String url,
                    java.lang.String username,
                    java.lang.String password)
Connect to the database at the host given by the url, using the given username and password

Parameters:
url - Specifies the host to connect to.
username - The account name used to log into the database.
password - The password to use to log in.

executeUpdate

public void executeUpdate(java.lang.String update)
Run the update statement in the string arg.

Parameters:
update - An SQL update statement, or any other statement that does not return values.

executeBatch

public void executeBatch(java.util.List<java.lang.String> statements)
Run the series of SQL statements in the list argument.

Parameters:
statements - A list of SQL statements to be executed.

databaseTableContainsColumn

public boolean databaseTableContainsColumn(java.lang.String dbName,
                                           java.lang.String tableName,
                                           java.lang.String columnName)
Tests to see if the table of the given name contain the given row in the current database. Used by Engine as an indication the version of database schema, since normally we add tables with new schema versions.

Parameters:
tableName - The name of the table.
columnName - The name of the column.
Returns:
True if the column is contained in the table; false otherwise.

databaseContainsTable

public boolean databaseContainsTable(java.lang.String dbName,
                                     java.lang.String tableName)
Tests to see if the table of the given name is present in a database. Used by Engine as an indication the version of database schema, since normally we add tables with new schema versions. However, this method requires MySQL version 5, and since some customers have MySQL 4, we can't use it.

Parameters:
dbName - The name of the database.
tableName - The name of the table.
Returns:
True if the table is contained in the database; false otherwise.

close

public void close()
Close the database connection.


AOAcctPasswdCheck

public int AOAcctPasswdCheck(java.lang.String username,
                             java.lang.String password)
Returns the atavism account id if the username and password match. otherwise, returns -1. Used by the master server.

Parameters:
username - The name of the user account.
password - The user's account password.
Returns:
The account id associated with the username.

resolveWorldID

public MasterDatabase.WorldInfo resolveWorldID(int worldID)
Resolves the passed-in world ID to a servername and port. The master server usually does this lookup to tell clients where to go to connect to a particular worldName.

Parameters:
worldName - The string name of the world.
Returns:
The servername and port in inetsocketaddress object, null if there is no match

getServerToConnectTo

public int getServerToConnectTo(java.lang.String username)
Works out which server the player should connect to. First checks to see what server they were last connected to and tries to connect them to that. If that fails, it will find the server they have the most characters on. If there are no characters it will choose the server with the lowest current population.

Parameters:
username -
Returns:

getCurrentWorld

public int getCurrentWorld(java.lang.String username)
Reads in the id of the world the player was last connected to.

Parameters:
username -
Returns:

getPassword

public java.lang.String getPassword(java.lang.String username)

getAccountId

public java.lang.Integer getAccountId(java.lang.String username)

passwordCheck

public OID passwordCheck(java.lang.String username,
                         java.lang.String password)
Checks password, returns the user OID if matches, otherwise returns null

Parameters:
username - The username string.
password - The password string.
Returns:
The oid associated with the username.

createAccount

public int createAccount(java.lang.String username,
                         java.lang.String password,
                         java.lang.String emailAddress,
                         boolean specificID,
                         int accountID)
Checks password, returns the user OID if matches, otherwise returns null

Parameters:
username - The username string.
password - The password string.
Returns:
The oid associated with the username.

executeSelect

public java.sql.ResultSet executeSelect(java.lang.String query)

generateSaltedPassword

public static java.lang.String generateSaltedPassword(java.lang.String passwd)

createUser

public boolean createUser(java.lang.String username,
                          java.lang.String password,
                          java.lang.String email,
                          int status)
Create a user - returns false if failed - usually because username is not unique.

Parameters:
username - The username string.
password - The password string.
Returns:
True if the user/password pair could be created; false otherwise.

updateUser

public void updateUser(java.lang.String username,
                       java.lang.String password,
                       int status)
Create a user - returns false if failed - usually because username is not unique.

Parameters:
username - The username string.
password - The password string.

updateUserWorld

public void updateUserWorld(java.lang.String username,
                            int worldID)

statusCheck

public int statusCheck(java.lang.String username)
Checks account status, returns the user OID if matches, otherwise returns null

Parameters:
username - The username string.
password - The password string.
Returns:
The oid associated with the username.

getUserName

public java.lang.String getUserName(long uid)
Get user name. Checks ID, returns user name if there is a match, otherwise returns null.

Parameters:
uid - The user oid.
Returns:
The string username corresponding to the oid, or null if not found.

checkPlayerCanConnectToWorld

public boolean checkPlayerCanConnectToWorld(int worldID)
Checks if the specified world is currently online and that there is sufficient population space for them to connect.

Parameters:
worldID -
Returns:

getWorldWithPlayersCharacters

public int getWorldWithPlayersCharacters(int accountID)
Reads in the servers the player has characters on and returns the one with the most players characters on that they can connect to.

Parameters:
accountID -
Returns:

getServerWithLowestPopulation

public int getServerWithLowestPopulation()
Finds the server with the lowest population that the player can connect to.

Returns:

ping

public void ping()
Runs a select statement to make sure we can still talk to the database.


main

public static void main(java.lang.String[] args)
A main program that exercises database functionality.

Parameters:
args - Command-line args with the format "java Database "


Copyright © 2018 Dragonsan Studios Sp. z o.o.