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.
This commit is contained in:
phosit 2026-03-02 20:45:36 +01:00
parent dbe89d10ae
commit 19c6977872
No known key found for this signature in database
GPG key ID: C9430B600671C268
3 changed files with 16 additions and 12 deletions

View file

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

View file

@ -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.

View file

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