-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathserver.lua
More file actions
1243 lines (1127 loc) · 48.3 KB
/
server.lua
File metadata and controls
1243 lines (1127 loc) · 48.3 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
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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
ESX = nil
TriggerEvent("esx:getSharedObject", function(obj) ESX = obj end)
local ResourceMetadata = {}
local ResourceFiles = {}
---------------------------
-------- BAN BOOGERS ------
---------------------------
function banlistregenerator()
local o = LoadResourceFile(GetCurrentResourceName(), "ac-bans.json")
if not o or o == "" then
SaveResourceFile(GetCurrentResourceName(), "ac-bans.json", "[]", -1)
print("^"..math.random(1, 9).."^3Warning! ^0Your ^1ac-bans.json ^0is missing, Regenerating your ^1ac-bans.json ^0file!")
else
local p = json.decode(o)
if not p then
SaveResourceFile(GetCurrentResourceName(), "ac-bans.json", "[]", -1)
p = {}
print("^"..math.random(1, 9).."^3Warning! ^0Your ^1ac-bans.json ^0is corrupted, Regenerating your ^1ac-bans.json ^0file!")
end
end
end
function IsPlayerWhitelisted(playerId)
local identifiers = GetPlayerIdentifiers(playerId)
for _, id in pairs(identifiers) do
for _, whitelistedId in pairs(Config.WhitelistedPlayers) do
if id == whitelistedId then
return true
end
end
end
return false
end
function AntiCheatBans(source,reason)
local config = LoadResourceFile(GetCurrentResourceName(), "ac-bans.json")
local data = json.decode(config)
local _src = source
if config == nil then
banlistregenerator()
return
end
if GetPlayerName(_src) == nil then -- Make sure no any nil to come on our json.
return
end
local myid = GetIdentifier(_src);
local playerSteam = myid.steam;
local playerLicense = myid.license;
local playerXbl = myid.xbl;
local playerLive = myid.live;
local playerDiscord = myid.discord;
local banInfo = {};
--Identifiers.
banInfo['ID'] = tonumber(GetAndBanID());
banInfo['reason'] = reason;
banInfo['license'] = "No Info";
banInfo['steam'] = "No Info";
banInfo['xbl'] = "No Info";
banInfo['live'] = "No Info";
banInfo['discord'] = "No Info";
--Input to our json.
if playerLicense ~= nil and playerLicense ~= "nil" and playerLicense ~= "" then
banInfo['license'] = tostring(playerLicense);
end
if playerSteam ~= nil and playerSteam ~= "nil" and playerSteam ~= "" then
banInfo['steam'] = tostring(playerSteam);
end
if playerXbl ~= nil and playerXbl ~= "nil" and playerXbl ~= "" then
banInfo['xbl'] = tostring(playerXbl);
end
if playerLive ~= nil and playerLive ~= "nil" and playerLive ~= "" then
banInfo['live'] = tostring(playerXbl);
end
if playerDiscord ~= nil and playerDiscord ~= "nil" and playerDiscord ~= "" then
banInfo['discord'] = tostring(playerDiscord);
end
data[tostring(GetPlayerName(source))] = banInfo;
SaveResourceFile(GetCurrentResourceName(), "ac-bans.json", json.encode(data, { indent = true }), -1)
end
function GetIdentifier(source)
local identifiers = {
steam = "",
ip = "",
discord = "",
license = "",
xbl = "",
live = ""
}
for i = 0, GetNumPlayerIdentifiers(source) - 1 do
local id = GetPlayerIdentifier(source, i)
--Full to 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 GetAndBanID()
local config = LoadResourceFile(GetCurrentResourceName(), "ac-bans.json")
local data = json.decode(config)
local banID = 0;
for k, v in pairs(data) do
banID = banID + 1;
end
return (banID + 1);
end
function sendwebhooktodc(content)
local _source = source
local connect =
{
{
["color"] = "23295",
["title"] = "Rawe AntiCheat",
["description"] = "Player: "..GetPlayerName(_source).. " " ..GetPlayerIdentifiers(_source)[1].."", content,
["footer"] = {
["text"] = "github.com/RaweRwe/rw-anticheat",
},
}
}
PerformHttpRequest(Config.WebhookDiscord, function(err, text, headers) end, 'POST', json.encode({username = "RW-AC", embeds = connect}), { ['Content-Type'] = 'application/json' })
end
-- kickorbancheater(source,"Content Text", "Info Text",kick,ban) c = Kick d = Ban
-- Example use: kickorbancheater(_src,"Weapon Explosion Detected", "This Player tried to change bullet type",true,true)
function kickorbancheater(source,content,info,c,d)
local _source = source
local sname = GetPlayerName(_source)
--Identifiers
local steam = "unknown"
local discord = "unknown"
local license = "unknown"
local live = "unknown"
local xbl = "unknown"
if IsPlayerWhitelisted(_source) then
return
end
for m, n in ipairs(GetPlayerIdentifiers(_source)) do
if n:match("steam") then
steam = n
elseif n:match("discord") then
discord = n:gsub("discord:", "")
elseif n:match("license") then
license = n
elseif n:match("live") then
live = n
elseif n:match("xbl") then
xbl = n
end
end
local discordinfo = {
{
["color"] = "23295",
["title"] = "Rawe AntiCheat",
["description"] = "**Player: **"..sname.. "\n**ServerID:** ".._source.."\n**Violation:** "..content.."\n**Details:** "..info.."\n**Steam:** "..steam.."\n**License: **"..license.."\n**Xbl: **"..xbl.."\n**Live: **"..live.."\n**Discord**: <@"..discord..">",
["footer"] = {
["text"] = "github.com/RaweRwe/rw-anticheat " ..os.date("%c").. "",
},
}
}
PerformHttpRequest(Config.WebhookDiscord, function(err, text, headers) end, 'POST', json.encode({username = "RW-AC", embeds = discordinfo}), { ['Content-Type'] = 'application/json' })
if d then
AntiCheatBans(source,content)
end
if c then
DropPlayer(source, "Kicked : "..Config.DropMsg)
end
end
function OnPlayerConnecting(name, setKickReason, deferrals)
deferrals.defer();
local src = source;
local banned = false;
local ban = getBanned(src);
Citizen.Wait(100);
if ban then
-- They are banned
local reason = ban['reason'];
print("[BANNED PLAYER] Player " .. GetPlayerName(src) .. " tried to join, but was banned for: " .. reason);
deferrals.done("(BAN ID: " .. ban['banID'] .. ") " .. Config.ReasonBanned);
banned = true;
CancelEvent();
return;
end
if not banned then
deferrals.done();
end
end
function getBanned(source)
local config = LoadResourceFile(GetCurrentResourceName(), "ac-bans.json")
local data = json.decode(config)
if config == nil then
banlistregenerator()
return
end
local myid = GetIdentifier(source);
local playerSteam = myid.steam;
local playerLicense = myid.license;
local playerXbl = myid.xbl;
local playerLive = myid.live;
local playerDisc = myid.discord;
for k, bigData in pairs(data) do
local reason = bigData['reason']
local id = bigData['ID']
local license = bigData['license']
local steam = bigData['steam']
local xbl = bigData['xbl']
local live = bigData['live']
local discord = bigData['discord']
if tostring(license) == tostring(playerLicense) then return { ['banID'] = id, ['reason'] = reason } end;
if tostring(steam) == tostring(playerSteam) then return { ['banID'] = id, ['reason'] = reason } end;
if tostring(xbl) == tostring(playerXbl) then return { ['banID'] = id, ['reason'] = reason } end;
if tostring(live) == tostring(playerLive) then return { ['banID'] = id, ['reason'] = reason } end;
if tostring(discord) == tostring(playerDisc) then return { ['banID'] = id, ['reason'] = reason } end;
end
return false;
end
AddEventHandler("playerConnecting", OnPlayerConnecting)
RegisterCommand('ac-unban', function(source, args, rawCommand)
local src = source;
if (src <= 0) then
-- Console unban
if #args == 0 then
-- Not enough arguments
print('^3[^6RW-AntiCheat^3] ^1Not enough arguments...');
return;
end
local banID = args[1];
if tonumber(banID) ~= nil then
local playerName = UnbanPlayer(banID);
if playerName then
print('^3[^6RW-AntiCheat^3] ^0Player ^1' .. playerName
.. ' ^0has been unbanned from the server by ^2CONSOLE');
TriggerClientEvent('chatMessage', -1, '^3[^6RW-AntiCheat^3] ^0Player ^1' .. playerName
.. ' ^0has been unbanned from the server by ^2CONSOLE');
else
-- Not a valid ban ID
print('^3[^6RW-AntiCheat^3] ^1That is not a valid ban ID. No one has been unbanned!');
end
end
return;
end
if IsPlayerWhitelisted(src) then
if #args == 0 then
-- Not enough arguments
TriggerClientEvent('chatMessage', src, '^3[^6RW-AntiCheat^3] ^1Not enough arguments...');
return;
end
local banID = args[1];
if tonumber(banID) ~= nil then
-- Is a valid ban ID
local playerName = UnbanPlayer(banID);
if playerName then
TriggerClientEvent('chatMessage', -1, '^3[^6RW-AntiCheat^3] ^0Player ^1' .. playerName
.. ' ^0has been unbanned from the server by ^2' .. GetPlayerName(src));
else
-- Not a valid ban ID
TriggerClientEvent('chatMessage', src, '^3[^6RW-AntiCheat^3] ^1That is not a valid ban ID. No one has been unbanned!');
end
else
-- Not a valid number
TriggerClientEvent('chatMessage', src, '^3[^6RW-AntiCheat^3] ^1That is not a valid number...');
end
else
TriggerClientEvent('chatMessage', src, '^3[^6RW-AntiCheat^3] ^1You do not have permission to use this command.');
end
end
end)
function UnbanPlayer(banID)
local config = LoadResourceFile(GetCurrentResourceName(), "ac-bans.json")
local cfg = json.decode(config)
for k, v in pairs(cfg) do
local id = tonumber(v['ID']);
if id == tonumber(banID) then
local name = k;
cfg[k] = nil;
SaveResourceFile(GetCurrentResourceName(), "ac-bans.json", json.encode(cfg, { indent = true }), -1)
return name;
end
end
return false;
end
-- /acban command
RegisterCommand("ac-ban", function(source, args, raw) -- /acban <id> <reason>
local src = source;
-- Check if the command is run from console
if src <= 0 then
-- Console command execution
if #args < 2 then
-- Not enough arguments
print("^5[^1RW-AntiCheat^5] ^1ERROR: You have supplied invalid amount of arguments... " ..
"^2Proper Usage: /acban <id> <reason>")
return
end
local id = args[1]
local playerIdentifiers = GetIdentifier(id)
if playerIdentifiers ~= nil then
-- Valid player ID
local reason = table.concat(args, ' '):gsub(id .. " ", "")
AntiCheatBans(id, reason)
print("^5[^1RW-AntiCheat^5] ^0Player ^1" .. id .. " ^0has been banned by ^2CONSOLE")
else
-- Invalid player ID
print("^5[^1RW-AntiCheat^5] ^1ERROR: There is no valid player with that ID online... " ..
"^2Proper Usage: /acban <id> <reason>")
end
return
end
-- Whitelist check
if IsPlayerWhitelisted(src) then
if #args < 2 then
-- Not enough arguments
TriggerClientEvent('chatMessage', source, "^5[^1RW-AntiCheat^5] ^1ERROR: You have supplied invalid amount of arguments... " ..
"^2Proper Usage: /acban <id> <reason>")
return
end
local id = args[1]
local playerIdentifiers = GetIdentifier(id)
if playerIdentifiers ~= nil then
-- Valid player ID
local reason = table.concat(args, ' '):gsub(id .. " ", "")
AntiCheatBans(id, reason)
TriggerClientEvent('chatMessage', -1, "^5[^1RW-AntiCheat^5] ^0Player ^1" .. id ..
" ^0has been banned by ^2" .. GetPlayerName(src))
else
-- Invalid player ID
TriggerClientEvent('chatMessage', source, "^5[^1RW-AntiCheat^5] ^1ERROR: There is no valid player with that ID online... " ..
"^2Proper Usage: /acban <id> <reason>")
end
else
-- If not whitelisted
TriggerClientEvent('chatMessage', src, '^5[^1RW-AntiCheat^5] ^1ERROR: You do not have permission to use this command.')
end
end)
-----
RegisterServerEvent("8jWpZudyvjkDXQ2RVXf9")
AddEventHandler("8jWpZudyvjkDXQ2RVXf9", function(type)
local _type = type or "default"
local _src = source
local _item = item or "none"
local _name = GetPlayerName(_src)
_type = string.lower(_type)
if (_type == "invisible") then
kickorbancheater(_src,"Tried to be Invisible", "This Player tried to Invisible",true,true)
elseif (_type == "antiragdoll") then
kickorbancheater(_src,"AntiRagdoll Detected", "This Player tried to activate Anti-Ragdoll",true,true)
elseif (_type == "displayradar") then
kickorbancheater(_src,"Radar Detected", "This Player tried to activate Radar",true,true)
elseif (_type == "explosiveweapon") then
kickorbancheater(_src,"Weapon Explosion Detected", "This Player tried to change bullet type",true,true)
elseif (_type == "spectatormode") then
kickorbancheater(_src,"Spectate Detected", "This Player tried to Spectate a Player",true,true)
elseif (_type == "speedhack") then
kickorbancheater(_src,"SpeedHack Detected", "This Player tried to SpeedHack",true,true)
elseif (_type == "blacklistedweapons") then
kickorbancheater(_src,"Weapon in Blacklist", "This Player tried to spawn a Blacklisted Weapon",true,true)
elseif (_type == "thermalvision") then
kickorbancheater(_src,"Thermal Camera Detected", "This Player tried to use Thermal Camera",true,true)
elseif (_type == "nightvision") then
kickorbancheater(_src,"Night Vision Detected", "This Player tried to use Night Vision",true,true)
elseif (_type == "antiresourcestop") then
kickorbancheater(_src,"Resource Stopped", "This Player tried to stop/start a Resource",true,true)
elseif (_type == "pedchanged") then
kickorbancheater(_src,"Ped Changed", "This Player tried to change his PED",true,true)
elseif (_type == "freecam") then
kickorbancheater(_src,"FreeCam Detected", "This Player tried to use Freecam (Fallout or similar)",true,true)
elseif (_type == "infiniteammo") then
kickorbancheater(_src,"Infinite Ammo Detected", "This Player tried to put Infinite Ammo",true,true)
elseif (_type == "resourcestarted") then
kickorbancheater(_src,"AntiResourceStart", "This Player tried to start a resource",true,true)
elseif (_type == "menyoo") then
kickorbancheater(_src,"Anti Menyoo", "This Player tried to inject Menyoo Menu",true,true)
elseif (_type == "givearmour") then
kickorbancheater(_src,"Anti Give Armor", "This Player tried to Give Armor",true,true)
elseif (_type == "aimassist") then
kickorbancheater(_src,"Aim Assist", "This Player tried Aim Assist Detected. Mode: ",false,false)
elseif (_type == "infinitestamina") then
kickorbancheater(_src,"Anti Infinite Stamina", "This Player tried to use Infinite Stamina",true,true)
elseif (_type == "superjump") then
if IsPlayerUsingSuperJump(_src) then
kickorbancheater(_src,"Superjump Detected", "This Player tried to use Superjump",true,true)
end
elseif (_type == "vehicleweapons") then
kickorbancheater(_src,"Vehicle Weapons Detected", "This Player tried to use Vehicle Weapons",true,true)
elseif (_type == "blacklistedtask") then
kickorbancheater(_src,"Blacklisted Task", "Tried to execute a blacklisted task.",true,true)
elseif (_type == "blacklistedanim") then
kickorbancheater(_src,"Blacklisted Anim", "Tried executing a blacklisted anim. This player might not be a cheater.",true,true)
elseif (_type == "receivedpickup") then
kickorbancheater(_src,"Pickup received", "Pickup received.",true,true)
elseif (_type == "shotplayerwithoutbeingonhisscreen") then
kickorbancheater(_src,"Anti Aimbot/TriggerBot", "Hit a Player Without Being in his Screen. Possible Aimbot/TriggerBot/RageBot. Distance Difference.",false,false) -- can do wrong ban
elseif (_type == "aimbot") then
kickorbancheater(_src,"Anti Aimbot", "Aimbot detected.",true,true)
elseif (_type == "silentaim") then
kickorbancheater(_src,"Silent Aim Detected", "Silent Aim logic triggered. " .. (_item or ""), true, true)
elseif (_type == "noclip") then
kickorbancheater(_src, "Noclip Detected", "Distance check triggered. " .. (_item or ""), true, true)
elseif (_type == "damagemodifier") then
kickorbancheater(_src, "Damage Modifier Detected", "Abnormal damage output. " .. (_item or ""), true, true)
elseif (_type == "menu_global") then
kickorbancheater(_src, "Global Injection Detected", "Malicious global variable detected: " .. (_item or ""), true, true)
elseif (_type == "overlay_detection") then
kickorbancheater(_src, "Overlay/Resolution Manipulation", "Suspicious resolution change detected. " .. (_item or ""), true, true)
elseif (_type == "stoppedac") then
kickorbancheater(_src,"Anti Resource Stop", "Tried to stop the Anticheat.",true,true)
elseif (_type == "stoppedresource") then
kickorbancheater(_src,"Anti Resource Stop", "Tried to stop a resource.",true,true)
end
end)
RegisterNetEvent('JzKD3yfGZMSLTqu9L4Qy')
AddEventHandler('JzKD3yfGZMSLTqu9L4Qy', function(resource, info)
local _src = source
if resource ~= nil and info ~= nil then
kickorbancheater(_src,"Injection detected", "Injection detected in resource: "..resource.. "Type: "..info,true,true)
end
end)
RegisterNetEvent('tYdirSYpJtB77dRC3cvX')
AddEventHandler('tYdirSYpJtB77dRC3cvX', function()
local _src = source
local players = {}
for _,v in pairs(GetPlayers()) do
table.insert(players, {
name = GetPlayerName(v),
id = v
})
end
kickorbancheater(_src,"Give Weapon To Ped", "This Player tried Give Weapon to Ped.",true,true)
end)
if Config.AntiResource or Config.AntiResourceManipulation then
RegisterNetEvent('PJHxig0KJQFvQsrIhd5h')
AddEventHandler('PJHxig0KJQFvQsrIhd5h', function(clientResourceList)
local _src = source
if not clientResourceList then return end
-- Build Server Resource List
local serverResources = {}
local numResources = GetNumResources()
for i = 0, numResources - 1 do
local resName = GetResourceByFindIndex(i)
if resName and GetResourceState(resName) == "started" then
serverResources[resName] = true
end
end
-- Check for Mismatches
for resName, metadata in pairs(clientResourceList) do
if not serverResources[resName] then
-- Client has a resource that Server DOES NOT have started.
-- Could be a client-side injected menu or a cached resource not cleaned up.
-- Check whitelist
if not Config.WhitelistedResources[resName] and resName ~= "_cfx_internal" then
kickorbancheater(_src, "Resource Manipulation", "Unknown resource detected running on client: " .. resName, true, true)
end
end
end
for resName, _ in pairs(serverResources) do
-- Check if client is MISSING a resource that should be running
-- Note: Some resources are server-only. We need to check if it has client scripts.
if GetResourceMetadata(resName, 'client_script', 0) or GetResourceMetadata(resName, 'client_scripts', 0) then
if not clientResourceList[resName] then
-- Client stopped a required resource
if not Config.WhitelistedResources[resName] then
kickorbancheater(_src, "Resource Manipulation", "Expected resource stopped: " .. resName, true, true)
end
end
end
end
-- Executor Check (Legacy names)
for k, v in pairs(clientResourceList) do
if k == "unex" or k == "Unex" or k == "rE" or k == "redENGINE" or k == "Eulen" then
kickorbancheater(_src,"Resource Injection", "Executor detected: "..k,true,true)
end
end
end)
end
------------------------------------
-------- Explosion Event --------
------------------------------------
AddEventHandler('explosionEvent', function(sender, ev)
local name = GetPlayerName(sender)
local _src = source
-- We need to make sure it is original from explosion sender.
if ev.damageScale ~= 0.0 and ev.ownerNetId == 0 then
kickorbancheater(_src,"ExplosionEvent Detected", "Explosion Type: "..ev.explosionType,true,true)
CancelEvent()
end
end)
-----
--Maybe need rework from entity created to entitycreating for performance of server side. -- need rework
-- Disable it for a while since it need to be reworked.
-----
------------------------------------
-------- Heartbeat System ----
------------------------------------
local PlayerHeartbeats = {}
if Config.Heartbeat then
RegisterServerEvent("rwe:HeartbeatReturn")
AddEventHandler("rwe:HeartbeatReturn", function(token)
local _src = source
if PlayerHeartbeats[_src] and PlayerHeartbeats[_src].token == token then
PlayerHeartbeats[_src].lastBeat = os.time()
else
-- Invalid token or unknown heartbeat
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(Config.HeartbeatInterval or 30000)
local current = os.time()
for _, playerId in ipairs(GetPlayers()) do
playerId = tonumber(playerId)
if not PlayerHeartbeats[playerId] then
PlayerHeartbeats[playerId] = { lastBeat = current, token = math.random(100000, 999999) }
TriggerClientEvent("rwe:HeartbeatCheck", playerId, PlayerHeartbeats[playerId].token)
else
if os.difftime(current, PlayerHeartbeats[playerId].lastBeat) > ((Config.HeartbeatInterval / 1000) * 3) then
-- Missed 3 beats
kickorbancheater(playerId, "Heartbeat Failed", "Client not responding.", true, true)
else
-- Send new token
PlayerHeartbeats[playerId].token = math.random(100000, 999999)
TriggerClientEvent("rwe:HeartbeatCheck", playerId, PlayerHeartbeats[playerId].token)
end
end
end
end
end)
AddEventHandler('playerDropped', function()
local _src = source
PlayerHeartbeats[_src] = nil
end)
end
------------------------------------
-------- OCR System -----
------------------------------------
function CaptureScreenshot(target)
if not Config.OCR then return end
-- This requires screenshot-basic or discord-screenshot resource
-- We will try to use the most common exports
local webhook = Config.OCRWebhook ~= "" and Config.OCRWebhook or Config.WebhookDiscord
if GetResourceState('screenshot-basic') == 'started' then
exports['screenshot-basic']:requestClientScreenshot(target, {
encoding = 'jpg',
quality = 0.8
}, function(err, data)
if not err and data then
PerformHttpRequest(webhook, function(err, text, headers) end, 'POST', json.encode({
username = "RW-AntiCheat OCR",
embeds = {{
title = "OCR Capture",
description = "Screenshot for Player ID: " .. target,
image = { url = data }
}}
}), { ['Content-Type'] = 'application/json' })
end
end)
end
end
------------------------------------
-------- Performance Init ----
------------------------------------
local BlacklistedVehiclesHash = {}
local BlacklistedPedsHash = {}
local BlacklistedObjectsHash = {}
Citizen.CreateThread(function()
-- Convert arrays to hash maps for O(1) lookup
for _, name in ipairs(Config.BlacklistedVehicles) do
BlacklistedVehiclesHash[GetHashKey(name)] = true
BlacklistedVehiclesHash[name] = true
end
for _, name in ipairs(Config.BlacklistedPeds) do
BlacklistedPedsHash[GetHashKey(name)] = true
BlacklistedPedsHash[name] = true
end
for _, name in ipairs(Config.BlacklistedObjects) do
BlacklistedObjectsHash[GetHashKey(name)] = true
BlacklistedObjectsHash[name] = true
end
end)
end)
------------------------------------
-------- Entity Protection ----
------------------------------------
-- Replaces old entityCreating and entityCreated logic
if Config.AntiEntity then
AddEventHandler('entityCreating', function(entity)
if not DoesEntityExist(entity) then return end
local src = NetworkGetEntityOwner(entity)
local script = GetEntityScript(entity)
local type = GetEntityType(entity) -- 1: Ped, 2: Vehicle, 3: Object
local model = GetEntityModel(entity)
-- Source 0 usually means server-side script, verify script name
if src == 0 or src == nil then
if script ~= nil then return end -- Trusted server script
-- If script is nil and src is 0, it might be map or unknown, proceed to blacklist check
end
-- If logic: Check strict control
-- If an entity is created by a known script, we trust it more,
-- but if it matches a BLACKLIST item, we still block it unless it's whitelisted explicitly.
if Config.StrictEntityControl and script == nil and src and src > 0 then
-- Player trying to spawn something without a script context (e.g., menu)
-- This is high risk. You might want to log this or be more aggressive.
end
if type == 1 and Config.AntiSpawnPeds then -- Ped
if BlacklistedPedsHash[model] then
CancelEvent()
if src and src > 0 then
kickorbancheater(src, "Blacklisted Ped Spawn", "Spawning blacklisted ped: " .. tostring(model) .. " (Script: "..(script or "None")..")", true, true)
end
return
end
elseif type == 2 and Config.AntiSpawnVehicles then -- Vehicle
if BlacklistedVehiclesHash[model] then
CancelEvent()
if src and src > 0 then
kickorbancheater(src, "Blacklisted Vehicle Spawn", "Spawning blacklisted vehicle: " .. tostring(model).. " (Script: "..(script or "None")..")", true, true)
end
return
end
elseif type == 3 and Config.AntiSpawnObjects then -- Object
if BlacklistedObjectsHash[model] then
CancelEvent()
if src and src > 0 then
kickorbancheater(src, "Blacklisted Object Spawn", "Spawning blacklisted object: " .. tostring(model).. " (Script: "..(script or "None")..")", true, true)
end
return
end
end
end)
end
-- Anti Entity Coords / Vehicle Fly (Server Side)
if Config.AntiEntityCoords then
Citizen.CreateThread(function()
local lastCoords = {}
while true do
Citizen.Wait(2000) -- Check every 2 seconds
for _, player in ipairs(GetPlayers()) do
local _src = tonumber(player)
local ped = GetPlayerPed(_src)
if DoesEntityExist(ped) then
local vehicle = GetVehiclePedIsIn(ped, false)
if vehicle and vehicle ~= 0 and GetPedInVehicleSeat(vehicle, -1) == ped then
-- Player is driver
local currentCoords = GetEntityCoords(vehicle)
if lastCoords[_src] then
local dist = #(currentCoords - lastCoords[_src])
-- 2 seconds interval. Max speed of fastest car ~140 mph ~= 62 m/s.
-- 2 seconds = 124m. Allow margin for falling/lag = 300m.
if dist > 400.0 then
-- Teleport or Fly Detected
-- Beware of interior teleports (check if routing bucket changed? FiveM handles this, coords usually jump)
-- Simple verification:
if GetEntityHeightAboveGround(vehicle) > 50.0 and not IsPedInAnyPlane(ped) and not IsPedInAnyHeli(ped) then
kickorbancheater(_src, "Vehicle Fly/Teleport", "Traveled " .. math.ceil(dist) .. " units in 2s.", true, true)
end
end
end
lastCoords[_src] = currentCoords
else
lastCoords[_src] = nil
end
end
end
end
end)
end
-- Anti Spoof Projectile & Projectile Security
if Config.AntiSpoofProjectile then
AddEventHandler("weaponDamageEvent", function(sender, data)
local _src = sender
-- data struct: damageType, weaponType, destructionDamage, tyreIndex...
-- FiveM doesn't give projectile origin explicitly in this event easily without parsing damageFlags
-- But we can check weapon type validity
-- Magic Bullet Check (Distance)
if data.weaponType ~= 911657153 and data.weaponType ~= 0 then -- Ignore Unarmed/Stun
local victim = NetworkGetEntityFromNetworkId(data.hitGlobalId)
local shooter = GetPlayerPed(_src)
if DoesEntityExist(victim) and DoesEntityExist(shooter) then
local vCoords = GetEntityCoords(victim)
local sCoords = GetEntityCoords(shooter)
local dist = #(vCoords - sCoords)
-- Hard limit for most guns is around 250-300m. Snipers more.
-- If distance is crazy (e.g. 1000m) and not a sniper, likely Magic Bullet / Spoof
if dist > 600.0 then
kickorbancheater(_src, "Projectile Spoof", "Hit player from " .. math.floor(dist) .. "m away.", true, true)
CancelEvent()
end
end
end
end)
end
------------------------------------
-------- Fake Message Chat --------
------------------------------------
RegisterNetEvent('chat:server:ServerPSA')
AddEventHandler('chat:server:ServerPSA', function()
local _src = source
kickorbancheater(_src,"Fake message detected", "Fake message detected",true,true)
end)
------------------------------------
-------- Anti Weapon Flag --------
------------------------------------
RegisterServerEvent('rwe:WeaponFlag')
AddEventHandler('rwe:WeaponFlag', function(weapon)
local _src = source
TriggerClientEvent("rwe:RemoveInventoryWeapons", _src)
kickorbancheater(_src,"Anti Weapon Flag", "Gave self a gun. Weapon: "..weapon,true,true)
end)
------------------------------------
-------- Blacklisted Events --------
------------------------------------
if Config.EventsDetect then
for k, v in pairs(Config.Events) do
RegisterServerEvent(v)
AddEventHandler(v, function()
local _src = source
kickorbancheater(_src,"Blacklisted Events", "Blacklisted Event Caught. Event: "..v,true,true)
CancelEvent()
end)
end
end
if Config.ProtectPoliceEvent then
for k, v in pairs(Config.PoliceEvents) do
RegisterServerEvent(v)
AddEventHandler(v, function()
local _src = source
local xPlayer = ESX.GetPlayerFromId(_src)
if xPlayer then
local job = xPlayer.getJob().name
if job ~= "police" and job ~= "sheriff" then
kickorbancheater(_src, "Police Events Detected", "Police Events Detected. Event: "..v, true, true)
end
end
end)
end
end
if Config.ProtectAmbulanceEvent then
for k, v in pairs(Config.AmbulanceEvents) do
RegisterServerEvent(v)
AddEventHandler(v, function()
local _src = source
local xPlayer = ESX.GetPlayerFromId(_src)
if xPlayer then
local job = xPlayer.getJob().name
if job ~= "ambulance" and job ~= "doctor" then
kickorbancheater(_src, "Ambulance Events Detected", "Ambulance Events Detected. Event: "..v, true, true)
end
end
end)
end
end
------------------------------------
-------- Blacklisted Word ----------
------------------------------------
AddEventHandler('chatMessage', function(source, color, message)
local _src = source
if not message then return end
if Config.AntiBlacklistedWords then
for k, v in pairs(Config.BlacklistWords) do
if string.match(message, v) then
Citizen.Wait(1500)
kickorbancheater(_src, "Blacklist Words Detected", "Blacklist Words Detected. Words: "..v, true, true)
CancelEvent()
return
end
end
end
end)
RegisterServerEvent('_chat:messageEntered')
AddEventHandler('_chat:messageEntered', function(author, color, message)
if not message then return end
local src = source
for k, v in pairs(Config.BlacklistWords) do
if string.match(message, v) then
Citizen.Wait(1500)
kickorbancheater(src, "Blacklist Words Detected", "Blacklist Words Detected. Words: "..v, true, true)
CancelEvent()
return
end
end
end)
------------------------------------
-------- Blacklisted Command -------
------------------------------------
Citizen.CreateThread(function()
for i=1, #Config.BlacklistedCommands, 1 do
RegisterCommand(Config.BlacklistedCommands[i], function(source)
local _src = source
kickorbancheater(_src, "Blacklist Command Detected", "Blacklist Command Detected.", true, true)
end)
end
end)
------------------------------------
-------- Admin Command -------
------------------------------------
RegisterCommand("entitywipe", function(source, args, raw)
local playerID = args[1]
if (playerID ~= nil and tonumber(playerID) ~= nil) then
EntityWipe(source, tonumber(playerID))
end
end, false)
function EntityWipe(source, target)
local _src = source
TriggerClientEvent("rwe:deletentity", -1, tonumber(target))
end
RegisterNetEvent('rwdeletevehiclesc', function(playerId)
local coords = GetEntityCoords(GetPlayerPed(playerId))
for _, v in pairs(GetAllVehicles()) do
local objCoords = GetEntityCoords(v)
local dist = #(coords - objCoords)
if dist < 2000 then
if DoesEntityExist(v) then
DeleteEntity(v)
end
end
end
end)
RegisterNetEvent('rwdeletepedsc', function(playerId)
local coords = GetEntityCoords(GetPlayerPed(playerId))
for _, v in pairs(GetAllPeds()) do
local objCoords = GetEntityCoords(v)
local dist = #(coords - objCoords)
if dist < 2000 then
if DoesEntityExist(v) then
DeleteEntity(v)
end
end
end
end)
RegisterNetEvent('rwdeleteobjectsc', function(playerId)
local coords = GetEntityCoords(GetPlayerPed(playerId))
for _, v in pairs(GetAllObjects()) do
local objCoords = GetEntityCoords(v)
local dist = #(coords - objCoords)
if dist < 2000 then
if DoesEntityExist(v) then
DeleteEntity(v)
end
end
end
end)
RegisterCommand("allentitywipe", function(source)
local _src = source
if IsPlayerWhitelisted(_src) then
TriggerEvent('rwdeletevehiclesc', tonumber(_src))
TriggerEvent('rwdeletepedsc', tonumber(_src))
TriggerEvent('rwdeleteobjectsc', tonumber(_src))
end
end, false)
--------------------------------------------
-------- Anti Taze & Weapon Event & AntiCrash ----------
--------------------------------------------
AddEventHandler("weaponDamageEvent", function(sender, data)
if Config.AntiTaze then
local _src = sender
if data.weaponType == 911657153 or data.weaponType == GetHashKey("WEAPON_STUNGUN") then
kickorbancheater(_src, "Anti Taze Player.", "Tried to shoot with a taser", true, true)
CancelEvent()
end
end
end)
AddEventHandler("giveWeaponEvent", function(sender,data)
if Config.AntiGiveWeaponEvent then
local _src = sender
if data.givenAsPickup == false then
kickorbancheater(_src, "Anti Give Weapon(event)", "Tried to give weapons to a Ped", true, true)
CancelEvent()
end
end
end)
if Config.AntiCrash then
AddEventHandler("playerDropped", function(reason)
for k, v in pairs(Config.BlacklistedCrash) do
local _src = source
if reason == v then
kickorbancheater(_src, "Crash Detected", "Blacklist Crash Detected", true, true)
end
end
end)
end
local Charset = {}
for i = 65, 90 do table.insert(Charset, string.char(i)) end
for i = 97, 122 do table.insert(Charset, string.char(i)) end
RandomLetter = function(length)
if length > 0 then
return RandomLetter(length - 1) .. Charset[math.random(1, #Charset)]
end
return ""
end
if Config.ProtectAmbulanceEvent then
for k, v in pairs(Config.AmbulanceEvents) do
RegisterServerEvent(v)
AddEventHandler(v, function()
local _src = source
if ESX.GetPlayerFromId(_src).getJob().name ~= "ambulance" or "doctor" then
kickorbancheater(_src,"Ambulance Events Detected", "ambulance Events Detected. Event: "..v,true,true)
end
end)
end
end