mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-03 14:26:09 +00:00
fix bug which could cause multiple players to have the same ID (closes #154)
This commit is contained in:
@@ -37,6 +37,7 @@ private:
|
||||
TResourceManager& mResourceManager;
|
||||
std::thread mUDPThread;
|
||||
std::thread mTCPThread;
|
||||
std::mutex mOpenIDMutex;
|
||||
|
||||
std::vector<uint8_t> UDPRcvFromClient(ip::udp::endpoint& ClientEndpoint);
|
||||
void HandleDownload(TConnection&& TCPSock);
|
||||
|
||||
@@ -577,6 +577,10 @@ void TNetwork::OnDisconnect(const std::weak_ptr<TClient>& ClientPtr) {
|
||||
}
|
||||
|
||||
int TNetwork::OpenID() {
|
||||
// This lock ensures that each call to OpenID is exclusive.
|
||||
// If we didn't have this, two concurrent calls to this function may result
|
||||
// in the same ID.
|
||||
std::unique_lock Lock(mOpenIDMutex);
|
||||
int ID = 0;
|
||||
bool found;
|
||||
do {
|
||||
|
||||
Reference in New Issue
Block a user