MegaAntiCheat / client-backend

GNU General Public License v3.0
117 stars 24 forks source link

Handle Ctrl+C exit gracefully. #140

Closed Bash-09 closed 4 months ago

Bash-09 commented 4 months ago

Previously I just let Ctrl+C kill the program, but there is a possibility that poor timing could lead to data loss if settings or records have not been written back to disk yet. This branch installs a handler for Ctrl+C which gives the program a chance to save any persistent data before exiting.

It works on Linux but I have not tested it on Windows, although the tokio::signal module claims to be cross-platform so I imagine it will probably work as expected there too.

megascatterbomb commented 4 months ago

Appears to work correctly during a normal ctrl-c

image

I tested a ctrl-c during startup and it doesn't appear to be handled. As long as the playerlist isn't being accessed at this time it should be okay?

image

Bash-09 commented 4 months ago

Hm yeah I did only setup the handler right before it enters the main loop, which I guessed would be fine, but it would probably wouldn't hurt to set it up earlier anyways.

I've pushed a commit that just moves it earlier before anything that could touch the settings and records, but it is after the masterbase check so that can still be cancelled early.