mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-20 07:00:30 +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;
|
TResourceManager& mResourceManager;
|
||||||
std::thread mUDPThread;
|
std::thread mUDPThread;
|
||||||
std::thread mTCPThread;
|
std::thread mTCPThread;
|
||||||
|
std::mutex mOpenIDMutex;
|
||||||
|
|
||||||
std::vector<uint8_t> UDPRcvFromClient(ip::udp::endpoint& ClientEndpoint);
|
std::vector<uint8_t> UDPRcvFromClient(ip::udp::endpoint& ClientEndpoint);
|
||||||
void HandleDownload(TConnection&& TCPSock);
|
void HandleDownload(TConnection&& TCPSock);
|
||||||
|
|||||||
@@ -577,6 +577,10 @@ void TNetwork::OnDisconnect(const std::weak_ptr<TClient>& ClientPtr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int TNetwork::OpenID() {
|
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;
|
int ID = 0;
|
||||||
bool found;
|
bool found;
|
||||||
do {
|
do {
|
||||||
|
|||||||
Reference in New Issue
Block a user