Marauroa Database Structure: Difference between revisions
imported>Hendrik Brummermann No edit summary |
imported>Kymara m →The whole picture: close brackets |
||
| (90 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
{{Navigation for Marauroa Top}} |
{{Navigation for Marauroa Top|Internals}} |
||
{{Navigation for Marauroa Developers}} |
{{Navigation for Marauroa Developers}} |
||
= Basic idea behind Database storage = |
|||
Arianne uses a database to store game state information so that the games can be truly persistent. |
|||
{{Database Access}} |
|||
__TOC__ |
|||
This are the tables of the Stendhal database schema: |
|||
{{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 | | |
|||
+----------+------------------------------------+------+-----+-------------------+----------------+ |
|||
This article describes the table structure of the Marauroa database. You might want to have a look at [[High Level Database Access]] which explains the high level API to access the database from your program code. The article [[Low Level Database Access]] describes how Marauroa accesses the database internally and how you can add support for your own tables. |
|||
Table banlist (InnoDB) |
|||
+---------+--------------+------+-----+---------+----------------+ |
|||
| 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 | | |
|||
+---------+--------------+------+-----+---------+----------------+ |
|||
Table characters (InnoDB) |
|||
+-----------+-------------+------+-----+---------+-------+ |
|||
| Field | Type | Null | Key | Default | Extra | |
|||
+-----------+-------------+------+-----+---------+-------+ |
|||
| player_id | int(11) | NO | | | | |
|||
| charname | varchar(32) | NO | PRI | | | |
|||
| object_id | int(11) | NO | | | | |
|||
+-----------+-------------+------+-----+---------+-------+ |
|||
== Accounts == |
|||
Table character_stats (MyISAM) |
|||
[[Image:Database-account-logs.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 | | |
|||
+----------+--------------+------+-----+-------------------+-------+ |
|||
Authentication information is stored in the table account. It consists of the username, the password hash, email address, and the timestamp of the account creation. Please note that for historic reasons foreign key columns pointing to the account table are not named account_id but player_id. |
|||
Table gameevents (InnoDB) |
|||
+----------+--------------+------+-----+-------------------+----------------+ |
|||
| 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 | | |
|||
+----------+--------------+------+-----+-------------------+----------------+ |
|||
For security reason every login (successful or not) is logged in the table loginEvent with the ip-address, timestamp, and a success flag. The column service is used to tell logins from a game and a website apart. The optional column seed stores a preauthentication seed. Marauroa automatically prevents logins for some time after too many failed tries. |
|||
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 | | | | |
|||
+----------+-------------+------+-----+---------+----------------+ |
|||
Password changes are logged in a similar way. In addition to normal loginEvents the old password hash is stored as well. This is a precaution to restore hacked accounts back to their original owner. |
|||
Table itemid (MyISAM) |
|||
+---------+---------+------+-----+---------+-------+ |
|||
| Field | Type | Null | Key | Default | Extra | |
|||
+---------+---------+------+-----+---------+-------+ |
|||
| last_id | int(11) | YES | | NULL | | |
|||
+---------+---------+------+-----+---------+-------+ |
|||
Note: It may be a good idea to delete old rows in this table regularly for privacy reasons. |
|||
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 | | |
|||
+----------+-------------+------+-----+-------------------+----------------+ |
|||
== Bans == |
|||
Table loginevent (InnoDB) |
|||
[[Image:Database-account-bans.png]] |
|||
+-----------+-------------+------+-----+-------------------+-------+ |
|||
| 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 | | |
|||
+-----------+-------------+------+-----+-------------------+-------+ |
|||
Unfortunately there are some unfriendly people out there that you may need to keep away. The tables accountban and banlist store such bans. |
|||
Table rpobject (InnoDB) |
|||
+-----------+---------+------+-----+---------+----------------+ |
|||
| Field | Type | Null | Key | Default | Extra | |
|||
+-----------+---------+------+-----+---------+----------------+ |
|||
| object_id | int(11) | NO | PRI | NULL | auto_increment | |
|||
| data | blob | YES | | NULL | | |
|||
+-----------+---------+------+-----+---------+----------------+ |
|||
The table accountban is on a per account basis. The person trying to login is displayed the reason. Account bans can expire automatically. |
|||
Table rpzone (InnoDB) |
|||
+---------+-------------+------+-----+---------+-------+ |
|||
| Field | Type | Null | Key | Default | Extra | |
|||
+---------+-------------+------+-----+---------+-------+ |
|||
| zone_id | varchar(32) | NO | PRI | | | |
|||
| data | blob | YES | | NULL | | |
|||
+---------+-------------+------+-----+---------+-------+ |
|||
The table banlist stores bans based on ip-address and ip-address-ranges. The mask 255.255.255.255 donates a single ip-address. |
|||
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 | | |
|||
+-----------------+-----------+------+-----+-------------------+-------+ |
|||
== RPObjects == |
|||
Table words (MyISAM) |
|||
[[Image:Database-rpobjects.png]] |
|||
+------------+-------------+------+-----+---------+----------------+ |
|||
| 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> |
|||
Marauroa knows two types of objects which can be stored to the database: players and zones. Both objects can contain other objects: Players have items in their bags, zones can contain objects that are flagged as storable. |
|||
Important tables which store original data, use the InnoDB engine. Tables with redundant data for easy access and logging use the MyISAM table type. |
|||
Player objects are linked to their account using the table characters. |
|||
== JDBC Database HOWTO== |
|||
{{TODO|Update to reflect DAOs}} |
|||
{{TODO|Add H2}} |
|||
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 relational databases. Unfortunatally it does not hide vendor specific stuff. Marauroa and Stendhal currently only work with MySQL because of that. Adding support for other database software would be very easy as the database specific code is concentrated in the classes JDBCDatabase (Marauroa) and StendhalPlayerDatabase (Stendhal). We have no need for that, so it was not done, yet. We will, however, accept patches for multi database system support, so if you need it, go ahead. |
|||
Note: Currently the rpobjects (including owned slots and rpojbects in those slots) are serialized in a Blob field. In the Marauroa Version 1.x it was a relational. Unfortunately that approach was failing performance requirements (MySQL is extremely slow on delete statements). There is a [[Meta object model for relational data storage|concept]] in development that proposes an improved relational structure. |
|||
== Game Logging == |
|||
You need to download MySQL Connector/J in order to get it to run: http://www.mysql.com/downloads/api-jdbc-stable.html |
|||
[[Image:Database-gamelog.png]] |
|||
There are two more tables used for logging: |
|||
To configure Marauroa to work with a JDBC source, run the appropriate GenerateINI program. For Stendhal this is games.stendhal.server.core.engine.GenerateINI. |
|||
gameEvents stores events that occur in the game world (killing monsters, trading, teleporting, etc.) with a time stamp and the player causing the event. The parameters param1 and param2 depend on the event. |
|||
Before using the application with the database, you need to create the database itself. So, with MySQL just run MySQL and enter: |
|||
<pre> |
|||
create database stendhal; |
|||
grant all on stendhal.* to stendhal_user@localhost identified by 'stendhal_passwd'; |
|||
</pre> |
|||
Unless disabled Marauroa logs statistical information every minute in the table statistics. This includes the network traffic data and number of players online. |
|||
The rest of code is handled by the server itself, and it will create the tables if they don't exist. |
|||
== |
== The whole picture == |
||
Objects are stored in the database to save their state. This is an expansive operation, so it is only done every 10 minutes or on special events (like logout). |
|||
The following diagram shows the all tables used by Marauroa. Games are, however, free to add their own tables if the need arises (JMapacman and Marboard don't need additional tables but Stendhal makes heavy use of [[Stendhal Database Structure|this possibility]].) |
|||
This decision is made in RPManager. It calculates how often an object has to be stored. |
|||
[[Image:Database-marauroa.png]] |
|||
Marauroa knows two types of objects which can be stored to the database: players and zones. Both objects can contain other objects: Players have items in their bags, zones can contain objects that are flagged as storable. |
|||
[[Category:Marauroa]] |
[[Category:Marauroa]] |
||
{{#breadcrumbs: [[Marauroa]] | [[Navigation for Marauroa Developers|Internals]] | [[Marauroa Database Structure|Database Structure]] }} |
|||
Latest revision as of 19:37, 14 April 2011
- Stendhal
This article describes the table structure of the Marauroa database. You might want to have a look at High Level Database Access which explains the high level API to access the database from your program code. The article Low Level Database Access describes how Marauroa accesses the database internally and how you can add support for your own tables.
Accounts
Authentication information is stored in the table account. It consists of the username, the password hash, email address, and the timestamp of the account creation. Please note that for historic reasons foreign key columns pointing to the account table are not named account_id but player_id.
For security reason every login (successful or not) is logged in the table loginEvent with the ip-address, timestamp, and a success flag. The column service is used to tell logins from a game and a website apart. The optional column seed stores a preauthentication seed. Marauroa automatically prevents logins for some time after too many failed tries.
Password changes are logged in a similar way. In addition to normal loginEvents the old password hash is stored as well. This is a precaution to restore hacked accounts back to their original owner.
Note: It may be a good idea to delete old rows in this table regularly for privacy reasons.
Bans
Unfortunately there are some unfriendly people out there that you may need to keep away. The tables accountban and banlist store such bans.
The table accountban is on a per account basis. The person trying to login is displayed the reason. Account bans can expire automatically.
The table banlist stores bans based on ip-address and ip-address-ranges. The mask 255.255.255.255 donates a single ip-address.
RPObjects
Marauroa knows two types of objects which can be stored to the database: players and zones. Both objects can contain other objects: Players have items in their bags, zones can contain objects that are flagged as storable.
Player objects are linked to their account using the table characters.
Note: Currently the rpobjects (including owned slots and rpojbects in those slots) are serialized in a Blob field. In the Marauroa Version 1.x it was a relational. Unfortunately that approach was failing performance requirements (MySQL is extremely slow on delete statements). There is a concept in development that proposes an improved relational structure.
Game Logging
There are two more tables used for logging:
gameEvents stores events that occur in the game world (killing monsters, trading, teleporting, etc.) with a time stamp and the player causing the event. The parameters param1 and param2 depend on the event.
Unless disabled Marauroa logs statistical information every minute in the table statistics. This includes the network traffic data and number of players online.
The whole picture
The following diagram shows the all tables used by Marauroa. Games are, however, free to add their own tables if the need arises (JMapacman and Marboard don't need additional tables but Stendhal makes heavy use of this possibility.)
{{#breadcrumbs: Marauroa | Internals | Database Structure }}



