mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 23:35:41 +00:00
Packet queuing on syncing
This commit is contained in:
parent
f0abfcc0ef
commit
3fe8d48ada
@ -54,7 +54,8 @@ public:
|
|||||||
void SetIsGuest(bool NewIsGuest) { mIsGuest = NewIsGuest; }
|
void SetIsGuest(bool NewIsGuest) { mIsGuest = NewIsGuest; }
|
||||||
void SetIsSynced(bool NewIsSynced) { mIsSynced = NewIsSynced; }
|
void SetIsSynced(bool NewIsSynced) { mIsSynced = NewIsSynced; }
|
||||||
void SetIsSyncing(bool NewIsSyncing) { mIsSyncing = NewIsSyncing; }
|
void SetIsSyncing(bool NewIsSyncing) { mIsSyncing = NewIsSyncing; }
|
||||||
void EnqueueMissedPacketDuringSyncing(const std::string& Packet) { mMissedPacketsDuringSyncing.push(Packet); }
|
void EnqueueMissedPacketDuringSyncing(const std::string& Packet);
|
||||||
|
[[nodiscard]] std::queue<std::string> MissedPacketQueue(){ return mMissedPacketsDuringSyncing; }
|
||||||
[[nodiscard]] size_t MissedPacketQueueSize() const { return mMissedPacketsDuringSyncing.size(); }
|
[[nodiscard]] size_t MissedPacketQueueSize() const { return mMissedPacketsDuringSyncing.size(); }
|
||||||
void SetIsConnected(bool NewIsConnected) { mIsConnected = NewIsConnected; }
|
void SetIsConnected(bool NewIsConnected) { mIsConnected = NewIsConnected; }
|
||||||
[[nodiscard]] TServer& Server() const;
|
[[nodiscard]] TServer& Server() const;
|
||||||
@ -66,6 +67,7 @@ private:
|
|||||||
bool mIsConnected = false;
|
bool mIsConnected = false;
|
||||||
bool mIsSynced = false;
|
bool mIsSynced = false;
|
||||||
bool mIsSyncing = false;
|
bool mIsSyncing = false;
|
||||||
|
std::mutex mMissedPacketsMutex;
|
||||||
std::queue<std::string> mMissedPacketsDuringSyncing;
|
std::queue<std::string> mMissedPacketsDuringSyncing;
|
||||||
std::set<std::string> mIdentifiers;
|
std::set<std::string> mIdentifiers;
|
||||||
bool mIsGuest = false;
|
bool mIsGuest = false;
|
||||||
@ -73,7 +75,7 @@ private:
|
|||||||
TSetOfVehicleData mVehicleData;
|
TSetOfVehicleData mVehicleData;
|
||||||
std::string mName = "Unknown Client";
|
std::string mName = "Unknown Client";
|
||||||
SOCKET mSocket[2] { SOCKET(-1) };
|
SOCKET mSocket[2] { SOCKET(-1) };
|
||||||
sockaddr_in mUDPAddress {}; // is this initialization OK?
|
sockaddr_in mUDPAddress {}; // is this initialization OK? yes it is
|
||||||
std::string mRole;
|
std::string mRole;
|
||||||
std::string mDID;
|
std::string mDID;
|
||||||
int mStatus = 0;
|
int mStatus = 0;
|
||||||
|
@ -17,8 +17,8 @@ public:
|
|||||||
void operator()() override;
|
void operator()() override;
|
||||||
|
|
||||||
bool TCPSend(TClient& c, const std::string& Data, bool IsSync = false);
|
bool TCPSend(TClient& c, const std::string& Data, bool IsSync = false);
|
||||||
void SendLarge(TClient& c, std::string Data);
|
void SendLarge(TClient& c, std::string Data, bool isSync = false);
|
||||||
void Respond(TClient& c, const std::string& MSG, bool Rel);
|
void Respond(TClient& c, const std::string& MSG, bool Rel, bool isSync = false);
|
||||||
std::shared_ptr<TClient> CreateClient(SOCKET TCPSock);
|
std::shared_ptr<TClient> CreateClient(SOCKET TCPSock);
|
||||||
std::string TCPRcv(TClient& c);
|
std::string TCPRcv(TClient& c);
|
||||||
void ClientKick(TClient& c, const std::string& R);
|
void ClientKick(TClient& c, const std::string& R);
|
||||||
|
@ -69,6 +69,11 @@ TServer& TClient::Server() const {
|
|||||||
return mServer;
|
return mServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TClient::EnqueueMissedPacketDuringSyncing(const std::string& Packet){
|
||||||
|
std::unique_lock Lock(mMissedPacketsMutex);
|
||||||
|
mMissedPacketsDuringSyncing.push(Packet);
|
||||||
|
}
|
||||||
|
|
||||||
TClient::TClient(TServer& Server)
|
TClient::TClient(TServer& Server)
|
||||||
: mServer(Server)
|
: mServer(Server)
|
||||||
, mLastPingTime(std::chrono::high_resolution_clock::now()) {
|
, mLastPingTime(std::chrono::high_resolution_clock::now()) {
|
||||||
|
@ -164,7 +164,12 @@ bool TTCPServer::TCPSend(TClient& c, const std::string& Data, bool IsSync) {
|
|||||||
if (c.IsSyncing() && !IsSync) {
|
if (c.IsSyncing() && !IsSync) {
|
||||||
c.EnqueueMissedPacketDuringSyncing(Data);
|
c.EnqueueMissedPacketDuringSyncing(Data);
|
||||||
return true;
|
return true;
|
||||||
} else if (!c.IsSyncing() && c.IsSynced() && c.MissedPacketQueueSize() != 0) {
|
} else if (!c.IsSyncing() && c.IsSynced() && c.MissedPacketQueueSize() != 0 && !IsSync) {
|
||||||
|
while(c.MissedPacketQueueSize() > 0){
|
||||||
|
std::string QData = c.MissedPacketQueue().front();
|
||||||
|
c.MissedPacketQueue().pop();
|
||||||
|
TCPSend(c, QData,true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
int32_t Size, Sent;
|
int32_t Size, Sent;
|
||||||
std::string Send(4, 0);
|
std::string Send(4, 0);
|
||||||
@ -522,21 +527,21 @@ bool TTCPServer::TCPSendRaw(SOCKET C, char* Data, int32_t Size) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TTCPServer::SendLarge(TClient& c, std::string Data) {
|
void TTCPServer::SendLarge(TClient& c, std::string Data, bool isSync) {
|
||||||
if (Data.length() > 400) {
|
if (Data.length() > 400) {
|
||||||
std::string CMP(Comp(Data));
|
std::string CMP(Comp(Data));
|
||||||
Data = "ABG:" + CMP;
|
Data = "ABG:" + CMP;
|
||||||
}
|
}
|
||||||
TCPSend(c, Data);
|
TCPSend(c, Data, isSync);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TTCPServer::Respond(TClient& c, const std::string& MSG, bool Rel) {
|
void TTCPServer::Respond(TClient& c, const std::string& MSG, bool Rel, bool isSync) {
|
||||||
char C = MSG.at(0);
|
char C = MSG.at(0);
|
||||||
if (Rel || C == 'W' || C == 'Y' || C == 'V' || C == 'E') {
|
if (Rel || C == 'W' || C == 'Y' || C == 'V' || C == 'E') {
|
||||||
if (C == 'O' || C == 'T' || MSG.length() > 1000) {
|
if (C == 'O' || C == 'T' || MSG.length() > 1000) {
|
||||||
SendLarge(c, MSG);
|
SendLarge(c, MSG);
|
||||||
} else {
|
} else {
|
||||||
TCPSend(c, MSG);
|
TCPSend(c, MSG, isSync);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
UDPServer().UDPSend(c, MSG);
|
UDPServer().UDPSend(c, MSG);
|
||||||
@ -571,7 +576,7 @@ void TTCPServer::SyncClient(const std::weak_ptr<TClient>& c) {
|
|||||||
Return = true;
|
Return = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Respond(*LockedClient, v.Data(), true);
|
Respond(*LockedClient, v.Data(), true, true);
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user