forked from lazhoroni/Plugins-for-CSGO-Servers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
basecommands2.sp
423 lines (351 loc) · 10.4 KB
/
basecommands2.sp
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod Basic Commands Plugin
* Implements basic admin commands.
*
* 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 1works) 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>
#undef REQUIRE_PLUGIN
#include <adminmenu>
#pragma newdecls required
public Plugin myinfo =
{
name = "Basic Commands",
author = "AlliedModders LLC",
description = "Basic Admin Commands",
version = SOURCEMOD_VERSION,
url = "http://www.sourcemod.net/"
};
TopMenu hTopMenu;
Menu g_MapList;
StringMap g_ProtectedVars;
#include "basecommands/kick.sp"
#include "basecommands/reloadadmins.sp"
#include "basecommands/cancelvote.sp"
#include "basecommands/who.sp"
#include "basecommands/map.sp"
#include "basecommands/execcfg.sp"
public void OnPluginStart()
{
LoadTranslations("common.phrases");
LoadTranslations("plugin.basecommands");
RegAdminCmd("sm_kick", Command_Kick, ADMFLAG_KICK, "sm_kick <#userid|name> [reason]");
RegAdminCmd("sm_map", Command_Map, ADMFLAG_CHANGEMAP, "sm_map <map>");
RegAdminCmd("sm_rcon", Command_Rcon, ADMFLAG_RCON, "sm_rcon <args>");
RegAdminCmd("sm_cvar", Command_Cvar, ADMFLAG_CONVARS, "sm_cvar <cvar> [value]");
RegAdminCmd("sm_resetcvar", Command_ResetCvar, ADMFLAG_CONVARS, "sm_resetcvar <cvar>");
RegAdminCmd("sm_execcfg", Command_ExecCfg, ADMFLAG_CONFIG, "sm_execcfg <filename>");
RegAdminCmd("sm_who", Command_Who, ADMFLAG_GENERIC, "sm_who [#userid|name]");
RegAdminCmd("sm_reloadadmins", Command_ReloadAdmins, ADMFLAG_BAN, "sm_reloadadmins");
RegAdminCmd("sm_cancelvote", Command_CancelVote, ADMFLAG_VOTE, "sm_cancelvote");
RegConsoleCmd("sm_revote", Command_ReVote);
/* Account for late loading */
TopMenu topmenu;
if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != null))
{
OnAdminMenuReady(topmenu);
}
g_MapList = new Menu(MenuHandler_ChangeMap, MenuAction_Display);
g_MapList.SetTitle("%T", "Please select a map", LANG_SERVER);
g_MapList.ExitBackButton = true;
char mapListPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, mapListPath, sizeof(mapListPath), "configs/adminmenu_maplist.ini");
SetMapListCompatBind("sm_map menu", mapListPath);
g_ProtectedVars = new StringMap();
ProtectVar("rcon_password");
ProtectVar("sm_show_activity");
ProtectVar("sm_immunity_mode");
}
public void OnMapStart()
{
ParseConfigs();
}
public void OnConfigsExecuted()
{
LoadMapList(g_MapList);
}
void ProtectVar(const char[] cvar)
{
g_ProtectedVars.SetValue(cvar, 1);
}
bool IsVarProtected(const char[] cvar)
{
int dummy_value;
return g_ProtectedVars.GetValue(cvar, dummy_value);
}
bool IsClientAllowedToChangeCvar(int client, const char[] cvarname)
{
ConVar hndl = FindConVar(cvarname);
bool allowed = false;
int client_flags = client == 0 ? ADMFLAG_ROOT : GetUserFlagBits(client);
if (client_flags & ADMFLAG_ROOT)
{
allowed = true;
}
else
{
if (hndl.Flags & FCVAR_PROTECTED)
{
allowed = ((client_flags & ADMFLAG_PASSWORD) == ADMFLAG_PASSWORD);
}
else if (StrEqual(cvarname, "sv_cheats"))
{
allowed = ((client_flags & ADMFLAG_CHEATS) == ADMFLAG_CHEATS);
}
else if (!IsVarProtected(cvarname))
{
allowed = true;
}
}
return allowed;
}
public void OnAdminMenuReady(Handle aTopMenu)
{
TopMenu topmenu = TopMenu.FromHandle(aTopMenu);
/* Block us from being called twice */
if (topmenu == hTopMenu)
{
return;
}
/* Save the Handle */
hTopMenu = topmenu;
/* Build the "Player Commands" category */
TopMenuObject player_commands = hTopMenu.FindCategory(ADMINMENU_PLAYERCOMMANDS);
if (player_commands != INVALID_TOPMENUOBJECT)
{
hTopMenu.AddItem("sm_kick", AdminMenu_Kick, player_commands, "sm_kick", ADMFLAG_KICK);
hTopMenu.AddItem("sm_who", AdminMenu_Who, player_commands, "sm_who", ADMFLAG_GENERIC);
}
TopMenuObject server_commands = hTopMenu.FindCategory(ADMINMENU_SERVERCOMMANDS);
if (server_commands != INVALID_TOPMENUOBJECT)
{
hTopMenu.AddItem("sm_reloadadmins", AdminMenu_ReloadAdmins, server_commands, "sm_reloadadmins", ADMFLAG_BAN);
hTopMenu.AddItem("sm_map", AdminMenu_Map, server_commands, "sm_map", ADMFLAG_CHANGEMAP);
hTopMenu.AddItem("sm_execcfg", AdminMenu_ExecCFG, server_commands, "sm_execcfg", ADMFLAG_CONFIG);
}
TopMenuObject voting_commands = hTopMenu.FindCategory(ADMINMENU_VOTINGCOMMANDS);
if (voting_commands != INVALID_TOPMENUOBJECT)
{
hTopMenu.AddItem("sm_cancelvote", AdminMenu_CancelVote, voting_commands, "sm_cancelvote", ADMFLAG_VOTE);
}
}
public void OnLibraryRemoved(const char[] name)
{
if (strcmp(name, "adminmenu") == 0)
{
hTopMenu = null;
}
}
#define FLAG_STRINGS 14
char g_FlagNames[FLAG_STRINGS][20] =
{
"res",
"admin",
"kick",
"ban",
"unban",
"slay",
"map",
"cvars",
"cfg",
"chat",
"vote",
"pass",
"rcon",
"cheat"
};
int CustomFlagsToString(char[] buffer, int maxlength, int flags)
{
char joins[6][6];
int total;
for (int i=view_as<int>(Admin_Custom1); i<=view_as<int>(Admin_Custom6); i++)
{
if (flags & (1<<i))
{
IntToString(i - view_as<int>(Admin_Custom1) + 1, joins[total++], 6);
}
}
ImplodeStrings(joins, total, ",", buffer, maxlength);
return total;
}
void FlagsToString(char[] buffer, int maxlength, int flags)
{
char joins[FLAG_STRINGS+1][32];
int total;
for (int i=0; i<FLAG_STRINGS; i++)
{
if (flags & (1<<i))
{
strcopy(joins[total++], 32, g_FlagNames[i]);
}
}
char custom_flags[32];
if (CustomFlagsToString(custom_flags, sizeof(custom_flags), flags))
{
Format(joins[total++], 32, "custom(%s)", custom_flags);
}
ImplodeStrings(joins, total, ", ", buffer, maxlength);
}
public Action Command_Cvar(int client, int args)
{
if (args < 1)
{
if (client == 0)
{
ReplyToCommand(client, "[SM] Usage: sm_cvar <cvar|protect> [value]");
}
else
{
ReplyToCommand(client, "[SM] Usage: sm_cvar <cvar> [value]");
}
return Plugin_Handled;
}
char cvarname[64];
GetCmdArg(1, cvarname, sizeof(cvarname));
if (client == 0 && StrEqual(cvarname, "protect"))
{
if (args < 2)
{
ReplyToCommand(client, "[SM] Usage: sm_cvar <protect> <cvar>");
return Plugin_Handled;
}
GetCmdArg(2, cvarname, sizeof(cvarname));
ProtectVar(cvarname);
ReplyToCommand(client, "[SM] %t", "Cvar is now protected", cvarname);
return Plugin_Handled;
}
ConVar hndl = FindConVar(cvarname);
if (hndl == null)
{
ReplyToCommand(client, "[SM] %t", "Unable to find cvar", cvarname);
return Plugin_Handled;
}
if (!IsClientAllowedToChangeCvar(client, cvarname))
{
ReplyToCommand(client, "[SM] %t", "No access to cvar");
return Plugin_Handled;
}
char value[255];
if (args < 2)
{
hndl.GetString(value, sizeof(value));
ReplyToCommand(client, "[SM] %t", "Value of cvar", cvarname, value);
return Plugin_Handled;
}
GetCmdArg(2, value, sizeof(value));
if ((hndl.Flags & FCVAR_PROTECTED) != FCVAR_PROTECTED)
{
ShowActivity2(client, "[SM] ", "%t", "Cvar changed", cvarname, value);
}
else
{
ReplyToCommand(client, "[SM] %t", "Cvar changed", cvarname, value);
}
LogAction(client, -1, "\"%L\" changed cvar (cvar \"%s\") (value \"%s\")", client, cvarname, value);
hndl.SetString(value, true);
return Plugin_Handled;
}
public Action Command_ResetCvar(int client, int args)
{
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_resetcvar <cvar>");
return Plugin_Handled;
}
char cvarname[64];
GetCmdArg(1, cvarname, sizeof(cvarname));
ConVar hndl = FindConVar(cvarname);
if (hndl == null)
{
ReplyToCommand(client, "[SM] %t", "Unable to find cvar", cvarname);
return Plugin_Handled;
}
if (!IsClientAllowedToChangeCvar(client, cvarname))
{
ReplyToCommand(client, "[SM] %t", "No access to cvar");
return Plugin_Handled;
}
hndl.RestoreDefault();
char value[255];
hndl.GetString(value, sizeof(value));
if ((hndl.Flags & FCVAR_PROTECTED) != FCVAR_PROTECTED)
{
ShowActivity2(client, "[SM] ", "%t", "Cvar changed", cvarname, value);
}
else
{
ReplyToCommand(client, "[SM] %t", "Cvar changed", cvarname, value);
}
LogAction(client, -1, "\"%L\" reset cvar (cvar \"%s\") (value \"%s\")", client, cvarname, value);
return Plugin_Handled;
}
public Action Command_Rcon(int client, int args)
{
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_rcon <args>");
return Plugin_Handled;
}
char argstring[255];
GetCmdArgString(argstring, sizeof(argstring));
LogAction(client, -1, "\"%L\" console command (cmdline \"%s\")", client, argstring);
if (client == 0) // They will already see the response in the console.
{
ServerCommand("%s", argstring);
} else {
char responseBuffer[4096];
ServerCommandEx(responseBuffer, sizeof(responseBuffer), "%s", argstring);
ReplyToCommand(client, responseBuffer);
}
return Plugin_Handled;
}
public Action Command_ReVote(int client, int args)
{
if (client == 0)
{
ReplyToCommand(client, "[SM] %t", "Command is in-game only");
return Plugin_Handled;
}
if (!IsVoteInProgress())
{
ReplyToCommand(client, "[SM] %t", "Vote Not In Progress");
return Plugin_Handled;
}
if (!IsClientInVotePool(client))
{
ReplyToCommand(client, "[SM] %t", "Cannot participate in vote");
return Plugin_Handled;
}
if (!RedrawClientVoteMenu(client))
{
ReplyToCommand(client, "[SM] %t", "Cannot change vote");
}
return Plugin_Handled;
}