• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ How to save the server before it crashes? [ANTI ROLLBACK]

gudan garam

Advanced OT User
Joined
Feb 13, 2011
Messages
353
Solutions
17
Reaction score
173
Location
São Paulo.
Hello guys, so I started looking into Anti Rollback systems but they all seem really heavy approaches, meaning, for example, that they save every player every 30 seconds, or they call a save to a player everytime he does some action that is worthy of being saved, i.e. moving an item, trading, etc...

So, I was wondering if there is a way to save the gamestate when something goes wrong (crash happens)?

I've read something about doing it in destructors, because apparently (some ppl said this is not true, and I couldn't do it) the destructor is called when a segmentation fault or something like that happens. I've tested it and ofc, no good result.

Also some people talked about SIGNALS but I couldn't find a good enough read to succeed on this. I can't make a function be called when a signal is sent because it expects the function to receive an x parameter that I don't know of.

C++:
signal(SIGSEGV, handler)
This didn't work because handler must have a specific parameter as I said above.

So if you found a good way to approach this issue, how did you do it? Not restraining it to saving the gamestate if the engine crashes, I'd also like to know if you could optmize the save in certain areas that it is not an issue to use it all the time anymore.
 
Last edited:
This has very little to do with the programming language in which the application is written in. It is more an OS thing as it's not the processes job to handle itself crashing, and destructors won't be called. First of all, there are several scenarios where a "crash" as you explain it can occur. You need to weigh in scenarios where there is internal issues with hardware, power outage, etc. The exhaustive solution is to have persistent saves to save the state.

Since this is more of an OS question it is relevant to share what OS you're planning on running your server on.
 
I'd be running it on a linux.

But see... persistent saves could easily cause lags to the whole server, thats why I thought it could be achieved in other ways.
 
I'd be running it on a linux.

But see... persistent saves could easily cause lags to the whole server, thats why I thought it could be achieved in other ways.

so go to the bottom to why it causes lags, there's no saying you have to do everything in the main or dispatch thread. What you explain as lags isn't really lag. If you do some expensive task synchronously on the main thread then of course you're gonna experience freezes
 
Last edited:
If you by any chance use gdb, you can call a function (i.e. call g_game.saveGameState()) upon catching a segmentation fault. However this will only work if the executable is built with debug symbols.
 
This questiion is probably best answered by @Mark or @Don Daniello or some other person(s) who maintain TFS.

I'd suggest something but I am just a custodial engineer (I sweep the city street)

I'd love to see what you have to suggest.

If you by any chance use gdb, you can call a function (i.e. call g_game.saveGameState()) upon catching a segmentation fault. However this will only work if the executable is built with debug symbols.

I like this but I haven't found anything on google about it, thanks anyways.
 
Back
Top