Index: source/network/NetClient.cpp =================================================================== --- source/network/NetClient.cpp +++ source/network/NetClient.cpp @@ -258,9 +258,27 @@ return false; } + auto setupConnection = [this, enetClient]() { + LOGMESSAGE("NetClient: connecting to server at %s:%i", m_ServerAddress, m_ServerPort); + + if (!g_NetClient->SetupConnection(enetClient)) + { + PushGuiMessage( + "type", "netstatus", + "status", "disconnected", + "reason", static_cast(NDR_UNKNOWN)); + return false; + } + return true; + }; + + if (!g_XmppClient) { + return setupConnection(); + } + CStr ip; u16 port = 0; - if (g_XmppClient && m_UseSTUN) + if (m_UseSTUN) { if (!StunClient::FindPublicIP(*enetClient, ip, port)) { @@ -281,7 +299,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 @@ -299,8 +317,6 @@ port = enetClient->address.port; } - LOGMESSAGE("NetClient: connecting to server at %s:%i", m_ServerAddress, m_ServerPort); - if (!ip.empty()) { // UDP hole-punching @@ -316,16 +332,7 @@ StunClient::SendHolePunchingMessages(*enetClient, m_ServerAddress, m_ServerPort); } - if (!g_NetClient->SetupConnection(enetClient)) - { - PushGuiMessage( - "type", "netstatus", - "status", "disconnected", - "reason", static_cast(NDR_UNKNOWN)); - return false; - } - - return true; + return setupConnection(); }