plugins/adminhelp.sp
author David Anderson <dvander@alliedmods.net>
Fri Aug 15 05:22:26 2008 +0000 (2008-08-15)
changeset 2226 d10b38524be3
parent 1952 b7aa2b626807
child 2289 44045ead61cd
permissions -rw-r--r--
Landed sourcepawn-1.2. The big changes:

1) JIT compilation/optimization now occurs per-function, and only when functions are first used. We're now officially a whole-method JIT rather than an AOT compiler (albiet, still a simple JIT). This has two implications: Functions are now much better abstracted internally, and loading a plugin is now much less expensive. If a function contains calls to other functions, THOSE functions are only compiled when they're invoked as well.

2) I've removed debug mode. We always show full backtraces now, as there was a very cheap way to implement this which really cleaned up everything. This is great for a number of reasons -- there's less code, the JIT is better designed, we don't need to relocate debug tables, and best of all we no longer have to tell users to enable debug mode at their own expense.
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod Admin Help Plugin
ds@1952
     5
 * Displays and searches SourceMod commands and descriptions.
ds@1952
     6
 *
ds@1952
     7
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     8
 * =============================================================================
ds@1952
     9
 *
ds@1952
    10
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
    11
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    12
 * Free Software Foundation.
ds@1952
    13
 * 
ds@1952
    14
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    16
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    17
 * details.
ds@1952
    18
 *
ds@1952
    19
 * You should have received a copy of the GNU General Public License along with
ds@1952
    20
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    21
 *
ds@1952
    22
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    23
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    24
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    25
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    26
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    27
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    28
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    29
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    30
 *
ds@1952
    31
 * Version: $Id$
ds@1952
    32
 */
ds@1952
    33
ds@1952
    34
#pragma semicolon 1
ds@1952
    35
ds@1952
    36
#include <sourcemod>
ds@1952
    37
ds@1952
    38
#define COMMANDS_PER_PAGE	10
ds@1952
    39
ds@1952
    40
public Plugin:myinfo = 
ds@1952
    41
{
ds@1952
    42
	name = "Admin Help",
ds@1952
    43
	author = "AlliedModders LLC",
ds@1952
    44
	description = "Display command information",
ds@1952
    45
	version = SOURCEMOD_VERSION,
ds@1952
    46
	url = "http://www.sourcemod.net/"
ds@1952
    47
};
ds@1952
    48
ds@1952
    49
public OnPluginStart()
ds@1952
    50
{
ds@1952
    51
	LoadTranslations("common.phrases");
ds@1952
    52
	LoadTranslations("adminhelp.phrases");
ds@1952
    53
	RegConsoleCmd("sm_help", HelpCmd, "Displays SourceMod commands and descriptions");
ds@1952
    54
	RegConsoleCmd("sm_searchcmd", HelpCmd, "Searches SourceMod commands");
ds@1952
    55
}
ds@1952
    56
ds@1952
    57
public Action:HelpCmd(client, args)
ds@1952
    58
{
ds@1952
    59
	decl String:arg[64], String:CmdName[20];
ds@1952
    60
	new PageNum = 1;
ds@1952
    61
	new bool:DoSearch;
ds@1952
    62
ds@1952
    63
	GetCmdArg(0, CmdName, sizeof(CmdName));
ds@1952
    64
ds@1952
    65
	if (GetCmdArgs() >= 1)
ds@1952
    66
	{
ds@1952
    67
		GetCmdArg(1, arg, sizeof(arg));
ds@1952
    68
		StringToIntEx(arg, PageNum);
ds@1952
    69
		PageNum = (PageNum <= 0) ? 1 : PageNum;
ds@1952
    70
	}
ds@1952
    71
ds@1952
    72
	DoSearch = (strcmp("sm_help", CmdName) == 0) ? false : true;
ds@1952
    73
ds@1952
    74
	if (GetCmdReplySource() == SM_REPLY_TO_CHAT)
ds@1952
    75
	{
ds@1952
    76
		ReplyToCommand(client, "[SM] %t", "See console for output");
ds@1952
    77
	}
ds@1952
    78
ds@1952
    79
	decl String:Name[64];
ds@1952
    80
	decl String:Desc[255];
ds@1952
    81
	decl String:NoDesc[128];
ds@1952
    82
	new Flags;
ds@1952
    83
	new Handle:CmdIter = GetCommandIterator();
ds@1952
    84
ds@1952
    85
	FormatEx(NoDesc, sizeof(NoDesc), "%t", "No description available");
ds@1952
    86
ds@1952
    87
	if (DoSearch)
ds@1952
    88
	{
ds@1952
    89
		new i = 1;
ds@1952
    90
		while (ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)))
