mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-04 00:36:14 +00:00
moved an if block again feeling good
This commit is contained in:
parent
b825e5685b
commit
e7ae71513c
@ -39,6 +39,7 @@ private:
|
|||||||
void HandleDownload(SOCKET TCPSock);
|
void HandleDownload(SOCKET TCPSock);
|
||||||
void OnConnect(const std::weak_ptr<TClient>& c);
|
void OnConnect(const std::weak_ptr<TClient>& c);
|
||||||
void TCPClient(const std::weak_ptr<TClient>& c);
|
void TCPClient(const std::weak_ptr<TClient>& c);
|
||||||
|
void Looper(const std::weak_ptr<TClient>& c);
|
||||||
int OpenID();
|
int OpenID();
|
||||||
void OnDisconnect(const std::weak_ptr<TClient>& ClientPtr, bool kicked);
|
void OnDisconnect(const std::weak_ptr<TClient>& ClientPtr, bool kicked);
|
||||||
void Parse(TClient& c, const std::string& Packet);
|
void Parse(TClient& c, const std::string& Packet);
|
||||||
|
@ -484,18 +484,8 @@ void TNetwork::ClientKick(TClient& c, const std::string& R) {
|
|||||||
c.SetStatus(-2);
|
c.SetStatus(-2);
|
||||||
CloseSocketProper(c.GetTCPSock());
|
CloseSocketProper(c.GetTCPSock());
|
||||||
}
|
}
|
||||||
|
void TNetwork::Looper(const std::weak_ptr<TClient>& c){
|
||||||
void TNetwork::TCPClient(const std::weak_ptr<TClient>& c) {
|
while(!c.expired()) {
|
||||||
// TODO: the c.expired() might cause issues here, remove if you end up here with your debugger
|
|
||||||
if (c.expired() || c.lock()->GetTCPSock() == -1) {
|
|
||||||
mServer.RemoveClient(c);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
OnConnect(c);
|
|
||||||
RegisterThread("(" + std::to_string(c.lock()->GetID()) + ") \"" + c.lock()->GetName() + "\"");
|
|
||||||
while (true) {
|
|
||||||
if (c.expired())
|
|
||||||
break;
|
|
||||||
auto Client = c.lock();
|
auto Client = c.lock();
|
||||||
if (Client->GetStatus() < 0) {
|
if (Client->GetStatus() < 0) {
|
||||||
debug("client status < 0, breaking client loop");
|
debug("client status < 0, breaking client loop");
|
||||||
@ -527,7 +517,31 @@ void TNetwork::TCPClient(const std::weak_ptr<TClient>& c) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void TNetwork::TCPClient(const std::weak_ptr<TClient>& c) {
|
||||||
|
// TODO: the c.expired() might cause issues here, remove if you end up here with your debugger
|
||||||
|
if (c.expired() || c.lock()->GetTCPSock() == -1) {
|
||||||
|
mServer.RemoveClient(c);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
OnConnect(c);
|
||||||
|
RegisterThread("(" + std::to_string(c.lock()->GetID()) + ") \"" + c.lock()->GetName() + "\"");
|
||||||
|
|
||||||
|
std::thread QueueSync(&TNetwork::Looper, this ,c);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (c.expired())
|
||||||
|
break;
|
||||||
|
auto Client = c.lock();
|
||||||
|
if (Client->GetStatus() < 0) {
|
||||||
|
debug("client status < 0, breaking client loop");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
auto res = TCPRcv(*Client);
|
auto res = TCPRcv(*Client);
|
||||||
if (res == "") {
|
if (res == "") {
|
||||||
debug("TCPRcv error, break client loop");
|
debug("TCPRcv error, break client loop");
|
||||||
@ -535,6 +549,8 @@ void TNetwork::TCPClient(const std::weak_ptr<TClient>& c) {
|
|||||||
}
|
}
|
||||||
TServer::GlobalParser(c, res, mPPSMonitor, *this);
|
TServer::GlobalParser(c, res, mPPSMonitor, *this);
|
||||||
}
|
}
|
||||||
|
if(QueueSync.joinable())QueueSync.join();
|
||||||
|
|
||||||
if (!c.expired()) {
|
if (!c.expired()) {
|
||||||
auto Client = c.lock();
|
auto Client = c.lock();
|
||||||
OnDisconnect(c, Client->GetStatus() == -2);
|
OnDisconnect(c, Client->GetStatus() == -2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user