Changeset View
Changeset View
Standalone View
Standalone View
source/lobby/XmppClient.cpp
Show All 19 Lines | |||||
#include "StanzaExtensions.h" | #include "StanzaExtensions.h" | ||||
#ifdef WIN32 | #ifdef WIN32 | ||||
# include <winsock2.h> | # include <winsock2.h> | ||||
#endif | #endif | ||||
#include "i18n/L10n.h" | #include "i18n/L10n.h" | ||||
#include "gui/GUI.h" | |||||
#include "gui/GUIManager.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/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" | ||||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | XmppClient::~XmppClient() | ||||
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); | ||||
} | } | ||||
shared_ptr<ScriptInterface> XmppClient::GetScriptInterface() | |||||
{ | |||||
return g_GUI->GetScriptInterface(); | |||||
} | |||||
/// Network | /// Network | ||||
void XmppClient::connect() | void XmppClient::connect() | ||||
{ | { | ||||
m_initialLoadComplete = false; | m_initialLoadComplete = false; | ||||
m_client->connect(false); | m_client->connect(false); | ||||
} | } | ||||
void XmppClient::disconnect() | void XmppClient::disconnect() | ||||
Show All 9 Lines | |||||
/** | /** | ||||
* Log (debug) Handler | * Log (debug) Handler | ||||
*/ | */ | ||||
void XmppClient::handleLog(gloox::LogLevel level, gloox::LogArea area, const std::string& message) | void XmppClient::handleLog(gloox::LogLevel level, gloox::LogArea area, const std::string& message) | ||||
{ | { | ||||
std::cout << "log: level: " << level << ", area: " << area << ", message: " << message << std::endl; | std::cout << "log: level: " << level << ", area: " << area << ", message: " << message << std::endl; | ||||
} | } | ||||
void XmppClient::CreateGUIMessage( | |||||
std::string type, | |||||
std::string level, | |||||
std::string prop1 = "", | |||||
std::string val1 = "", | |||||
std::string prop2 = "", | |||||
std::string val2 = "", | |||||
std::time_t time = std::time(nullptr)) | |||||
{ | |||||
JSContext* cx = GetScriptInterface()->GetContext(); | |||||
JSAutoRequest rq(cx); | |||||
JS::RootedValue message(cx); | |||||
GetScriptInterface()->Eval("({})", &message); | |||||
GetScriptInterface()->SetProperty(message, "time", (double)time); | |||||
GetScriptInterface()->SetProperty(message, "type", type); | |||||
GetScriptInterface()->SetProperty(message, "level", level); | |||||
if (!prop1.empty()) | |||||
GetScriptInterface()->SetProperty(message, prop1.c_str(), val1); | |||||
if (!prop2.empty()) | |||||
GetScriptInterface()->SetProperty(message, prop2.c_str(), val2); | |||||
m_GuiMessageQueue.push_back(JS::Heap<JS::Value>(message)); | |||||
} | |||||
#define CREATE_GUI_MESSAGE_SYSTEM(level) \ | |||||
CreateGUIMessage("system", level); | |||||
#define CREATE_GUI_MESSAGE_ERROR(text) \ | |||||
CreateGUIMessage("system", "error", "text", text); | |||||
#define CREATE_GUI_MESSAGE_GAME(level) \ | |||||
CreateGUIMessage("game", level); | |||||
#define CREATE_GUI_MESSAGE_CHAT(msg, priv) \ | |||||
CreateGUIMessage( \ | |||||
"chat", \ | |||||
priv ? "private-message" : "room-message", \ | |||||
"from", msg.from().resource().to_string(), \ | |||||
"text", msg.body().to_string(), \ | |||||
ComputeTimestamp(msg)); | |||||
/***************************************************** | /***************************************************** | ||||
* Connection handlers * | * Connection handlers * | ||||
*****************************************************/ | *****************************************************/ | ||||
/** | /** | ||||
* Handle connection | * Handle connection | ||||
*/ | */ | ||||
void XmppClient::onConnect() | void XmppClient::onConnect() | ||||
{ | { | ||||
if (m_mucRoom) | if (m_mucRoom) | ||||
{ | { | ||||
CreateGUIMessage("system", "connected"); | CREATE_GUI_MESSAGE_SYSTEM("connected"); | ||||
m_mucRoom->join(); | m_mucRoom->join(); | ||||
} | } | ||||
if (m_registration) | if (m_registration) | ||||
m_registration->fetchRegistrationFields(); | m_registration->fetchRegistrationFields(); | ||||
} | } | ||||
/** | /** | ||||
Show All 13 Lines | 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); | ||||
m_BoardList.clear(); | m_BoardList.clear(); | ||||
m_GameList.clear(); | m_GameList.clear(); | ||||
m_PlayerMap.clear(); | m_PlayerMap.clear(); | ||||
m_Profile.clear(); | m_Profile.clear(); | ||||
CreateGUIMessage("system", "disconnected", ConnectionErrorToString(error)); | CreateGUIMessage("system", "disconnected", "reason", ConnectionErrorToString(error)); | ||||
} | } | ||||
/** | /** | ||||
* Handle TLS connection | * Handle TLS connection | ||||
*/ | */ | ||||
bool XmppClient::onTLSConnect(const glooxwrapper::CertInfo& info) | bool XmppClient::onTLSConnect(const glooxwrapper::CertInfo& info) | ||||
{ | { | ||||
UNUSED2(info); | UNUSED2(info); | ||||
Show All 9 Lines | bool XmppClient::onTLSConnect(const glooxwrapper::CertInfo& info) | ||||
return true; | return true; | ||||
} | } | ||||
/** | /** | ||||
* Handle MUC room errors | * Handle MUC room errors | ||||
*/ | */ | ||||
void XmppClient::handleMUCError(glooxwrapper::MUCRoom*, gloox::StanzaError err) | void XmppClient::handleMUCError(glooxwrapper::MUCRoom*, gloox::StanzaError err) | ||||
{ | { | ||||
CreateGUIMessage("system", "error", StanzaErrorToString(err)); | CREATE_GUI_MESSAGE_ERROR(StanzaErrorToString(err)); | ||||
} | } | ||||
/***************************************************** | /***************************************************** | ||||
* Requests to server * | * Requests to server * | ||||
*****************************************************/ | *****************************************************/ | ||||
/** | /** | ||||
* Request the leaderboard data from the server. | * Request the leaderboard data from the server. | ||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | void XmppClient::handleRegistrationFields(const glooxwrapper::JID&, int fields, glooxwrapper::string) | ||||
vals.username = m_username; | vals.username = m_username; | ||||
vals.password = m_password; | vals.password = m_password; | ||||
m_registration->createAccount(fields, vals); | m_registration->createAccount(fields, vals); | ||||
} | } | ||||
void XmppClient::handleRegistrationResult(const glooxwrapper::JID&, gloox::RegistrationResult result) | void XmppClient::handleRegistrationResult(const glooxwrapper::JID&, gloox::RegistrationResult result) | ||||
{ | { | ||||
if (result == gloox::RegistrationSuccess) | if (result == gloox::RegistrationSuccess) | ||||
CreateGUIMessage("system", "registered"); | CREATE_GUI_MESSAGE_SYSTEM("registered") | ||||
else | else | ||||
CreateGUIMessage("system", "error", RegistrationResultToString(result)); | CREATE_GUI_MESSAGE_ERROR(RegistrationResultToString(result)) | ||||
disconnect(); | disconnect(); | ||||
} | } | ||||
void XmppClient::handleAlreadyRegistered(const glooxwrapper::JID&) | void XmppClient::handleAlreadyRegistered(const glooxwrapper::JID&) | ||||
{ | { | ||||
DbgXMPP("the account already exists"); | DbgXMPP("the account already exists"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | |||||
void XmppClient::GuiPollMessage(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) | void XmppClient::GuiPollMessage(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) | ||||
{ | { | ||||
if (m_GuiMessageQueue.empty()) | if (m_GuiMessageQueue.empty()) | ||||
{ | { | ||||
ret.setUndefined(); | ret.setUndefined(); | ||||
return; | return; | ||||
} | } | ||||
GUIMessage message = m_GuiMessageQueue.front(); | JSContext* cx = GetScriptInterface()->GetContext(); | ||||
JSContext* cx = scriptInterface.GetContext(); | |||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedValue retVal(cx, m_GuiMessageQueue.front()); | |||||
scriptInterface.Eval("({})", ret); | ret.set(scriptInterface.CloneValueFromOtherContext(*GetScriptInterface(), retVal)); | ||||
scriptInterface.SetProperty(ret, "type", message.type); | |||||
if (!message.from.empty()) | |||||
scriptInterface.SetProperty(ret, "from", message.from); | |||||
if (!message.text.empty()) | |||||
scriptInterface.SetProperty(ret, "text", message.text); | |||||
if (!message.level.empty()) | |||||
scriptInterface.SetProperty(ret, "level", message.level); | |||||
if (!message.data.empty()) | |||||
scriptInterface.SetProperty(ret, "data", message.data); | |||||
scriptInterface.SetProperty(ret, "time", (double)message.time); | |||||
m_GuiMessageQueue.pop_front(); | m_GuiMessageQueue.pop_front(); | ||||
} | } | ||||
/** | /** | ||||
* Send a standard MUC textual message. | * Send a standard MUC textual message. | ||||
*/ | */ | ||||
void XmppClient::SendMUCMessage(const std::string& message) | void XmppClient::SendMUCMessage(const std::string& message) | ||||
{ | { | ||||
m_mucRoom->send(message); | m_mucRoom->send(message); | ||||
} | } | ||||
/** | /** | ||||
* Push a message onto the GUI queue. | |||||
* | |||||
* @param message Message to add to the queue | |||||
*/ | |||||
void XmppClient::PushGuiMessage(XmppClient::GUIMessage message) | |||||
{ | |||||
m_GuiMessageQueue.push_back(std::move(message)); | |||||
} | |||||
/** | |||||
* Clears all presence updates from the message queue. | * Clears all presence updates from the message queue. | ||||
* Used when rejoining the lobby, since we don't need to handle past presence changes. | * Used when rejoining the lobby, since we don't need to handle past presence changes. | ||||
*/ | */ | ||||
void XmppClient::ClearPresenceUpdates() | void XmppClient::ClearPresenceUpdates() | ||||
{ | { | ||||
m_GuiMessageQueue.erase( | JSContext* cx = GetScriptInterface()->GetContext(); | ||||
std::remove_if(m_GuiMessageQueue.begin(), m_GuiMessageQueue.end(), | JSAutoRequest rq(cx); | ||||
[](XmppClient::GUIMessage& message) | |||||
for (std::deque<JS::Heap<JS::Value>>::iterator message = m_GuiMessageQueue.begin(); message != m_GuiMessageQueue.end(); ) | |||||
{ | { | ||||
return message.type == L"chat" && message.level == L"presence"; | JS::RootedValue messageVal(cx, message->get()); | ||||
std::string type, level; | |||||
if (GetScriptInterface()->HasProperty(messageVal, "type") && | |||||
GetScriptInterface()->HasProperty(messageVal, "level") && | |||||
GetScriptInterface()->GetProperty(messageVal, "type", type) && | |||||
GetScriptInterface()->GetProperty(messageVal, "level", level) && | |||||
type == "chat" && level == "presence") | |||||
message = m_GuiMessageQueue.erase(message); | |||||
else | |||||
++message; | |||||
} | } | ||||
), 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()); | ||||
CREATE_GUI_MESSAGE_CHAT(msg, priv); | |||||
GUIMessage message; | |||||
message.type = L"chat"; | |||||
message.level = priv ? L"private-message" : L"room-message"; | |||||
message.from = wstring_from_utf8(msg.from().resource().to_string()); | |||||
message.text = wstring_from_utf8(msg.body().to_string()); | |||||
message.time = ComputeTimestamp(msg); | |||||
PushGuiMessage(message); | |||||
} | } | ||||
/** | /** | ||||
* 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()); | ||||
CREATE_GUI_MESSAGE_CHAT(msg, true); | |||||
GUIMessage message; | |||||
message.type = L"chat"; | |||||
message.level = L"private-message"; | |||||
message.from = wstring_from_utf8(msg.from().username().to_string()); | |||||
message.text = wstring_from_utf8(msg.body().to_string()); | |||||
message.time = ComputeTimestamp(msg); | |||||
PushGuiMessage(message); | |||||
} | } | ||||
/** | /** | ||||
* 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) | ||||
{ | { | ||||
const GameListQuery* gq = iq.findExtension<GameListQuery>(EXTGAMELISTQUERY); | const GameListQuery* gq = iq.findExtension<GameListQuery>(EXTGAMELISTQUERY); | ||||
const BoardListQuery* bq = iq.findExtension<BoardListQuery>(EXTBOARDLISTQUERY); | const BoardListQuery* bq = iq.findExtension<BoardListQuery>(EXTBOARDLISTQUERY); | ||||
const ProfileQuery* pq = iq.findExtension<ProfileQuery>(EXTPROFILEQUERY); | const ProfileQuery* pq = iq.findExtension<ProfileQuery>(EXTPROFILEQUERY); | ||||
if (gq) | if (gq) | ||||
{ | { | ||||
for (const glooxwrapper::Tag* const& t : m_GameList) | for (const glooxwrapper::Tag* const& t : m_GameList) | ||||
glooxwrapper::Tag::free(t); | glooxwrapper::Tag::free(t); | ||||
m_GameList.clear(); | m_GameList.clear(); | ||||
for (const glooxwrapper::Tag* const& t : gq->m_GameList) | for (const glooxwrapper::Tag* const& t : gq->m_GameList) | ||||
m_GameList.emplace_back(t->clone()); | m_GameList.emplace_back(t->clone()); | ||||
CreateGUIMessage("game", "gamelist"); | CREATE_GUI_MESSAGE_GAME("gamelist"); | ||||
} | } | ||||
if (bq) | if (bq) | ||||
{ | { | ||||
if (bq->m_Command == "boardlist") | if (bq->m_Command == "boardlist") | ||||
{ | { | ||||
for (const glooxwrapper::Tag* const& t : m_BoardList) | for (const glooxwrapper::Tag* const& t : m_BoardList) | ||||
glooxwrapper::Tag::free(t); | glooxwrapper::Tag::free(t); | ||||
m_BoardList.clear(); | m_BoardList.clear(); | ||||
for (const glooxwrapper::Tag* const& t : bq->m_StanzaBoardList) | for (const glooxwrapper::Tag* const& t : bq->m_StanzaBoardList) | ||||
m_BoardList.emplace_back(t->clone()); | m_BoardList.emplace_back(t->clone()); | ||||
CreateGUIMessage("game", "leaderboard"); | CREATE_GUI_MESSAGE_GAME("leaderboard"); | ||||
} | } | ||||
else if (bq->m_Command == "ratinglist") | else if (bq->m_Command == "ratinglist") | ||||
{ | { | ||||
for (const glooxwrapper::Tag* const& t : bq->m_StanzaBoardList) | for (const glooxwrapper::Tag* const& t : bq->m_StanzaBoardList) | ||||
{ | { | ||||
std::string name = t->findAttribute("name").to_string(); | std::string name = t->findAttribute("name").to_string(); | ||||
if (m_PlayerMap.find(name) != m_PlayerMap.end()) | if (m_PlayerMap.find(name) != m_PlayerMap.end()) | ||||
m_PlayerMap[name][1] = t->findAttribute("rating").to_string(); | m_PlayerMap[name][1] = t->findAttribute("rating").to_string(); | ||||
} | } | ||||
CreateGUIMessage("game", "ratinglist"); | CREATE_GUI_MESSAGE_GAME("ratinglist"); | ||||
} | } | ||||
} | } | ||||
if (pq) | if (pq) | ||||
{ | { | ||||
for (const glooxwrapper::Tag* const& t : m_Profile) | for (const glooxwrapper::Tag* const& t : m_Profile) | ||||
glooxwrapper::Tag::free(t); | glooxwrapper::Tag::free(t); | ||||
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"); | CREATE_GUI_MESSAGE_GAME("profile"); | ||||
} | } | ||||
} | } | ||||
else if (iq.subtype() == gloox::IQ::Error) | else if (iq.subtype() == gloox::IQ::Error) | ||||
{ | { | ||||
gloox::StanzaError err = iq.error_error(); | CREATE_GUI_MESSAGE_ERROR(StanzaErrorToString(iq.error_error())); | ||||
CreateGUIMessage("system", "error", StanzaErrorToString(err)); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
CreateGUIMessage("system", "error", g_L10n.Translate("unknown subtype (see logs)")); | CREATE_GUI_MESSAGE_ERROR(g_L10n.Translate("unknown subtype (see logs)")); | ||||
std::string tag = tag_name(iq); | LOGMESSAGE("unknown subtype '%s'", tag_name(iq).c_str()); | ||||
LOGMESSAGE("unknown subtype '%s'", tag.c_str()); | |||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
/** | |||||
* Create a new detail message for the GUI. | |||||
* | |||||
* @param type General message type | |||||
* @param level Detailed message type | |||||
* @param text Body of the message | |||||
* @param data Optional field, used for auxiliary data | |||||
*/ | |||||
void XmppClient::CreateGUIMessage(const std::string& type, const std::string& level, const std::string& text, const std::string& data) | |||||
{ | |||||
GUIMessage message; | |||||
message.type = wstring_from_utf8(type); | |||||
message.level = wstring_from_utf8(level); | |||||
message.text = wstring_from_utf8(text); | |||||
message.data = wstring_from_utf8(data); | |||||
message.time = std::time(nullptr); | |||||
PushGuiMessage(message); | |||||
} | |||||
/***************************************************** | /***************************************************** | ||||
* Presence, nickname, and subject * | * Presence, nickname, and subject * | ||||
*****************************************************/ | *****************************************************/ | ||||
/** | /** | ||||
* Update local data when a user changes presence. | * Update local data when a user changes presence. | ||||
*/ | */ | ||||
void XmppClient::handleMUCParticipantPresence(glooxwrapper::MUCRoom*, const glooxwrapper::MUCRoomParticipant participant, const glooxwrapper::Presence& presence) | void XmppClient::handleMUCParticipantPresence(glooxwrapper::MUCRoom*, const glooxwrapper::MUCRoomParticipant participant, const glooxwrapper::Presence& presence) | ||||
{ | { | ||||
std::string nick = participant.nick->resource().to_string(); | std::string nick = participant.nick->resource().to_string(); | ||||
gloox::Presence::PresenceType presenceType = presence.presence(); | gloox::Presence::PresenceType presenceType = presence.presence(); | ||||
std::string presenceString, roleString; | std::string presenceString, roleString; | ||||
GetPresenceString(presenceType, presenceString); | GetPresenceString(presenceType, presenceString); | ||||
GetRoleString(participant.role, roleString); | GetRoleString(participant.role, roleString); | ||||
if (presenceType == gloox::Presence::Unavailable) | if (presenceType == gloox::Presence::Unavailable) | ||||
{ | { | ||||
if (!participant.newNick.empty() && (participant.flags & (gloox::UserNickChanged | gloox::UserSelf))) | if (!participant.newNick.empty() && (participant.flags & (gloox::UserNickChanged | gloox::UserSelf))) | ||||
{ | { | ||||
// we have a nick change | // we have a nick change | ||||
std::string newNick = participant.newNick.to_string(); | std::string newNick = participant.newNick.to_string(); | ||||
m_PlayerMap[newNick].resize(3); | m_PlayerMap[newNick].resize(3); | ||||
m_PlayerMap[newNick][0] = presenceString; | m_PlayerMap[newNick][0] = presenceString; | ||||
m_PlayerMap[newNick][2] = roleString; | m_PlayerMap[newNick][2] = roleString; | ||||
CreateGUIMessage("chat", "nick", nick, participant.newNick.to_string()); | |||||
DbgXMPP(nick << " is now known as " << participant.newNick.to_string()); | DbgXMPP(nick << " is now known as " << participant.newNick.to_string()); | ||||
CreateGUIMessage("chat", "nick", "oldnick", nick, "newnick", participant.newNick.to_string()); | |||||
} | } | ||||
else if (participant.flags & gloox::UserKicked) | else if (participant.flags & gloox::UserKicked) | ||||
{ | { | ||||
DbgXMPP(nick << " was kicked. Reason: " << participant.reason.to_string()); | DbgXMPP(nick << " was kicked. Reason: " << participant.reason.to_string()); | ||||
CreateGUIMessage("chat", "kicked", nick, participant.reason.to_string()); | CreateGUIMessage("chat", "kicked", "nick", nick, "reason", participant.reason.to_string()); | ||||
} | } | ||||
else if (participant.flags & gloox::UserBanned) | else if (participant.flags & gloox::UserBanned) | ||||
{ | { | ||||
DbgXMPP(nick << " was banned. Reason: " << participant.reason.to_string()); | DbgXMPP(nick << " was banned. Reason: " << participant.reason.to_string()); | ||||
CreateGUIMessage("chat", "banned", nick, participant.reason.to_string()); | CreateGUIMessage("chat", "banned", "nick", nick, "reason", participant.reason.to_string()); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
DbgXMPP(nick << " left the room (flags " << participant.flags << ")"); | DbgXMPP(nick << " left the room (flags " << participant.flags << ")"); | ||||
CreateGUIMessage("chat", "leave", nick); | CreateGUIMessage("chat", "leave", "nick", nick); | ||||
} | } | ||||
m_PlayerMap.erase(nick); | m_PlayerMap.erase(nick); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
/* During the initialization process, we recieve join messages for everyone | /* During the initialization process, we recieve join messages for everyone | ||||
* currently in the room. We don't want to display these, so we filter them | * currently in the room. We don't want to display these, so we filter them | ||||
* out. We will always be the last to join during initialization. | * out. We will always be the last to join during initialization. | ||||
*/ | */ | ||||
if (!m_initialLoadComplete) | if (!m_initialLoadComplete) | ||||
{ | { | ||||
if (m_mucRoom->nick().to_string() == nick) | if (m_mucRoom->nick().to_string() == nick) | ||||
m_initialLoadComplete = true; | m_initialLoadComplete = true; | ||||
} | } | ||||
else if (m_PlayerMap.find(nick) == m_PlayerMap.end()) | else if (m_PlayerMap.find(nick) == m_PlayerMap.end()) | ||||
CreateGUIMessage("chat", "join", nick); | CreateGUIMessage("chat", "join", "nick", nick); | ||||
else if (m_PlayerMap[nick][2] != roleString) | else if (m_PlayerMap[nick][2] != roleString) | ||||
CreateGUIMessage("chat", "role", nick, m_PlayerMap[nick][2]); | CreateGUIMessage("chat", "role", "nick", nick, "role", m_PlayerMap[nick][2]); | ||||
else | else | ||||
CreateGUIMessage("chat", "presence", nick); | CreateGUIMessage("chat", "presence", "nick", nick); | ||||
DbgXMPP(nick << " is in the room, presence : " << (int)presenceType); | DbgXMPP(nick << " is in the room, presence : " << (int)presenceType); | ||||
m_PlayerMap[nick].resize(3); | m_PlayerMap[nick].resize(3); | ||||
m_PlayerMap[nick][0] = presenceString; | m_PlayerMap[nick][0] = presenceString; | ||||
m_PlayerMap[nick][2] = roleString; | m_PlayerMap[nick][2] = roleString; | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Update local cache when subject changes. | * Update local cache when subject changes. | ||||
*/ | */ | ||||
void XmppClient::handleMUCSubject(glooxwrapper::MUCRoom*, const glooxwrapper::string& UNUSED(nick), const glooxwrapper::string& subject) | void XmppClient::handleMUCSubject(glooxwrapper::MUCRoom*, const glooxwrapper::string& UNUSED(nick), const glooxwrapper::string& subject) | ||||
{ | { | ||||
m_Subject = subject.c_str(); | m_Subject = subject.c_str(); | ||||
CreateGUIMessage("chat", "subject", m_Subject); | CreateGUIMessage("chat", "subject", "subject", m_Subject); | ||||
} | } | ||||
/** | /** | ||||
* Get current subject. | * Get current subject. | ||||
* | * | ||||
* @param topic Variable to store subject in. | * @param topic Variable to store subject in. | ||||
*/ | */ | ||||
void XmppClient::GetSubject(std::string& subject) | void XmppClient::GetSubject(std::string& subject) | ||||
▲ Show 20 Lines • Show All 299 Lines • ▼ Show 20 Lines | void XmppClient::handleSessionInitiation(const glooxwrapper::Jingle::Session::Jingle* jingle) | ||||
if (candidate.ip.empty()) | if (candidate.ip.empty()) | ||||
{ | { | ||||
LOGERROR("Failed to retrieve Jingle candidate"); | LOGERROR("Failed to retrieve Jingle candidate"); | ||||
return; | return; | ||||
} | } | ||||
g_NetServer->SendHolePunchingMessage(candidate.ip.to_string(), candidate.port); | g_NetServer->SendHolePunchingMessage(candidate.ip.to_string(), candidate.port); | ||||
} | } | ||||
#undef CREATE_GUI_MESSAGE_SYSTEM | |||||
#undef CREATE_GUI_MESSAGE_ERROR | |||||
#undef CREATE_GUI_MESSAGE_GAME | |||||
#undef CREATE_GUI_MESSAGE_CHAT |
Wildfire Games · Phabricator