From 180aa5c60daa4d7e4deba33db8498ad3a69c7d99 Mon Sep 17 00:00:00 2001 From: scythetwirler Date: Sat, 12 Apr 2014 23:40:36 +0000 Subject: [PATCH] Makes the moderator prefix visible in the chatbox. This was SVN commit r14922. --- binaries/data/mods/public/gui/lobby/lobby.js | 5 +++++ source/gui/scripting/ScriptFunctions.cpp | 1 + source/lobby/IXmppClient.h | 1 + source/lobby/XmppClient.cpp | 14 ++++++++++++++ source/lobby/XmppClient.h | 1 + source/lobby/scripting/JSInterface_Lobby.cpp | 10 ++++++++++ source/lobby/scripting/JSInterface_Lobby.h | 1 + 7 files changed, 33 insertions(+) diff --git a/binaries/data/mods/public/gui/lobby/lobby.js b/binaries/data/mods/public/gui/lobby/lobby.js index 315107d2c8..1f4104a788 100644 --- a/binaries/data/mods/public/gui/lobby/lobby.js +++ b/binaries/data/mods/public/gui/lobby/lobby.js @@ -681,6 +681,11 @@ function handleSpecialCommand(text) */ function addChatMessage(msg) { + // Display the moderator symbol in the chatbox. + var playerRole = Engine.LobbyGetPlayerRole(msg.from); + if (playerRole == "moderator") + msg.from = g_modPrefix + msg.from; + // Highlight local user's nick if (msg.text.indexOf(g_Name) != -1 && g_Name != msg.from) msg.text = msg.text.replace(new RegExp('\\b' + '\\' + g_Name + '\\b', "g"), colorPlayerName(g_Name)); diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp index b8b50462c8..cc195c00ba 100644 --- a/source/gui/scripting/ScriptFunctions.cpp +++ b/source/gui/scripting/ScriptFunctions.cpp @@ -927,6 +927,7 @@ void GuiScriptingInit(ScriptInterface& scriptInterface) scriptInterface.RegisterFunction("LobbyKick"); scriptInterface.RegisterFunction("LobbyBan"); scriptInterface.RegisterFunction("LobbyGetPlayerPresence"); + scriptInterface.RegisterFunction("LobbyGetPlayerRole"); scriptInterface.RegisterFunction("EncryptPassword"); scriptInterface.RegisterFunction("IsRankedGame"); scriptInterface.RegisterFunction("SetRankedGame"); diff --git a/source/lobby/IXmppClient.h b/source/lobby/IXmppClient.h index ae19e4f557..da2dcbdf3b 100644 --- a/source/lobby/IXmppClient.h +++ b/source/lobby/IXmppClient.h @@ -44,6 +44,7 @@ public: virtual void ban(const std::string& nick, const std::string& reason) = 0; virtual void SetPresence(const std::string& presence) = 0; virtual void GetPresence(const std::string& nickname, std::string& presence) = 0; + virtual void GetRole(const std::string& nickname, std::string& role) = 0; virtual void GetSubject(std::string& subject) = 0; virtual CScriptValRooted GUIGetPlayerList(ScriptInterface& scriptInterface) = 0; diff --git a/source/lobby/XmppClient.cpp b/source/lobby/XmppClient.cpp index b8ac7c2abe..eecd1ad54e 100644 --- a/source/lobby/XmppClient.cpp +++ b/source/lobby/XmppClient.cpp @@ -847,6 +847,20 @@ void XmppClient::GetPresence(const std::string& nick, std::string& presence) presence = "offline"; } +/** + * Get the current xmpp role of the given nick. + * + * @param nick Nickname to look up presence for + * @param role Variable to store the role in + */ +void XmppClient::GetRole(const std::string& nick, std::string& role) +{ + if (m_PlayerMap.find(nick) != m_PlayerMap.end()) + role = m_PlayerMap[nick][2]; + else + role = ""; +} + /***************************************************** * Utilities * *****************************************************/ diff --git a/source/lobby/XmppClient.h b/source/lobby/XmppClient.h index f60dcfed6d..3bcedbb94a 100644 --- a/source/lobby/XmppClient.h +++ b/source/lobby/XmppClient.h @@ -71,6 +71,7 @@ public: void ban(const std::string& nick, const std::string& reason); void SetPresence(const std::string& presence); void GetPresence(const std::string& nickname, std::string& presence); + void GetRole(const std::string& nickname, std::string& role); void GetSubject(std::string& subject); CScriptValRooted GUIGetPlayerList(ScriptInterface& scriptInterface); diff --git a/source/lobby/scripting/JSInterface_Lobby.cpp b/source/lobby/scripting/JSInterface_Lobby.cpp index 5a8d2817f8..d3758f3f97 100644 --- a/source/lobby/scripting/JSInterface_Lobby.cpp +++ b/source/lobby/scripting/JSInterface_Lobby.cpp @@ -228,6 +228,16 @@ std::wstring JSI_Lobby::LobbyGetPlayerPresence(ScriptInterface::CxPrivate* UNUSE return wstring_from_utf8(presence); } +std::wstring JSI_Lobby::LobbyGetPlayerRole(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstring nickname) +{ + if (!g_XmppClient) + return L""; + + std::string role; + g_XmppClient->GetRole(utf8_from_wstring(nickname), role); + return wstring_from_utf8(role); +} + // Non-public secure PBKDF2 hash function with salting and 1,337 iterations std::string JSI_Lobby::EncryptPassword(const std::string& password, const std::string& username) { diff --git a/source/lobby/scripting/JSInterface_Lobby.h b/source/lobby/scripting/JSInterface_Lobby.h index e487bb3906..99fa8d7573 100644 --- a/source/lobby/scripting/JSInterface_Lobby.h +++ b/source/lobby/scripting/JSInterface_Lobby.h @@ -51,6 +51,7 @@ namespace JSI_Lobby void LobbyKick(ScriptInterface::CxPrivate* pCxPrivate, std::wstring nick, std::wstring reason); void LobbyBan(ScriptInterface::CxPrivate* pCxPrivate, std::wstring nick, std::wstring reason); std::wstring LobbyGetPlayerPresence(ScriptInterface::CxPrivate* pCxPrivate, std::wstring nickname); + std::wstring LobbyGetPlayerRole(ScriptInterface::CxPrivate* pCxPrivate, std::wstring nickname); std::wstring LobbyGetRoomSubject(ScriptInterface::CxPrivate* pCxPrivate); // Non-public secure PBKDF2 hash function with salting and 1,337 iterations