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