1
0
mirror of https://github.com/vcmi/vcmi.git synced 2026-05-22 09:55:17 +02:00

Address comments

This commit is contained in:
George King
2026-05-07 12:19:58 +02:00
parent 272d7e0511
commit d631186dca
10 changed files with 70 additions and 52 deletions
+5 -3
View File
@@ -344,11 +344,13 @@ bool CServerHandler::isGuest() const
bool CServerHandler::hasRemoteClientInLobby() const
{
std::set<GameConnectionID> connectedClients;
for(const auto & playerEntry : playerNames)
connectedClients.insert(playerEntry.second.connection);
{
if(playerEntry.second.connection != hostClientId)
return true;
}
return connectedClients.size() > 1;
return false;
}
const std::string & CServerHandler::getLocalHostname() const
+1
View File
@@ -53,6 +53,7 @@ public:
{
}
void visitLobbyClientConnected(LobbyClientConnected & pack) override;
void visitLobbyClientDisconnected(LobbyClientDisconnected & pack) override;
void visitLobbyChatMessage(LobbyChatMessage & pack) override;
void visitLobbyGuiAction(LobbyGuiAction & pack) override;
+14 -7
View File
@@ -51,10 +51,11 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyQuickLoadGame(LobbyQuickLoadGa
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientConnected(LobbyClientConnected & pack)
{
result = false;
const bool isLocalClient = pack.uuid == handler.logicConnection->uuid;
result = !isLocalClient;
// Check if it's LobbyClientConnected for our client
if(pack.uuid == handler.logicConnection->uuid)
if(isLocalClient)
{
handler.logicConnection->setSerializationVersion(pack.version);
handler.logicConnection->connectionID = pack.clientId;
@@ -94,22 +95,28 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientConnected(LobbyClientCon
}
}
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientDisconnected(LobbyClientDisconnected & pack)
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientDisconnected(LobbyClientDisconnected &)
{
if(pack.clientId != handler.logicConnection->connectionID)
{
result = false;
return;
}
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyClientConnected(LobbyClientConnected & pack)
{
if(!lobby || pack.clientId == handler.logicConnection->connectionID)
return;
}
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyClientDisconnected(LobbyClientDisconnected & pack)
{
if(pack.clientId == handler.logicConnection->connectionID)
{
if(auto w = ENGINE->windows().topWindow<CLoadingScreen>())
ENGINE->windows().popWindow(w);
if(ENGINE->windows().count() > 0)
ENGINE->windows().popWindows(1);
return;
}
}
void ApplyOnLobbyScreenNetPackVisitor::visitLobbyChatMessage(LobbyChatMessage & pack)
+1 -9
View File
@@ -219,15 +219,6 @@ void CLobbyScreen::toggleTab(std::shared_ptr<CIntObject> tab)
CSelectionBase::toggleTab(tab);
}
void CLobbyScreen::tick(uint32_t msPassed)
{
CSelectionBase::tick(msPassed);
updateHostLobbyChatState();
if(curTab != tabBattleOnlyMode)
updateStartButtonState();
}
void CLobbyScreen::start(bool campaign)
{
if(curTab == tabBattleOnlyMode)
@@ -336,6 +327,7 @@ void CLobbyScreen::updateAfterStateChange()
updateHostLobbyChatState();
const bool shouldFilterByPlayerCount = screenType == ESelectionScreen::newGame && GAME->server().loadMode == ELoadMode::MULTI;
const size_t requiredHumanPlayers = shouldFilterByPlayerCount ? std::max<size_t>(2, GAME->server().playerNames.size()) : 0;
tabSel->setRequiredHumanPlayers(requiredHumanPlayers);
if(!compatibilityFilterInitialized || (shouldFilterByPlayerCount && requiredHumanPlayers != lastRequiredHumanPlayers))
{
-1
View File
@@ -31,7 +31,6 @@ public:
CLobbyScreen(ESelectionScreen type, bool hideScreen = false);
~CLobbyScreen();
void toggleTab(std::shared_ptr<CIntObject> tab) final;
void tick(uint32_t msPassed) override;
void start(bool campaign);
void startCampaign();
void startScenario(bool allowOnlyAI = false);
+6 -2
View File
@@ -1012,8 +1012,12 @@ bool SelectionTab::isMapCompatibleWithLobbyPlayerCount(const ElementInfo & info)
size_t SelectionTab::getRequiredHumanPlayers() const
{
const size_t minimumPlayers = (GAME->server().loadMode == ELoadMode::MULTI || GAME->server().hotseatMode) ? 2 : 1;
return std::max(minimumPlayers, GAME->server().playerNames.size());
return requiredHumanPlayers;
}
void SelectionTab::setRequiredHumanPlayers(size_t players)
{
requiredHumanPlayers = players;
}
void SelectionTab::parseMaps(const std::unordered_set<ResourcePath> & files)
+2
View File
@@ -91,6 +91,7 @@ public:
int currentMapSizeFilter = 0;
bool showRandom;
std::string lastCompatibilityNotice;
size_t requiredHumanPlayers = 1;
std::shared_ptr<CTextInput> inputName;
@@ -115,6 +116,7 @@ public:
void selectFileName(std::string fname);
void selectNewestFile();
std::shared_ptr<ElementInfo> getSelectedMapInfo() const;
void setRequiredHumanPlayers(size_t players);
void rememberCurrentSelection();
void restoreLastSelection();
+23 -1
View File
@@ -434,7 +434,7 @@ void CGameHandler::changeSecSkill(const CGHeroInstance * hero, SecondarySkill wh
}
void CGameHandler::handleClientDisconnection(GameConnectionID connectionID)
void CGameHandler::handleClientDisconnection(GameConnectionID connectionID, const std::vector<PlayerConnectionID> & disconnectedPlayerIds)
{
if(gameServer().getState() == EServerState::SHUTDOWN || !gameState().getStartInfo())
{
@@ -457,6 +457,28 @@ void CGameHandler::handleClientDisconnection(GameConnectionID connectionID)
remainingPlayers.push_back(player.first);
}
if(disconnectedPlayers.empty() && !disconnectedPlayerIds.empty())
{
for(const auto & player : gameState().players)
{
if (gameInfo().getPlayerState(player.first)->status != EPlayerStatus::INGAME)
continue;
const auto playerSettings = gameInfo().getPlayerSettings(player.first);
if(!playerSettings)
continue;
for(const auto disconnectedPlayerId : disconnectedPlayerIds)
{
if(vstd::contains(playerSettings->connectedPlayerIDs, disconnectedPlayerId))
{
disconnectedPlayers.push_back(player.first);
break;
}
}
}
}
for (const auto & inGamePlayer : remainingPlayers)
{
for (const auto & lostPlayer : disconnectedPlayers)
+2 -1
View File
@@ -17,6 +17,7 @@
#include "../lib/gameState/GameStatistics.h"
#include "../lib/networkPacks/PacksForServer.h"
#include "../lib/serializer/GameConnectionID.h"
#include "../lib/serializer/PlayerConnectionID.h"
VCMI_LIB_NAMESPACE_BEGIN
@@ -205,7 +206,7 @@ public:
//////////////////////////////////////////////////////////////////////////
void init(StartInfo *si, Load::ProgressAccumulator & progressTracking);
void handleClientDisconnection(GameConnectionID connectionI);
void handleClientDisconnection(GameConnectionID connectionID, const std::vector<PlayerConnectionID> & disconnectedPlayerIds = {});
void handleReceivedPack(GameConnectionID connectionId, CPackForServer & pack);
bool hasPlayerAt(PlayerColor player, GameConnectionID connectionId) const;
bool hasBothPlayersAtSameConnection(PlayerColor left, PlayerColor right) const;
+7 -19
View File
@@ -520,26 +520,20 @@ void CVCMIServer::clientDisconnected(std::shared_ptr<GameConnection> connection)
vstd::erase(activeConnections, connection);
std::vector<PlayerConnectionID> disconnectedPlayerIds;
std::vector<std::string> disconnectedPlayerNames;
for(const auto & playerEntry : playerNames)
{
if(playerEntry.second.connection == connection->connectionID)
{
disconnectedPlayerIds.push_back(playerEntry.first);
disconnectedPlayerNames.push_back(playerEntry.second.name);
}
}
if(playerEntry.second.connection != connection->connectionID)
continue;
for(const auto & playerName : disconnectedPlayerNames)
{
logNetwork->info("Player disconnected from lobby: name='%s', connectionId=%d", playerName, static_cast<int>(connection->connectionID));
disconnectedPlayerIds.push_back(playerEntry.first);
logNetwork->info("Player disconnected from lobby: name='%s', connectionId=%d", playerEntry.second.name, static_cast<int>(connection->connectionID));
MetaString disconnectMessage;
disconnectMessage.appendTextID("vcmi.lobby.system.playerDisconnected");
disconnectMessage.replaceRawString(playerName);
disconnectMessage.replaceRawString(playerEntry.second.name);
announceTxt(disconnectMessage);
}
if(disconnectedPlayerNames.empty())
if(disconnectedPlayerIds.empty())
logNetwork->info("Connection %d disconnected from lobby with no mapped player names", static_cast<int>(connection->connectionID));
if(activeConnections.empty() || hostClientId == connection->connectionID)
@@ -550,23 +544,17 @@ void CVCMIServer::clientDisconnected(std::shared_ptr<GameConnection> connection)
if(gh && getState() == EServerState::GAMEPLAY)
{
gh->handleClientDisconnection(connection->connectionID);
gh->handleClientDisconnection(connection->connectionID, disconnectedPlayerIds);
}
for(const auto & playerId : disconnectedPlayerIds)
playerNames.erase(playerId);
if(!disconnectedPlayerIds.empty())
{
for(auto & playerInfoEntry : si->playerInfos)
{
auto & connectedPlayerIDs = playerInfoEntry.second.connectedPlayerIDs;
for(const auto & playerId : disconnectedPlayerIds)
connectedPlayerIDs.erase(playerId);
if(connectedPlayerIDs.empty())
setPlayerConnectedId(playerInfoEntry.second, PlayerConnectionID::PLAYER_AI);
}
}
}