Save connected players to DB when gracefully terminating the server.

This commit is contained in:
2020-10-02 19:31:47 +02:00
parent 8a144a359f
commit 35a2110698
3 changed files with 11 additions and 1 deletions

View File

@@ -47,9 +47,13 @@ void CNShardServer::keepAliveTimer(CNServer* serv, time_t currTime) {
}
void CNShardServer::periodicSaveTimer(CNServer* serv, time_t currTime) {
std::cout << "[INFO] Saving players to DB..." << std::endl;
for (auto& pair : PlayerManager::players) {
Database::updatePlayer(pair.second.plr);
}
std::cout << "[INFO] Done." << std::endl;
}
void CNShardServer::newConnection(CNSocket* cns) {
@@ -85,6 +89,12 @@ void CNShardServer::killConnection(CNSocket *cns) {
_killConnection(cns);
}
// flush the DB when terminating the server
void CNShardServer::kill() {
periodicSaveTimer(nullptr, 0);
CNServer::kill();
}
void CNShardServer::onStep() {
time_t currTime = getTime();