From 15ea360b8a131135288f8fc72655f3b6da1272b2 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 19 Dec 2014 17:58:50 +1100 Subject: [PATCH] Replaced lambda implementations with calls to the 'full unload' methods IT should be noted that ClientManager::CheckConnections() no longer removes a client; instead, it returns a client index that needs to be removed via another means. This allows ServerApplication to use the 'full unload' method. --- server/clients/client_manager.cpp | 2 +- server/server_connections.cpp | 35 ++++--------------------------- server/server_logic.cpp | 22 +------------------ 3 files changed, 6 insertions(+), 53 deletions(-) diff --git a/server/clients/client_manager.cpp b/server/clients/client_manager.cpp index d2ae9bf..86ccdb3 100644 --- a/server/clients/client_manager.cpp +++ b/server/clients/client_manager.cpp @@ -39,7 +39,7 @@ int ClientManager::CheckConnections() { for (auto& it : elementMap) { if (it.second.GetAttempts() > 2) { int ret = it.first; - elementMap.erase(it.first); +// elementMap.erase(it.first); return ret; } } diff --git a/server/server_connections.cpp b/server/server_connections.cpp index b9ca988..79d8c23 100644 --- a/server/server_connections.cpp +++ b/server/server_connections.cpp @@ -137,18 +137,8 @@ void ServerApplication::HandleLogoutRequest(ClientPacket* const argPacket) { network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); - //save and unload this accounts characters - characterMgr.UnloadIf([&](std::pair it) -> bool { - if (argPacket->accountIndex == it.second.GetOwner()) { - //pump the unload message to all remaining clients - //TODO: pump character unload - return true; - } - return false; - }); - - //unload this account - accountMgr.Unload(argPacket->accountIndex); + //save and unload this account and it's characters + FullAccountUnload(argPacket->accountIndex); //finished this routine std::cout << "New logout, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; @@ -174,25 +164,8 @@ void ServerApplication::HandleDisconnectRequest(ClientPacket* const argPacket) { network.SendTo(clientData->GetAddress(), static_cast(&newPacket)); - //TODO: need a method for this redundunt chunk of redundant code - //find and unload the accounts associated with this client - accountMgr.UnloadIf([&](std::pair account) -> bool { - if (account.second.GetClientIndex() == argPacket->clientIndex) { - //find and unload the characters associated with this account - characterMgr.UnloadIf([&](std::pair character) -> bool { - if (character.second.GetOwner() == account.first) { - //TODO: pump character unload - return true; - } - return false; - }); - return true; - } - return false; - }); - - //unload this client - clientMgr.Unload(argPacket->clientIndex); + //unload the client, it's accounts, and their characters + FullClientUnload(argPacket->clientIndex); //finished this routine std::cout << "New disconnection, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl; diff --git a/server/server_logic.cpp b/server/server_logic.cpp index 0a76d59..0b20037 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -182,27 +182,7 @@ void ServerApplication::Proc() { //Check connections int disconnected = clientMgr.CheckConnections(); if (disconnected != -1) { - //find and unload the accounts associated with this client - accountMgr.UnloadIf([&](std::pair account) -> bool { - if (account.second.GetClientIndex() == disconnected) { - //find and unload the characters associated with this account - characterMgr.UnloadIf([&](std::pair character) -> bool { - if (character.second.GetOwner() == account.first) { - //pump character delete - CharacterPacket newPacket; - newPacket.type = SerialPacketType::CHARACTER_DELETE; - newPacket.characterIndex = character.first; - PumpPacket(static_cast(&newPacket)); - - //unload this character - return true; - } - return false; - }); - return true; - } - return false; - }); + FullClientUnload(disconnected); } //give the computer a break