faluco@1127: /** faluco@1127: * adminhelp.sp faluco@1127: * Displays and searches SourceMod commands and descriptions. faluco@1127: * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC faluco@1127: * faluco@1127: * This program is free software; you can redistribute it and/or faluco@1127: * modify it under the terms of the GNU General Public License faluco@1127: * as published by the Free Software Foundation; either version 2 faluco@1127: * of the License, or (at your option) any later version. faluco@1127: * faluco@1127: * This program is distributed in the hope that it will be useful, faluco@1127: * but WITHOUT ANY WARRANTY; without even the implied warranty of faluco@1127: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the faluco@1127: * GNU General Public License for more details. faluco@1127: * faluco@1127: * You should have received a copy of the GNU General Public License faluco@1127: * along with this program; if not, write to the Free Software faluco@1127: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. faluco@1127: * faluco@1127: * Version: $Id$ faluco@1127: */ faluco@1127: faluco@1127: #pragma semicolon 1 faluco@1127: faluco@1127: #include faluco@1127: faluco@1127: #define COMMANDS_PER_PAGE 10 faluco@1127: faluco@1127: public Plugin:myinfo = faluco@1127: { faluco@1127: name = "Admin Help", faluco@1127: author = "AlliedModders LLC", faluco@1127: description = "Display command information", faluco@1127: version = SOURCEMOD_VERSION, faluco@1127: url = "http://www.sourcemod.net/" faluco@1127: }; faluco@1127: faluco@1127: public OnPluginStart() faluco@1127: { faluco@1127: LoadTranslations("common.phrases"); faluco@1127: LoadTranslations("plugin.adminhelp"); faluco@1127: RegConsoleCmd("sm_help", HelpCmd, "Displays SourceMod commands and descriptions"); faluco@1127: RegConsoleCmd("sm_searchcmd", HelpCmd, "Searches SourceMod commands"); faluco@1127: } faluco@1127: faluco@1127: public Action:HelpCmd(client, args) faluco@1127: { faluco@1127: decl String:arg[64], String:CmdName[20]; faluco@1127: new PageNum = 1; faluco@1127: new bool:DoSearch; faluco@1127: faluco@1127: GetCmdArg(0, CmdName, sizeof(CmdName)); faluco@1127: faluco@1127: if (GetCmdArgs() >= 1) faluco@1127: { faluco@1127: GetCmdArg(1, arg, sizeof(arg)); faluco@1127: StringToIntEx(arg, PageNum); faluco@1127: PageNum = (PageNum <= 0) ? 1 : PageNum; faluco@1127: } faluco@1127: faluco@1127: DoSearch = (strcmp("sm_help", CmdName) == 0) ? false : true; faluco@1127: faluco@1127: if (GetCmdReplySource() == SM_REPLY_TO_CHAT) faluco@1127: { faluco@1127: ReplyToCommand(client, "[SM] %t", "See console for output"); faluco@1127: } faluco@1127: faluco@1127: decl String:Name[64]; faluco@1127: decl String:Desc[255]; faluco@1127: decl String:NoDesc[128]; faluco@1127: new Flags; faluco@1127: new Handle:CmdIter = GetCommandIterator(); faluco@1127: faluco@1127: FormatEx(NoDesc, sizeof(NoDesc), "%t", "No description available"); faluco@1127: faluco@1127: if (DoSearch) faluco@1127: { faluco@1127: new i = 1; faluco@1127: while (ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc))) faluco@1127: { faluco@1127: if ((StrContains(Name, arg, false) != -1) && CheckCommandAccess(client, Name, Flags)) faluco@1127: { faluco@1127: PrintToConsole(client, "[%03d] %s - %s", i++, Name, (Desc[0] == '\0') ? NoDesc : Desc); faluco@1127: } faluco@1127: } faluco@1127: faluco@1127: if (i == 1) faluco@1127: { faluco@1127: PrintToConsole(client, "%t", "No matching results found"); faluco@1127: } faluco@1127: } else { faluco@1127: PrintToConsole(client, "%t", "SM help commands"); faluco@1127: faluco@1127: /* Skip the first N commands if we need to */ faluco@1127: if (PageNum > 1) faluco@1127: { faluco@1127: new i; faluco@1127: new EndCmd = (PageNum-1) * COMMANDS_PER_PAGE - 1; faluco@1127: for (i=0; ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && i