diff --git a/src/CNShardServer.cpp b/src/CNShardServer.cpp index fbc8294..134ea36 100644 --- a/src/CNShardServer.cpp +++ b/src/CNShardServer.cpp @@ -17,6 +17,7 @@ CNShardServer::CNShardServer(uint16_t p) { port = p; pHandler = &CNShardServer::handlePacket; REGISTER_SHARD_TIMER(keepAliveTimer, 2000); + REGISTER_SHARD_TIMER(periodicSaveTimer, settings::DBSAVEINTERVAL*1000); init(); } @@ -44,6 +45,13 @@ void CNShardServer::keepAliveTimer(CNServer* serv, uint64_t currTime) { } } +void CNShardServer::periodicSaveTimer(CNServer* serv, uint64_t currTime) { + auto cachedPlayers = PlayerManager::players; + for (auto pair : cachedPlayers) { + Database::updatePlayer(*pair.second.plr); + } +} + void CNShardServer::newConnection(CNSocket* cns) { cns->setActiveKey(SOCKETKEY_E); // by default they accept keys encrypted with the default key } diff --git a/src/CNShardServer.hpp b/src/CNShardServer.hpp index 56f6303..3ced4fd 100644 --- a/src/CNShardServer.hpp +++ b/src/CNShardServer.hpp @@ -13,6 +13,7 @@ private: static void handlePacket(CNSocket* sock, CNPacketData* data); static void keepAliveTimer(CNServer*, uint64_t); + static void periodicSaveTimer(CNServer* serv, uint64_t currTime); public: static std::map ShardPackets; diff --git a/src/settings.cpp b/src/settings.cpp index f6cd64b..1309207 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -7,6 +7,7 @@ int settings::VERBOSITY = 1; int settings::LOGINPORT = 8001; bool settings::APPROVEALLNAMES = true; +int settings::DBSAVEINTERVAL = 240; int settings::SHARDPORT = 8002; std::string settings::SHARDSERVERIP = "127.0.0.1"; @@ -37,10 +38,11 @@ void settings::init() { } APPROVEALLNAMES = reader.GetBoolean("", "acceptallcustomnames", APPROVEALLNAMES); - VERBOSITY = reader.GetInteger("", "verbosity", VERBOSITY); + VERBOSITY = reader.GetInteger("", "verbosity", VERBOSITY); LOGINPORT = reader.GetInteger("login", "port", LOGINPORT); SHARDPORT = reader.GetInteger("shard", "port", SHARDPORT); SHARDSERVERIP = reader.Get("shard", "ip", "127.0.0.1"); + DBSAVEINTERVAL = reader.GetInteger("shard", "dbsaveinterval", DBSAVEINTERVAL); PLAYERDISTANCE = reader.GetInteger("shard", "playerdistance", PLAYERDISTANCE); NPCDISTANCE = reader.GetInteger("shard", "npcdistance", NPCDISTANCE); SPAWN_X = reader.GetInteger("shard", "spawnx", SPAWN_X); diff --git a/src/settings.hpp b/src/settings.hpp index de8121b..ae04f54 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -3,8 +3,8 @@ namespace settings { extern int VERBOSITY; extern int LOGINPORT; - extern bool LOGINRANDCHARACTERS; extern bool APPROVEALLNAMES; + extern int DBSAVEINTERVAL; extern int SHARDPORT; extern std::string SHARDSERVERIP; extern int PLAYERDISTANCE;