1.1 --- a/plugins/basecommands.sp Mon Jan 07 22:36:39 2008 +0000
1.2 +++ b/plugins/basecommands.sp Tue Jan 08 03:06:33 2008 +0000
1.3 @@ -49,6 +49,7 @@
1.4 new Handle:hTopMenu = INVALID_HANDLE;
1.5
1.6 new Handle:g_MapList;
1.7 +new Handle:g_ProtectedVars;
1.8
1.9 #include "basecommands/kick.sp"
1.10 #include "basecommands/reloadadmins.sp"
1.11 @@ -85,6 +86,11 @@
1.12 decl String:mapListPath[PLATFORM_MAX_PATH];
1.13 BuildPath(Path_SM, mapListPath, sizeof(mapListPath), "configs/adminmenu_maplist.ini");
1.14 SetMapListCompatBind("sm_map menu", mapListPath);
1.15 +
1.16 + g_ProtectedVars = CreateTrie();
1.17 + ProtectVar("rcon_password");
1.18 + ProtectVar("sm_show_activity");
1.19 + ProtectVar("sm_immunity_mode");
1.20 }
1.21
1.22 public OnMapStart()
1.23 @@ -97,6 +103,17 @@
1.24 LoadMapList(g_MapList);
1.25 }
1.26
1.27 +ProtectVar(const String:cvar[])
1.28 +{
1.29 + SetTrieValue(g_ProtectedVars, cvar, 1);
1.30 +}
1.31 +
1.32 +bool:IsVarProtected(const String:cvar[])
1.33 +{
1.34 + decl dummy_value;
1.35 + return GetTrieValue(g_ProtectedVars, cvar, dummy_value);
1.36 +}
1.37 +
1.38 public OnAdminMenuReady(Handle:topmenu)
1.39 {
1.40 /* Block us from being called twice */
1.41 @@ -244,12 +261,32 @@
1.42 {
1.43 if (args < 1)
1.44 {
1.45 - ReplyToCommand(client, "[SM] Usage: sm_cvar <cvar> [value]");
1.46 + if (client == 0)
1.47 + {
1.48 + ReplyToCommand(client, "[SM] Usage: sm_cvar <cvar|protect> [value]");
1.49 + }
1.50 + else
1.51 + {
1.52 + ReplyToCommand(client, "[SM] Usage: sm_cvar <cvar> [value]");
1.53 + }
1.54 return Plugin_Handled;
1.55 }
1.56
1.57 decl String:cvarname[64];
1.58 GetCmdArg(1, cvarname, sizeof(cvarname));
1.59 +
1.60 + if (client == 0 && StrEqual(cvarname, "protect"))
1.61 + {
1.62 + if (args < 2)
1.63 + {
1.64 + ReplyToCommand(client, "[SM] Usage: sm_cvar <protect> <cvar>");
1.65 + return Plugin_Handled;
1.66 + }
1.67 + GetCmdArg(2, cvarname, sizeof(cvarname));
1.68 + ProtectVar(cvarname);
1.69 + ReplyToCommand(client, "[SM] %t", "Cvar is now protected", cvarname);
1.70 + return Plugin_Handled;
1.71 + }
1.72
1.73 new Handle:hndl = FindConVar(cvarname);
1.74 if (hndl == INVALID_HANDLE)
1.75 @@ -257,36 +294,30 @@
1.76 ReplyToCommand(client, "[SM] %t", "Unable to find cvar", cvarname);
1.77 return Plugin_Handled;
1.78 }
1.79 -
1.80 +
1.81 new bool:allowed = false;
1.82 - if (GetConVarFlags(hndl) & FCVAR_PROTECTED)
1.83 + new client_flags = GetUserFlagBits(client);
1.84 +
1.85 + if (client_flags & ADMFLAG_ROOT)
1.86 + {
1.87 + allowed = true;
1.88 + }
1.89 + else
1.90 {
1.91 - /* If they're root, allow anything */
1.92 - if ((GetUserFlagBits(client) & ADMFLAG_ROOT) == ADMFLAG_ROOT)
1.93 + if (GetConVarFlags(hndl) & FCVAR_PROTECTED)
1.94 {
1.95 - allowed = true;
1.96 + allowed = ((client_flags & ADMFLAG_PASSWORD) == ADMFLAG_PASSWORD);
1.97 }
1.98 - /* If they're not root, and getting sv_password, see if they have ADMFLAG_PASSWORD */
1.99 - else if (StrEqual(cvarname, "sv_password") && (GetUserFlagBits(client) & ADMFLAG_PASSWORD))
1.100 + else if (StrEqual(cvarname, "sv_cheats"))
1.101 + {
1.102 + allowed = ((client_flags & ADMFLAG_CHEATS) == ADMFLAG_CHEATS);
1.103 + }
1.104 + else if (!IsVarProtected(cvarname))
1.105 {
1.106 allowed = true;
1.107 }
1.108 }
1.109 - /* Do a check for the cheat cvar */
1.110 - else if (StrEqual(cvarname, "sv_cheats"))
1.111 - {
1.112 - if (GetUserFlagBits(client) & ADMFLAG_CHEATS
1.113 - || GetUserFlagBits(client) & ADMFLAG_ROOT)
1.114 - {
1.115 - allowed = true;
1.116 - }
1.117 - }
1.118 - /* If we drop down to here, it was a normal cvar. */
1.119 - else
1.120 - {
1.121 - allowed = true;
1.122 - }
1.123 -
1.124 +
1.125 if (!allowed)
1.126 {
1.127 ReplyToCommand(client, "[SM] %t", "No access to cvar");