1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-02 00:10:22 +02:00

Removed no longer used mutexes from match server

This commit is contained in:
Ivan Savenko 2024-02-03 17:04:14 +02:00
parent f97ffd8e9a
commit 6eef197cea
10 changed files with 13 additions and 36 deletions

View File

@ -983,11 +983,8 @@ void CGameHandler::start(bool resume)
for (PlayerColor color : players)
{
sbuffer << color << " ";
{
boost::unique_lock<boost::recursive_mutex> lock(gsm);
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<int32_t> answer, PlayerColor player)
{
boost::unique_lock<boost::recursive_mutex> lock(gsm);
logGlobal->trace("Player %s attempts answering query %d with answer:", player, qid);
if (answer)
logGlobal->trace("%d", *answer);

View File

@ -73,7 +73,6 @@ public:
std::map<PlayerColor, std::set<std::shared_ptr<CConnection>>> connections; //player color -> connection to client with interface of that player
//queries stuff
boost::recursive_mutex gsm;
ui32 QID;
SpellCastEnvironment * spellEnv;

View File

@ -247,7 +247,6 @@ void CVCMIServer::prepareToRestart()
for(auto c : activeConnections)
c->enterLobbyConnectionMode();
boost::unique_lock<boost::recursive_mutex> queueLock(mx);
gh = nullptr;
}
@ -407,8 +406,7 @@ bool CVCMIServer::passHost(int toConnectionId)
void CVCMIServer::clientConnected(std::shared_ptr<CConnection> c, std::vector<std::string> & 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;
}

View File

@ -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<std::shared_ptr<CConnection>> activeConnections;
std::unique_ptr<INetworkHandler> networkHandler;
private:
bool restartGameplay; // FIXME: this is just a hack
boost::recursive_mutex mx;
std::shared_ptr<CApplier<CBaseForServerApply>> applier;
EServerState state;
@ -76,6 +70,9 @@ private:
ui8 currentPlayerId;
public:
/// List of all active connections
std::vector<std::shared_ptr<CConnection>> activeConnections;
// INetworkListener impl
void onDisconnected(const std::shared_ptr<INetworkConnection> & connection, const std::string & errorMessage) override;
void onPacketReceived(const std::shared_ptr<INetworkConnection> & connection, const std::vector<std::byte> & message) override;
@ -109,13 +106,14 @@ public:
void clientDisconnected(std::shared_ptr<CConnection> c);
void reconnectPlayer(int connId);
public:
void announceMessage(const std::string & txt);
void handleReceivedPack(std::unique_ptr<CPackForLobby> pack);
void updateAndPropagateLobbyState();
INetworkHandler & getNetworkHandler();
void setState(EServerState value);
EServerState getState() const;

View File

@ -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<INetworkConnection> & connection, const std::string & errorMessage)

View File

@ -29,7 +29,6 @@ TurnTimerHandler::TurnTimerHandler(CGameHandler & gh):
void TurnTimerHandler::onGameplayStart(PlayerColor player)
{
std::lock_guard<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> guard(mx);
const auto * gs = gameHandler.gameState();
const auto * si = gameHandler.getStartInfo();
if(!si || !gs)

View File

@ -29,7 +29,6 @@ class TurnTimerHandler
std::map<PlayerColor, TurnTimerInfo> timers;
std::map<PlayerColor, int> lastUpdate;
std::map<PlayerColor, bool> endTurnAllowed;
std::recursive_mutex mx;
void onPlayerMakingTurn(PlayerColor player, int waitTime);
void onBattleLoop(const BattleID & battleID, int waitTime);

View File

@ -49,8 +49,6 @@ CQuery::CQuery(CGameHandler * gameHandler)
: owner(gameHandler->queries.get())
, gh(gameHandler)
{
boost::unique_lock<boost::mutex> l(QueriesProcessor::mx);
static QueryID QID = QueryID(0);
queryID = ++QID;

View File

@ -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);

View File

@ -23,8 +23,6 @@ private:
std::map<PlayerColor, std::vector<QueryPtr>> queries; //player => stack of queries
public:
static boost::mutex mx;
void addQuery(QueryPtr query);
void popQuery(const CQuery &query);
void popQuery(QueryPtr query);