From 19c697787224d166e1e25a5168f4707881282b81 Mon Sep 17 00:00:00 2001 From: phosit Date: Mon, 2 Mar 2026 20:45:36 +0100 Subject: [PATCH] Request connection-data in the client constructor This way it doesn't has to be requested manually and it can't be requested to late. --- source/network/NetClient.cpp | 12 +++++++----- source/network/NetClient.h | 13 ++++++++----- source/network/scripting/JSInterface_Network.cpp | 3 +-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/source/network/NetClient.cpp b/source/network/NetClient.cpp index a388641930..5198e6561a 100644 --- a/source/network/NetClient.cpp +++ b/source/network/NetClient.cpp @@ -138,6 +138,13 @@ CNetClient::CNetClient(CGame* game, const CStrW& username, const CStr& hostJID, SetFirstState(NCS_UNCONNECTED); } +CNetClient::CNetClient(CGame* game, const CStrW& username, const CStr& hostJID, + std::string hashedPassword, IXmppClient& xmppClient) : + CNetClient{game, username, hostJID, std::move(hashedPassword)} +{ + xmppClient.SendIqGetConnectionData(m_HostJID, m_Password, m_UserName.ToUTF8(), false); +} + CNetClient::~CNetClient() { // Try to flush messages before dying (probably fails). @@ -158,11 +165,6 @@ bool CNetClient::SetupConnection(ENetHost* enetClient) return ok; } -void CNetClient::SetupConnectionViaLobby() -{ - g_XmppClient->SendIqGetConnectionData(m_HostJID, m_Password, m_UserName.ToUTF8(), false); -} - void CNetClient::SetupServerData(CStr address, u16 port) { ENSURE(!m_Session); diff --git a/source/network/NetClient.h b/source/network/NetClient.h index 1b9c742ddb..66cdb76be8 100644 --- a/source/network/NetClient.h +++ b/source/network/NetClient.h @@ -44,6 +44,7 @@ class CNetClientSession; class CNetClientTurnManager; class JSTracer; class ScriptInterface; +class IXmppClient; typedef struct _ENetHost ENetHost; @@ -81,6 +82,13 @@ public: CNetClient(CGame* game, const CStrW& username = L"anonymous", const CStr& hostJID = {}, std::string hashedPassword = {}, std::string controllerSecret = {}); + /** + * This constructor additionally requests connection information over the + * lobby. + */ + CNetClient(CGame* game, const CStrW& username, const CStr& hostJID, + std::string hashedPassword, IXmppClient& xmppClient); + virtual ~CNetClient(); bool IsController() const { return m_IsController; } @@ -104,11 +112,6 @@ public: */ bool SetupConnection(ENetHost* enetClient); - /** - * Request connection information over the lobby. - */ - void SetupConnectionViaLobby(); - /** * Connect to the remote networked server using lobby. * Push netstatus messages on failure. diff --git a/source/network/scripting/JSInterface_Network.cpp b/source/network/scripting/JSInterface_Network.cpp index c19de2e6a9..f4189c8f4d 100644 --- a/source/network/scripting/JSInterface_Network.cpp +++ b/source/network/scripting/JSInterface_Network.cpp @@ -168,8 +168,7 @@ void StartNetworkJoinLobby(const CStrW& playerName, const CStr& hostJID, const C CStr hashedPass = HashCryptographically(password, hostJID + password + PS_SERIALIZATION_VERSION); g_Game = new CGame(true); - g_NetClient = new CNetClient(g_Game, playerName, hostJID, hashedPass); - g_NetClient->SetupConnectionViaLobby(); + g_NetClient = new CNetClient(g_Game, playerName, hostJID, hashedPass, *g_XmppClient); } void DisconnectNetworkGame()