Index: source/lobby/XmppClient.cpp =================================================================== --- source/lobby/XmppClient.cpp +++ source/lobby/XmppClient.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -862,7 +862,12 @@ } g_NetClient->SetupServerData(cd->m_Ip.to_string(), stoi(cd->m_Port.to_string()), !cd->m_UseSTUN.empty()); - g_NetClient->TryToConnect(iq.from().full(), !cd->m_IsLocalIP.empty()); + + if (!g_NetClient->TryToConnectViaLobby(iq.from().full(), !cd->m_IsLocalIP.empty())) + { + LOGMESSAGE("XmppClient: Failed to establish connection"); + return true; + } } if (gq) { Index: source/network/NetClient.h =================================================================== --- source/network/NetClient.h +++ source/network/NetClient.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -121,6 +121,8 @@ /** * Set up a connection to the remote networked server. * Must call SetupServerData first. + * @param enetClient Pointer to an existing Enet Client. If a `nullptr` is + * passed, a new client will be createed. * @return true on success, false on connection failure */ bool SetupConnection(ENetHost* enetClient); @@ -131,12 +133,12 @@ void SetupConnectionViaLobby(); /** - * Connect to the remote networked server using lobby. + * Connect to the remote networked server using the lobby. * Push netstatus messages on failure. * @param localNetwork - if true, assume we are trying to connect on the local network. * @return true on success, false on connection failure */ - bool TryToConnect(const CStr& hostJID, bool localNetwork); + bool TryToConnectViaLobby(const CStr& hostJID, bool localNetwork); /** * Destroy the connection to the server. Index: source/network/NetClient.cpp =================================================================== --- source/network/NetClient.cpp +++ source/network/NetClient.cpp @@ -233,8 +233,10 @@ ); } -bool CNetClient::TryToConnect(const CStr& hostJID, bool localNetwork) +bool CNetClient::TryToConnectViaLobby(const CStr& hostJID, bool localNetwork) { + ENSURE(g_XmppClient); + if (m_Session) return false; @@ -261,7 +263,7 @@ CStr ip; u16 port = 0; - if (g_XmppClient && m_UseSTUN) + if (m_UseSTUN) { if (!StunClient::FindPublicIP(*enetClient, ip, port)) { @@ -282,7 +284,7 @@ return true; } } - else if (g_XmppClient && localNetwork) + else if (localNetwork) { // We may need to punch a hole through the local firewall, so fetch our local IP. // NB: we'll ignore failures here, and hope that the firewall will be open to connection @@ -317,7 +319,7 @@ StunClient::SendHolePunchingMessages(*enetClient, m_ServerAddress, m_ServerPort); } - if (!g_NetClient->SetupConnection(enetClient)) + if (!SetupConnection(enetClient)) { PushGuiMessage( "type", "netstatus",