Marauroa Database Structure: Difference between revisions
imported>MiguelAngelBlanchLardin No edit summary |
imported>Kymara m →The whole picture: close brackets |
||
| (194 intermediate revisions by 6 users not shown) | |||
| Line 1: | Line 1: | ||
{{Navigation for Marauroa Top|Internals}} |
|||
= Basic idea behind Database storage = |
|||
{{Navigation for Marauroa Developers}} |
|||
We use database to store game state so that the game becomes a true persisten game. |
|||
==Database Tables and Relationships == |
|||
{{Database Access}} |
|||
The database table relationship schema is: |
|||
__TOC__ |
|||
<pre> |
|||
Table PLAYER |
|||
{ |
|||
PK(username) |
|||
password |
|||
} |
|||
Table CHARACTERS |
|||
{ |
|||
PK(character) |
|||
content |
|||
} |
|||
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 LOGIN_EVENT |
|||
{ |
|||
PK(id) |
|||
address |
|||
timedate |
|||
result |
|||
} |
|||
Table STATISTICS |
|||
( |
|||
PK(timedate) |
|||
== Accounts == |
|||
bytes_send |
|||
[[Image:Database-account-logs.png]] |
|||
bytes_recv |
|||
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. |
|||
players_login |
|||
players_logout |
|||
players_timeout |
|||
players_online |
|||
) |
|||
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 RPOBJECT |
|||
( |
|||
PK(id) |
|||
slot_id |
|||
) |
|||
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 RPATTRIBUTE |
|||
( |
|||
PK(object_id) |
|||
PK(name) |
|||
value |
|||
) |
|||
Note: It may be a good idea to delete old rows in this table regularly for privacy reasons. |
|||
Table RPSLOT |
|||
( |
|||
object_id |
|||
name |
|||
PK(slot_id) |
|||
) |
|||
</pre> |
|||
== Bans == |
|||
Relationships: |
|||
[[Image:Database-account-bans.png]] |
|||
<pre> |
|||
Relationship PLAYER_CHARACTERS |
|||
{ |
|||
PK(player_username) |
|||
PK(characters_character) |
|||
} |
|||
Unfortunately there are some unfriendly people out there that you may need to keep away. The tables accountban and banlist store such bans. |
|||
Relationship PLAYER_LOGIN_EVENT |
|||
{ |
|||
PK(player_username) |
|||
PK(login_event_id) |
|||
} |
|||
</pre> |
|||
Translate this to SQL easily and you have the SQL schema of Marauroa |
|||
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. |
|||
== 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. |
|||
== RPObjects == |
|||
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. |
|||
[[Image:Database-rpobjects.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. |
|||
You need to download MySQL Connector/J in order to get it to run. <br> |
|||
http://www.mysql.com/downloads/api-jdbc-stable.html |
|||
Player objects are linked to their account using the table characters. |
|||
To configure Marauroa to work with a JDBC source we need to modify the configuration of the JDBC Connection. |
|||
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. |
|||
So open the configuration file '''marauroad.ini''' ''(or whatever you choose to name it)'' and edit the next fields |
|||
<pre> |
|||
marauroa_DATABASE=JDBCPlayerDatabase |
|||
== Game Logging == |
|||
jdbc_class=com.mysql.jdbc.Driver |
|||
[[Image:Database-gamelog.png]] |
|||
jdbc_url=jdbc:mysql://localhost/marauroa |
|||
jdbc_user=marauroa_dbuser |
|||
jdbc_pwd=marauroa_dbpwd |
|||
</pre> |
|||
There are two more tables used for logging: |
|||
* ''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. |
|||
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. |
|||
Now, simply save the changes and your configuration file is ready. |
|||
Unless disabled Marauroa logs statistical information every minute in the table statistics. This includes the network traffic data and number of players online. |
|||
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 marauroa; |
|||
grant all on marauroa.* to marauroa_dbuser@localhost identified by 'marauroa_dbpwd'; |
|||
</pre> |
|||
== The whole picture == |
|||
The rest of code is handled by the server itself, and it will create the tables if they don't exist. |
|||
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]].) |
|||
[[Image:Database-marauroa.png]] |
|||
[[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 }}



