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.
This commit is contained in:
@@ -39,7 +39,7 @@ int ClientManager::CheckConnections() {
|
|||||||
for (auto& it : elementMap) {
|
for (auto& it : elementMap) {
|
||||||
if (it.second.GetAttempts() > 2) {
|
if (it.second.GetAttempts() > 2) {
|
||||||
int ret = it.first;
|
int ret = it.first;
|
||||||
elementMap.erase(it.first);
|
// elementMap.erase(it.first);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,18 +137,8 @@ void ServerApplication::HandleLogoutRequest(ClientPacket* const argPacket) {
|
|||||||
|
|
||||||
network.SendTo(clientData->GetAddress(), static_cast<SerialPacket*>(&newPacket));
|
network.SendTo(clientData->GetAddress(), static_cast<SerialPacket*>(&newPacket));
|
||||||
|
|
||||||
//save and unload this accounts characters
|
//save and unload this account and it's characters
|
||||||
characterMgr.UnloadIf([&](std::pair<int, CharacterData> it) -> bool {
|
FullAccountUnload(argPacket->accountIndex);
|
||||||
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);
|
|
||||||
|
|
||||||
//finished this routine
|
//finished this routine
|
||||||
std::cout << "New logout, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl;
|
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<SerialPacket*>(&newPacket));
|
network.SendTo(clientData->GetAddress(), static_cast<SerialPacket*>(&newPacket));
|
||||||
|
|
||||||
//TODO: need a method for this redundunt chunk of redundant code
|
//unload the client, it's accounts, and their characters
|
||||||
//find and unload the accounts associated with this client
|
FullClientUnload(argPacket->clientIndex);
|
||||||
accountMgr.UnloadIf([&](std::pair<const int, AccountData> account) -> bool {
|
|
||||||
if (account.second.GetClientIndex() == argPacket->clientIndex) {
|
|
||||||
//find and unload the characters associated with this account
|
|
||||||
characterMgr.UnloadIf([&](std::pair<const int, CharacterData> 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);
|
|
||||||
|
|
||||||
//finished this routine
|
//finished this routine
|
||||||
std::cout << "New disconnection, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl;
|
std::cout << "New disconnection, " << clientMgr.GetLoadedCount() << " clients and " << accountMgr.GetLoadedCount() << " accounts total" << std::endl;
|
||||||
|
|||||||
+1
-21
@@ -182,27 +182,7 @@ void ServerApplication::Proc() {
|
|||||||
//Check connections
|
//Check connections
|
||||||
int disconnected = clientMgr.CheckConnections();
|
int disconnected = clientMgr.CheckConnections();
|
||||||
if (disconnected != -1) {
|
if (disconnected != -1) {
|
||||||
//find and unload the accounts associated with this client
|
FullClientUnload(disconnected);
|
||||||
accountMgr.UnloadIf([&](std::pair<const int, AccountData> account) -> bool {
|
|
||||||
if (account.second.GetClientIndex() == disconnected) {
|
|
||||||
//find and unload the characters associated with this account
|
|
||||||
characterMgr.UnloadIf([&](std::pair<const int, CharacterData> 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<SerialPacket*>(&newPacket));
|
|
||||||
|
|
||||||
//unload this character
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//give the computer a break
|
//give the computer a break
|
||||||
|
|||||||
Reference in New Issue
Block a user