faluco@1127: /** ds@1330: * vim: set ts=4 : ds@1330: * ============================================================================= ds@1330: * SourceMod Admin Help Plugin faluco@1127: * Displays and searches SourceMod commands and descriptions. ds@1330: * ds@1330: * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. ds@1330: * ============================================================================= faluco@1127: * ds@1330: * This program is free software; you can redistribute it and/or modify it under ds@1330: * the terms of the GNU General Public License, version 3.0, as published by the ds@1330: * Free Software Foundation. ds@1330: * ds@1330: * This program is distributed in the hope that it will be useful, but WITHOUT ds@1330: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ds@1330: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ds@1330: * details. faluco@1127: * ds@1330: * You should have received a copy of the GNU General Public License along with ds@1330: * this program. If not, see . ds@1330: * ds@1330: * As a special exception, AlliedModders LLC gives you permission to link the ds@1330: * code of this program (as well as its derivative works) to "Half-Life 2," the ds@1330: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software ds@1330: * by the Valve Corporation. You must obey the GNU General Public License in ds@1330: * all respects for all other code used. Additionally, AlliedModders LLC grants ds@1330: * this exception to all derivative works. AlliedModders LLC defines further ds@1330: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), ds@1330: * or . 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"); ferret99gt@1187: LoadTranslations("adminhelp.phrases"); 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