From 6eef197ceadde502c0e5c7be31703d2c985cd251 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sat, 3 Feb 2024 17:04:14 +0200 Subject: [PATCH] Removed no longer used mutexes from match server --- server/CGameHandler.cpp | 7 +------ server/CGameHandler.h | 1 - server/CVCMIServer.cpp | 10 ++++++---- server/CVCMIServer.h | 12 +++++------- server/GlobalLobbyProcessor.cpp | 2 +- server/TurnTimerHandler.cpp | 10 ---------- server/TurnTimerHandler.h | 1 - server/queries/CQuery.cpp | 2 -- server/queries/QueriesProcessor.cpp | 2 -- server/queries/QueriesProcessor.h | 2 -- 10 files changed, 13 insertions(+), 36 deletions(-) diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index e192c62b9..4ea1e8029 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -983,10 +983,7 @@ void CGameHandler::start(bool resume) for (PlayerColor color : players) { sbuffer << color << " "; - { - boost::unique_lock lock(gsm); - connections[color].insert(cc); - } + connections[color].insert(cc); } logGlobal->info(sbuffer.str()); } @@ -3183,8 +3180,6 @@ bool CGameHandler::setFormation(ObjectInstanceID hid, EArmyFormation formation) bool CGameHandler::queryReply(QueryID qid, std::optional answer, PlayerColor player) { - boost::unique_lock lock(gsm); - logGlobal->trace("Player %s attempts answering query %d with answer:", player, qid); if (answer) logGlobal->trace("%d", *answer); diff --git a/server/CGameHandler.h b/server/CGameHandler.h index dc81b0c92..934554123 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -73,7 +73,6 @@ public: std::map>> connections; //player color -> connection to client with interface of that player //queries stuff - boost::recursive_mutex gsm; ui32 QID; SpellCastEnvironment * spellEnv; diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 9f170b33d..8d55c85cd 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -247,7 +247,6 @@ void CVCMIServer::prepareToRestart() for(auto c : activeConnections) c->enterLobbyConnectionMode(); - boost::unique_lock queueLock(mx); gh = nullptr; } @@ -407,8 +406,7 @@ bool CVCMIServer::passHost(int toConnectionId) void CVCMIServer::clientConnected(std::shared_ptr c, std::vector & names, const std::string & uuid, EStartMode mode) { - if(state != EServerState::LOBBY) - throw std::runtime_error("CVCMIServer::clientConnected called while game is not accepting clients!"); + assert(state == EServerState::LOBBY); c->connectionID = currentClientId++; @@ -945,6 +943,10 @@ ui8 CVCMIServer::getIdOfFirstUnallocatedPlayer() const if(!si->getPlayersSettings(i->first)) return i->first; } - return 0; } + +INetworkHandler & CVCMIServer::getNetworkHandler() +{ + return *networkHandler; +} diff --git a/server/CVCMIServer.h b/server/CVCMIServer.h index bdee4e164..c53d21b98 100644 --- a/server/CVCMIServer.h +++ b/server/CVCMIServer.h @@ -57,16 +57,10 @@ class CVCMIServer : public LobbyInfo, public INetworkServerListener, public INet std::chrono::steady_clock::time_point gameplayStartTime; std::chrono::steady_clock::time_point lastTimerUpdateTime; -public: - /// List of all active connections - std::vector> activeConnections; - std::unique_ptr networkHandler; -private: bool restartGameplay; // FIXME: this is just a hack - boost::recursive_mutex mx; std::shared_ptr> applier; EServerState state; @@ -76,6 +70,9 @@ private: ui8 currentPlayerId; public: + /// List of all active connections + std::vector> activeConnections; + // INetworkListener impl void onDisconnected(const std::shared_ptr & connection, const std::string & errorMessage) override; void onPacketReceived(const std::shared_ptr & connection, const std::vector & message) override; @@ -109,13 +106,14 @@ public: void clientDisconnected(std::shared_ptr c); void reconnectPlayer(int connId); -public: void announceMessage(const std::string & txt); void handleReceivedPack(std::unique_ptr pack); void updateAndPropagateLobbyState(); + INetworkHandler & getNetworkHandler(); + void setState(EServerState value); EServerState getState() const; diff --git a/server/GlobalLobbyProcessor.cpp b/server/GlobalLobbyProcessor.cpp index 3bafe24f5..b29142d25 100644 --- a/server/GlobalLobbyProcessor.cpp +++ b/server/GlobalLobbyProcessor.cpp @@ -24,7 +24,7 @@ void GlobalLobbyProcessor::establishNewConnection() { std::string hostname = settings["lobby"]["hostname"].String(); int16_t port = settings["lobby"]["port"].Integer(); - owner.networkHandler->connectToRemote(*this, hostname, port); + owner.getNetworkHandler().connectToRemote(*this, hostname, port); } void GlobalLobbyProcessor::onDisconnected(const std::shared_ptr & connection, const std::string & errorMessage) diff --git a/server/TurnTimerHandler.cpp b/server/TurnTimerHandler.cpp index 84a05c740..247ee4804 100644 --- a/server/TurnTimerHandler.cpp +++ b/server/TurnTimerHandler.cpp @@ -29,7 +29,6 @@ TurnTimerHandler::TurnTimerHandler(CGameHandler & gh): void TurnTimerHandler::onGameplayStart(PlayerColor player) { - std::lock_guard guard(mx); if(const auto * si = gameHandler.getStartInfo()) { timers[player] = si->turnTimerInfo; @@ -45,7 +44,6 @@ void TurnTimerHandler::onGameplayStart(PlayerColor player) void TurnTimerHandler::setTimerEnabled(PlayerColor player, bool enabled) { - std::lock_guard guard(mx); assert(player.isValidPlayer()); timers[player].isActive = enabled; sendTimerUpdate(player); @@ -53,7 +51,6 @@ void TurnTimerHandler::setTimerEnabled(PlayerColor player, bool enabled) void TurnTimerHandler::setEndTurnAllowed(PlayerColor player, bool enabled) { - std::lock_guard guard(mx); assert(player.isValidPlayer()); endTurnAllowed[player] = enabled; } @@ -69,7 +66,6 @@ void TurnTimerHandler::sendTimerUpdate(PlayerColor player) void TurnTimerHandler::onPlayerGetTurn(PlayerColor player) { - std::lock_guard guard(mx); if(const auto * si = gameHandler.getStartInfo()) { if(si->turnTimerInfo.isEnabled()) @@ -87,7 +83,6 @@ void TurnTimerHandler::onPlayerGetTurn(PlayerColor player) void TurnTimerHandler::update(int waitTime) { - std::lock_guard guard(mx); if(!gameHandler.getStartInfo()->turnTimerInfo.isEnabled()) return; @@ -122,7 +117,6 @@ bool TurnTimerHandler::timerCountDown(int & timer, int initialTimer, PlayerColor void TurnTimerHandler::onPlayerMakingTurn(PlayerColor player, int waitTime) { - std::lock_guard guard(mx); const auto * gs = gameHandler.gameState(); const auto * si = gameHandler.getStartInfo(); if(!si || !gs || !si->turnTimerInfo.isEnabled()) @@ -164,7 +158,6 @@ bool TurnTimerHandler::isPvpBattle(const BattleID & battleID) const void TurnTimerHandler::onBattleStart(const BattleID & battleID) { - std::lock_guard guard(mx); const auto * gs = gameHandler.gameState(); const auto * si = gameHandler.getStartInfo(); if(!si || !gs) @@ -192,7 +185,6 @@ void TurnTimerHandler::onBattleStart(const BattleID & battleID) void TurnTimerHandler::onBattleEnd(const BattleID & battleID) { - std::lock_guard guard(mx); const auto * gs = gameHandler.gameState(); const auto * si = gameHandler.getStartInfo(); if(!si || !gs) @@ -221,7 +213,6 @@ void TurnTimerHandler::onBattleEnd(const BattleID & battleID) void TurnTimerHandler::onBattleNextStack(const BattleID & battleID, const CStack & stack) { - std::lock_guard guard(mx); const auto * gs = gameHandler.gameState(); const auto * si = gameHandler.getStartInfo(); if(!si || !gs || !gs->getBattle(battleID)) @@ -248,7 +239,6 @@ void TurnTimerHandler::onBattleNextStack(const BattleID & battleID, const CStack void TurnTimerHandler::onBattleLoop(const BattleID & battleID, int waitTime) { - std::lock_guard guard(mx); const auto * gs = gameHandler.gameState(); const auto * si = gameHandler.getStartInfo(); if(!si || !gs) diff --git a/server/TurnTimerHandler.h b/server/TurnTimerHandler.h index c97eff721..8f6fae5a6 100644 --- a/server/TurnTimerHandler.h +++ b/server/TurnTimerHandler.h @@ -29,7 +29,6 @@ class TurnTimerHandler std::map timers; std::map lastUpdate; std::map endTurnAllowed; - std::recursive_mutex mx; void onPlayerMakingTurn(PlayerColor player, int waitTime); void onBattleLoop(const BattleID & battleID, int waitTime); diff --git a/server/queries/CQuery.cpp b/server/queries/CQuery.cpp index ad23dcc25..0580b75ed 100644 --- a/server/queries/CQuery.cpp +++ b/server/queries/CQuery.cpp @@ -49,8 +49,6 @@ CQuery::CQuery(CGameHandler * gameHandler) : owner(gameHandler->queries.get()) , gh(gameHandler) { - boost::unique_lock l(QueriesProcessor::mx); - static QueryID QID = QueryID(0); queryID = ++QID; diff --git a/server/queries/QueriesProcessor.cpp b/server/queries/QueriesProcessor.cpp index 259e33a3e..73918cbf4 100644 --- a/server/queries/QueriesProcessor.cpp +++ b/server/queries/QueriesProcessor.cpp @@ -12,8 +12,6 @@ #include "CQuery.h" -boost::mutex QueriesProcessor::mx; - void QueriesProcessor::popQuery(PlayerColor player, QueryPtr query) { LOG_TRACE_PARAMS(logGlobal, "player='%s', query='%s'", player % query); diff --git a/server/queries/QueriesProcessor.h b/server/queries/QueriesProcessor.h index d0fd6df35..b46cd24fd 100644 --- a/server/queries/QueriesProcessor.h +++ b/server/queries/QueriesProcessor.h @@ -23,8 +23,6 @@ private: std::map> queries; //player => stack of queries public: - static boost::mutex mx; - void addQuery(QueryPtr query); void popQuery(const CQuery &query); void popQuery(QueryPtr query);