forked from JaredScar/Badger-Anticheat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.lua
378 lines (364 loc) · 16.2 KB
/
server.lua
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
BlacklistedEvents = Config.BlacklistedEvents;
webhookURL = ''
local counter = {}
function BanPlayer(src, reason)
local config = LoadResourceFile(GetCurrentResourceName(), "ac-bans.json")
local cfg = json.decode(config)
local ids = ExtractIdentifiers(src);
local ip = ids.ip;
cfg[tostring(ip)] = reason;
SaveResourceFile(GetCurrentResourceName(), "ac-bans.json", json.encode(cfg, { indent = true }), -1)
end
function UnbanPlayer(ip)
local config = LoadResourceFile(GetCurrentResourceName(), "ac-bans.json")
local cfg = json.decode(config)
cfg[tostring(ip)] = nil;
SaveResourceFile(GetCurrentResourceName(), "ac-bans.json", json.encode(cfg, { indent = true }), -1)
end
function GetBans()
local config = LoadResourceFile(GetCurrentResourceName(), "ac-bans.json")
local cfg = json.decode(config)
return cfg;
end
Citizen.CreateThread(function()
while true do
Wait(10000); -- Every 10 seconds
local bans = GetBans();
for _, id in pairs(GetPlayers()) do
local playerIP = ExtractIdentifiers(id).ip;
if bans[tostring(playerIP)] ~= nil then
-- Banned, kick em
DropPlayer(id, "[Badger-Anticheat] " .. bans[tostring(playerIP)]);
end
end
end
end)
function OnPlayerConnecting(name, setKickReason, deferrals)
deferrals.defer();
print("[Badger-Anticheat] Checking their Ban Data");
local src = source;
local playerIP = ExtractIdentifiers(src).ip;
local bans = GetBans();
local banned = false;
if bans[tostring(playerIP)] ~= nil then
-- They are banned
local reason = bans[tostring(playerIP)];
print("[Badger-Anticheat] (BANNED PLAYER) Player " .. GetPlayerName(src) .. " tried to join, but was banned for: " .. reason);
deferrals.done("[Badger-Anticheat] " .. reason);
banned = true;
CancelEvent();
return;
end
if not banned then
deferrals.done();
end
end
AddEventHandler("playerConnecting", OnPlayerConnecting)
RegisterServerEvent("Anticheat:NoClip")
AddEventHandler("Anticheat:NoClip", function(distance)
if Config.Components.AntiNoclip and not IsPlayerAceAllowed(source, "Anticheat.Bypass") then
local name = GetPlayerName(source)
local id = source;
local ids = ExtractIdentifiers(id);
local steam = ids.steam:gsub("steam:", "");
local steamDec = tostring(tonumber(steam,16));
if counter[ids.steam] ~= nil then
counter[ids.steam] = counter[ids.steam] + 1;
else
counter[ids.steam] = 1;
end
if counter[ids.steam] ~= nil and counter[ids.steam] >= Config.NoClipTriggerCount then
steam = "https://steamcommunity.com/profiles/" .. steamDec;
local gameLicense = ids.license;
local discord = ids.discord;
if (Config.BanComponents.AntiNoClip) then
BanPlayer(id, "Why you no-clipping and not staff? Stoopid ass hoe")
sendToDisc("[BANNED] CONFIRMED HACKER (NoClipping around): _[" .. tostring(id) .. "] " .. GetPlayerName(id) .. "_",
'Steam: **' .. steam .. '**\n' ..
'GameLicense: **' .. gameLicense .. '**\n' ..
'Discord Tag: **<@' .. discord:gsub('discord:', '') .. '>**\n' ..
'Discord UID: **' .. discord:gsub('discord:', '') .. '**\n');
else
sendToDisc("CONFIRMED HACKER [NoClipping around]: _[" .. tostring(id) .. "] " .. GetPlayerName(id) .. "_",
'Steam: **' .. steam .. '**\n' ..
'GameLicense: **' .. gameLicense .. '**\n' ..
'Discord Tag: **<@' .. discord:gsub('discord:', '') .. '>**\n' ..
'Discord UID: **' .. discord:gsub('discord:', '') .. '**\n');
end
DropPlayer(id, "[Badger-Anticheat]: Why you no-clipping and not staff? Stoopid ass hoe")
end
Wait(6000);
counter[ids.steam] = counter[ids.steam] - 1;
end
end)
-- Props to Lance Good for this code (most of it at least): [https://github.com/DevLanceGood]
function IsLegal(entity)
local model = GetEntityModel(entity)
if (model ~= nil) then
if (GetEntityType(entity) == 1 and GetEntityPopulationType(entity) == 7) then
local WhitelistPedModels = Config.WhitelistPedModels;
local isWhitelisted = false;
for i = 1, #WhitelistPedModels do
if GetHashKey(WhitelistPedModels[i]) == model then
isWhitelisted = true;
end
end
if not isWhitelisted then
return "Spawning Peds";
else
return false;
end
end
for i=1, #Config.BlacklistedModels do
local hashkey = tonumber(Config.BlacklistedModels[i]) ~= nil and tonumber(Config.BlacklistedModels[i]) or GetHashKey(Config.BlacklistedModels[i])
if (hashkey == model) then
if (GetEntityPopulationType(entity) ~= 7) then
return Config.BlacklistedModels[i];
else
return false
end
end
end
end
return false
end
-- End props
RegisterNetEvent("Anticheat:ModderESX")
AddEventHandler("Anticheat:ModderESX", function(type, reason)
local id = source;
local ids = ExtractIdentifiers(id);
local steam = ids.steam:gsub("steam:", "");
local steamDec = tostring(tonumber(steam,16));
steam = "https://steamcommunity.com/profiles/" .. steamDec;
local gameLicense = ids.license;
local discord = ids.discord;
if Config.BanComponents.AntiESX then
BanPlayer(id, reason);
sendToDisc("[BANNED] " .. type .. ": _[" .. tostring(id) .. "] " .. GetPlayerName(id) .. "_",
'Steam: **' .. steam .. '**\n' ..
'GameLicense: **' .. gameLicense .. '**\n' ..
'Discord Tag: **<@' .. discord:gsub('discord:', '') .. '>**\n' ..
'Discord UID: **' .. discord:gsub('discord:', '') .. '**\n');
else
sendToDisc("" .. type .. ": _[" .. tostring(id) .. "] " .. GetPlayerName(id) .. "_",
'Steam: **' .. steam .. '**\n' ..
'GameLicense: **' .. gameLicense .. '**\n' ..
'Discord Tag: **<@' .. discord:gsub('discord:', '') .. '>**\n' ..
'Discord UID: **' .. discord:gsub('discord:', '') .. '**\n');
end
DropPlayer(id, reason)
end)
RegisterNetEvent("Anticheat:Modder")
AddEventHandler("Anticheat:Modder", function(type, reason)
local id = source;
local ids = ExtractIdentifiers(id);
local steam = ids.steam:gsub("steam:", "");
local steamDec = tostring(tonumber(steam,16));
steam = "https://steamcommunity.com/profiles/" .. steamDec;
local gameLicense = ids.license;
local discord = ids.discord;
if Config.BanComponents.AntiCommands then
BanPlayer(id, reason);
sendToDisc("[BANNED] " .. type .. ": _[" .. tostring(id) .. "] " .. GetPlayerName(id) .. "_",
'Steam: **' .. steam .. '**\n' ..
'GameLicense: **' .. gameLicense .. '**\n' ..
'Discord Tag: **<@' .. discord:gsub('discord:', '') .. '>**\n' ..
'Discord UID: **' .. discord:gsub('discord:', '') .. '**\n');
else
sendToDisc("" .. type .. ": _[" .. tostring(id) .. "] " .. GetPlayerName(id) .. "_",
'Steam: **' .. steam .. '**\n' ..
'GameLicense: **' .. gameLicense .. '**\n' ..
'Discord Tag: **<@' .. discord:gsub('discord:', '') .. '>**\n' ..
'Discord UID: **' .. discord:gsub('discord:', '') .. '**\n');
end
DropPlayer(id, reason)
end)
RegisterNetEvent("Anticheat:ModderNoKick")
AddEventHandler("Anticheat:ModderNoKick", function(type, reason, bool)
local id = source;
local ids = ExtractIdentifiers(id);
local steam = ids.steam:gsub("steam:", "");
local steamDec = tostring(tonumber(steam,16));
steam = "https://steamcommunity.com/profiles/" .. steamDec;
local gameLicense = ids.license;
local discord = ids.discord;
sendToDisc("" .. type .. ": _[" .. tostring(id) .. "] " .. GetPlayerName(id) .. "_",
'Steam: **' .. steam .. '**\n' ..
'GameLicense: **' .. gameLicense .. '**\n' ..
'Discord Tag: **<@' .. discord:gsub('discord:', '') .. '>**\n' ..
'Discord UID: **' .. discord:gsub('discord:', '') .. '**\n');
if bool then
DropPlayer(id, reason)
end
end)
RegisterNetEvent("Anticheat:SpectateTrigger")
AddEventHandler("Anticheat:SpectateTrigger", function(reason)
if Config.Components.AntiSpectate and not IsPlayerAceAllowed(source, "Anticheat.Bypass") then
local id = source;
local ids = ExtractIdentifiers(id);
local steam = ids.steam:gsub("steam:", "");
local steamDec = tostring(tonumber(steam,16));
steam = "https://steamcommunity.com/profiles/" .. steamDec;
local gameLicense = ids.license;
local discord = ids.discord;
if Config.BanComponents.AntiSpectate then
BanPlayer(id, reason);
sendToDisc("[BANNED] CONFIRMED HACKER (Tried spectating a player): _[" .. tostring(id) .. "] " .. GetPlayerName(id) .. "_",
'Steam: **' .. steam .. '**\n' ..
'GameLicense: **' .. gameLicense .. '**\n' ..
'Discord Tag: **<@' .. discord:gsub('discord:', '') .. '>**\n' ..
'Discord UID: **' .. discord:gsub('discord:', '') .. '**\n');
else
sendToDisc("CONFIRMED HACKER [Tried spectating a player]: _[" .. tostring(id) .. "] " .. GetPlayerName(id) .. "_",
'Steam: **' .. steam .. '**\n' ..
'GameLicense: **' .. gameLicense .. '**\n' ..
'Discord Tag: **<@' .. discord:gsub('discord:', '') .. '>**\n' ..
'Discord UID: **' .. discord:gsub('discord:', '') .. '**\n');
end
DropPlayer(id, reason)
end
end)
AddEventHandler('chatMessage', function(source, name, msg)
local id = source;
local ids = ExtractIdentifiers(id);
local ip = ids.ip;
local steam = ids.steam:gsub("steam:", "");
local steamDec = tostring(tonumber(steam,16));
steam = "https://steamcommunity.com/profiles/" .. steamDec;
local gameLicense = ids.license;
local discord = ids.discord;
local realName = GetPlayerName(source);
if (name ~= realName) then
if Config.BanComponents.AntiFakeMessage then
BanPlayer(id, "Why you tryna be someone else? Stoopid ass hoe")
sendToDisc("[BANNED] CONFIRMED HACKER (Fake Chat Message): _[" .. tostring(id) .. "] " .. GetPlayerName(id) .. "_",
'Steam: **' .. steam .. '**\n' ..
'GameLicense: **' .. gameLicense .. '**\n' ..
'Discord Tag: **<@' .. discord:gsub('discord:', '') .. '>**\n' ..
'Discord UID: **' .. discord:gsub('discord:', '') .. '**\n'
.. 'Tried to say: `' .. msg .. '` with name `' .. name .. '`');
else
sendToDisc("CONFIRMED HACKER [Fake Chat Message]: _[" .. tostring(id) .. "] " .. GetPlayerName(id) .. "_",
'Steam: **' .. steam .. '**\n' ..
'GameLicense: **' .. gameLicense .. '**\n' ..
'Discord Tag: **<@' .. discord:gsub('discord:', '') .. '>**\n' ..
'Discord UID: **' .. discord:gsub('discord:', '') .. '**\n'
.. 'Tried to say: `' .. msg .. '` with name `' .. name .. '`');
end
DropPlayer(id, "[Badger-Anticheat]: Why you tryna be someone else? Stoopid ass hoe")
end
end)
function GetEntityOwner(entity)
if (not DoesEntityExist(entity)) then
return nil
end
local owner = NetworkGetEntityOwner(entity)
if (GetEntityPopulationType(entity) ~= 7) then return nil end
return owner
end
AddEventHandler('explosionEvent', function(sender, ev)
local sender = tonumber(sender)
CancelEvent()
if (sender ~= nil and sender > 0) then
CancelEvent()
end
end)
for i=1, #BlacklistedEvents, 1 do
RegisterServerEvent(BlacklistedEvents[i])
AddEventHandler(BlacklistedEvents[i], function()
local id = source;
local ids = ExtractIdentifiers(id);
local steam = ids.steam:gsub("steam:", "");
local steamDec = tostring(tonumber(steam,16));
steam = "https://steamcommunity.com/profiles/" .. steamDec;
local gameLicense = ids.license;
local discord = ids.discord;
if Config.BanComponents.AntiBlacklistedEvent then
BanPlayer(id, "Lua execution: "..BlacklistedEvents[i]);
sendToDisc("[BANNED] CONFIRMED HACKER (Tried executing `".. BlacklistedEvents[i] .."`): _[" .. tostring(id) .. "] " .. GetPlayerName(id) .. "_",
'Steam: **' .. steam .. '**\n' ..
'GameLicense: **' .. gameLicense .. '**\n' ..
'Discord Tag: **<@' .. discord:gsub('discord:', '') .. '>**\n' ..
'Discord UID: **' .. discord:gsub('discord:', '') .. '**\n');
else
sendToDisc("CONFIRMED HACKER [Tried executing `".. BlacklistedEvents[i] .."`]: _[" .. tostring(id) .. "] " .. GetPlayerName(id) .. "_",
'Steam: **' .. steam .. '**\n' ..
'GameLicense: **' .. gameLicense .. '**\n' ..
'Discord Tag: **<@' .. discord:gsub('discord:', '') .. '>**\n' ..
'Discord UID: **' .. discord:gsub('discord:', '') .. '**\n');
end
DropPlayer(id, "Lua execution: "..BlacklistedEvents[i],true)
end)
end
AddEventHandler("entityCreating", function(entity)
local owner = GetEntityOwner(entity)
local cancelled = false
local model = IsLegal(entity);
if (model) then
if (owner ~= nil and owner > 0) then
local id = owner;
local ids = ExtractIdentifiers(id);
local steam = ids.steam:gsub("steam:", "");
local steamDec = tostring(tonumber(steam,16));
steam = "https://steamcommunity.com/profiles/" .. steamDec;
local gameLicense = ids.license;
local discord = ids.discord;
sendToDisc("HACKER (Probably) [via Blacklisted Entity]: _[" .. tostring(id) .. "] " .. GetPlayerName(id) .. "_ has spawned something...",
'Steam: **' .. steam .. '**\n' ..
'GameLicense: **' .. gameLicense .. '**\n' ..
'Discord Tag: **<@' .. discord:gsub('discord:', '') .. '>**\n' ..
'Discord UID: **' .. discord:gsub('discord:', '') .. '**\n'
.. 'Blacklisted Item: **' .. tostring(model) .. "**");
DropPlayer(owner, "Possible Hacker (Blacklisted Item: " .. tostring(model) .. ")")
end
CancelEvent()
cancelled = true
end
end)
function ExtractIdentifiers(src)
local identifiers = {
steam = "",
ip = "",
discord = "",
license = "",
xbl = "",
live = ""
}
--Loop over all identifiers
for i = 0, GetNumPlayerIdentifiers(src) - 1 do
local id = GetPlayerIdentifier(src, i)
--Convert it to a nice table.
if string.find(id, "steam") then
identifiers.steam = id
elseif string.find(id, "ip") then
identifiers.ip = id
elseif string.find(id, "discord") then
identifiers.discord = id
elseif string.find(id, "license") then
identifiers.license = id
elseif string.find(id, "xbl") then
identifiers.xbl = id
elseif string.find(id, "live") then
identifiers.live = id
end
end
return identifiers
end
function sendToDisc(title, message, footer)
local embed = {}
embed = {
{
["color"] = 16711680, -- GREEN = 65280 --- RED = 16711680
["title"] = "**".. title .."**",
["description"] = "" .. message .. "",
["footer"] = {
["text"] = footer,
},
}
}
-- Start
-- TODO Input Webhook
PerformHttpRequest(webhookURL,
function(err, text, headers) end, 'POST', json.encode({username = name, embeds = embed}), { ['Content-Type'] = 'application/json' })
-- END
end