Skip to main content
GameDev.net gamedev.net
🔒 Locked

Online Rpg Database

Started by Demx Nov 16, 2011 at 9:09 PM 1 replies 1.5k views
Original Post
Demx
Demx
hi, im making a simple rpg using a Server, client and a MySql database .

every second the client renders 20 frames and if a key is pressed it updates the database of the new position

while ( 1 ) {

handle events

move player if a key is pressed

if postition of player has changed write new position to database

}

the problem is i think the database is put under too much stress for updating the position evey 50-75 ms


Is there another way to update the positions ?

thx
Ravyne
Ravyne
in general, the game server is what handles the real-time updates, and the database is used for long-term persistence of data. For example, the database proper doesn't need to hold the current position, but it would be used to store the player's position at time of log-off.
throw table_exception("(? ???)? ? ???");
rneckelmann
rneckelmann
Obviously you don't want to let your client access the database directly, since that will cause all kinds of potential security problems.

You might want to let the client be authoritative on position, since if movement has to go through the server before it's displayed on the client, it will feel very laggy. Whenever the player (client) moves, just let him send a "my position is x,y,z" to the server. As Ravyne points out, you don't need to save the position every time it changes, but you still need to save it on a certain interval. These database writes can be batched for all clients, for better performance. It's not enough to only save the position on log-out, since then information will be lost if the server crashes. A save interval of 5-10 seconds will probably work fine.

Note that this is just for position. For more important updates like "player looted Sword of Doom" you want to save it to the database immediately. Players tend to get grumpy if their epic gear disappears.

If you're scared that people will hack the client and cheat with the position (they will if your game becomes popular), you probably want to do some "sanity" checks of the positioning data on the server.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.