forked from alliedmodders/sourcemod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasebans.sp
More file actions
395 lines (327 loc) · 9.55 KB
/
basebans.sp
File metadata and controls
395 lines (327 loc) · 9.55 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
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
/**
* 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 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>
#undef REQUIRE_PLUGIN
#include <adminmenu>
#pragma newdecls required
public Plugin myinfo =
{
name = "Basic Ban Commands",
author = "AlliedModders LLC",
description = "Basic Banning Commands",
version = SOURCEMOD_VERSION,
url = "http://www.sourcemod.net/"
};
TopMenu hTopMenu;
enum struct PlayerInfo {
int banTarget;
int banTargetUserId;
int banTime;
int isWaitingForChatReason;
}
PlayerInfo playerinfo[MAXPLAYERS+1];
KeyValues g_hKvBanReasons;
char g_BanReasonsPath[PLATFORM_MAX_PATH];
#include "basebans/ban.sp"
public void OnPluginStart()
{
BuildPath(Path_SM, g_BanReasonsPath, sizeof(g_BanReasonsPath), "configs/banreasons.txt");
LoadBanReasons();
LoadTranslations("common.phrases");
LoadTranslations("basebans.phrases");
LoadTranslations("core.phrases");
RegAdminCmd("sm_ban", Command_Ban, ADMFLAG_BAN, "sm_ban <#userid|name> <minutes|0> [reason]");
RegAdminCmd("sm_unban", Command_Unban, ADMFLAG_UNBAN, "sm_unban <steamid|ip>");
RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_RCON, "sm_addban <time> <steamid> [reason]");
RegAdminCmd("sm_banip", Command_BanIp, ADMFLAG_BAN, "sm_banip <ip|#userid|name> <time> [reason]");
//This to manage custom ban reason messages
RegConsoleCmd("sm_abortban", Command_AbortBan, "sm_abortban");
/* Account for late loading */
TopMenu topmenu;
if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != null))
{
OnAdminMenuReady(topmenu);
}
}
public void OnConfigsExecuted()
{
//(Re-)Load BanReasons
LoadBanReasons();
}
public void OnClientDisconnect(int client)
{
playerinfo[client].isWaitingForChatReason = false;
}
void LoadBanReasons()
{
delete g_hKvBanReasons;
g_hKvBanReasons = new KeyValues("banreasons");
if (g_hKvBanReasons.ImportFromFile(g_BanReasonsPath))
{
char sectionName[255];
if (!g_hKvBanReasons.GetSectionName(sectionName, sizeof(sectionName)))
{
SetFailState("Error in %s: File corrupt or in the wrong format", g_BanReasonsPath);
return;
}
if (strcmp(sectionName, "banreasons") != 0)
{
SetFailState("Error in %s: Couldn't find 'banreasons'", g_BanReasonsPath);
return;
}
//Reset kvHandle
g_hKvBanReasons.Rewind();
} else {
SetFailState("Error in %s: File not found, corrupt or in the wrong format", g_BanReasonsPath);
return;
}
}
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;
/* Find the "Player Commands" category */
TopMenuObject player_commands = hTopMenu.FindCategory(ADMINMENU_PLAYERCOMMANDS);
if (player_commands != INVALID_TOPMENUOBJECT)
{
hTopMenu.AddItem("sm_ban", AdminMenu_Ban, player_commands, "sm_ban", ADMFLAG_BAN);
}
}
public Action Command_BanIp(int client, int args)
{
if (args < 2)
{
ReplyToCommand(client, "[SM] Usage: sm_banip <ip|#userid|name> <time> [reason]");
return Plugin_Handled;
}
int len, next_len;
char Arguments[256];
char arg[50], time[20];
GetCmdArgString(Arguments, sizeof(Arguments));
len = BreakString(Arguments, arg, sizeof(arg));
if ((next_len = BreakString(Arguments[len], time, sizeof(time))) != -1)
{
len += next_len;
}
else
{
len = 0;
Arguments[0] = '\0';
}
if (StrEqual(arg, "0"))
{
ReplyToCommand(client, "[SM] %t", "Cannot ban that IP");
return Plugin_Handled;
}
char target_name[MAX_TARGET_LENGTH];
int target_list[1];
bool tn_is_ml;
int found_client = -1;
if (ProcessTargetString(
arg,
client,
target_list,
1,
COMMAND_FILTER_CONNECTED|COMMAND_FILTER_NO_MULTI,
target_name,
sizeof(target_name),
tn_is_ml) > 0)
{
found_client = target_list[0];
}
bool has_rcon;
if (client == 0 || (client == 1 && !IsDedicatedServer()))
{
has_rcon = true;
}
else
{
AdminId id = GetUserAdmin(client);
has_rcon = (id == INVALID_ADMIN_ID) ? false : GetAdminFlag(id, Admin_RCON);
}
int hit_client = -1;
if (found_client != -1
&& !IsFakeClient(found_client)
&& (has_rcon || CanUserTarget(client, found_client)))
{
GetClientIP(found_client, arg, sizeof(arg));
hit_client = found_client;
}
if (hit_client == -1 && !has_rcon)
{
ReplyToCommand(client, "[SM] %t", "No Access");
return Plugin_Handled;
}
int minutes = StringToInt(time);
LogAction(client,
hit_client,
"\"%L\" added ban (minutes \"%d\") (ip \"%s\") (reason \"%s\")",
client,
minutes,
arg,
Arguments[len]);
ReplyToCommand(client, "[SM] %t", "Ban added");
BanIdentity(arg,
minutes,
BANFLAG_IP,
Arguments[len],
"sm_banip",
client);
if (hit_client != -1)
{
KickClient(hit_client, "Banned: %s", Arguments[len]);
}
return Plugin_Handled;
}
public Action Command_AddBan(int client, int args)
{
if (args < 2)
{
ReplyToCommand(client, "[SM] Usage: sm_addban <time> <steamid> [reason]");
return Plugin_Handled;
}
char arg_string[256];
char time[50];
char authid[50];
GetCmdArgString(arg_string, sizeof(arg_string));
int len, total_len;
/* Get time */
if ((len = BreakString(arg_string, time, sizeof(time))) == -1)
{
ReplyToCommand(client, "[SM] Usage: sm_addban <time> <steamid> [reason]");
return Plugin_Handled;
}
total_len += len;
/* Get steamid */
if ((len = BreakString(arg_string[total_len], authid, sizeof(authid))) != -1)
{
total_len += len;
}
else
{
total_len = 0;
arg_string[0] = '\0';
}
/* Verify steamid */
bool idValid = false;
if (!strncmp(authid, "STEAM_", 6) && authid[7] == ':')
idValid = true;
else if (!strncmp(authid, "[U:", 3))
idValid = true;
if (!idValid)
{
ReplyToCommand(client, "[SM] %t", "Invalid SteamID specified");
return Plugin_Handled;
}
AdminId tid = FindAdminByIdentity("steam", authid);
if (client && !CanAdminTarget(GetUserAdmin(client), tid))
{
ReplyToCommand(client, "[SM] %t", "No Access");
return Plugin_Handled;
}
int minutes = StringToInt(time);
LogAction(client,
-1,
"\"%L\" added ban (minutes \"%d\") (id \"%s\") (reason \"%s\")",
client,
minutes,
authid,
arg_string[total_len]);
BanIdentity(authid,
minutes,
BANFLAG_AUTHID,
arg_string[total_len],
"sm_addban",
client);
ReplyToCommand(client, "[SM] %t", "Ban added");
return Plugin_Handled;
}
public Action Command_Unban(int client, int args)
{
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_unban <steamid|ip>");
return Plugin_Handled;
}
char arg[50];
GetCmdArgString(arg, sizeof(arg));
ReplaceString(arg, sizeof(arg), "\"", "");
int ban_flags;
if (IsCharNumeric(arg[0]))
{
ban_flags |= BANFLAG_IP;
}
else
{
ban_flags |= BANFLAG_AUTHID;
}
LogAction(client, -1, "\"%L\" removed ban (filter \"%s\")", client, arg);
RemoveBan(arg, ban_flags, "sm_unban", client);
ReplyToCommand(client, "[SM] %t", "Removed bans matching", arg);
return Plugin_Handled;
}
public Action Command_AbortBan(int client, int args)
{
if(!CheckCommandAccess(client, "sm_ban", ADMFLAG_BAN))
{
ReplyToCommand(client, "[SM] %t", "No Access");
return Plugin_Handled;
}
if(playerinfo[client].isWaitingForChatReason)
{
playerinfo[client].isWaitingForChatReason = false;
ReplyToCommand(client, "[SM] %t", "AbortBan applied successfully");
}
else
{
ReplyToCommand(client, "[SM] %t", "AbortBan not waiting for custom reason");
}
return Plugin_Handled;
}
public Action OnClientSayCommand(int client, const char[] command, const char[] sArgs)
{
if(playerinfo[client].isWaitingForChatReason && !IsChatTrigger())
{
playerinfo[client].isWaitingForChatReason = false;
PrepareBan(client, playerinfo[client].banTarget, playerinfo[client].banTime, sArgs);
return Plugin_Stop;
}
return Plugin_Continue;
}