From cf412c947c7353789ae1a8854bfbadf97ae63fd5 Mon Sep 17 00:00:00 2001 From: Benau Date: Tue, 15 Oct 2019 16:28:48 +0800 Subject: [PATCH] Show player count with AI in server browser --- src/network/protocols/server_lobby.cpp | 5 +++-- src/network/protocols/server_lobby.hpp | 3 +++ src/network/stk_host.cpp | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index 2d08457d8..8ec40eae6 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -537,6 +537,7 @@ void ServerLobby::setup() m_winner_peer_id = 0; m_client_starting_time = 0; m_ai_count = 0; + m_lobby_players.store(0); auto players = STKHost::get()->getPlayersForNewGame(); if (m_game_setup->isGrandPrix() && !m_game_setup->isGrandPrixStarted()) { @@ -2302,8 +2303,7 @@ void ServerLobby::checkIncomingConnectionRequests() const TransportAddress &addr = STKHost::get()->getPublicAddress(); request->addParameter("address", addr.getIP() ); request->addParameter("port", addr.getPort()); - request->addParameter("current-players", - STKHost::get()->getTotalPlayers()); + request->addParameter("current-players", getLobbyPlayers()); request->addParameter("game-started", m_state.load() == WAITING_FOR_START_GAME ? 0 : 1); Track* current_track = getPlayingTrack(); @@ -3209,6 +3209,7 @@ void ServerLobby::updatePlayerList(bool update_when_reset_server) all_profiles.insert(all_profiles.end(), ai_profiles.begin(), ai_profiles.end()); } + m_lobby_players.store((int)all_profiles.size()); NetworkString* pl = getNetworkString(); pl->setSynchronous(true); diff --git a/src/network/protocols/server_lobby.hpp b/src/network/protocols/server_lobby.hpp index 020f1ac39..8caa378cd 100644 --- a/src/network/protocols/server_lobby.hpp +++ b/src/network/protocols/server_lobby.hpp @@ -191,6 +191,8 @@ private: std::atomic m_game_mode; + std::atomic m_lobby_players; + std::atomic m_last_success_poll_time; uint64_t m_server_started_at, m_server_delay; @@ -351,6 +353,7 @@ public: float getStartupBoostOrPenaltyForKart(uint32_t ping, unsigned kart_id); int getDifficulty() const { return m_difficulty.load(); } int getGameMode() const { return m_game_mode.load(); } + int getLobbyPlayers() const { return m_lobby_players.load(); } void saveInitialItems(); void saveIPBanTable(const TransportAddress& addr); void listBanTable(); diff --git a/src/network/stk_host.cpp b/src/network/stk_host.cpp index ddfe281e3..a309d8ea1 100644 --- a/src/network/stk_host.cpp +++ b/src/network/stk_host.cpp @@ -1329,7 +1329,7 @@ void STKHost::handleDirectSocketRequest(Network* direct_socket, s.addUInt32(ServerConfig::m_server_version); s.encodeString(name); s.addUInt8((uint8_t)ServerConfig::m_server_max_players); - s.addUInt8((uint8_t)getTotalPlayers()); + s.addUInt8((uint8_t)sl->getLobbyPlayers()); s.addUInt16(m_private_port); s.addUInt8((uint8_t)sl->getDifficulty()); s.addUInt8((uint8_t)sl->getGameMode());