Changeset View
Changeset View
Standalone View
Standalone View
source/network/NetClient.cpp
Show First 20 Lines • Show All 233 Lines • ▼ Show 20 Lines | PushGuiMessage( | ||||
"status", "disconnected", | "status", "disconnected", | ||||
"reason", static_cast<i32>(NDR_SERVER_REFUSED)); | "reason", static_cast<i32>(NDR_SERVER_REFUSED)); | ||||
return false; | return false; | ||||
} | } | ||||
ENetHost* enetClient = nullptr; | ENetHost* enetClient = nullptr; | ||||
if (g_XmppClient && m_UseSTUN) | if (g_XmppClient && m_UseSTUN) | ||||
{ | { | ||||
// Find an unused port | ENetAddress hostAddr{ ENET_HOST_ANY, 0 }; | ||||
for (int i = 0; i < 5 && !enetClient; ++i) | |||||
Stan: Why remove this? On windows, two apps using the same port will crash. | |||||
Done Inline ActionsIt's not removed, it's upgraded. By hosting on port 0, the OS will find an available port itself. wraitii: It's not removed, it's upgraded. By hosting on port 0, the OS will find an available port… | |||||
Not Done Inline ActionsSo if port 22 is available on Windows, it will try to use that? that sounds bad. Stan: So if port 22 is available on Windows, it will try to use that? that sounds bad. | |||||
Done Inline Actionswraitii: https://en.wikipedia.org/wiki/Ephemeral_port | |||||
{ | |||||
// Ports below 1024 are privileged on unix | |||||
u16 port = 1024 + rand() % (UINT16_MAX - 1024); | |||||
ENetAddress hostAddr{ ENET_HOST_ANY, port }; | |||||
enetClient = enet_host_create(&hostAddr, 1, 1, 0, 0); | enetClient = enet_host_create(&hostAddr, 1, 1, 0, 0); | ||||
++hostAddr.port; | |||||
} | |||||
if (!enetClient) | if (!enetClient) | ||||
{ | { | ||||
PushGuiMessage( | PushGuiMessage( | ||||
"type", "netstatus", | "type", "netstatus", | ||||
"status", "disconnected", | "status", "disconnected", | ||||
"reason", static_cast<i32>(NDR_STUN_PORT_FAILED)); | "reason", static_cast<i32>(NDR_STUN_PORT_FAILED)); | ||||
return false; | return false; | ||||
} | } | ||||
StunClient::StunEndpoint stunEndpoint; | Networking::IPAddress publicIP; | ||||
if (!StunClient::FindStunEndpointJoin(*enetClient, stunEndpoint)) | if (!StunClient::FindPublicIP(*enetClient, publicIP)) | ||||
{ | { | ||||
PushGuiMessage( | PushGuiMessage( | ||||
"type", "netstatus", | "type", "netstatus", | ||||
"status", "disconnected", | "status", "disconnected", | ||||
"reason", static_cast<i32>(NDR_STUN_ENDPOINT_FAILED)); | "reason", static_cast<i32>(NDR_STUN_ENDPOINT_FAILED)); | ||||
return false; | return false; | ||||
} | } | ||||
g_XmppClient->SendStunEndpointToHost(stunEndpoint, hostJID); | g_XmppClient->SendStunEndpointToHost(publicIP.GetIP(), publicIP.GetPort(), hostJID); | ||||
SDL_Delay(1000); | SDL_Delay(1000); | ||||
StunClient::SendHolePunchingMessages(*enetClient, m_ServerAddress, m_ServerPort); | StunClient::SendHolePunchingMessages(*enetClient, m_ServerAddress, m_ServerPort); | ||||
} | } | ||||
if (!g_NetClient->SetupConnection(enetClient)) | if (!g_NetClient->SetupConnection(enetClient)) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 691 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Why remove this? On windows, two apps using the same port will crash.