plugins/adminhelp.sp
author David Anderson <dvander@alliedmods.net>
Fri Jul 27 21:00:50 2007 +0000 (2007-07-27)
changeset 1193 6860e7bd800c
parent 1187 85c0934305bd
child 1330 ab94316bb52b
permissions -rw-r--r--
fixed a bug where HandleSecurity was not initialized properly for the datapack natives
     1 /**
     2  * adminhelp.sp
     3  * Displays and searches SourceMod commands and descriptions.
     4  * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC
     5  *
     6  * This program is free software; you can redistribute it and/or
     7  * modify it under the terms of the GNU General Public License
     8  * as published by the Free Software Foundation; either version 2
     9  * of the License, or (at your option) any later version.
    10  *
    11  * This program is distributed in the hope that it will be useful,
    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  * GNU General Public License for more details.
    15  * 
    16  * You should have received a copy of the GNU General Public License
    17  * along with this program; if not, write to the Free Software
    18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    19  *
    20  * Version: $Id$
    21  */
    22 
    23 #pragma semicolon 1
    24 
    25 #include <sourcemod>
    26 
    27 #define COMMANDS_PER_PAGE	10
    28 
    29 public Plugin:myinfo = 
    30 {
    31 	name = "Admin Help",
    32 	author = "AlliedModders LLC",
    33 	description = "Display command information",
    34 	version = SOURCEMOD_VERSION,
    35 	url = "http://www.sourcemod.net/"
    36 };
    37 
    38 public OnPluginStart()
    39 {
    40 	LoadTranslations("common.phrases");
    41 	LoadTranslations("adminhelp.phrases");
    42 	RegConsoleCmd("sm_help", HelpCmd, "Displays SourceMod commands and descriptions");
    43 	RegConsoleCmd("sm_searchcmd", HelpCmd, "Searches SourceMod commands");
    44 }
    45 
    46 public Action:HelpCmd(client, args)
    47 {
    48 	decl String:arg[64], String:CmdName[20];
    49 	new PageNum = 1;
    50 	new bool:DoSearch;
    51 
    52 	GetCmdArg(0, CmdName, sizeof(CmdName));
    53 
    54 	if (GetCmdArgs() >= 1)
    55 	{
    56 		GetCmdArg(1, arg, sizeof(arg));
    57 		StringToIntEx(arg, PageNum);
    58 		PageNum = (PageNum <= 0) ? 1 : PageNum;
    59 	}
    60 
    61 	DoSearch = (strcmp("sm_help", CmdName) == 0) ? false : true;
    62 
    63 	if (GetCmdReplySource() == SM_REPLY_TO_CHAT)
    64 	{
    65 		ReplyToCommand(client, "[SM] %t", "See console for output");
    66 	}
    67 
    68 	decl String:Name[64];
    69 	decl String:Desc[255];
    70 	decl String:NoDesc[128];
    71 	new Flags;
    72 	new Handle:CmdIter = GetCommandIterator();
    73 
    74 	FormatEx(NoDesc, sizeof(NoDesc), "%t", "No description available");
    75 
    76 	if (DoSearch)
    77 	{
    78 		new i = 1;
    79 		while (ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)))
    80 		{
    81 			if ((StrContains(Name, arg, false) != -1) && CheckCommandAccess(client, Name, Flags))
    82 			{
    83 				PrintToConsole(client, "[%03d] %s - %s", i++, Name, (Desc[0] == '\0') ? NoDesc : Desc);
    84 			}
    85 		}
    86 
    87 		if (i == 1)
    88 		{
    89 			PrintToConsole(client, "%t", "No matching results found");
    90 		}
    91 	} else {
    92 		PrintToConsole(client, "%t", "SM help commands");		
    93 
    94 		/* Skip the first N commands if we need to */
    95 		if (PageNum > 1)
    96 		{
    97 			new i;
    98 			new EndCmd = (PageNum-1) * COMMANDS_PER_PAGE - 1;
    99 			for (i=0; ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && i<EndCmd; )
   100 			{
   101 				if (CheckCommandAccess(client, Name, Flags))
   102 				{
   103 					i++;
   104 				}
   105 			}
   106 
   107 			if (i == 0)
   108 			{
   109 				PrintToConsole(client, "%t", "No commands available");
   110 				CloseHandle(CmdIter);
   111 				return Plugin_Handled;
   112 			}
   113 		}
   114 
   115 		/* Start printing the commands to the client */
   116 		new i;
   117 		new StartCmd = (PageNum-1) * COMMANDS_PER_PAGE;
   118 		for (i=0; ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && i<COMMANDS_PER_PAGE; )
   119 		{
   120 			if (CheckCommandAccess(client, Name, Flags))
   121 			{
   122 				i++;
   123 				PrintToConsole(client, "[%03d] %s - %s", i+StartCmd, Name, (Desc[0] == '\0') ? NoDesc : Desc);
   124 			}
   125 		}
   126 
   127 		if (i == 0)
   128 		{
   129 			PrintToConsole(client, "%t", "No commands available");
   130 		} else {
   131 			PrintToConsole(client, "%t", "Entries n - m in page k", StartCmd+1, i+StartCmd, PageNum);
   132 		}
   133 
   134 		/* Test if there are more commands available */
   135 		if (ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && CheckCommandAccess(client, Name, Flags))
   136 		{
   137 			PrintToConsole(client, "%t", "Type sm_help to see more", PageNum+1);
   138 		}
   139 	}
   140 
   141 	CloseHandle(CmdIter);
   142 
   143 	return Plugin_Handled;
   144 }