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