mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-28 04:11:51 +00:00
Hide ip and port from users until they want to join, add optional password
Current issue with the lobby, is that we make ips of hosts public for anyone to read. This patch consists of 3 parts. 1.) Removing ips and ports from lobby javascript 2.) Removing need of script on the server to attach public ips to game stanza by asking the host using xmppclient as proxy. 3.) Implementing password protected matches, to deny this information to not trusted players. Further description: Do not send ports and stunip to the bots. Removed from stanza. Do not send ip to the lobby. Removed from mapping gamelist from backend to gui (still on the backend side, because it is done by script on 0ad server). Get ip and ports on request when trying to connect. On the host side, ask stun server what is host's public ip and remember it. On the client side, send iq through xmppclient to the hosting player and ask for ip, port and if Stun is used, then if answer is success, continue with connecting, else fail. Add optional password for matches. Add password required identifier to the stanza. Allow host to setup password for the match. Hash it on the host side and store inside Netserver. If no password is given, matches will behave as it is not required. On the client side, if password for the match is required, show additional window before trying to connect and ask for password, then hash it and send with iq request for ip, port and stun. Server will answer with ip, port and stun only if passwords matches, else will asnwer with error string. Some security: Passwords are hashed before sending, so it is not easy to guess what users typed. (per wraitii) Hashes are using different salt as lobby hashing and not using usernames as salt (as that is not doable), so they are different even typing the same password as for the lobby account. Client remembers which user was asked for connection data and iq's id of request. If answer doesn't match these things, it is ignored. (thnx user1) Every request for connection data is logged with hostname of the requester to the mainlog file (no ips). If user gets iq to send connection data and is not hosting the match, will respond with error string "not_server". If server gets iq::result with connection data, request is ignored. Differential revision: D3184 Reviewed by: @wraitii Comments by: @Stan, @bb, @Imarok, @vladislavbelov Tested in lobby This was SVN commit r24728.
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "lib/byte_order.h"
|
||||
#include "lib/external_libraries/enet.h"
|
||||
#include "lib/external_libraries/libsdl.h"
|
||||
#include "lib/sysdep/sysdep.h"
|
||||
#include "lobby/IXmppClient.h"
|
||||
#include "ps/CConsole.h"
|
||||
@@ -37,6 +38,7 @@
|
||||
#include "ps/Threading.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
#include "simulation2/Simulation2.h"
|
||||
#include "network/StunClient.h"
|
||||
|
||||
CNetClient *g_NetClient = NULL;
|
||||
|
||||
@@ -76,6 +78,8 @@ CNetClient::CNetClient(CGame* game, bool isLocalClient) :
|
||||
m_GameAttributes(game->GetSimulation2()->GetScriptInterface().GetGeneralJSContext()),
|
||||
m_IsLocalClient(isLocalClient),
|
||||
m_LastConnectionCheck(0),
|
||||
m_ServerAddress(),
|
||||
m_ServerPort(0),
|
||||
m_Rejoin(false)
|
||||
{
|
||||
m_Game->SetTurnManager(NULL); // delete the old local turn manager so we don't accidentally use it
|
||||
@@ -171,15 +175,102 @@ void CNetClient::SetHostingPlayerName(const CStr& hostingPlayerName)
|
||||
m_HostingPlayerName = hostingPlayerName;
|
||||
}
|
||||
|
||||
bool CNetClient::SetupConnection(const CStr& server, const u16 port, ENetHost* enetClient)
|
||||
bool CNetClient::SetupConnection(ENetHost* enetClient)
|
||||
{
|
||||
CNetClientSession* session = new CNetClientSession(*this);
|
||||
bool ok = session->Connect(server, port, m_IsLocalClient, enetClient);
|
||||
bool ok = session->Connect(m_ServerAddress, m_ServerPort, m_IsLocalClient, enetClient);
|
||||
SetAndOwnSession(session);
|
||||
m_PollingThread = std::thread(Threading::HandleExceptions<CNetClientSession::RunNetLoop>::Wrapper, m_Session);
|
||||
return ok;
|
||||
}
|
||||
|
||||
void CNetClient::SetupServerData(CStr address, u16 port, bool stun)
|
||||
{
|
||||
ENSURE(!m_Session);
|
||||
|
||||
m_ServerAddress = address;
|
||||
m_ServerPort = port;
|
||||
m_UseSTUN = stun;
|
||||
}
|
||||
|
||||
void CNetClient::HandleGetServerDataFailed(const CStr& error)
|
||||
{
|
||||
if (m_Session)
|
||||
return;
|
||||
|
||||
PushGuiMessage(
|
||||
"type", "serverdata",
|
||||
"status", "failed",
|
||||
"reason", error
|
||||
);
|
||||
}
|
||||
|
||||
bool CNetClient::TryToConnect(const CStr& hostJID)
|
||||
{
|
||||
if (m_Session)
|
||||
return false;
|
||||
|
||||
if (m_ServerAddress.empty())
|
||||
{
|
||||
PushGuiMessage(
|
||||
"type", "netstatus",
|
||||
"status", "disconnected",
|
||||
"reason", static_cast<i32>(NDR_SERVER_REFUSED));
|
||||
return false;
|
||||
}
|
||||
|
||||
ENetHost* enetClient = nullptr;
|
||||
if (g_XmppClient && m_UseSTUN)
|
||||
{
|
||||
// Find an unused port
|
||||
for (int i = 0; i < 5 && !enetClient; ++i)
|
||||
{
|
||||
// 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);
|
||||
++hostAddr.port;
|
||||
}
|
||||
|
||||
if (!enetClient)
|
||||
{
|
||||
PushGuiMessage(
|
||||
"type", "netstatus",
|
||||
"status", "disconnected",
|
||||
"reason", static_cast<i32>(NDR_STUN_PORT_FAILED));
|
||||
return false;
|
||||
}
|
||||
|
||||
StunClient::StunEndpoint stunEndpoint;
|
||||
if (!StunClient::FindStunEndpointJoin(*enetClient, stunEndpoint))
|
||||
{
|
||||
PushGuiMessage(
|
||||
"type", "netstatus",
|
||||
"status", "disconnected",
|
||||
"reason", static_cast<i32>(NDR_STUN_ENDPOINT_FAILED));
|
||||
return false;
|
||||
}
|
||||
|
||||
g_XmppClient->SendStunEndpointToHost(stunEndpoint, hostJID);
|
||||
|
||||
SDL_Delay(1000);
|
||||
|
||||
StunClient::SendHolePunchingMessages(*enetClient, m_ServerAddress, m_ServerPort);
|
||||
}
|
||||
|
||||
if (!g_NetClient->SetupConnection(enetClient))
|
||||
{
|
||||
PushGuiMessage(
|
||||
"type", "netstatus",
|
||||
"status", "disconnected",
|
||||
"reason", static_cast<i32>(NDR_UNKNOWN));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CNetClient::SetAndOwnSession(CNetClientSession* session)
|
||||
{
|
||||
delete m_Session;
|
||||
|
||||
Reference in New Issue
Block a user