temp fix and small refactor

This commit is contained in:
CPunch 2020-09-17 21:41:09 -05:00
parent 22e3e9e4de
commit 31ef03610d
3 changed files with 9 additions and 11 deletions

View File

@ -34,9 +34,7 @@ void CNShardServer::handlePacket(CNSocket* sock, CNPacketData* data) {
}
void CNShardServer::keepAliveTimer(CNServer* serv, time_t currTime) {
auto cachedPlayers = PlayerManager::players;
for (auto& pair : cachedPlayers) {
for (auto& pair : PlayerManager::players) {
if (pair.second.lastHeartbeat != 0 && currTime - pair.second.lastHeartbeat > settings::TIMEOUT) {
// if the client hasn't responded in 60 seconds, its a dead connection so throw it out
pair.first->kill();
@ -49,9 +47,8 @@ void CNShardServer::keepAliveTimer(CNServer* serv, time_t currTime) {
}
void CNShardServer::periodicSaveTimer(CNServer* serv, time_t currTime) {
auto cachedPlayers = PlayerManager::players;
for (auto& pair : cachedPlayers) {
std::cout << "players size: " << PlayerManager::players.size() << std::endl;
for (auto& pair : PlayerManager::players) {
Database::updatePlayer(pair.second.plr);
}
}
@ -65,13 +62,13 @@ void CNShardServer::killConnection(CNSocket* cns) {
if (PlayerManager::players.find(cns) == PlayerManager::players.end())
return;
int64_t key = PlayerManager::getPlayer(cns)->SerialKey;
// save player to DB
Database::updatePlayer(PlayerManager::players[cns].plr);
// remove from CNSharedData
int64_t key = PlayerManager::getPlayer(cns)->SerialKey;
PlayerManager::removePlayer(cns);
// remove from CNSharedData
CNSharedData::erasePlayer(key);
}

View File

@ -43,8 +43,6 @@ void ChunkManager::addPlayer(int posX, int posY, CNSocket* sock) {
Chunk* chunk = chunks[pos];
chunk->players.insert(sock);
// TODO: update view for all players in surrounding chunks
}
std::pair<int, int> ChunkManager::grabChunk(int posX, int posY) {

View File

@ -96,6 +96,9 @@ void PlayerManager::removePlayerFromChunks(std::vector<Chunk*> chunks, CNSocket*
exitPlayer.iID = players[otherSock].plr->iID;
sock->sendPacket((void*)&exitPlayer, P_FE2CL_PC_EXIT, sizeof(sP_FE2CL_PC_EXIT));
}
// temp-fix for weird edgecase
chunk->players.erase(sock);
}
}