Server can handle multiple dropped clients at once

This commit is contained in:
Kayne Ruse
2015-02-17 20:48:03 +11:00
parent 87af4f1a1e
commit 2cc7260552
3 changed files with 28 additions and 17 deletions
+8 -8
View File
@@ -21,11 +21,15 @@
*/
#include "client_manager.hpp"
#include "ip_operators.hpp"
#include "udp_network_utility.hpp"
#include <chrono>
int ClientManager::CheckConnections() {
std::list<int> ClientManager::CheckConnections() {
//list of clients to disconnect
std::list<int> returnList;
for (auto& it : elementMap) {
//3 seconds between beats
if (ClientData::Clock::now() - it.second.GetLastBeat() > std::chrono::seconds(3)) {
@@ -38,21 +42,17 @@ int ClientManager::CheckConnections() {
for (auto& it : elementMap) {
if (it.second.GetAttempts() > 2) {
int ret = it.first;
// elementMap.erase(it.first);
return ret;
returnList.push_back(it.first);
}
}
return -1;
return returnList;
}
void ClientManager::HandlePong(ServerPacket* const argPacket) {
//find and update the specified client
for (auto& it : elementMap) {
if (it.second.GetAddress().host == argPacket->srcAddress.host &&
it.second.GetAddress().port == argPacket->srcAddress.port
) {
if (it.second.GetAddress() == argPacket->srcAddress) {
it.second.ResetAttempts();
return;
}
+2 -1
View File
@@ -29,12 +29,13 @@
#include "SDL/SDL_net.h"
#include <functional>
#include <list>
#include <map>
class ClientManager: public Singleton<ClientManager> {
public:
//methods
int CheckConnections();
std::list<int> CheckConnections();
void HandlePong(ServerPacket* const argPacket);
//common public methods