ethanmoffat / etheos

[Eth]an's [E]ndless [O]nline [S]erver - fork of eoserv project
zlib License
13 stars 8 forks source link

Add support for automatic dump/restore of world. Remove long-running open database transaction. #29

Closed ethanmoffat closed 3 years ago

ethanmoffat commented 3 years ago

Add support for dumping and restoring the world object when server shuts down and starts. Both graceful and ungraceful shutdown cases will capture a crash dump in the configured file location. This file is formatted as json. A new dependency is added to nlohmann::json (installed via the install-dependencies script for a given platform).

Crash dump occurs when server throws an exception or traps a fatal signal. It also happens unconditionally on graceful shutdown of the server. When launching, the dump file is examined if it exists and state is restored. Characters, guilds, map items, and chest items are captured for restoration. NPC state is not captured since this is much more dynamic.

Characters will not be restored if an existing character in the database has a higher usage property. Any other existing state is clobbered by what is contained in the crash dump file, as world restoration should only ever be called when the server is first starting up.

A side effect of this change is the removal of the long-running transaction that is constantly open. TimedSave will now write state to the database instead of committing a transaction and opening a new one. This fixes issues with using sqlite after background thread changes were added to login and account creation, since multiple threads were trying to perform operations on the database concurrently (which is a big no-no in the world of sqlite).