diff --git a/include/TNetwork.h b/include/TNetwork.h index 743f188..a4d28c5 100644 --- a/include/TNetwork.h +++ b/include/TNetwork.h @@ -44,6 +44,6 @@ private: void OnDisconnect(const std::weak_ptr& ClientPtr, bool kicked); void Parse(TClient& c, const std::string& Packet); void SendFile(TClient& c, const std::string& Name); - static bool TCPSendRaw(SOCKET C, char* Data, int32_t Size); + static bool TCPSendRaw(TClient& C, SOCKET socket, char* Data, int32_t Size); static void SplitLoad(TClient& c, size_t Sent, size_t Size, bool D, const std::string& Name); }; diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 0a067e0..33bd092 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -390,8 +390,8 @@ bool TNetwork::TCPSend(TClient& c, const std::string& Data, bool IsSync) { return false; } Sent += Temp; + c.UpdatePingTime(); } while (Sent < Size); - c.UpdatePingTime(); return true; } @@ -757,7 +757,7 @@ void TNetwork::SplitLoad(TClient& c, size_t Sent, size_t Size, bool D, const std if (Diff > Split) { f.seekg(Sent, std::ios_base::beg); f.read(Data, Split); - if (!TCPSendRaw(TCPSock, Data, Split)) { + if (!TCPSendRaw(c, TCPSock, Data, Split)) { if (c.GetStatus() > -1) c.SetStatus(-1); break; @@ -766,7 +766,7 @@ void TNetwork::SplitLoad(TClient& c, size_t Sent, size_t Size, bool D, const std } else { f.seekg(Sent, std::ios_base::beg); f.read(Data, Diff); - if (!TCPSendRaw(TCPSock, Data, int32_t(Diff))) { + if (!TCPSendRaw(c, TCPSock, Data, int32_t(Diff))) { if (c.GetStatus() > -1) c.SetStatus(-1); break; @@ -778,16 +778,17 @@ void TNetwork::SplitLoad(TClient& c, size_t Sent, size_t Size, bool D, const std f.close(); } -bool TNetwork::TCPSendRaw(SOCKET C, char* Data, int32_t Size) { +bool TNetwork::TCPSendRaw(TClient& C, SOCKET socket, char* Data, int32_t Size) { intmax_t Sent = 0; do { - intmax_t Temp = send(C, &Data[Sent], int(Size - Sent), 0); + intmax_t Temp = send(socket, &Data[Sent], int(Size - Sent), 0); if (Temp < 1) { - info("Socket Closed! " + std::to_string(C)); - CloseSocketProper(C); + info("Socket Closed! " + std::to_string(socket)); + CloseSocketProper(socket); return false; } Sent += Temp; + C.UpdatePingTime(); } while (Sent < Size); return true; } diff --git a/src/TPPSMonitor.cpp b/src/TPPSMonitor.cpp index 0bd296b..80f4115 100644 --- a/src/TPPSMonitor.cpp +++ b/src/TPPSMonitor.cpp @@ -36,17 +36,15 @@ void TPPSMonitor::operator()() { ReadLock Lock(mServer.GetClientMutex()); if (!ClientPtr.expired()) { c = ClientPtr.lock(); - } else return true; + } else + return true; } if (c->GetCarCount() > 0) { C++; V += c->GetCarCount(); } - if (!c->IsSynced() || c->IsSyncing()) { - c->UpdatePingTime(); - } // kick on "no ping" - if (c->SecondsSinceLastPing() > 30 && c->IsSynced() && !c->IsSyncing()) { + if (c->SecondsSinceLastPing() > 30) { debug("client " + std::string("(") + std::to_string(c->GetID()) + ")" + c->GetName() + " timing out: " + std::to_string(c->SecondsSinceLastPing()) + ", pps: " + Application::PPS()); TimedOutClients.push_back(c); }