mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-06-17 14:12:25 +00:00
fix identification & check thread issue with atomic bool
This commit is contained in:
@@ -78,10 +78,10 @@ std::string GetRole(const std::string& DID) {
|
|||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
void Check(SOCKET TCPSock, std::reference_wrapper<std::atomic_bool> ok) {
|
void Check(SOCKET TCPSock, std::shared_ptr<std::atomic_bool> ok) {
|
||||||
DebugPrintTID();
|
DebugPrintTID();
|
||||||
size_t accum = 0;
|
size_t accum = 0;
|
||||||
while (!ok.get()) {
|
while (!*ok) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
accum += 100;
|
accum += 100;
|
||||||
if (accum >= 5000) {
|
if (accum >= 5000) {
|
||||||
@@ -136,8 +136,8 @@ std::string GenerateM(RSA* key) {
|
|||||||
void Identification(SOCKET TCPSock, RSA* Skey) {
|
void Identification(SOCKET TCPSock, RSA* Skey) {
|
||||||
DebugPrintTID();
|
DebugPrintTID();
|
||||||
Assert(Skey);
|
Assert(Skey);
|
||||||
std::atomic_bool ok { false };
|
std::shared_ptr<std::atomic_bool> ok = std::make_shared<std::atomic_bool>(false);
|
||||||
std::thread Timeout(Check, TCPSock, std::ref<std::atomic_bool>(ok));
|
std::thread Timeout(Check, TCPSock, ok);
|
||||||
Timeout.detach();
|
Timeout.detach();
|
||||||
std::string Name, DID, Role;
|
std::string Name, DID, Role;
|
||||||
if (!Send(TCPSock, GenerateM(Skey))) {
|
if (!Send(TCPSock, GenerateM(Skey))) {
|
||||||
@@ -155,7 +155,7 @@ void Identification(SOCKET TCPSock, RSA* Skey) {
|
|||||||
|
|
||||||
std::string Res = Rcv(TCPSock);
|
std::string Res = Rcv(TCPSock);
|
||||||
std::string Ver = Rcv(TCPSock);
|
std::string Ver = Rcv(TCPSock);
|
||||||
ok = true;
|
*ok = true;
|
||||||
Ver = RSA_D(Ver, Skey);
|
Ver = RSA_D(Ver, Skey);
|
||||||
if (Ver.size() > 3 && Ver.substr(0, 2) == Sec("VC")) {
|
if (Ver.size() > 3 && Ver.substr(0, 2) == Sec("VC")) {
|
||||||
Ver = Ver.substr(2);
|
Ver = Ver.substr(2);
|
||||||
|
|||||||
Reference in New Issue
Block a user