plugins/adminhelp.sp
changeset 1952 b7aa2b626807
child 2289 44045ead61cd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/adminhelp.sp	Sun Mar 30 07:00:22 2008 +0000
     1.3 @@ -0,0 +1,155 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod Admin Help Plugin
     1.8 + * Displays and searches SourceMod commands and descriptions.
     1.9 + *
    1.10 + * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
    1.11 + * =============================================================================
    1.12 + *
    1.13 + * This program is free software; you can redistribute it and/or modify it under
    1.14 + * the terms of the GNU General Public License, version 3.0, as published by the
    1.15 + * Free Software Foundation.
    1.16 + * 
    1.17 + * This program is distributed in the hope that it will be useful, but WITHOUT
    1.18 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.19 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.20 + * details.
    1.21 + *
    1.22 + * You should have received a copy of the GNU General Public License along with
    1.23 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.24 + *
    1.25 + * As a special exception, AlliedModders LLC gives you permission to link the
    1.26 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.27 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.28 + * by the Valve Corporation.  You must obey the GNU General Public License in
    1.29 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.30 + * this exception to all derivative works.  AlliedModders LLC defines further
    1.31 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.32 + * or <http://www.sourcemod.net/license.php>.
    1.33 + *
    1.34 + * Version: $Id$
    1.35 + */
    1.36 +
    1.37 +#pragma semicolon 1
    1.38 +
    1.39 +#include <sourcemod>
    1.40 +
    1.41 +#define COMMANDS_PER_PAGE	10
    1.42 +
    1.43 +public Plugin:myinfo = 
    1.44 +{
    1.45 +	name = "Admin Help",
    1.46 +	author = "AlliedModders LLC",
    1.47 +	description = "Display command information",
    1.48 +	version = SOURCEMOD_VERSION,
    1.49 +	url = "http://www.sourcemod.net/"
    1.50 +};
    1.51 +
    1.52 +public OnPluginStart()
    1.53 +{
    1.54 +	LoadTranslations("common.phrases");
    1.55 +	LoadTranslations("adminhelp.phrases");
    1.56 +	RegConsoleCmd("sm_help", HelpCmd, "Displays SourceMod commands and descriptions");
    1.57 +	RegConsoleCmd("sm_searchcmd", HelpCmd, "Searches SourceMod commands");
    1.58 +}
    1.59 +
    1.60 +public Action:HelpCmd(client, args)
    1.61 +{
    1.62 +	decl String:arg[64], String:CmdName[20];
    1.63 +	new PageNum = 1;
    1.64 +	new bool:DoSearch;
    1.65 +
    1.66 +	GetCmdArg(0, CmdName, sizeof(CmdName));
    1.67 +
    1.68 +	if (GetCmdArgs() >= 1)
    1.69 +	{
    1.70 +		GetCmdArg(1, arg, sizeof(arg));
    1.71 +		StringToIntEx(arg, PageNum);
    1.72 +		PageNum = (PageNum <= 0) ? 1 : PageNum;
    1.73 +	}
    1.74 +
    1.75 +	DoSearch = (strcmp("sm_help", CmdName) == 0) ? false : true;
    1.76 +
    1.77 +	if (GetCmdReplySource() == SM_REPLY_TO_CHAT)
    1.78 +	{
    1.79 +		ReplyToCommand(client, "[SM] %t", "See console for output");
    1.80 +	}
    1.81 +
    1.82 +	decl String:Name[64];
    1.83 +	decl String:Desc[255];
    1.84 +	decl String:NoDesc[128];
    1.85 +	new Flags;
    1.86 +	new Handle:CmdIter = GetCommandIterator();
    1.87 +
    1.88 +	FormatEx(NoDesc, sizeof(NoDesc), "%t", "No description available");
    1.89 +
    1.90 +	if (DoSearch)
    1.91 +	{
    1.92 +		new i = 1;
    1.93 +		while (ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)))
    1.94 +		{
    1.95 +			if ((StrContains(Name, arg, false) != -1) && CheckCommandAccess(client, Name, Flags))
    1.96 +			{
    1.97 +				PrintToConsole(client, "[%03d] %s - %s", i++, Name, (Desc[0] == '\0') ? NoDesc : Desc);
    1.98 +			}
    1.99 +		}
   1.100 +
   1.101 +		if (i == 1)
   1.102 +		{
   1.103 +			PrintToConsole(client, "%t", "No matching results found");
   1.104 +		}
   1.105 +	} else {
   1.106 +		PrintToConsole(client, "%t", "SM help commands");		
   1.107 +
   1.108 +		/* Skip the first N commands if we need to */
   1.109 +		if (PageNum > 1)
   1.110 +		{
   1.111 +			new i;
   1.112 +			new EndCmd = (PageNum-1) * COMMANDS_PER_PAGE - 1;
   1.113 +			for (i=0; ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && i<EndCmd; )
   1.114 +			{
   1.115 +				if (CheckCommandAccess(client, Name, Flags))
   1.116 +				{
   1.117 +					i++;
   1.118 +				}
   1.119 +			}
   1.120 +
   1.121 +			if (i == 0)
   1.122 +			{
   1.123 +				PrintToConsole(client, "%t", "No commands available");
   1.124 +				CloseHandle(CmdIter);
   1.125 +				return Plugin_Handled;
   1.126 +			}
   1.127 +		}
   1.128 +
   1.129 +		/* Start printing the commands to the client */
   1.130 +		new i;
   1.131 +		new StartCmd = (PageNum-1) * COMMANDS_PER_PAGE;
   1.132 +		for (i=0; ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && i<COMMANDS_PER_PAGE; )
   1.133 +		{
   1.134 +			if (CheckCommandAccess(client, Name, Flags))
   1.135 +			{
   1.136 +				i++;
   1.137 +				PrintToConsole(client, "[%03d] %s - %s", i+StartCmd, Name, (Desc[0] == '\0') ? NoDesc : Desc);
   1.138 +			}
   1.139 +		}
   1.140 +
   1.141 +		if (i == 0)
   1.142 +		{
   1.143 +			PrintToConsole(client, "%t", "No commands available");
   1.144 +		} else {
   1.145 +			PrintToConsole(client, "%t", "Entries n - m in page k", StartCmd+1, i+StartCmd, PageNum);
   1.146 +		}
   1.147 +
   1.148 +		/* Test if there are more commands available */
   1.149 +		if (ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && CheckCommandAccess(client, Name, Flags))
   1.150 +		{
   1.151 +			PrintToConsole(client, "%t", "Type sm_help to see more", PageNum+1);
   1.152 +		}
   1.153 +	}
   1.154 +
   1.155 +	CloseHandle(CmdIter);
   1.156 +
   1.157 +	return Plugin_Handled;
   1.158 +}