Marauroa Database Structure: Difference between revisions

From Arianne
Jump to navigation Jump to search
imported>StephenIerodiaconou
mNo edit summary
imported>StephenIerodiaconou
mNo edit summary
(No difference)

Revision as of 10:41, 9 February 2005

Basic idea behind Database storage

Arianne uses a database to store game state information so that the games can be truly persistent.

Database Tables and Relationships

The database table relationship schema is:

Table PLAYER
  {
  PK(username)
  password
  }

Table CHARACTERS
  {
  PK(character)
  content
  }

Table LOGIN_EVENT
  {
  PK(id)
  address
  timedate
  result
  }

Table STATISTICS
  (
  PK(timedate)

  bytes_send
  bytes_recv

  players_login
  players_logout
  players_timeout
  players_online
  )

Table RPOBJECT
  (
  PK(id)
  slot_id
  )

Table RPATTRIBUTE
  (
  PK(object_id)
  PK(name)
  value
  )

Table RPSLOT
  (
  object_id
  name
  PK(slot_id)
  )

Relationships:

Relationship PLAYER_CHARACTERS
  {
  PK(player_username)
  PK(characters_character)
  }

Relationship PLAYER_LOGIN_EVENT
  {
  PK(player_username)
  PK(login_event_id)
  }

Translate this to SQL easily and you have the SQL schema of Marauroa


JDBC Database HOWTO

JDBC technology is an API that lets you access virtually any tabular data source from the Java programming language. It provides cross-DBMS connectivity to a wide range of SQL databases, and now, with the new JDBC API, it also provides access to other tabular data sources, such as spreadsheets or flat files.

JDBCPlayerDatabase is anyway not database independent; on the Player table we are using AUTOINCREMENT that is a unique keyword of MySQL that is not part of the SQL standard.

You need to download MySQL Connector/J in order to get it to run.
http://www.mysql.com/downloads/api-jdbc-stable.html

To configure Marauroa to work with a JDBC source we need to modify the configuration of the JDBC Connection.

So open the configuration file marauroad.ini (or whatever you choose to name it) and edit the next fields

marauroa_DATABASE=JDBCPlayerDatabase

jdbc_class=com.mysql.jdbc.Driver
jdbc_url=jdbc:mysql://localhost/marauroa
jdbc_user=marauroa_dbuser
jdbc_pwd=marauroa_dbpwd
  • jdbc_class: This field tells the engine what Driver to use for database access. Please refer to your software manual to see the multiple options.
  • jdbc_url: This points to the type and source of the information, for MySQL the string must be as follows:
    • jdbc:mysql://ip:database_name/
  • jdbc_user: This is the username for the database
  • jdbc_pwd: This is the password for that username in the database.

Now, simply save the changes and your configuration file is ready.

Before using the application with the database, you need to create the database itself. So, with MySQL just run MySQL and enter:

create database marauroa;
grant all on marauroa.* to marauroa_dbuser@localhost identified by 'marauroa_dbpwd';

The rest of code is handled by the server itself, and it will create the tables if they don't exist.

Storing objects in the database

Objects are stored in the database to save their state. This is a heavy (intensive) operation, so we should cache objects and store them only from time to time.

This decision is made in RPManager. It calculates how often an object has to be stored.

You have to write the code to load all the database objects into RPWorld. This loading must be coded in the RPWorld class inside the onInit and onFinish methods.

How objects are identified

It is important to notice that RPObject.ID is only valid while the object is online. So there is no guarantee that any new object won't have that same RPObject.ID once the previous object has been removed.

To solve this problem we store a hidden attribute in each object called #db_id which gives a unique id to each object regardless of whether the object is online at a particular point in time or not.

When an object is loaded in to the game again, it will be assigned a new valid RPObject.ID. However, the object will still have a valid and unique persisten #db_id which can be used when we need to store the object again. We can simply update the existing copy already on the database.