Changeset View
Changeset View
Standalone View
Standalone View
source/lobby/XmppClient.cpp
Show All 40 Lines | |||||
#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(); | ||||
ret = tag->xml().to_string(); | ret = tag->xml(); | ||||
glooxwrapper::Tag::free(tag); | glooxwrapper::Tag::free(tag); | ||||
return ret; | return ret; | ||||
} | } | ||||
#endif | #endif | ||||
static std::string tag_name(const glooxwrapper::IQ& iq) | static std::string tag_name(const glooxwrapper::IQ& iq) | ||||
{ | { | ||||
std::string ret; | std::string ret; | ||||
glooxwrapper::Tag* tag = iq.tag(); | glooxwrapper::Tag* tag = iq.tag(); | ||||
ret = tag->name().to_string(); | ret = tag->name(); | ||||
glooxwrapper::Tag::free(tag); | glooxwrapper::Tag::free(tag); | ||||
return ret; | return ret; | ||||
} | } | ||||
IXmppClient* IXmppClient::create(const ScriptInterface* scriptInterface, const std::string& sUsername, const std::string& sPassword, const std::string& sRoom, const std::string& sNick, const int historyRequestSize,bool regOpt) | IXmppClient* IXmppClient::create(const ScriptInterface* scriptInterface, const std::string& sUsername, const std::string& sPassword, const std::string& sRoom, const std::string& sNick, const int historyRequestSize,bool regOpt) | ||||
{ | { | ||||
return new XmppClient(scriptInterface, sUsername, sPassword, sRoom, sNick, historyRequestSize, regOpt); | return new XmppClient(scriptInterface, sUsername, sPassword, sRoom, sNick, historyRequestSize, regOpt); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 795 Lines • ▼ Show 20 Lines | if (pq) | ||||
CreateGUIMessage("game", "profile", std::time(nullptr)); | CreateGUIMessage("game", "profile", std::time(nullptr)); | ||||
} | } | ||||
} | } | ||||
else if (iq.subtype() == gloox::IQ::Set) | else if (iq.subtype() == gloox::IQ::Set) | ||||
{ | { | ||||
const LobbyAuth* lobbyAuth = iq.findExtension<LobbyAuth>(EXTLOBBYAUTH); | const LobbyAuth* lobbyAuth = iq.findExtension<LobbyAuth>(EXTLOBBYAUTH); | ||||
if (lobbyAuth) | if (lobbyAuth) | ||||
{ | { | ||||
LOGMESSAGE("XmppClient: Received lobby auth: %s from %s", lobbyAuth->m_Token.to_string(), iq.from().username()); | LOGMESSAGE("XmppClient: Received lobby auth: %s from %s", lobbyAuth->m_Token.c_str(), iq.from().username()); | ||||
glooxwrapper::IQ response(gloox::IQ::Result, iq.from(), iq.id()); | glooxwrapper::IQ response(gloox::IQ::Result, iq.from(), iq.id()); | ||||
m_client->send(response); | m_client->send(response); | ||||
if (g_NetServer) | if (g_NetServer) | ||||
g_NetServer->OnLobbyAuth(iq.from().username(), lobbyAuth->m_Token.to_string()); | g_NetServer->OnLobbyAuth(iq.from().username(), lobbyAuth->m_Token); | ||||
else | else | ||||
LOGERROR("Received lobby authentication request, but not hosting currently!"); | LOGERROR("Received lobby authentication request, but not hosting currently!"); | ||||
} | } | ||||
} | } | ||||
else if (iq.subtype() == gloox::IQ::Error) | else if (iq.subtype() == gloox::IQ::Error) | ||||
CreateGUIMessage("system", "error", std::time(nullptr), "text", iq.error_error()); | CreateGUIMessage("system", "error", std::time(nullptr), "text", iq.error_error()); | ||||
else | else | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | void XmppClient::handleMUCParticipantPresence(glooxwrapper::MUCRoom& UNUSED(room), const glooxwrapper::MUCRoomParticipant participant, const glooxwrapper::Presence& presence) | ||||
m_PlayerMapUpdate = true; | m_PlayerMapUpdate = true; | ||||
} | } | ||||
/** | /** | ||||
* Update local cache when subject changes. | * Update local cache when subject changes. | ||||
*/ | */ | ||||
void XmppClient::handleMUCSubject(glooxwrapper::MUCRoom& UNUSED(room), const glooxwrapper::string& nick, const glooxwrapper::string& subject) | void XmppClient::handleMUCSubject(glooxwrapper::MUCRoom& UNUSED(room), const glooxwrapper::string& nick, const glooxwrapper::string& subject) | ||||
{ | { | ||||
m_Subject = wstring_from_utf8(subject.to_string()); | m_Subject = wstring_from_utf8(subject); | ||||
CreateGUIMessage( | CreateGUIMessage( | ||||
"chat", | "chat", | ||||
"subject", | "subject", | ||||
std::time(nullptr), | std::time(nullptr), | ||||
"nick", nick, | "nick", nick, | ||||
"subject", m_Subject); | "subject", m_Subject); | ||||
} | } | ||||
Show All 18 Lines | |||||
/** | /** | ||||
* Get current nickname. | * Get current nickname. | ||||
* | * | ||||
* @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(); | ||||
} | } | ||||
/** | /** | ||||
* 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 | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
std::wstring XmppClient::GetRating(const std::string& nick) | std::wstring XmppClient::GetRating(const std::string& nick) | ||||
{ | { | ||||
const PlayerMap::iterator it = m_PlayerMap.find(nick); | const PlayerMap::iterator it = m_PlayerMap.find(nick); | ||||
if (it == m_PlayerMap.end()) | if (it == m_PlayerMap.end()) | ||||
return std::wstring(); | return std::wstring(); | ||||
return wstring_from_utf8(it->second.m_Rating.to_string()); | return wstring_from_utf8(it->second.m_Rating); | ||||
} | } | ||||
/***************************************************** | /***************************************************** | ||||
* Utilities * | * Utilities * | ||||
*****************************************************/ | *****************************************************/ | ||||
/** | /** | ||||
* Parse and return the timestamp of a historic chat message and return the current time for new chat messages. | * Parse and return the timestamp of a historic chat message and return the current time for new chat messages. | ||||
* Historic chat messages are implement as DelayedDelivers as specified in XEP-0203. | * Historic chat messages are implement as DelayedDelivers as specified in XEP-0203. | ||||
* Hence, their timestamp MUST be in UTC and conform to the DateTime format XEP-0082. | * Hence, their timestamp MUST be in UTC and conform to the DateTime format XEP-0082. | ||||
* | * | ||||
* @returns Seconds since the epoch. | * @returns Seconds since the epoch. | ||||
*/ | */ | ||||
std::time_t XmppClient::ComputeTimestamp(const glooxwrapper::Message& msg) | std::time_t XmppClient::ComputeTimestamp(const glooxwrapper::Message& msg) | ||||
{ | { | ||||
// Only historic messages contain a timestamp! | // Only historic messages contain a timestamp! | ||||
if (!msg.when()) | if (!msg.when()) | ||||
return std::time(nullptr); | return std::time(nullptr); | ||||
// The locale is irrelevant, because the XMPP date format doesn't contain written month names | // The locale is irrelevant, because the XMPP date format doesn't contain written month names | ||||
for (const std::string& format : std::vector<std::string>{ "Y-M-d'T'H:m:sZ", "Y-M-d'T'H:m:s.SZ" }) | for (const std::string& format : std::vector<std::string>{ "Y-M-d'T'H:m:sZ", "Y-M-d'T'H:m:s.SZ" }) | ||||
{ | { | ||||
UDate dateTime = g_L10n.ParseDateTime(msg.when()->stamp().to_string(), format, icu::Locale::getUS()); | UDate dateTime = g_L10n.ParseDateTime(msg.when()->stamp(), format, icu::Locale::getUS()); | ||||
if (dateTime) | if (dateTime) | ||||
return dateTime / 1000.0; | return dateTime / 1000.0; | ||||
} | } | ||||
return std::time(nullptr); | return std::time(nullptr); | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | void XmppClient::handleSessionInitiation(glooxwrapper::Jingle::Session& UNUSED(session), const glooxwrapper::Jingle::Session::Jingle& jingle) | ||||
} | } | ||||
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, candidate.port); | ||||
} | } |
Wildfire Games · Phabricator