Makes the moderator prefix visible in the chatbox.

This was SVN commit r14922.
This commit is contained in:
scythetwirler 2014-04-12 23:40:36 +00:00
parent 5a0c1a799b
commit 180aa5c60d
7 changed files with 33 additions and 0 deletions

View File

@ -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));

View File

@ -927,6 +927,7 @@ void GuiScriptingInit(ScriptInterface& scriptInterface)
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::LobbyKick>("LobbyKick");
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::LobbyBan>("LobbyBan");
scriptInterface.RegisterFunction<std::wstring, std::wstring, &JSI_Lobby::LobbyGetPlayerPresence>("LobbyGetPlayerPresence");
scriptInterface.RegisterFunction<std::wstring, std::wstring, &JSI_Lobby::LobbyGetPlayerRole>("LobbyGetPlayerRole");
scriptInterface.RegisterFunction<std::wstring, std::wstring, std::wstring, &JSI_Lobby::EncryptPassword>("EncryptPassword");
scriptInterface.RegisterFunction<bool, &JSI_Lobby::IsRankedGame>("IsRankedGame");
scriptInterface.RegisterFunction<void, bool, &JSI_Lobby::SetRankedGame>("SetRankedGame");

View File

@ -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;

View File

@ -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 *
*****************************************************/

View File

@ -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);

View File

@ -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)
{

View File

@ -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