The server-side heartbeat is working and stable

This commit is contained in:
Kayne Ruse
2014-09-03 03:23:56 +10:00
parent 79c7e48139
commit 246a5ee541
4 changed files with 74 additions and 2 deletions
+19
View File
@@ -26,6 +26,7 @@
#include "utility.hpp"
#include <stdexcept>
#include <chrono>
#include <iostream>
#include <string>
@@ -144,6 +145,24 @@ void ServerApplication::Proc() {
//update the internals
//BUG: #30 Update the internals i.e. player positions
//TODO: This could be checked only every few seconds
//Check connections
for (auto& it : clientMap) {
if (std::chrono::steady_clock::now() - it.second.GetLastBeat() > std::chrono::seconds(5)) {
ServerPacket newPacket;
newPacket.type = SerialPacketType::PING;
network.SendTo(it.second.GetAddress(), &newPacket);
it.second.IncrementAttempts();
}
if (it.second.GetAttempts() > 2) {
CleanupLostConnection(it.first);
//all iterators are invalid, so we can't continue
break;
}
}
//give the computer a break
SDL_Delay(10);
}