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