Marauroa Database Structure: Difference between revisions

Content deleted Content added
imported>Kymara
imported>Hendrik Brummermann
added iamges
Line 2:
{{Navigation for Marauroa Developers}}
 
This article describes the table structure of the Marauroa database. You might want to have a look at [[Database Access]] which explains the high level API to access the database from your program code.
= Basic idea behind Database storage =
Arianne uses a database to store game state information so that the games can be truly persistent.
 
==Database Tables==
 
== Accounts ==
This are the tables of the Stendhal database schema:
[[Image:Database-account-logs.png‎]]
{{TODO|draw diagrams instead of listing tables}}
{{TODO|add new tables}}
<pre>
Table account (InnoDB)
+----------+------------------------------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------------------------------+------+-----+-------------------+----------------+
| id | int(11) | NO | MUL | NULL | auto_increment |
| username | varchar(32) | NO | PRI | | |
| password | varchar(255) | NO | | | |
| email | varchar(64) | NO | | | |
| timedate | timestamp | NO | | CURRENT_TIMESTAMP | |
| status | enum('active','inactive','banned') | NO | | active | |
+----------+------------------------------------+------+-----+-------------------+----------------+
 
== Bans ==
Table banlist (InnoDB)
[[Image:Database-account-bans.png‎]]
+---------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| address | varchar(15) | YES | | NULL | |
| mask | varchar(15) | YES | | NULL | |
| reason | varchar(255) | YES | | NULL | |
+---------+--------------+------+-----+---------+----------------+
 
== RPObjects ==
Table characters (InnoDB)
[[Image:Database-rpobjects.png‎]]
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| player_id | int(11) | NO | | | |
| charname | varchar(32) | NO | PRI | | |
| object_id | int(11) | NO | | | |
+-----------+-------------+------+-----+---------+-------+
 
== Game Logging ==
Table character_stats (MyISAM)
[[Image:Database-gamelog.png‎]]
+----------+--------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+-------------------+-------+
| name | varchar(32) | NO | PRI | | |
| online | tinyint(1) | YES | | NULL | |
| admin | int(11) | YES | | 0 | |
| sentence | varchar(256) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
| level | int(11) | YES | | NULL | |
| outfit | varchar(32) | YES | | NULL | |
| xp | int(11) | YES | | NULL | |
| money | int(11) | YES | | NULL | |
| married | varchar(32) | YES | | NULL | |
| atk | int(11) | YES | | NULL | |
| def | int(11) | YES | | NULL | |
| hp | int(11) | YES | | NULL | |
| karma | int(11) | YES | | NULL | |
| head | varchar(32) | YES | | NULL | |
| armor | varchar(32) | YES | | NULL | |
| lhand | varchar(32) | YES | | NULL | |
| rhand | varchar(32) | YES | | NULL | |
| legs | varchar(32) | YES | | NULL | |
| feet | varchar(32) | YES | | NULL | |
| cloak | varchar(32) | YES | | NULL | |
| timedate | timestamp | NO | | CURRENT_TIMESTAMP | |
+----------+--------------+------+-----+-------------------+-------+
 
== The whole picture ==
Table gameevents (InnoDB)
[[Image:Database-marauroa.png‎]]
+----------+--------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+-------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| timedate | timestamp | NO | | CURRENT_TIMESTAMP | |
| source | varchar(64) | YES | | NULL | |
| event | varchar(64) | YES | | NULL | |
| param1 | varchar(128) | YES | | NULL | |
| param2 | varchar(255) | YES | | NULL | |
+----------+--------------+------+-----+-------------------+----------------+
 
== Other stuff ==
Table halloffame (MyISAM)
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| charname | varchar(32) | NO | | | |
| fametype | char(1) | NO | | | |
| points | int(11) | NO | | | |
+----------+-------------+------+-----+---------+----------------+
 
Table itemid (MyISAM)
+---------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------+------+-----+---------+-------+
| last_id | int(11) | YES | | NULL | |
+---------+---------+------+-----+---------+-------+
 
Table itemlog (MyISAM)
+----------+-------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+-------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| timedate | timestamp | NO | | CURRENT_TIMESTAMP | |
| itemid | int(11) | YES | | NULL | |
| source | varchar(64) | YES | | NULL | |
| event | varchar(64) | YES | | NULL | |
| param1 | varchar(64) | YES | | NULL | |
| param2 | varchar(64) | YES | | NULL | |
| param3 | varchar(64) | YES | | NULL | |
| param4 | varchar(64) | YES | | NULL | |
+----------+-------------+------+-----+-------------------+----------------+
 
Table loginevent (InnoDB)
+-----------+-------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+-------------------+-------+
| player_id | int(11) | NO | | | |
| address | varchar(64) | YES | | NULL | |
| timedate | timestamp | NO | | CURRENT_TIMESTAMP | |
| result | tinyint(4) | YES | | NULL | |
+-----------+-------------+------+-----+-------------------+-------+
 
Table rpobject (InnoDB)
+-----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+----------------+
| object_id | int(11) | NO | PRI | NULL | auto_increment |
| data | blob | YES | | NULL | |
+-----------+---------+------+-----+---------+----------------+
 
Table rpzone (InnoDB)
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| zone_id | varchar(32) | NO | PRI | | |
| data | blob | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
 
Table statistics (InnoDB)
+-----------------+-----------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-----------+------+-----+-------------------+-------+
| timedate | timestamp | NO | | CURRENT_TIMESTAMP | |
| bytes_send | int(11) | YES | | NULL | |
| bytes_recv | int(11) | YES | | NULL | |
| players_login | int(11) | YES | | NULL | |
| players_logout | int(11) | YES | | NULL | |
| players_timeout | int(11) | YES | | NULL | |
| players_online | int(11) | YES | | NULL | |
+-----------------+-----------+------+-----+-------------------+-------+
 
Table words (MyISAM)
+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| normalized | varchar(64) | NO | | | |
| type | varchar(64) | YES | | NULL | |
| plural | varchar(64) | YES | | NULL | |
| value | int(11) | YES | | NULL | |
| alias_id | int(11) | YES | | NULL | |
+------------+-------------+------+-----+---------+----------------+
</pre>
 
{{Move everything below these lines into the [[Database Access]] article}}
Important tables which store original data, use the InnoDB engine. Tables with redundant data for easy access and logging use the MyISAM table type.
 
=== JDBC Database HOWTO===
{{TODO|Update to reflect DAOs}}
{{TODO|Add H2}}
Line 186 ⟶ 42:
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 an expensive operation, so it is only done every 10 minutes or on special events (like logout).