forked from VANCOLD/fm_drive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FM_ADMIN_BAN.sma
360 lines (297 loc) · 9.69 KB
/
FM_ADMIN_BAN.sma
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
#include "feckinmad/fm_global"
#include "feckinmad/fm_player_get"
#include "feckinmad/fm_admin_api"
#include "feckinmad/fm_admin_access"
#include "feckinmad/fm_ban"
new Array:g_BanList = Invalid_Array
new g_iCurrentBanIdent
new const g_sBanFile[] = "fm_bans.dat"
new g_sBanFilePath[128]
public plugin_init()
{
fm_RegisterPlugin()
g_BanList = fm_CreateBanList()
fm_BuildAMXFilePath(g_sBanFile, g_sBanFilePath, charsmax(g_sBanFilePath), "amxx_datadir")
g_iCurrentBanIdent = fm_ReadBanFile(g_BanList, g_sBanFilePath)
if (g_iCurrentBanIdent > 0)
{
new iPruned = fm_PruneTimedBans(g_BanList)
if (iPruned > 0)
{
fm_WriteBanFile(g_BanList, g_sBanFilePath, g_iCurrentBanIdent)
}
log_amx("Loaded %d bans from \"%s\"", ArraySize(g_BanList), g_sBanFilePath)
register_concmd("admin_ban", "Admin_Ban", ADMIN_MEMBER, "<target|steamid> [length] [reason]")
register_concmd("admin_unban", "Admin_UnBan", ADMIN_MEMBER, "<steamid>")
register_concmd("admin_listbans", "Admin_ListBans", ADMIN_MEMBER)
}
else
{
fm_WarningLog("g_iCurrentBanIdent <= 0 (%d)", g_iCurrentBanIdent)
}
register_concmd("addbansfromtxt", "ReadTempBanTxt")
}
public client_authorized(id)
{
new BanInfo[eBanInfo_t], sAuthid[MAX_AUTHID_LEN]
get_user_authid(id, sAuthid, charsmax(sAuthid))
if (fm_GetBanInfoByAuth(g_BanList, sAuthid, BanInfo) != -1)
{
if (fm_HasTimedBanExpired(BanInfo))
{
fm_RemoveBanByIdent(g_BanList, fm_GetBanIdent(BanInfo))
fm_WriteBanFile(g_BanList, g_sBanFilePath, g_iCurrentBanIdent)
}
else
{
new sLength[64]; fm_FormatBanLength(BanInfo, sLength, charsmax(sLength))
server_cmd("kick #%d \"You are banned %s\"", get_user_userid(id), sLength)
}
}
}
public Admin_ListBans(id, iLevel, iCommand)
{
// Check the user has access
if (!fm_CommandAccess(id, iLevel, true))
{
return PLUGIN_HANDLED
}
// Check and remove expired time bans before listing
if (fm_PruneTimedBans(g_BanList) > 0)
{
fm_WriteBanFile(g_BanList, g_sBanFilePath, g_iCurrentBanIdent)
}
new iCount = ArraySize(g_BanList)
new sArgs[8]; read_args(sArgs, charsmax(sArgs))
new iStart = str_to_num(sArgs) - 1
if (iStart < 0)
{
iStart = 0
}
if (iStart >= iCount)
{
iStart = iCount - 1
}
new iEnd = iStart + 10
if (iEnd > iCount)
{
iEnd = iCount
}
new Buffer[eBanInfo_t], sType[128], AdminInfo[eAdmin_t]
console_print(id, "\n\nCurrent Bans:")
for (new i = iStart; i < iEnd; i++)
{
ArrayGetArray(g_BanList, i, Buffer)
fm_GetAdminInfoByIdent(Buffer[m_iBanAdmin], AdminInfo)
fm_FormatBanType(Buffer, sType, charsmax(sType))
console_print(id, "#%d %s<%s> %s - Admin: #%d %s - Reason: %s", Buffer[m_iBanIdent], Buffer[m_sBanName], Buffer[m_sBanAuthid], sType, Buffer[m_iBanAdmin], AdminInfo[m_sAdminName], Buffer[m_sBanReason])
}
if (iEnd < iCount)
{
console_print(id, "Displaying bans %d to %d. Type \"admin_listbans %d\" for more\n", iStart + 1, iEnd, iEnd + 1)
}
return PLUGIN_HANDLED
}
// admin_unban <steamid>
public Admin_UnBan(id, iLevel, iCommand)
{
// Check the user has access and entered the correct number of parameters
if (!fm_CommandAccess(id, iLevel, true) || !fm_CommandUsage(id, iCommand, 2))
{
return PLUGIN_HANDLED
}
// Check the user entered a steam ID
new sArgs[192]; read_args(sArgs, charsmax(sArgs))
trim(sArgs)
if (!equal(sArgs, "STEAM_", 6))
{
console_print(id, "Please provide a valid steam ID to unban")
return PLUGIN_HANDLED
}
// Check the steam ID has been banned
new BanInfo[eBanInfo_t], iIndex = fm_GetBanInfoByAuth(g_BanList, sArgs, BanInfo)
if (iIndex == -1)
{
console_print(id, "No ban found for \"%s\"", sArgs)
return PLUGIN_HANDLED
}
// Remove the ban from the array and update the ban file
fm_RemoveBanByIndex(g_BanList, iIndex)
fm_WriteBanFile(g_BanList, g_sBanFilePath, g_iCurrentBanIdent)
// Notify user/clients
new sAdminName[MAX_NAME_LEN]; get_user_name(id, sAdminName, charsmax(sAdminName))
new sAdminAuthid[MAX_AUTHID_LEN]; get_user_authid(id, sAdminAuthid, charsmax(sAdminAuthid))
new sAdminRealName[MAX_NAME_LEN]; fm_GetUserRealname(id, sAdminRealName, charsmax(sAdminRealName))
client_print(0, print_chat, "* ADMIN #%d %s: unbanned %s<%s>", fm_GetUserIdent(id), sAdminRealName, BanInfo[m_sBanName], BanInfo[m_sBanAuthid])
console_print(id, "You have unbanned %s<%s>", BanInfo[m_sBanName], BanInfo[m_sBanAuthid])
log_amx("\"%s<%s>(%s)\" admin_unban \"%s<%s>\"", sAdminName, sAdminAuthid, sAdminRealName, BanInfo[m_sBanName], BanInfo[m_sBanAuthid])
return PLUGIN_HANDLED
}
// admin_ban <target|steamid> <length> [reason]
public Admin_Ban(id, iLevel, iCommand)
{
// Check the user has access and entered the correct number of parameters
if (!fm_CommandAccess(id, iLevel, true) || !fm_CommandUsage(id, iCommand, 2))
{
return PLUGIN_HANDLED
}
new sArgs[192], sTarget[64]; read_args(sArgs, charsmax(sArgs))
argbreak(sArgs, sTarget, charsmax(sTarget), sArgs, charsmax(sArgs))
new BanInfo[eBanInfo_t]
// Try and find the target player
new iPlayer = fm_CommandGetPlayer(id, sTarget)
if (!iPlayer)
{
// Cannot find target, check if the user entered a steam ID
if (!equal(sTarget, "STEAM_", 6))
{
return PLUGIN_HANDLED
}
console_print(id, "Banning via steam ID instead")
// Check if the steam ID is banned
new iIndex = fm_GetBanInfoByAuth(g_BanList, sTarget, BanInfo)
if (iIndex != -1)
{
if (fm_HasTimedBanExpired(BanInfo))
{
fm_RemoveBanByIndex(g_BanList, iIndex)
fm_WriteBanFile(g_BanList, g_sBanFilePath, g_iCurrentBanIdent)
}
else
{
console_print(id, "%s is already banned:", sTarget)
fm_PrintBanInfo(id, BanInfo)
return PLUGIN_HANDLED
}
}
copy(BanInfo[m_sBanName], MAX_NAME_LEN - 1, "n/a")
copy(BanInfo[m_sBanAuthid], MAX_AUTHID_LEN - 1, sTarget)
}
else
{
get_user_name(iPlayer, BanInfo[m_sBanName], MAX_NAME_LEN - 1)
get_user_authid(iPlayer, BanInfo[m_sBanAuthid], MAX_AUTHID_LEN - 1)
new iIndex = fm_GetBanInfoByAuth(g_BanList, BanInfo[m_sBanAuthid], BanInfo)
if (iIndex != -1)
{
fm_WarningLog("Attempted to create a duplicate ban on player %s<%s>", BanInfo[m_sBanName], BanInfo[m_sBanAuthid])
return PLUGIN_HANDLED
}
}
new sLength[128]
argbreak(sArgs, sLength, charsmax(sLength), BanInfo[m_sBanReason], MAX_REASON_LEN - 1)
trim(BanInfo[m_sBanReason])
if (!BanInfo[m_sBanReason][0])
{
copy(BanInfo[m_sBanReason], MAX_REASON_LEN - 1, "None")
}
new iLength
if (sLength[0])
{
// check the user actually entered a number for the length
if (!is_str_num2(sLength))
{
console_print(id, "Length must be a number")
return PLUGIN_HANDLED
}
iLength = str_to_num(sLength)
}
else
{
// If the the user didn't specify a length, default to map based ban
iLength = -1
}
if (iLength < 0)
{
fm_SetBanType(BanInfo, BANTYPE_MAP)
}
else if (!iLength)
{
/*
if (fm_GetUserAccess(id) & ADMIN_HIGHER)
{
*/
fm_SetBanType(BanInfo, BANTYPE_PERMANENT)
/*
}
else
{
console_print(id, "You do not have access to permanently ban players")
return PLUGIN_HANDLED
}
*/
}
else
{
fm_SetBanType(BanInfo, BANTYPE_TIMED)
if (iLength > MAX_BAN_LEN_MINS)
{
iLength = MAX_BAN_LEN_MINS
}
iLength *= 60 // Convert minutes to seconds
BanInfo[m_iBanLength] = iLength
}
BanInfo[m_iBanIdent] = g_iCurrentBanIdent++
BanInfo[m_iBanTime] = get_systime()
BanInfo[m_iBanAdmin] = fm_GetUserIdent(id)
// Add the ban to the array
fm_AddBanByStruct(g_BanList, BanInfo)
// Update the ban file if required
if (fm_GetBanType(BanInfo) != BANTYPE_MAP)
{
fm_WriteBanFile(g_BanList, g_sBanFilePath, g_iCurrentBanIdent)
}
// Kick the target player if they are connected
fm_FormatBanLength(BanInfo, sLength, charsmax(sLength))
if (iPlayer)
{
server_cmd("kick #%d \"You are banned %s\"", get_user_userid(iPlayer), sLength)
}
// Notify user/clients
new sAdminName[MAX_NAME_LEN]; get_user_name(id, sAdminName, charsmax(sAdminName))
new sAdminAuthid[MAX_AUTHID_LEN]; get_user_authid(id, sAdminAuthid, charsmax(sAdminAuthid))
new sAdminRealName[MAX_NAME_LEN]; fm_GetUserRealname(id, sAdminRealName, charsmax(sAdminRealName))
client_print(0, print_chat, "* ADMIN #%d %s: banned %s<%s> %s Reason: %s", fm_GetUserIdent(id), sAdminRealName, BanInfo[m_sBanName], BanInfo[m_sBanAuthid], sLength, BanInfo[m_sBanReason])
console_print(id, "You have banned %s<%s> %s", BanInfo[m_sBanName], BanInfo[m_sBanAuthid], sLength)
log_amx("\"%s<%s>(%s)\" admin_ban \"%s<%s>\" %s", sAdminName, sAdminAuthid, sAdminRealName, BanInfo[m_sBanName], BanInfo[m_sBanAuthid], sLength)
return PLUGIN_HANDLED
}
public plugin_end()
{
if (g_BanList != Invalid_Array)
{
ArrayDestroy(g_BanList)
}
}
public ReadTempBanTxt(id)
{
new iFileHandle = fopen("banlistedit.txt", "rt")
if (iFileHandle)
{
new sData[512]
while (!feof(iFileHandle))
{
fgets(iFileHandle, sData, charsmax(sData))
trim(sData) // Clean spaces and line breaks from either end
new BanInfo[eBanInfo_t]
strtok(sData, BanInfo[m_sBanName], MAX_NAME_LEN -1, sData, charsmax(sData), ';')
strtok(sData, BanInfo[m_sBanAuthid], MAX_AUTHID_LEN - 1, sData, charsmax(sData), ';')
new iIndex = fm_GetBanInfoByAuth(g_BanList, BanInfo[m_sBanAuthid], BanInfo)
if (iIndex != -1)
{
console_print(id, "Ban \"%s\" already exists", BanInfo[m_sBanAuthid])
continue
}
strtok(sData, BanInfo[m_sBanReason], MAX_REASON_LEN - 1, sData, charsmax(sData), ';')
new sBuffer[32]
strtok(sData, sBuffer, charsmax(sBuffer), sData, charsmax(sData), ';')
BanInfo[m_iBanAdmin] = str_to_num(sBuffer)
strtok(sData, sBuffer, charsmax(sBuffer), sData, charsmax(sData), ';')
BanInfo[m_iBanTime] = str_to_num(sBuffer)
BanInfo[m_iBanType] = BANTYPE_PERMANENT
BanInfo[m_iBanIdent] = g_iCurrentBanIdent++
fm_AddBanByStruct(g_BanList, BanInfo)
}
fm_WriteBanFile(g_BanList, g_sBanFilePath, g_iCurrentBanIdent)
}
}