From 231b13a0e760ae24a85698c9d5ae409d1a9830a7 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Wed, 5 Oct 2022 18:11:27 +0200 Subject: [PATCH] fix a ghost client bug --- include/Compat.h | 31 ------------------------------- src/TNetwork.cpp | 8 ++++---- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/include/Compat.h b/include/Compat.h index 1a3cc63..fd4de59 100644 --- a/include/Compat.h +++ b/include/Compat.h @@ -5,54 +5,23 @@ // ======================= UNIX ======================== #ifdef BEAMMP_LINUX -#include #include -#include #include #include -using SOCKET = int; -using DWORD = unsigned long; -using PDWORD = unsigned long*; -using LPDWORD = unsigned long*; char _getch(); -inline void CloseSocketProper(int TheSocket) { - shutdown(TheSocket, SHUT_RDWR); - close(TheSocket); -} #endif // unix // ======================= APPLE ======================== #ifdef BEAMMP_APPLE -#include #include -#include #include #include -using SOCKET = int; -using DWORD = unsigned long; -using PDWORD = unsigned long*; -using LPDWORD = unsigned long*; char _getch(); -inline void CloseSocketProper(int TheSocket) { - shutdown(TheSocket, SHUT_RDWR); - close(TheSocket); -} #endif // unix // ======================= WINDOWS ======================= #ifdef BEAMMP_WINDOWS #include -#include -inline void CloseSocketProper(SOCKET TheSocket) { - shutdown(TheSocket, 2); // 2 == SD_BOTH - closesocket(TheSocket); -} #endif // WIN32 - -#ifdef INVALID_SOCKET -static inline constexpr int BEAMMP_INVALID_SOCKET = INVALID_SOCKET; -#else -static inline constexpr int BEAMMP_INVALID_SOCKET = -1; -#endif diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 35ace21..8a2ec52 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -397,7 +397,6 @@ std::vector TNetwork::TCPRcv(TClient& c) { return {}; } Header = *reinterpret_cast(HeaderData.data()); - beammp_tracef("Expecting to read {} bytes", Header); std::vector Data; // TODO: This is arbitrary, this needs to be handled another way @@ -498,10 +497,13 @@ void TNetwork::TCPClient(const std::weak_ptr& c) { auto res = TCPRcv(*Client); if (res.empty()) { - beammp_debug("TCPRcv empty, ignoring"); + beammp_debug("TCPRcv empty"); + Client->Disconnect("TCPRcv failed"); + break; } TServer::GlobalParser(c, std::move(res), mPPSMonitor, *this); } + if (QueueSync.joinable()) QueueSync.join(); @@ -929,9 +931,7 @@ bool TNetwork::UDPSend(TClient& Client, std::vector Data) { std::vector TNetwork::UDPRcvFromClient(ip::udp::endpoint& ClientEndpoint) { std::array Ret {}; boost::system::error_code ec; - beammp_debugf("receiving data from {}:{}", ClientEndpoint.address().to_string(), ClientEndpoint.port()); const auto Rcv = mUDPSock.receive_from(mutable_buffer(Ret.data(), Ret.size()), ClientEndpoint, 0, ec); - beammp_debugf("received {} bytes from {}:{}", Rcv, ClientEndpoint.address().to_string(), ClientEndpoint.port()); if (ec) { beammp_errorf("UDP recvfrom() failed: {}", ec.what()); return {};