Use mutex to prevent joining of players when start selection

This commit is contained in:
Benau 2018-03-09 09:22:13 +08:00
parent 2d86adce3c
commit db68756fd6
2 changed files with 7 additions and 0 deletions

View File

@ -463,6 +463,7 @@ void ServerLobby::signalRaceStartToClients()
*/
void ServerLobby::startSelection(const Event *event)
{
std::lock_guard<std::mutex> lock(m_connection_mutex);
if (NetworkConfig::get()->isWAN())
{
assert(m_server_registered);
@ -663,6 +664,7 @@ void ServerLobby::clientDisconnected(Event* event)
*/
void ServerLobby::connectionRequested(Event* event)
{
std::lock_guard<std::mutex> lock(m_connection_mutex);
STKPeer* peer = event->getPeer();
const NetworkString &data = event->data();

View File

@ -6,6 +6,7 @@
#include "utils/synchronised.hpp"
#include <atomic>
#include <mutex>
#include <set>
class ServerLobby : public LobbyProtocol
@ -66,6 +67,10 @@ private:
/** Timeout counter for showing the result screen. */
float m_timeout;
/** Lock this mutex whenever a client is connect / disconnect or
* starting race. */
std::mutex m_connection_mutex;
// connection management
void clientDisconnected(Event* event);
void connectionRequested(Event* event);