ds@1952
    91
		{
ds@1952
    92
			if ((StrContains(Name, arg, false) != -1) && CheckCommandAccess(client, Name, Flags))
ds@1952
    93
			{
ds@1952
    94
				PrintToConsole(client, "[%03d] %s - %s", i++, Name, (Desc[0] == '\0') ? NoDesc : Desc);
ds@1952
    95
			}
ds@1952
    96
		}
ds@1952
    97
ds@1952
    98
		if (i == 1)
ds@1952
    99
		{
ds@1952
   100
			PrintToConsole(client, "%t", "No matching results found");
ds@1952
   101
		}
ds@1952
   102
	} else {
ds@1952
   103
		PrintToConsole(client, "%t", "SM help commands");		
ds@1952
   104
ds@1952
   105
		/* Skip the first N commands if we need to */
ds@1952
   106
		if (PageNum > 1)
ds@1952
   107
		{
ds@1952
   108
			new i;
ds@1952
   109
			new EndCmd = (PageNum-1) * COMMANDS_PER_PAGE - 1;
ds@1952
   110
			for (i=0; ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && i<EndCmd; )
ds@1952
   111
			{
ds@1952
   112
				if (CheckCommandAccess(client, Name, Flags))
ds@1952
   113
				{
ds@1952
   114
					i++;
ds@1952
   115
				}
ds@1952
   116
			}
ds@1952
   117
ds@1952
   118
			if (i == 0)
ds@1952
   119
			{
ds@1952
   120
				PrintToConsole(client, "%t", "No commands available");
ds@1952
   121
				CloseHandle(CmdIter);
ds@1952
   122
				return Plugin_Handled;
ds@1952
   123
			}
ds@1952
   124
		}
ds@1952
   125
ds@1952
   126
		/* Start printing the commands to the client */
ds@1952
   127
		new i;
ds@1952
   128
		new StartCmd = (PageNum-1) * COMMANDS_PER_PAGE;
ds@1952
   129
		for (i=0; ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && i<COMMANDS_PER_PAGE; )
ds@1952
   130
		{
ds@1952
   131
			if (CheckCommandAccess(client, Name, Flags))
ds@1952
   132
			{
ds@1952
   133
				i++;
ds@1952
   134
				PrintToConsole(client, "[%03d] %s - %s", i+StartCmd, Name, (Desc[0] == '\0') ? NoDesc : Desc);
ds@1952
   135
			}
ds@1952
   136
		}
ds@1952
   137
ds@1952
   138
		if (i == 0)
ds@1952
   139
		{
ds@1952
   140
			PrintToConsole(client, "%t", "No commands available");
ds@1952
   141
		} else {
ds@1952
   142
			PrintToConsole(client, "%t", "Entries n - m in page k", StartCmd+1, i+StartCmd, PageNum);
ds@1952
   143
		}
ds@1952
   144
ds@1952
   145
		/* Test if there are more commands available */
ds@1952
   146
		if (ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && CheckCommandAccess(client, Name, Flags))
ds@1952
   147
		{
ds@1952
   148
			PrintToConsole(client, "%t", "Type sm_help to see more", PageNum+1);
ds@1952
   149
		}
ds@1952
   150
	}
ds@1952
   151
ds@1952
   152
	CloseHandle(CmdIter);
ds@1952
   153
ds@1952
   154
	return Plugin_Handled;
ds@1952
   155
}