Changeset View
Changeset View
Standalone View
Standalone View
source/lobby/XmppClient.cpp
Show All 26 Lines | |||||
#include "i18n/L10n.h" | #include "i18n/L10n.h" | ||||
#include "lib/external_libraries/enet.h" | #include "lib/external_libraries/enet.h" | ||||
#include "lib/utf8.h" | #include "lib/utf8.h" | ||||
#include "network/NetServer.h" | #include "network/NetServer.h" | ||||
#include "network/NetClient.h" | #include "network/NetClient.h" | ||||
#include "network/StunClient.h" | #include "network/StunClient.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/ConfigDB.h" | #include "ps/ConfigDB.h" | ||||
#include "ps/GUID.h" | |||||
#include "ps/Pyrogenesis.h" | #include "ps/Pyrogenesis.h" | ||||
#include "scriptinterface/ScriptExtraHeaders.h" // StructuredClone | #include "scriptinterface/ScriptExtraHeaders.h" // StructuredClone | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include <gloox/gloox.h> | #include <gloox/gloox.h> | ||||
#include <iostream> | #include <iostream> | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | XmppClient::XmppClient(const ScriptInterface* scriptInterface, const std::string& sUsername, const std::string& sPassword, const std::string& sRoom, const std::string& sNick, const int historyRequestSize, bool regOpt) | ||||
std::string sXpartamupp; | std::string sXpartamupp; | ||||
std::string sEchelon; | std::string sEchelon; | ||||
CFG_GET_VAL("lobby.server", m_server); | CFG_GET_VAL("lobby.server", m_server); | ||||
CFG_GET_VAL("lobby.xpartamupp", sXpartamupp); | CFG_GET_VAL("lobby.xpartamupp", sXpartamupp); | ||||
CFG_GET_VAL("lobby.echelon", sEchelon); | CFG_GET_VAL("lobby.echelon", sEchelon); | ||||
m_xpartamuppId = sXpartamupp + "@" + m_server + "/CC"; | m_xpartamuppId = sXpartamupp + "@" + m_server + "/CC"; | ||||
m_echelonId = sEchelon + "@" + m_server + "/CC"; | m_echelonId = sEchelon + "@" + m_server + "/CC"; | ||||
glooxwrapper::JID clientJid(sUsername + "@" + m_server + "/0ad"); | // Generate a unique, unpredictable resource to allow multiple 0 A.D. instances to connect to the lobby. | ||||
glooxwrapper::JID clientJid(sUsername + "@" + m_server + "/0ad-" + ps_generate_guid()); | |||||
wraitii: This is un-necessary, but it's somewhat useful to be able to connect two 0 A.D. instances to… | |||||
Not Done Inline ActionsCould generate a GUID maybe? Stan: Could generate a GUID maybe? | |||||
glooxwrapper::JID roomJid(m_room + "@conference." + m_server + "/" + sNick); | glooxwrapper::JID roomJid(m_room + "@conference." + m_server + "/" + sNick); | ||||
// If we are connecting, use the full jid and a password | // If we are connecting, use the full jid and a password | ||||
// If we are registering, only use the server name | // If we are registering, only use the server name | ||||
if (!regOpt) | if (!regOpt) | ||||
m_client = new glooxwrapper::Client(clientJid, sPassword); | m_client = new glooxwrapper::Client(clientJid, sPassword); | ||||
else | else | ||||
m_client = new glooxwrapper::Client(m_server); | m_client = new glooxwrapper::Client(m_server); | ||||
▲ Show 20 Lines • Show All 378 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Send lobby authentication token. | * Send lobby authentication token. | ||||
*/ | */ | ||||
void XmppClient::SendIqLobbyAuth(const std::string& to, const std::string& token) | void XmppClient::SendIqLobbyAuth(const std::string& to, const std::string& token) | ||||
{ | { | ||||
LobbyAuth* auth = new LobbyAuth(); | LobbyAuth* auth = new LobbyAuth(); | ||||
auth->m_Token = token; | auth->m_Token = token; | ||||
glooxwrapper::JID clientJid(to + "@" + m_server + "/0ad"); | glooxwrapper::JID clientJid(to); | ||||
glooxwrapper::IQ iq(gloox::IQ::Set, clientJid, m_client->getID()); | glooxwrapper::IQ iq(gloox::IQ::Set, clientJid, m_client->getID()); | ||||
iq.addExtension(auth); | iq.addExtension(auth); | ||||
DbgXMPP("SendIqLobbyAuth [" << tag_xml(iq) << "]"); | DbgXMPP("SendIqLobbyAuth [" << tag_xml(iq) << "]"); | ||||
m_client->send(iq); | m_client->send(iq); | ||||
} | } | ||||
/***************************************************** | /***************************************************** | ||||
* Account registration * | * Account registration * | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
void XmppClient::GUIGetGameList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) | void XmppClient::GUIGetGameList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) | ||||
{ | { | ||||
ScriptRequest rq(scriptInterface); | ScriptRequest rq(scriptInterface); | ||||
ScriptInterface::CreateArray(rq, ret); | ScriptInterface::CreateArray(rq, ret); | ||||
int j = 0; | int j = 0; | ||||
const char* stats[] = { "name", "hostUsername", "state", "hasPassword", | const char* stats[] = { "name", "hostUsername", "hostJID", "state", "hasPassword", | ||||
"nbp", "maxnbp", "players", "mapName", "niceMapName", "mapSize", "mapType", | "nbp", "maxnbp", "players", "mapName", "niceMapName", "mapSize", "mapType", | ||||
"victoryConditions", "startTime", "mods" }; | "victoryConditions", "startTime", "mods" }; | ||||
for(const glooxwrapper::Tag* const& t : m_GameList) | for(const glooxwrapper::Tag* const& t : m_GameList) | ||||
{ | { | ||||
JS::RootedValue game(rq.cx); | JS::RootedValue game(rq.cx); | ||||
ScriptInterface::CreateObject(rq, &game); | ScriptInterface::CreateObject(rq, &game); | ||||
▲ Show 20 Lines • Show All 554 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* @param nick Variable to store the nickname in. | * @param nick Variable to store the nickname in. | ||||
*/ | */ | ||||
void XmppClient::GetNick(std::string& nick) | void XmppClient::GetNick(std::string& nick) | ||||
{ | { | ||||
nick = m_mucRoom->nick().to_string(); | nick = m_mucRoom->nick().to_string(); | ||||
} | } | ||||
std::string XmppClient::GetJID() const | |||||
Not Done Inline ActionsWonder if it should be like the above a void with an out parameter ? Stan: Wonder if it should be like the above a void with an out parameter ? | |||||
Done Inline ActionsI'm not too sure why this was done, since other functions don't take out parameters here. wraitii: I'm not too sure why this was done, since other functions don't take out parameters here. | |||||
{ | |||||
return m_client->getJID().to_string(); | |||||
} | |||||
/** | /** | ||||
* Kick a player from the current room. | * Kick a player from the current room. | ||||
* | * | ||||
* @param nick Nickname to be kicked | * @param nick Nickname to be kicked | ||||
* @param reason Reason the player was kicked | * @param reason Reason the player was kicked | ||||
*/ | */ | ||||
void XmppClient::kick(const std::string& nick, const std::string& reason) | void XmppClient::kick(const std::string& nick, const std::string& reason) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 319 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
This is un-necessary, but it's somewhat useful to be able to connect two 0 A.D. instances to the lobby for testing. It also enforces that the resource isn't "0ad", which I suppose is a good thing.
Note that this isn't particularly "unique", but I didn't care too much.