1
0
forked from 0ad/0ad

Clientside Lobby support for muted players (visitor role).

Displays a chat message and a notification in the player details to
everyone if someone was muted and
hides the chat input to visitors.

Differential Revision: https://code.wildfiregames.com/D339
Reviewed By: user1
This was SVN commit r19514.
This commit is contained in:
elexis 2017-05-05 01:13:12 +00:00
parent ba37ff9907
commit 76bc9b579a
2 changed files with 45 additions and 3 deletions

View File

@ -53,6 +53,12 @@ const g_PlayerStatuses = {
"unknown": { "color": "178 178 178", "status": translateWithContext("lobby presence", "Unknown") }
};
const g_RoleNames = {
"moderator": translate("Moderator"),
"participant": translate("Player"),
"visitor": translate("Muted Player")
};
/**
* Color for error messages in the chat.
*/
@ -136,6 +142,7 @@ var g_NetMessageTypes = {
for (let button of ["host", "leaderboard", "userprofile", "toggleBuddy"])
Engine.GetGUIObjectByName(button + "Button").enabled = false;
Engine.GetGUIObjectByName("chatInput").hidden = true;
if (!g_Kicked)
addChatMessage({
@ -175,6 +182,40 @@ var g_NetMessageTypes = {
},
"presence": msg => {
},
"role": msg => {
Engine.GetGUIObjectByName("chatInput").hidden = Engine.LobbyGetPlayerRole(g_Username) == "visitor";
let me = g_Username == msg.text;
let role = Engine.LobbyGetPlayerRole(msg.text);
let txt =
role == "visitor" ?
me ?
translate("You have been muted.") :
translate("%(nick)s has been muted.") :
role == "moderator" ?
me ?
translate("You are now a moderator.") :
translate("%(nick)s is now a moderator.") :
msg.data == "visitor" ?
me ?
translate("You have been unmuted.") :
translate("%(nick)s has been unmuted.") :
me ?
translate("You are not a moderator anymore.") :
translate("%(nick)s is not a moderator anymore.");
addChatMessage({
"text": "/special " + sprintf(txt, { "nick": msg.text }),
"isSpecial": true
});
// Update status information if that player is selected
if (g_SelectedPlayer == msg.text)
{
let playersBox = Engine.GetGUIObjectByName("playersBox");
playersBox.selected = playersBox.list.indexOf(g_SelectedPlayer);
}
},
"nick": msg => {
addChatMessage({
"text": "/special " + sprintf(translate("%(oldnick)s is now known as %(newnick)s."), {
@ -657,9 +698,8 @@ function lookupSelectedUserProfile(guiObjectName)
Engine.SendGetProfile(playerName);
let isModerator = Engine.LobbyGetPlayerRole(playerName) == "moderator";
Engine.GetGUIObjectByName("usernameText").caption = playerName;
Engine.GetGUIObjectByName("roleText").caption = isModerator ? translate("Moderator") : translate("Player");
Engine.GetGUIObjectByName("roleText").caption = g_RoleNames[Engine.LobbyGetPlayerRole(playerName)]
Engine.GetGUIObjectByName("rankText").caption = translate("N/A");
Engine.GetGUIObjectByName("highestRatingText").caption = translate("N/A");
Engine.GetGUIObjectByName("totalGamesText").caption = translate("N/A");

View File

@ -751,12 +751,12 @@ void XmppClient::CreateGUIMessage(const std::string& type, const std::string& le
*/
void XmppClient::handleMUCParticipantPresence(glooxwrapper::MUCRoom*, const glooxwrapper::MUCRoomParticipant participant, const glooxwrapper::Presence& presence)
{
//std::string jid = participant.jid->full();
std::string nick = participant.nick->resource().to_string();
gloox::Presence::PresenceType presenceType = presence.presence();
std::string presenceString, roleString;
GetPresenceString(presenceType, presenceString);
GetRoleString(participant.role, roleString);
if (presenceType == gloox::Presence::Unavailable)
{
if (!participant.newNick.empty() && (participant.flags & (gloox::UserNickChanged | gloox::UserSelf)))
@ -800,6 +800,8 @@ void XmppClient::handleMUCParticipantPresence(glooxwrapper::MUCRoom*, const gloo
}
else if (m_PlayerMap.find(nick) == m_PlayerMap.end())
CreateGUIMessage("chat", "join", nick);
else if (m_PlayerMap[nick][2] != roleString)
CreateGUIMessage("chat", "role", nick, m_PlayerMap[nick][2]);
else
CreateGUIMessage("chat", "presence", nick);