Changeset View
Changeset View
Standalone View
Standalone View
source/network/scripting/JSInterface_Network.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | if (!g_NetServer->SetupConnection(serverPort)) | ||||
return; | return; | ||||
} | } | ||||
g_Game = new CGame(); | g_Game = new CGame(); | ||||
g_NetClient = new CNetClient(g_Game, true); | g_NetClient = new CNetClient(g_Game, true); | ||||
g_NetClient->SetUserName(playerName); | g_NetClient->SetUserName(playerName); | ||||
g_NetClient->SetHostingPlayerName(hostLobbyName); | g_NetClient->SetHostingPlayerName(hostLobbyName); | ||||
if (!g_NetClient->SetupConnection("127.0.0.1", serverPort)) | if (!g_NetClient->SetupConnection("127.0.0.1", serverPort, nullptr)) | ||||
{ | { | ||||
pCxPrivate->pScriptInterface->ReportError("Failed to connect to server"); | pCxPrivate->pScriptInterface->ReportError("Failed to connect to server"); | ||||
SAFE_DELETE(g_NetClient); | SAFE_DELETE(g_NetClient); | ||||
SAFE_DELETE(g_Game); | SAFE_DELETE(g_Game); | ||||
} | } | ||||
} | } | ||||
void JSI_Network::StartNetworkJoin(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& playerName, const CStr& serverAddress, u16 serverPort, bool useSTUN, const CStr& hostJID) | void JSI_Network::StartNetworkJoin(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& playerName, const CStr& serverAddress, u16 serverPort, bool useSTUN, const CStr& hostJID) | ||||
Show All 16 Lines | if (g_XmppClient && useSTUN) | ||||
} | } | ||||
if (!enetClient) | if (!enetClient) | ||||
{ | { | ||||
pCxPrivate->pScriptInterface->ReportError("Could not find an unused port for the enet STUN client"); | pCxPrivate->pScriptInterface->ReportError("Could not find an unused port for the enet STUN client"); | ||||
return; | return; | ||||
} | } | ||||
StunClient::StunEndpoint* stunEndpoint = StunClient::FindStunEndpointJoin(enetClient); | StunClient::StunEndpoint stunEndpoint; | ||||
if (!stunEndpoint) | if (!StunClient::FindStunEndpointJoin(*enetClient, stunEndpoint)) | ||||
{ | { | ||||
pCxPrivate->pScriptInterface->ReportError("Could not find the STUN endpoint"); | pCxPrivate->pScriptInterface->ReportError("Could not find the STUN endpoint"); | ||||
return; | return; | ||||
} | } | ||||
g_XmppClient->SendStunEndpointToHost(stunEndpoint, hostJID); | g_XmppClient->SendStunEndpointToHost(stunEndpoint, hostJID); | ||||
delete stunEndpoint; | |||||
SDL_Delay(1000); | SDL_Delay(1000); | ||||
} | } | ||||
g_Game = new CGame(); | g_Game = new CGame(); | ||||
g_NetClient = new CNetClient(g_Game, false); | g_NetClient = new CNetClient(g_Game, false); | ||||
g_NetClient->SetUserName(playerName); | g_NetClient->SetUserName(playerName); | ||||
g_NetClient->SetHostingPlayerName(hostJID.substr(0, hostJID.find("@"))); | g_NetClient->SetHostingPlayerName(hostJID.substr(0, hostJID.find("@"))); | ||||
if (g_XmppClient && useSTUN) | if (g_XmppClient && useSTUN) | ||||
StunClient::SendHolePunchingMessages(enetClient, serverAddress.c_str(), serverPort); | StunClient::SendHolePunchingMessages(*enetClient, serverAddress.c_str(), serverPort); | ||||
if (!g_NetClient->SetupConnection(serverAddress, serverPort, enetClient)) | if (!g_NetClient->SetupConnection(serverAddress, serverPort, enetClient)) | ||||
{ | { | ||||
pCxPrivate->pScriptInterface->ReportError("Failed to connect to server"); | pCxPrivate->pScriptInterface->ReportError("Failed to connect to server"); | ||||
SAFE_DELETE(g_NetClient); | SAFE_DELETE(g_NetClient); | ||||
SAFE_DELETE(g_Game); | SAFE_DELETE(g_Game); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 112 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator