added periodic DB saves, fixed some settings

This commit is contained in:
kamilprzyb 2020-09-09 00:23:45 +02:00 committed by dongresource
parent 1d9a7139a8
commit 3d83f93167
4 changed files with 13 additions and 2 deletions

View File

@ -17,6 +17,7 @@ CNShardServer::CNShardServer(uint16_t p) {
port = p; port = p;
pHandler = &CNShardServer::handlePacket; pHandler = &CNShardServer::handlePacket;
REGISTER_SHARD_TIMER(keepAliveTimer, 2000); REGISTER_SHARD_TIMER(keepAliveTimer, 2000);
REGISTER_SHARD_TIMER(periodicSaveTimer, settings::DBSAVEINTERVAL*1000);
init(); 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) { void CNShardServer::newConnection(CNSocket* cns) {
cns->setActiveKey(SOCKETKEY_E); // by default they accept keys encrypted with the default key cns->setActiveKey(SOCKETKEY_E); // by default they accept keys encrypted with the default key
} }

View File

@ -13,6 +13,7 @@ private:
static void handlePacket(CNSocket* sock, CNPacketData* data); static void handlePacket(CNSocket* sock, CNPacketData* data);
static void keepAliveTimer(CNServer*, uint64_t); static void keepAliveTimer(CNServer*, uint64_t);
static void periodicSaveTimer(CNServer* serv, uint64_t currTime);
public: public:
static std::map<uint32_t, PacketHandler> ShardPackets; static std::map<uint32_t, PacketHandler> ShardPackets;

View File

@ -7,6 +7,7 @@ int settings::VERBOSITY = 1;
int settings::LOGINPORT = 8001; int settings::LOGINPORT = 8001;
bool settings::APPROVEALLNAMES = true; bool settings::APPROVEALLNAMES = true;
int settings::DBSAVEINTERVAL = 240;
int settings::SHARDPORT = 8002; int settings::SHARDPORT = 8002;
std::string settings::SHARDSERVERIP = "127.0.0.1"; std::string settings::SHARDSERVERIP = "127.0.0.1";
@ -37,10 +38,11 @@ void settings::init() {
} }
APPROVEALLNAMES = reader.GetBoolean("", "acceptallcustomnames", APPROVEALLNAMES); APPROVEALLNAMES = reader.GetBoolean("", "acceptallcustomnames", APPROVEALLNAMES);
VERBOSITY = reader.GetInteger("", "verbosity", VERBOSITY); VERBOSITY = reader.GetInteger("", "verbosity", VERBOSITY);
LOGINPORT = reader.GetInteger("login", "port", LOGINPORT); LOGINPORT = reader.GetInteger("login", "port", LOGINPORT);
SHARDPORT = reader.GetInteger("shard", "port", SHARDPORT); SHARDPORT = reader.GetInteger("shard", "port", SHARDPORT);
SHARDSERVERIP = reader.Get("shard", "ip", "127.0.0.1"); SHARDSERVERIP = reader.Get("shard", "ip", "127.0.0.1");
DBSAVEINTERVAL = reader.GetInteger("shard", "dbsaveinterval", DBSAVEINTERVAL);
PLAYERDISTANCE = reader.GetInteger("shard", "playerdistance", PLAYERDISTANCE); PLAYERDISTANCE = reader.GetInteger("shard", "playerdistance", PLAYERDISTANCE);
NPCDISTANCE = reader.GetInteger("shard", "npcdistance", NPCDISTANCE); NPCDISTANCE = reader.GetInteger("shard", "npcdistance", NPCDISTANCE);
SPAWN_X = reader.GetInteger("shard", "spawnx", SPAWN_X); SPAWN_X = reader.GetInteger("shard", "spawnx", SPAWN_X);

View File

@ -3,8 +3,8 @@
namespace settings { namespace settings {
extern int VERBOSITY; extern int VERBOSITY;
extern int LOGINPORT; extern int LOGINPORT;
extern bool LOGINRANDCHARACTERS;
extern bool APPROVEALLNAMES; extern bool APPROVEALLNAMES;
extern int DBSAVEINTERVAL;
extern int SHARDPORT; extern int SHARDPORT;
extern std::string SHARDSERVERIP; extern std::string SHARDSERVERIP;
extern int PLAYERDISTANCE; extern int PLAYERDISTANCE;