mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-05 06:50:04 +00:00
temp fix and small refactor
This commit is contained in:
parent
22e3e9e4de
commit
31ef03610d
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user