Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 57 additions & 11 deletions addons/sourcemod/scripting/CustomChatColors.sp
Original file line number Diff line number Diff line change
Expand Up @@ -2209,6 +2209,23 @@ bool HasFlag(int client, AdminFlag ADMFLAG)
return false;
}

// Same flag as sm_tagmenu and the other personal tag commands, and the only one whose personal row is read on join
bool CanCustomizeTag(int client)
{
return HasFlag(client, Admin_Custom1);
}

// Same flags as the "Administrative Options" entry of the main menu (sm_cccreset / sm_cccban: slay, sm_forcetag: cheats)
bool CanUseAdminMenu(int client)
{
return HasFlag(client, Admin_Slay) || HasFlag(client, Admin_Cheats);
}

bool CanUseTagMenu(int client)
{
return CanCustomizeTag(client) || CanUseAdminMenu(client);
}

// CPrintToChat() throws an error for the server console (client 0), reply to the command there instead
void PrintToChatOrReply(int client, const char[] message, any ...)
{
Expand Down Expand Up @@ -3907,27 +3924,42 @@ public void Menu_Main(int client)
if (IsVoteInProgress())
return;

bool bCustomize = CanCustomizeTag(client);
bool bAdmin = CanUseAdminMenu(client);

if (!bCustomize && !bAdmin)
{
CPrintToChat(client, "{green}[{red}C{green}C{blue}C{green}]{default} %t", "CCC_NoTagAccess");
return;
}

Menu MenuMain = new Menu(MenuHandler_Main);
MenuMain.SetTitle("%T", "CCC_Menu_MainTitle", client);

AddMenuItemTranslated(MenuMain, "Current", client, "CCC_Menu_ViewCurrent");
AddMenuItemTranslated(MenuMain, "Tag", client, "CCC_Menu_TagOptions");
AddMenuItemTranslated(MenuMain, "Name", client, "CCC_Menu_NameOptions");
AddMenuItemTranslated(MenuMain, "Chat", client, "CCC_Menu_ChatOptions");
// The personal tag and colors are only loaded back on join for ADMFLAG_CUSTOM1 (OnClientPostAdminCheck):
// don't offer them to anyone else, their changes would be lost on the next map
if (bCustomize)
{
AddMenuItemTranslated(MenuMain, "Current", client, "CCC_Menu_ViewCurrent");
AddMenuItemTranslated(MenuMain, "Tag", client, "CCC_Menu_TagOptions");
AddMenuItemTranslated(MenuMain, "Name", client, "CCC_Menu_NameOptions");
AddMenuItemTranslated(MenuMain, "Chat", client, "CCC_Menu_ChatOptions");

char sBuffer[128], sState[64];
Format(sState, sizeof(sState), "%T", g_iClientEnable[client] ? "CCC_Enabled" : "CCC_Disabled", client);
Format(sBuffer, sizeof(sBuffer), "%T", "CCC_Menu_ColorsAndTag", client, sState);
MenuMain.AddItem("CCC", sBuffer);
char sBuffer[128], sState[64];
Format(sState, sizeof(sState), "%T", g_iClientEnable[client] ? "CCC_Enabled" : "CCC_Disabled", client);
Format(sBuffer, sizeof(sBuffer), "%T", "CCC_Menu_ColorsAndTag", client, sState);
MenuMain.AddItem("CCC", sBuffer);
}

if (g_bWaitingForChatInput[client])
{
AddMenuItemTranslated(MenuMain, "CancelCInput", client, "CCC_Menu_CancelInput");
}

if (HasFlag(client, Admin_Slay) || HasFlag(client, Admin_Cheats))
if (bAdmin)
{
MenuMain.AddItem("", "", ITEMDRAW_SPACER);
if (bCustomize)
MenuMain.AddItem("", "", ITEMDRAW_SPACER);
AddMenuItemTranslated(MenuMain, "Admin", client, "CCC_Menu_AdminOptions");
}

Expand All @@ -3947,6 +3979,19 @@ public int MenuHandler_Main(Menu MenuMain, MenuAction action, int param1, int pa
char Selected[32];
MenuMain.GetItem(param2, Selected, sizeof(Selected));

// The admin flags can change while the menu is open (sm_reloadadmins, expired access)
bool bAllowed;
if (strcmp(Selected, "Admin", false) == 0)
bAllowed = CanUseAdminMenu(param1);
else
bAllowed = strcmp(Selected, "CancelCInput", false) == 0 || CanCustomizeTag(param1);

if (!bAllowed)
{
CPrintToChat(param1, "{green}[{red}C{green}C{blue}C{green}]{default} %t", "CCC_NoTagAccess");
return 0;
}

if (strcmp(Selected, "Tag", false) == 0)
{
Menu_TagPrefs(param1);
Expand Down Expand Up @@ -5065,7 +5110,8 @@ public void ShowSettingsMenu(int client)
Format(sTag, sizeof(sTag), "%T", "CCC_Settings_TagSettings", client);

menu.AddItem("0", sPsay);
menu.AddItem("1", sTag);
// Kept (disabled) when the client cannot use the tag menu, so the item indexes stay stable
menu.AddItem("1", sTag, CanUseTagMenu(client) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED);

menu.ExitBackButton = true;
menu.Display(client, MENU_TIME_FOREVER);
Expand Down
2 changes: 1 addition & 1 deletion addons/sourcemod/scripting/include/ccc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#define CCC_V_MAJOR "8"
#define CCC_V_MINOR "1"
#define CCC_V_PATCH "8"
#define CCC_V_PATCH "9"

#define CCC_VERSION CCC_V_MAJOR..."."...CCC_V_MINOR..."."...CCC_V_PATCH

Expand Down
10 changes: 10 additions & 0 deletions addons/sourcemod/translations/ccc.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,16 @@
"pt" "Configurações de tag"
"chi" "标签设置"
}
"CCC_NoTagAccess"
{
"en" "You do not have access to the custom tag and colors."
"fr" "Vous n'avez pas accès au tag et aux couleurs personnalisés."
"ru" "У вас нет доступа к собственному тегу и цветам."
"es" "No tienes acceso a la etiqueta y los colores personalizados."
"de" "Du hast keinen Zugriff auf den eigenen Tag und die Farben."
"pt" "Você não tem acesso à tag e às cores personalizadas."
"chi" "你没有使用自定义标签和颜色的权限。"
}
"CCC_Enabled"
{
"en" "Enabled"
Expand Down
Loading