From 3a02db6a1e7004a3813b83e1c0bbdee8f1e496e7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 7 Jun 2007 23:48:51 +0000 Subject: [PATCH] added sm_cvar --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40926 --- plugins/basecommands.sp | 77 ++++++++++++++++++++++++++++ translations/plugin.basecommands.cfg | 25 +++++++++ 2 files changed, 102 insertions(+) create mode 100644 translations/plugin.basecommands.cfg diff --git a/plugins/basecommands.sp b/plugins/basecommands.sp index 21e88c08..32b8625e 100644 --- a/plugins/basecommands.sp +++ b/plugins/basecommands.sp @@ -36,9 +36,86 @@ public Plugin:myinfo = public OnPluginStart() { LoadTranslations("common.cfg"); + LoadTranslations("plugin.basecommands.cfg"); RegAdminCmd("sm_kick", Command_Kick, ADMFLAG_KICK, "sm_kick <#userid|name> [reason]"); RegAdminCmd("sm_map", Command_Map, ADMFLAG_CHANGEMAP, "sm_map "); RegAdminCmd("sm_rcon", Command_Rcon, ADMFLAG_RCON, "sm_rcon "); + RegAdminCmd("sm_cvar", Command_Cvar, ADMFLAG_CONVARS, "sm_cvar [value]"); +} + +public Action:Command_Cvar(client, args) +{ + if (args < 1) + { + ReplyToCommand(client, "[SM] Usage: sm_cvar [value]"); + return Plugin_Handled; + } + + new String:cvarname[33]; + GetCmdArg(1, cvarname, sizeof(cvarname)); + + new Handle:hndl = FindConVar(cvarname); + if (hndl == INVALID_HANDLE) + { + ReplyToCommand(client, "[SM] %t", "Unable to find cvar", cvarname); + return Plugin_Handled; + } + + new bool:allowed = false; + if (GetConVarFlags(hndl) & FCVAR_PROTECTED) + { + /* If they're root, allow anything */ + if ((GetUserFlagBits(client) & ADMFLAG_ROOT) == ADMFLAG_ROOT) + { + allowed = true; + } + /* If they're not root, and getting sv_password, see if they have ADMFLAG_PASSWORD */ + else if (StrEqual(cvarname, "sv_password") && (GetUserFlagBits(client) & ADMFLAG_PASSWORD)) + { + allowed = true; + } + } + /* Do a check for the cheat cvar */ + else if (StrEqual(cvarname, "sv_cheats")) + { + if (GetUserFlagBits(client) & ADMFLAG_CHEATS) + { + allowed = true; + } + } + /* If we drop down to here, it was a normal cvar. */ + else + { + allowed = true; + } + + if (!allowed) + { + ReplyToCommand(client, "[SM] %t", "No access to cvar"); + return Plugin_Handled; + } + + decl String:value[255]; + if (args < 2) + { + GetConVarString(hndl, value, sizeof(value)); + + ReplyToCommand(client, "[SM] %t", "Value of cvar", cvarname, value); + return Plugin_Handled; + } + + GetCmdArg(2, value, sizeof(value)); + + LogMessage("\"%L\" changed cvar (cvar \"%s\") (value \"%s\")", client, cvarname, value); + if ((GetConVarFlags(hndl) & FCVAR_PROTECTED) != FCVAR_PROTECTED) + { + ShowActivity(client, "%t", "Cvar changed", cvarname, value); + } + + SetConVarString(hndl, value); + ReplyToCommand(client, "[SM] %t", "Cvar changed", cvarname, value); + + return Plugin_Handled; } public Action:Command_Rcon(client, args) diff --git a/translations/plugin.basecommands.cfg b/translations/plugin.basecommands.cfg new file mode 100644 index 00000000..0c6b88fb --- /dev/null +++ b/translations/plugin.basecommands.cfg @@ -0,0 +1,25 @@ +"Phrases" +{ + "Unable to find cvar" + { + "#format" "{1:s}" + "en" "Unable to find cvar: {1}" + } + + "No access to cvar" + { + "en" "You do not have access to this cvar." + } + + "Value of cvar" + { + "#format" "{1:s},{2:s}" + "en" "Value of cvar '{1}': '{2}'" + } + + "Cvar changed" + { + "#format" "{1:s},{2:s}" + "en" "Changed cvar '{1}' to '{2}'." + } +}