Changeset View
Changeset View
Standalone View
Standalone View
source/lobby/XmppClient.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 157 Lines • ▼ Show 20 Lines | XmppClient::~XmppClient() | ||||
delete m_client; | delete m_client; | ||||
for (const glooxwrapper::Tag* const& t : m_GameList) | for (const glooxwrapper::Tag* const& t : m_GameList) | ||||
glooxwrapper::Tag::free(t); | glooxwrapper::Tag::free(t); | ||||
for (const glooxwrapper::Tag* const& t : m_BoardList) | for (const glooxwrapper::Tag* const& t : m_BoardList) | ||||
glooxwrapper::Tag::free(t); | glooxwrapper::Tag::free(t); | ||||
for (const glooxwrapper::Tag* const& t : m_Profile) | for (const glooxwrapper::Tag* const& t : m_Profile) | ||||
glooxwrapper::Tag::free(t); | glooxwrapper::Tag::free(t); | ||||
delete m_sessionManager; | |||||
} | } | ||||
/// Network | /// Network | ||||
void XmppClient::connect() | void XmppClient::connect() | ||||
{ | { | ||||
m_initialLoadComplete = false; | m_initialLoadComplete = false; | ||||
m_client->connect(false); | m_client->connect(false); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,008 Lines • ▼ Show 20 Lines | #define DEBUG_CASE(X, Y) case gloox::X: return g_L10n.Translate("Error") + " (" + Y + ")" | ||||
DEBUG_CASE(RegistrationNotAllowed, "Server does not permit password changes"); | DEBUG_CASE(RegistrationNotAllowed, "Server does not permit password changes"); | ||||
default: | default: | ||||
return ""; | return ""; | ||||
} | } | ||||
#undef DEBUG_CASE | #undef DEBUG_CASE | ||||
#undef CASE | #undef CASE | ||||
} | } | ||||
void XmppClient::SendStunEndpointToHost(StunClient::StunEndpoint* stunEndpoint, const std::string& hostJIDStr) | void XmppClient::SendStunEndpointToHost(StunClient::StunEndpoint& stunEndpoint, const std::string& hostJIDStr) | ||||
JoshuaJB: const stunEndpoint? | |||||
Done Inline Actionsack elexis: ack | |||||
{ | { | ||||
ENSURE(stunEndpoint); | |||||
char ipStr[256] = "(error)"; | char ipStr[256] = "(error)"; | ||||
ENetAddress addr; | ENetAddress addr; | ||||
addr.host = ntohl(stunEndpoint->ip); | addr.host = ntohl(stunEndpoint.ip); | ||||
enet_address_get_host_ip(&addr, ipStr, ARRAY_SIZE(ipStr)); | enet_address_get_host_ip(&addr, ipStr, ARRAY_SIZE(ipStr)); | ||||
glooxwrapper::JID hostJID(hostJIDStr); | glooxwrapper::JID hostJID(hostJIDStr); | ||||
glooxwrapper::Jingle::Session session = m_sessionManager->createSession(hostJID); | glooxwrapper::Jingle::Session session = m_sessionManager->createSession(hostJID); | ||||
session.sessionInitiate(ipStr, stunEndpoint->port); | session.sessionInitiate(ipStr, stunEndpoint.port); | ||||
} | } | ||||
void XmppClient::handleSessionAction(gloox::Jingle::Action action, glooxwrapper::Jingle::Session* UNUSED(session), const glooxwrapper::Jingle::Session::Jingle* jingle) | void XmppClient::handleSessionAction(gloox::Jingle::Action action, glooxwrapper::Jingle::Session& session, const glooxwrapper::Jingle::Session::Jingle& jingle) | ||||
{ | { | ||||
if (action == gloox::Jingle::SessionInitiate) | if (action == gloox::Jingle::SessionInitiate) | ||||
handleSessionInitiation(jingle); | handleSessionInitiation(session, jingle); | ||||
} | } | ||||
void XmppClient::handleSessionInitiation(const glooxwrapper::Jingle::Session::Jingle* jingle) | void XmppClient::handleSessionInitiation(glooxwrapper::Jingle::Session& UNUSED(session), const glooxwrapper::Jingle::Session::Jingle& jingle) | ||||
elexisAuthorUnsubmitted Done Inline Actions(handleSessionInitiation sounds a lot like it has legitimate access to session, hence the UNUSED moved from handleSessionAction) elexis: (`handleSessionInitiation` sounds a lot like it has legitimate access to `session`, hence the… | |||||
{ | { | ||||
glooxwrapper::Jingle::ICEUDP::Candidate candidate = jingle->getCandidate(); | glooxwrapper::Jingle::ICEUDP::Candidate candidate = jingle.getCandidate(); | ||||
if (candidate.ip.empty()) | if (candidate.ip.empty()) | ||||
{ | { | ||||
LOGERROR("Failed to retrieve Jingle candidate"); | LOGERROR("Failed to retrieve Jingle candidate"); | ||||
return; | return; | ||||
} | } | ||||
if (!g_NetServer) | if (!g_NetServer) | ||||
{ | { | ||||
LOGERROR("Received STUN connection request, but not hosting currently!"); | LOGERROR("Received STUN connection request, but not hosting currently!"); | ||||
return; | return; | ||||
} | } | ||||
g_NetServer->SendHolePunchingMessage(candidate.ip.to_string(), candidate.port); | g_NetServer->SendHolePunchingMessage(candidate.ip.to_string(), candidate.port); | ||||
} | } |
Wildfire Games · Phabricator
const stunEndpoint?