Database and user data saving + loading

This was last updated when game had version: dev - 2.0.7

This describes how data is being manipulated, how it is saved / loaded to / from database in the game.


Top

Following ER diagram displays the structure of major part of the database. Fields displayed in blue color have on delete cascade constraint.
That means, that if row is deleted from table, to which is the foreign key, then the value with the blue field will also be deleted (if there is valid / any FK).

Following ER diagram displays the structure of translations table:

1 Introduction

There are 3 main entities. nodeJS game, SQL database, Game Webpage.



1.1 nodeJS game

That is a project written using NodeJS and EJS templating system.
The project itself is hosted on Heroku.
It allows a user to play the game (using javascript, sockets), but also allows a user to log in or join lobbies.
To create the GUI and buttons, lists, game hud, HTML is used (using EJS templating system)

The game, however, requires resources and data, such as weapon names, database table names and column names, textures, css styles....
Some of the resources are required by the Game Webpage as well.


1.2 Game Webpage

That is a project written using Nette.
Allows users to log in, see game statistics, forums and so on.

The page requires resources as well, and some of them are common for the nodeJS game as well.
These are for example:


The following common resources are placed in the Game Webpage, and the nodeJS game downloads it from the page if needed.


The following common resources are placed in the nodeJS game, and the Game Webpage downloads it from the page if needed.


1.3 SQL database

Functions as classic data storage for both Game Webpage, and the nodeJS game
Contains abilities, game items, monsters, users, forums (posts, replies, threads), game dialogues and so on.

2 NodeJS game

This describes how database data is being manipulated within the nodeJS game

Warning: This diagram is no longer up to date, just because the amount of data loaded is increased every day so quickly, so that it si not possible to keep it up to date...
2.1 Data loading from database (diagram)

Data is loaded from the SQL database only once, and upon starting the server.
Following diagram shows the action of loading various data. When it is loaded, and in what order.


In the game, DatabaseModels (for example MonsterDatabaseModel ) and DAOs ( AbilitiesAllDAO ,ItemPrototypeDAO ) are being used.


2.2 Class entities

2.2.1 MonsterDatabaseModel

This describes the idea behind the MonsterDatabaseModel in the game code.


2.3 Abilities

Abilities are being loaded only once from the database at the start of the game server.
Then, all game ability class instances are created according to data from database and saved in memory for later use.
All the ability data is being sent to the client, regardless if the ability is for monster only, or not (as client needs to be able to recreate monster attack on the client side).
The data is sent to the client when the client connects.
The data transportation is being explained in networking


2.4 User data

User data is being explained here

2.5 Optimalization

Data retrieval from database can be optimalized in same way, as explained in localization optimalization