Changeset View
Changeset View
Standalone View
Standalone View
source/lobby/XmppClient.cpp
Show All 29 Lines | |||||
#include "network/NetServer.h" | #include "network/NetServer.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/Pyrogenesis.h" | #include "ps/Pyrogenesis.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
//debug | //debug | ||||
#if 1 | #if 1 | ||||
Imarok: Will revert that next time I change this diff | |||||
#define DbgXMPP(x) | #define DbgXMPP(x) | ||||
#else | #else | ||||
#define DbgXMPP(x) std::cout << x << std::endl; | #define DbgXMPP(x) std::cout << x << std::endl; | ||||
static std::string tag_xml(const glooxwrapper::IQ& iq) | static std::string tag_xml(const glooxwrapper::IQ& iq) | ||||
{ | { | ||||
std::string ret; | std::string ret; | ||||
glooxwrapper::Tag* tag = iq.tag(); | glooxwrapper::Tag* tag = iq.tag(); | ||||
Show All 23 Lines | |||||
* @param sUsername Username to login with of register. | * @param sUsername Username to login with of register. | ||||
* @param sPassword Password to login with or register. | * @param sPassword Password to login with or register. | ||||
* @param sRoom MUC room to join. | * @param sRoom MUC room to join. | ||||
* @param sNick Nick to join with. | * @param sNick Nick to join with. | ||||
* @param historyRequestSize Number of stanzas of room history to request. | * @param historyRequestSize Number of stanzas of room history to request. | ||||
* @param regOpt If we are just registering or not. | * @param regOpt If we are just registering or not. | ||||
*/ | */ | ||||
XmppClient::XmppClient(const std::string& sUsername, const std::string& sPassword, const std::string& sRoom, const std::string& sNick, const int historyRequestSize, bool regOpt) | XmppClient::XmppClient(const std::string& sUsername, const std::string& sPassword, const std::string& sRoom, const std::string& sNick, const int historyRequestSize, bool regOpt) | ||||
: m_client(NULL), m_mucRoom(NULL), m_registration(NULL), m_username(sUsername), m_password(sPassword), m_nick(sNick), m_initialLoadComplete(false), m_isConnected(false), m_sessionManager() | : m_client(NULL), m_mucRoom(NULL), m_registration(NULL), m_username(sUsername), m_password(sPassword), m_room(sRoom), m_nick(sNick), m_initialLoadComplete(false), m_isConnected(false), m_sessionManager() | ||||
{ | { | ||||
// Read lobby configuration from default.cfg | // Read lobby configuration from default.cfg | ||||
std::string sServer; | |||||
std::string sXpartamupp; | std::string sXpartamupp; | ||||
Done Inline Actionsunused and nothing complained elexis: unused and nothing complained | |||||
CFG_GET_VAL("lobby.server", sServer); | CFG_GET_VAL("lobby.server", m_server); | ||||
CFG_GET_VAL("lobby.xpartamupp", sXpartamupp); | CFG_GET_VAL("lobby.xpartamupp", sXpartamupp); | ||||
m_xpartamuppId = sXpartamupp + "@" + sServer + "/CC"; | m_xpartamuppId = sXpartamupp + "@" + m_server + "/CC"; | ||||
glooxwrapper::JID clientJid(sUsername + "@" + sServer + "/0ad"); | glooxwrapper::JID clientJid(sUsername + "@" + m_server + "/0ad"); | ||||
Not Done Inline Actions(should remove that hardcoding someday for 500ad) elexis: (should remove that hardcoding someday for 500ad) | |||||
glooxwrapper::JID roomJid(sRoom + "@conference." + sServer + "/" + 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(sServer); | m_client = new glooxwrapper::Client(m_server); | ||||
// Disable TLS as we haven't set a certificate on the server yet | // Disable TLS as we haven't set a certificate on the server yet | ||||
m_client->setTls(gloox::TLSDisabled); | m_client->setTls(gloox::TLSDisabled); | ||||
// Disable use of the SASL PLAIN mechanism, to prevent leaking credentials | // Disable use of the SASL PLAIN mechanism, to prevent leaking credentials | ||||
// if the server doesn't list any supported SASL mechanism or the response | // if the server doesn't list any supported SASL mechanism or the response | ||||
// has been modified to exclude those. | // has been modified to exclude those. | ||||
const int mechs = gloox::SaslMechAll ^ gloox::SaslMechPlain; | const int mechs = gloox::SaslMechAll ^ gloox::SaslMechPlain; | ||||
Show All 9 Lines | XmppClient::XmppClient(const std::string& sUsername, const std::string& sPassword, const std::string& sRoom, const std::string& sNick, const int historyRequestSize, bool regOpt) | ||||
m_client->registerIqHandler(this, EXTGAMELISTQUERY); | m_client->registerIqHandler(this, EXTGAMELISTQUERY); | ||||
m_client->registerStanzaExtension(new BoardListQuery()); | m_client->registerStanzaExtension(new BoardListQuery()); | ||||
m_client->registerIqHandler(this, EXTBOARDLISTQUERY); | m_client->registerIqHandler(this, EXTBOARDLISTQUERY); | ||||
m_client->registerStanzaExtension(new ProfileQuery()); | m_client->registerStanzaExtension(new ProfileQuery()); | ||||
m_client->registerIqHandler(this, EXTPROFILEQUERY); | m_client->registerIqHandler(this, EXTPROFILEQUERY); | ||||
m_client->registerStanzaExtension(new LobbyAuth()); | |||||
m_client->registerIqHandler(this, EXTLOBBYAUTH); | |||||
m_client->registerMessageHandler(this); | m_client->registerMessageHandler(this); | ||||
// Uncomment to see the raw stanzas | // Uncomment to see the raw stanzas | ||||
//m_client->getWrapped()->logInstance().registerLogHandler( gloox::LogLevelDebug, gloox::LogAreaAll, this ); | //m_client->getWrapped()->logInstance().registerLogHandler( gloox::LogLevelDebug, gloox::LogAreaAll, this ); | ||||
if (!regOpt) | if (!regOpt) | ||||
{ | { | ||||
// Create a Multi User Chat Room | // Create a Multi User Chat Room | ||||
▲ Show 20 Lines • Show All 283 Lines • ▼ Show 20 Lines | void XmppClient::SendIqChangeStateGame(const std::string& nbp, const std::string& players) | ||||
glooxwrapper::IQ iq(gloox::IQ::Set, xpartamuppJid, m_client->getID()); | glooxwrapper::IQ iq(gloox::IQ::Set, xpartamuppJid, m_client->getID()); | ||||
iq.addExtension(g); | iq.addExtension(g); | ||||
DbgXMPP("SendIqChangeStateGame [" << tag_xml(iq) << "]"); | DbgXMPP("SendIqChangeStateGame [" << tag_xml(iq) << "]"); | ||||
m_client->send(iq); | m_client->send(iq); | ||||
} | } | ||||
/***************************************************** | /***************************************************** | ||||
* iq to clients * | |||||
Done Inline Actionswhitespace elexis: whitespace | |||||
*****************************************************/ | |||||
/** | |||||
* Send lobby authentication token. | |||||
*/ | |||||
void XmppClient::SendIqLobbyAuth(const std::string& to, const std::string& token) | |||||
{ | |||||
LobbyAuth* auth = new LobbyAuth(); | |||||
auth->m_Token = token; | |||||
glooxwrapper::JID clientJid(to + "@" + m_server + "/0ad"); | |||||
glooxwrapper::IQ iq(gloox::IQ::Set, clientJid, m_client->getID()); | |||||
iq.addExtension(auth); | |||||
DbgXMPP("SendIqLobbyAuth [" << tag_xml(iq) << "]"); | |||||
m_client->send(iq); | |||||
} | |||||
/***************************************************** | |||||
* Account registration * | * Account registration * | ||||
*****************************************************/ | *****************************************************/ | ||||
void XmppClient::handleRegistrationFields(const glooxwrapper::JID&, int fields, glooxwrapper::string) | void XmppClient::handleRegistrationFields(const glooxwrapper::JID&, int fields, glooxwrapper::string) | ||||
{ | { | ||||
glooxwrapper::RegistrationFields vals; | glooxwrapper::RegistrationFields vals; | ||||
vals.username = m_username; | vals.username = m_username; | ||||
vals.password = m_password; | vals.password = m_password; | ||||
▲ Show 20 Lines • Show All 223 Lines • ▼ Show 20 Lines | void XmppClient::ClearPresenceUpdates() | ||||
), m_GuiMessageQueue.end()); | ), m_GuiMessageQueue.end()); | ||||
} | } | ||||
/** | /** | ||||
* Handle a room message. | * Handle a room message. | ||||
*/ | */ | ||||
void XmppClient::handleMUCMessage(glooxwrapper::MUCRoom*, const glooxwrapper::Message& msg, bool priv) | void XmppClient::handleMUCMessage(glooxwrapper::MUCRoom*, const glooxwrapper::Message& msg, bool priv) | ||||
{ | { | ||||
DbgXMPP(msg.from().resource() << " said " << msg.body()); | DbgXMPP(msg.from().resource() << " said " << msg.body()); | ||||
Done Inline ActionsLOGERROR? elexis: LOGERROR? | |||||
Done Inline Actionsunify the triplicate elexis: unify the triplicate | |||||
CreateGUIMessage( | CreateGUIMessage( | ||||
"chat", | "chat", | ||||
priv ? "private-message" : "room-message", | priv ? "private-message" : "room-message", | ||||
"from", msg.from().resource().to_string(), | "from", msg.from().resource().to_string(), | ||||
"text", msg.body().to_string(), | "text", msg.body().to_string(), | ||||
ComputeTimestamp(msg)); | ComputeTimestamp(msg)); | ||||
} | } | ||||
/** | /** | ||||
* Handle a private message. | * Handle a private message. | ||||
*/ | */ | ||||
void XmppClient::handleMessage(const glooxwrapper::Message& msg, glooxwrapper::MessageSession*) | void XmppClient::handleMessage(const glooxwrapper::Message& msg, glooxwrapper::MessageSession*) | ||||
{ | { | ||||
DbgXMPP("type " << msg.subtype() << ", subject " << msg.subject() | DbgXMPP("type " << msg.subtype() << ", subject " << msg.subject() | ||||
<< ", message " << msg.body() << ", thread id " << msg.thread()); | << ", message " << msg.body() << ", thread id " << msg.thread()); | ||||
CreateGUIMessage( | CreateGUIMessage( | ||||
"chat", | "chat", | ||||
"private-message", | "private-message", | ||||
"from", msg.from().resource().to_string(), | "from", msg.from().resource().to_string(), | ||||
"text", msg.body().to_string(), | "text", msg.body().to_string(), | ||||
ComputeTimestamp(msg)); | ComputeTimestamp(msg)); | ||||
} | } | ||||
Done Inline Actionss/else/return elexis: s/else/return | |||||
/** | /** | ||||
* Handle portions of messages containing custom stanza extensions. | * Handle portions of messages containing custom stanza extensions. | ||||
*/ | */ | ||||
bool XmppClient::handleIq(const glooxwrapper::IQ& iq) | bool XmppClient::handleIq(const glooxwrapper::IQ& iq) | ||||
{ | { | ||||
DbgXMPP("handleIq [" << tag_xml(iq) << "]"); | DbgXMPP("handleIq [" << tag_xml(iq) << "]"); | ||||
if (iq.subtype() == gloox::IQ::Result) | if (iq.subtype() == gloox::IQ::Result) | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | if (pq) | ||||
m_Profile.clear(); | m_Profile.clear(); | ||||
for (const glooxwrapper::Tag* const& t : pq->m_StanzaProfile) | for (const glooxwrapper::Tag* const& t : pq->m_StanzaProfile) | ||||
m_Profile.emplace_back(t->clone()); | m_Profile.emplace_back(t->clone()); | ||||
CreateGUIMessage("game", "profile"); | CreateGUIMessage("game", "profile"); | ||||
} | } | ||||
} | } | ||||
else if (iq.subtype() == gloox::IQ::Set) | |||||
{ | |||||
const LobbyAuth* lobbyAuth = iq.findExtension<LobbyAuth>(EXTLOBBYAUTH); | |||||
Done Inline ActionslobbyAuth would be more readable elexis: lobbyAuth would be more readable | |||||
if (lobbyAuth) | |||||
{ | |||||
LOGMESSAGE("XmppClient: Received lobby auth: %s from %s", lobbyAuth->m_Token.to_string(), iq.from().username()); | |||||
glooxwrapper::IQ response(gloox::IQ::Result, iq.from(), iq.id()); | |||||
m_client->send(response); | |||||
if (g_NetServer) | |||||
g_NetServer->OnLobbyAuth(iq.from().username(), lobbyAuth->m_Token.to_string()); | |||||
Not Done Inline ActionsThese references to globals (g_NetServer) are not good, but we already have them. Should add a setter sometime. elexis: These references to globals (`g_NetServer`) are not good, but we already have them. Should add… | |||||
} | |||||
} | |||||
Not Done Inline ActionsWe should split this function some day. elexis: We should split this function some day. | |||||
else if (iq.subtype() == gloox::IQ::Error) | else if (iq.subtype() == gloox::IQ::Error) | ||||
CreateGUIMessage("system", "error", "text", StanzaErrorToString(iq.error_error())); | CreateGUIMessage("system", "error", "text", StanzaErrorToString(iq.error_error())); | ||||
else | else | ||||
{ | { | ||||
CreateGUIMessage("system", "error", "text", g_L10n.Translate("unknown subtype (see logs)")); | CreateGUIMessage("system", "error", "text", g_L10n.Translate("unknown subtype (see logs)")); | ||||
LOGMESSAGE("unknown subtype '%s'", tag_name(iq).c_str()); | LOGMESSAGE("unknown subtype '%s'", tag_name(iq).c_str()); | ||||
} | } | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 401 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Will revert that next time I change this diff