mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-08-18 01:06:47 +00:00
fix issue with spamming 1kB until death
This commit is contained in:
parent
3fe8d48ada
commit
3c48ac6145
@ -55,7 +55,8 @@ public:
|
|||||||
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);
|
void EnqueueMissedPacketDuringSyncing(const std::string& Packet);
|
||||||
[[nodiscard]] std::queue<std::string> MissedPacketQueue(){ return mMissedPacketsDuringSyncing; }
|
[[nodiscard]] std::queue<std::string>& MissedPacketQueue() { return mMissedPacketsDuringSyncing; }
|
||||||
|
[[nodiscard]] const std::queue<std::string>& MissedPacketQueue() const { 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;
|
||||||
|
@ -110,7 +110,7 @@ void TTCPServer::Authentication(SOCKET TCPSock) {
|
|||||||
Client->SetName(AuthResponse["username"].GetString());
|
Client->SetName(AuthResponse["username"].GetString());
|
||||||
Client->SetRoles(AuthResponse["roles"].GetString());
|
Client->SetRoles(AuthResponse["roles"].GetString());
|
||||||
Client->SetIsGuest(AuthResponse["guest"].GetBool());
|
Client->SetIsGuest(AuthResponse["guest"].GetBool());
|
||||||
for(const auto& ID : AuthResponse["identifiers"].GetArray()){
|
for (const auto& ID : AuthResponse["identifiers"].GetArray()) {
|
||||||
Client->AddIdentifier(ID.GetString());
|
Client->AddIdentifier(ID.GetString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -161,14 +161,17 @@ std::shared_ptr<TClient> TTCPServer::CreateClient(SOCKET TCPSock) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool TTCPServer::TCPSend(TClient& c, const std::string& Data, bool IsSync) {
|
bool TTCPServer::TCPSend(TClient& c, const std::string& Data, bool IsSync) {
|
||||||
if (c.IsSyncing() && !IsSync) {
|
if (!IsSync) {
|
||||||
|
if (c.IsSyncing()) {
|
||||||
c.EnqueueMissedPacketDuringSyncing(Data);
|
c.EnqueueMissedPacketDuringSyncing(Data);
|
||||||
return true;
|
return true;
|
||||||
} else if (!c.IsSyncing() && c.IsSynced() && c.MissedPacketQueueSize() != 0 && !IsSync) {
|
} else if (!c.IsSyncing() && c.IsSynced() && c.MissedPacketQueueSize() != 0) {
|
||||||
while(c.MissedPacketQueueSize() > 0){
|
while (c.MissedPacketQueueSize() > 0) {
|
||||||
std::string QData = c.MissedPacketQueue().front();
|
std::string QData = c.MissedPacketQueue().front();
|
||||||
c.MissedPacketQueue().pop();
|
c.MissedPacketQueue().pop();
|
||||||
TCPSend(c, QData,true);
|
debug("sending a missed packet of size " + std::to_string(QData.size()));
|
||||||
|
TCPSend(c, QData, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int32_t Size, Sent;
|
int32_t Size, Sent;
|
||||||
@ -539,7 +542,7 @@ void TTCPServer::Respond(TClient& c, const std::string& MSG, bool Rel, bool isSy
|
|||||||
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, isSync);
|
||||||
} else {
|
} else {
|
||||||
TCPSend(c, MSG, isSync);
|
TCPSend(c, MSG, isSync);
|
||||||
}
|
}
|
||||||
@ -558,9 +561,9 @@ void TTCPServer::SyncClient(const std::weak_ptr<TClient>& c) {
|
|||||||
// Syncing, later set isSynced
|
// Syncing, later set isSynced
|
||||||
// after syncing is done, we apply all packets they missed
|
// after syncing is done, we apply all packets they missed
|
||||||
Respond(*LockedClient, ("Sn") + LockedClient->GetName(), true);
|
Respond(*LockedClient, ("Sn") + LockedClient->GetName(), true);
|
||||||
LockedClient->SetIsSyncing(true);
|
|
||||||
UDPServer().SendToAll(LockedClient.get(), ("JWelcome ") + LockedClient->GetName() + "!", false, true);
|
UDPServer().SendToAll(LockedClient.get(), ("JWelcome ") + LockedClient->GetName() + "!", false, true);
|
||||||
TriggerLuaEvent(("onPlayerJoin"), false, nullptr, std::make_unique<TLuaArg>(TLuaArg { { LockedClient->GetID() } }), false);
|
TriggerLuaEvent(("onPlayerJoin"), false, nullptr, std::make_unique<TLuaArg>(TLuaArg { { LockedClient->GetID() } }), false);
|
||||||
|
LockedClient->SetIsSyncing(true);
|
||||||
bool Return = false;
|
bool Return = false;
|
||||||
mServer.ForEachClient([&](const std::weak_ptr<TClient>& ClientPtr) -> bool {
|
mServer.ForEachClient([&](const std::weak_ptr<TClient>& ClientPtr) -> bool {
|
||||||
if (!ClientPtr.expired()) {
|
if (!ClientPtr.expired()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user