mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-08-17 00:36:55 +00:00
fix a ghost client bug
This commit is contained in:
parent
7d2e4d4581
commit
231b13a0e7
@ -5,54 +5,23 @@
|
|||||||
// ======================= UNIX ========================
|
// ======================= UNIX ========================
|
||||||
|
|
||||||
#ifdef BEAMMP_LINUX
|
#ifdef BEAMMP_LINUX
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
using SOCKET = int;
|
|
||||||
using DWORD = unsigned long;
|
|
||||||
using PDWORD = unsigned long*;
|
|
||||||
using LPDWORD = unsigned long*;
|
|
||||||
char _getch();
|
char _getch();
|
||||||
inline void CloseSocketProper(int TheSocket) {
|
|
||||||
shutdown(TheSocket, SHUT_RDWR);
|
|
||||||
close(TheSocket);
|
|
||||||
}
|
|
||||||
#endif // unix
|
#endif // unix
|
||||||
|
|
||||||
// ======================= APPLE ========================
|
// ======================= APPLE ========================
|
||||||
|
|
||||||
#ifdef BEAMMP_APPLE
|
#ifdef BEAMMP_APPLE
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
using SOCKET = int;
|
|
||||||
using DWORD = unsigned long;
|
|
||||||
using PDWORD = unsigned long*;
|
|
||||||
using LPDWORD = unsigned long*;
|
|
||||||
char _getch();
|
char _getch();
|
||||||
inline void CloseSocketProper(int TheSocket) {
|
|
||||||
shutdown(TheSocket, SHUT_RDWR);
|
|
||||||
close(TheSocket);
|
|
||||||
}
|
|
||||||
#endif // unix
|
#endif // unix
|
||||||
|
|
||||||
// ======================= WINDOWS =======================
|
// ======================= WINDOWS =======================
|
||||||
|
|
||||||
#ifdef BEAMMP_WINDOWS
|
#ifdef BEAMMP_WINDOWS
|
||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
#include <winsock2.h>
|
|
||||||
inline void CloseSocketProper(SOCKET TheSocket) {
|
|
||||||
shutdown(TheSocket, 2); // 2 == SD_BOTH
|
|
||||||
closesocket(TheSocket);
|
|
||||||
}
|
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
|
|
||||||
#ifdef INVALID_SOCKET
|
|
||||||
static inline constexpr int BEAMMP_INVALID_SOCKET = INVALID_SOCKET;
|
|
||||||
#else
|
|
||||||
static inline constexpr int BEAMMP_INVALID_SOCKET = -1;
|
|
||||||
#endif
|
|
||||||
|
@ -397,7 +397,6 @@ std::vector<uint8_t> TNetwork::TCPRcv(TClient& c) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
Header = *reinterpret_cast<int32_t*>(HeaderData.data());
|
Header = *reinterpret_cast<int32_t*>(HeaderData.data());
|
||||||
beammp_tracef("Expecting to read {} bytes", Header);
|
|
||||||
|
|
||||||
std::vector<uint8_t> Data;
|
std::vector<uint8_t> Data;
|
||||||
// TODO: This is arbitrary, this needs to be handled another way
|
// TODO: This is arbitrary, this needs to be handled another way
|
||||||
@ -498,10 +497,13 @@ void TNetwork::TCPClient(const std::weak_ptr<TClient>& c) {
|
|||||||
|
|
||||||
auto res = TCPRcv(*Client);
|
auto res = TCPRcv(*Client);
|
||||||
if (res.empty()) {
|
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);
|
TServer::GlobalParser(c, std::move(res), mPPSMonitor, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (QueueSync.joinable())
|
if (QueueSync.joinable())
|
||||||
QueueSync.join();
|
QueueSync.join();
|
||||||
|
|
||||||
@ -929,9 +931,7 @@ bool TNetwork::UDPSend(TClient& Client, std::vector<uint8_t> Data) {
|
|||||||
std::vector<uint8_t> TNetwork::UDPRcvFromClient(ip::udp::endpoint& ClientEndpoint) {
|
std::vector<uint8_t> TNetwork::UDPRcvFromClient(ip::udp::endpoint& ClientEndpoint) {
|
||||||
std::array<char, 1024> Ret {};
|
std::array<char, 1024> Ret {};
|
||||||
boost::system::error_code ec;
|
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);
|
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) {
|
if (ec) {
|
||||||
beammp_errorf("UDP recvfrom() failed: {}", ec.what());
|
beammp_errorf("UDP recvfrom() failed: {}", ec.what());
|
||||||
return {};
|
return {};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user