08.01.2016, 06:14
So recently I got back into coding servers after years away from SA-MP, and now I've got a "blocking" question that I can't seem to wrap my mind around.
Setting up the server and the database isn't the issue here. What I can't seem to understand is how the game state is synced with a database. Allow me to explain.
On server start I fetch the data from my database to have the initial game state.
On server close I store the data back into the database.
But what happens in between? What if I make a gamemode where users can buy a house. If the house is bought, nobody else can buy it. If I only sync data on server start and close, a house that has been bought within the "current" server session will not be displayed as bought for other players, because the state is not synced with the database.
So the kinda impractical solutions I've thought through are:
1. Will I need an additional "source of truth" (in-memory database or simply a massive object replicating the database structure) to handle all changes to the game state so that all players can immediately see changes (such as a house going from available to unavailable if someone buys it)
2. Sync with the database every time a player does something sync-worthy, like buying a house, dying, depositing cash, etc.
3. Sync on interval (performance hit?)
Are there any other solutions to this? I feel like I'm seriously over-complicating this...
Setting up the server and the database isn't the issue here. What I can't seem to understand is how the game state is synced with a database. Allow me to explain.
On server start I fetch the data from my database to have the initial game state.
On server close I store the data back into the database.
But what happens in between? What if I make a gamemode where users can buy a house. If the house is bought, nobody else can buy it. If I only sync data on server start and close, a house that has been bought within the "current" server session will not be displayed as bought for other players, because the state is not synced with the database.
So the kinda impractical solutions I've thought through are:
1. Will I need an additional "source of truth" (in-memory database or simply a massive object replicating the database structure) to handle all changes to the game state so that all players can immediately see changes (such as a house going from available to unavailable if someone buys it)
2. Sync with the database every time a player does something sync-worthy, like buying a house, dying, depositing cash, etc.
3. Sync on interval (performance hit?)
Are there any other solutions to this? I feel like I'm seriously over-complicating this...