1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Minor fixes and corrections to network-related code. No functionality

changes.
This commit is contained in:
Ivan Savenko 2024-02-12 18:57:20 +02:00
parent dc8d48a3b6
commit 7c34d48258
5 changed files with 28 additions and 29 deletions

View File

@ -163,7 +163,7 @@ void CServerHandler::threadRunNetwork()
logGlobal->info("Ending network thread");
}
void CServerHandler::resetStateForLobby(EStartMode mode, ESelectionScreen screen, EServerMode newServerMode, const std::vector<std::string> & names)
void CServerHandler::resetStateForLobby(EStartMode mode, ESelectionScreen screen, EServerMode newServerMode, const std::vector<std::string> & playerNames)
{
hostClientId = -1;
setState(EClientState::NONE);
@ -172,15 +172,15 @@ void CServerHandler::resetStateForLobby(EStartMode mode, ESelectionScreen screen
th = std::make_unique<CStopWatch>();
logicConnection.reset();
si = std::make_shared<StartInfo>();
playerNames.clear();
localPlayerNames.clear();
si->difficulty = 1;
si->mode = mode;
screenType = screen;
myNames.clear();
if(!names.empty()) //if have custom set of player names - use it
myNames = names;
localPlayerNames.clear();
if(!playerNames.empty()) //if have custom set of player names - use it
localPlayerNames = playerNames;
else
myNames.push_back(settings["general"]["playerName"].String());
localPlayerNames.push_back(settings["general"]["playerName"].String());
}
GlobalLobbyClient & CServerHandler::getGlobalLobby()
@ -421,7 +421,7 @@ void CServerHandler::sendClientConnecting() const
{
LobbyClientConnected lcc;
lcc.uuid = uuid;
lcc.names = myNames;
lcc.names = localPlayerNames;
lcc.mode = si->mode;
sendLobbyPack(lcc);
}

View File

@ -101,7 +101,7 @@ class CServerHandler final : public IServerAPI, public LobbyInfo, public INetwor
std::unique_ptr<GlobalLobbyClient> lobbyClient;
std::unique_ptr<CApplier<CBaseForLobbyApply>> applier;
std::shared_ptr<CMapInfo> mapToStart;
std::vector<std::string> myNames;
std::vector<std::string> localPlayerNames;
std::shared_ptr<HighScoreCalculation> highScoreCalc;
boost::thread threadRunLocalServer;
@ -148,7 +148,7 @@ public:
CServerHandler();
~CServerHandler();
void resetStateForLobby(EStartMode mode, ESelectionScreen screen, EServerMode serverMode, const std::vector<std::string> & names);
void resetStateForLobby(EStartMode mode, ESelectionScreen screen, EServerMode serverMode, const std::vector<std::string> & playerNames);
void startLocalServerAndConnect(bool connectToLobby);
void connectToServer(const std::string & addr, const ui16 port);

View File

@ -22,7 +22,7 @@ bool LobbyServer::isAccountNameValid(const std::string & accountName) const
if(accountName.size() < 4)
return false;
if(accountName.size() < 20)
if(accountName.size() > 20)
return false;
for(const auto & c : accountName)

View File

@ -250,8 +250,8 @@ void CVCMIServer::prepareToRestart()
campaignBonus = si->campState->getBonusID(campaignMap).value_or(-1);
}
for(auto c : activeConnections)
c->enterLobbyConnectionMode();
for(auto activeConnection : activeConnections)
activeConnection->enterLobbyConnectionMode();
gh = nullptr;
}
@ -322,8 +322,8 @@ bool CVCMIServer::prepareToStartGame()
void CVCMIServer::startGameImmediately()
{
for(auto c : activeConnections)
c->enterGameplayConnectionMode(gh->gs);
for(auto activeConnection : activeConnections)
activeConnection->enterGameplayConnectionMode(gh->gs);
gh->start(si->mode == EStartMode::LOAD_GAME);
setState(EServerState::GAMEPLAY);
@ -364,14 +364,13 @@ void CVCMIServer::handleReceivedPack(std::unique_ptr<CPackForLobby> pack)
void CVCMIServer::announcePack(std::unique_ptr<CPackForLobby> pack)
{
for(auto c : activeConnections)
for(auto activeConnection : activeConnections)
{
// FIXME: we need to avoid sending something to client that not yet get answer for LobbyClientConnected
// Until UUID set we only pass LobbyClientConnected to this client
//if(c->uuid == uuid && !dynamic_cast<LobbyClientConnected *>(pack.get()))
// continue;
c->sendPack(pack.get());
activeConnection->sendPack(pack.get());
}
applier->getApplier(CTypeList::getInstance().getTypeID(pack.get()))->applyOnServerAfter(this, pack.get());
@ -396,14 +395,14 @@ void CVCMIServer::announceTxt(const std::string & txt, const std::string & playe
bool CVCMIServer::passHost(int toConnectionId)
{
for(auto c : activeConnections)
for(auto activeConnection : activeConnections)
{
if(isClientHost(c->connectionID))
if(isClientHost(activeConnection->connectionID))
continue;
if(c->connectionID != toConnectionId)
if(activeConnection->connectionID != toConnectionId)
continue;
hostClientId = c->connectionID;
hostClientId = activeConnection->connectionID;
announceTxt(boost::str(boost::format("Pass host to connection %d") % toConnectionId));
return true;
}
@ -447,10 +446,10 @@ void CVCMIServer::clientConnected(std::shared_ptr<CConnection> c, std::vector<st
}
}
void CVCMIServer::clientDisconnected(std::shared_ptr<CConnection> c)
void CVCMIServer::clientDisconnected(std::shared_ptr<CConnection> connection)
{
c->getConnection()->close();
vstd::erase(activeConnections, c);
connection->getConnection()->close();
vstd::erase(activeConnections, connection);
// PlayerReinitInterface startAiPack;
// startAiPack.playerConnectionId = PlayerSettings::PLAYER_AI;

View File

@ -206,8 +206,8 @@ void ApplyOnServerNetPackVisitor::visitLobbyRestartGame(LobbyRestartGame & pack)
void ApplyOnServerAfterAnnounceNetPackVisitor::visitLobbyRestartGame(LobbyRestartGame & pack)
{
for(const auto & c : srv.activeConnections)
c->enterLobbyConnectionMode();
for(const auto & connection : srv.activeConnections)
connection->enterLobbyConnectionMode();
}
void ClientPermissionsCheckerNetPackVisitor::visitLobbyPrepareStartGame(LobbyPrepareStartGame & pack)
@ -250,11 +250,11 @@ void ApplyOnServerAfterAnnounceNetPackVisitor::visitLobbyStartGame(LobbyStartGam
srv.startGameImmediately();
else
{
for(const auto & c : srv.activeConnections)
for(const auto & connection : srv.activeConnections)
{
if(c->connectionID == pack.clientId)
if(connection->connectionID == pack.clientId)
{
c->enterGameplayConnectionMode(srv.gh->gameState());
connection->enterGameplayConnectionMode(srv.gh->gameState());
srv.reconnectPlayer(pack.clientId);
}
}