Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/network/NetClient.cpp
Show All 27 Lines | |||||
#include "lib/external_libraries/libsdl.h" | #include "lib/external_libraries/libsdl.h" | ||||
#include "lib/sysdep/sysdep.h" | #include "lib/sysdep/sysdep.h" | ||||
#include "lobby/IXmppClient.h" | #include "lobby/IXmppClient.h" | ||||
#include "ps/CConsole.h" | #include "ps/CConsole.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Compress.h" | #include "ps/Compress.h" | ||||
#include "ps/CStr.h" | #include "ps/CStr.h" | ||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/Hashing.h" | |||||
#include "ps/Loader.h" | #include "ps/Loader.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/Threading.h" | #include "ps/Threading.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "scriptinterface/JSON.h" | #include "scriptinterface/JSON.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "network/StunClient.h" | #include "network/StunClient.h" | ||||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | |||||
void CNetClient::SetHostJID(const CStr& jid) | void CNetClient::SetHostJID(const CStr& jid) | ||||
{ | { | ||||
m_HostJID = jid; | m_HostJID = jid; | ||||
} | } | ||||
void CNetClient::SetGamePassword(const CStr& hashedPassword) | void CNetClient::SetGamePassword(const CStr& hashedPassword) | ||||
{ | { | ||||
m_Password = hashedPassword; | // Hash on top with the user's name, to make sure not all | ||||
// hashing data is in control of the host. | |||||
m_Password = HashCryptographically(hashedPassword, m_UserName.ToUTF8()); | |||||
} | } | ||||
void CNetClient::SetControllerSecret(const std::string& secret) | void CNetClient::SetControllerSecret(const std::string& secret) | ||||
{ | { | ||||
m_ControllerSecret = secret; | m_ControllerSecret = secret; | ||||
} | } | ||||
bool CNetClient::SetupConnection(ENetHost* enetClient) | bool CNetClient::SetupConnection(ENetHost* enetClient) | ||||
{ | { | ||||
CNetClientSession* session = new CNetClientSession(*this); | CNetClientSession* session = new CNetClientSession(*this); | ||||
bool ok = session->Connect(m_ServerAddress, m_ServerPort, enetClient); | bool ok = session->Connect(m_ServerAddress, m_ServerPort, enetClient); | ||||
SetAndOwnSession(session); | SetAndOwnSession(session); | ||||
m_PollingThread = std::thread(Threading::HandleExceptions<CNetClientSession::RunNetLoop>::Wrapper, m_Session); | m_PollingThread = std::thread(Threading::HandleExceptions<CNetClientSession::RunNetLoop>::Wrapper, m_Session); | ||||
return ok; | return ok; | ||||
} | } | ||||
void CNetClient::SetupConnectionViaLobby() | |||||
{ | |||||
g_XmppClient->SendIqGetConnectionData(m_HostJID, m_Password, m_UserName.ToUTF8(), false); | |||||
} | |||||
void CNetClient::SetupServerData(CStr address, u16 port, bool stun) | void CNetClient::SetupServerData(CStr address, u16 port, bool stun) | ||||
{ | { | ||||
ENSURE(!m_Session); | ENSURE(!m_Session); | ||||
m_ServerAddress = address; | m_ServerAddress = address; | ||||
m_ServerPort = port; | m_ServerPort = port; | ||||
m_UseSTUN = stun; | m_UseSTUN = stun; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | if (!StunClient::FindPublicIP(*enetClient, ip, port)) | ||||
return false; | return false; | ||||
} | } | ||||
// If the host is on the same network, we risk failing to connect | // If the host is on the same network, we risk failing to connect | ||||
// on routers that don't support NAT hairpinning/NAT loopback. | // on routers that don't support NAT hairpinning/NAT loopback. | ||||
// To work around that, send again a connection data request, but for internal IP this time. | // To work around that, send again a connection data request, but for internal IP this time. | ||||
if (ip == m_ServerAddress) | if (ip == m_ServerAddress) | ||||
{ | { | ||||
g_XmppClient->SendIqGetConnectionData(m_HostJID, m_Password, true); | g_XmppClient->SendIqGetConnectionData(m_HostJID, m_Password, m_UserName.ToUTF8(), true); | ||||
// Return true anyways - we're on a success path here. | // Return true anyways - we're on a success path here. | ||||
return true; | return true; | ||||
} | } | ||||
g_XmppClient->SendStunEndpointToHost(ip, port, hostJID); | g_XmppClient->SendStunEndpointToHost(ip, port, hostJID); | ||||
SDL_Delay(1000); | SDL_Delay(1000); | ||||
▲ Show 20 Lines • Show All 696 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator