1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/adminhelp.sp Mon Jul 16 17:49:18 2007 +0000
1.3 @@ -0,0 +1,144 @@
1.4 +/**
1.5 + * adminhelp.sp
1.6 + * Displays and searches SourceMod commands and descriptions.
1.7 + * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License
1.11 + * as published by the Free Software Foundation; either version 2
1.12 + * of the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1.22 + *
1.23 + * Version: $Id$
1.24 + */
1.25 +
1.26 +#pragma semicolon 1
1.27 +
1.28 +#include <sourcemod>
1.29 +
1.30 +#define COMMANDS_PER_PAGE 10
1.31 +
1.32 +public Plugin:myinfo =
1.33 +{
1.34 + name = "Admin Help",
1.35 + author = "AlliedModders LLC",
1.36 + description = "Display command information",
1.37 + version = SOURCEMOD_VERSION,
1.38 + url = "http://www.sourcemod.net/"
1.39 +};
1.40 +
1.41 +public OnPluginStart()
1.42 +{
1.43 + LoadTranslations("common.phrases");
1.44 + LoadTranslations("plugin.adminhelp");
1.45 + RegConsoleCmd("sm_help", HelpCmd, "Displays SourceMod commands and descriptions");
1.46 + RegConsoleCmd("sm_searchcmd", HelpCmd, "Searches SourceMod commands");
1.47 +}
1.48 +
1.49 +public Action:HelpCmd(client, args)
1.50 +{
1.51 + decl String:arg[64], String:CmdName[20];
1.52 + new PageNum = 1;
1.53 + new bool:DoSearch;
1.54 +
1.55 + GetCmdArg(0, CmdName, sizeof(CmdName));
1.56 +
1.57 + if (GetCmdArgs() >= 1)
1.58 + {
1.59 + GetCmdArg(1, arg, sizeof(arg));
1.60 + StringToIntEx(arg, PageNum);
1.61 + PageNum = (PageNum <= 0) ? 1 : PageNum;
1.62 + }
1.63 +
1.64 + DoSearch = (strcmp("sm_help", CmdName) == 0) ? false : true;
1.65 +
1.66 + if (GetCmdReplySource() == SM_REPLY_TO_CHAT)
1.67 + {
1.68 + ReplyToCommand(client, "[SM] %t", "See console for output");
1.69 + }
1.70 +
1.71 + decl String:Name[64];
1.72 + decl String:Desc[255];
1.73 + decl String:NoDesc[128];
1.74 + new Flags;
1.75 + new Handle:CmdIter = GetCommandIterator();
1.76 +
1.77 + FormatEx(NoDesc, sizeof(NoDesc), "%t", "No description available");
1.78 +
1.79 + if (DoSearch)
1.80 + {
1.81 + new i = 1;
1.82 + while (ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)))
1.83 + {
1.84 + if ((StrContains(Name, arg, false) != -1) && CheckCommandAccess(client, Name, Flags))
1.85 + {
1.86 + PrintToConsole(client, "[%03d] %s - %s", i++, Name, (Desc[0] == '\0') ? NoDesc : Desc);
1.87 + }
1.88 + }
1.89 +
1.90 + if (i == 1)
1.91 + {
1.92 + PrintToConsole(client, "%t", "No matching results found");
1.93 + }
1.94 + } else {
1.95 + PrintToConsole(client, "%t", "SM help commands");
1.96 +
1.97 + /* Skip the first N commands if we need to */
1.98 + if (PageNum > 1)
1.99 + {
1.100 + new i;
1.101 + new EndCmd = (PageNum-1) * COMMANDS_PER_PAGE - 1;
1.102 + for (i=0; ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && i<EndCmd; )
1.103 + {
1.104 + if (CheckCommandAccess(client, Name, Flags))
1.105 + {
1.106 + i++;
1.107 + }
1.108 + }
1.109 +
1.110 + if (i == 0)
1.111 + {
1.112 + PrintToConsole(client, "%t", "No commands available");
1.113 + CloseHandle(CmdIter);
1.114 + return Plugin_Handled;
1.115 + }
1.116 + }
1.117 +
1.118 + /* Start printing the commands to the client */
1.119 + new i;
1.120 + new StartCmd = (PageNum-1) * COMMANDS_PER_PAGE;
1.121 + for (i=0; ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && i<COMMANDS_PER_PAGE; )
1.122 + {
1.123 + if (CheckCommandAccess(client, Name, Flags))
1.124 + {
1.125 + i++;
1.126 + PrintToConsole(client, "[%03d] %s - %s", i+StartCmd, Name, (Desc[0] == '\0') ? NoDesc : Desc);
1.127 + }
1.128 + }
1.129 +
1.130 + if (i == 0)
1.131 + {
1.132 + PrintToConsole(client, "%t", "No commands available");
1.133 + } else {
1.134 + PrintToConsole(client, "%t", "Entries n - m in page k", StartCmd+1, i+StartCmd, PageNum);
1.135 + }
1.136 +
1.137 + /* Test if there are more commands available */
1.138 + if (ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && CheckCommandAccess(client, Name, Flags))
1.139 + {
1.140 + PrintToConsole(client, "%t", "Type sm_help to see more", PageNum+1);
1.141 + }
1.142 + }
1.143 +
1.144 + CloseHandle(CmdIter);
1.145 +
1.146 + return Plugin_Handled;
1.147 +}