-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathserver.lua
More file actions
149 lines (128 loc) · 4.32 KB
/
server.lua
File metadata and controls
149 lines (128 loc) · 4.32 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
--[[
Nertigel's Simple Anti-Cheat
]]
local oldPrint = print
print = function(trash)
oldPrint('^2[NSAC] '..trash..'^0')
end
--[[
Add your discord webhook here
]]
local discord_webhook = 'https://discordapp.com/api/webhooks/xxx/xxx'
RegisterNetEvent('nsac:trigger')
AddEventHandler('nsac:trigger', function(reason)
local _source = source
local identifiers = GetPlayerIdentifiers(_source)
if reason == nil or reason == '' then reason = 'no reason' end
banUser(_source)
DropPlayer(_source, ' Nertigel\'s Simple Anti-Cheat \n You have been kicked for the reason: '..reason..'.\n github.com/nertigel/NSAC')
if #identifiers >= 1 then --[[Anti-spam(if triggered in a loop then it will spam server console & logs)]]
print('detection: '.._source..' - reason: '..reason)
print('identifiers: '..json.encode(identifiers))
TriggerEvent('nsac:log', 'nsac - detection: '..reason)
end
end)
RegisterNetEvent('nsac:log')
AddEventHandler('nsac:log', function(reason)
local _source = source
if reason == nil or reason == '' then reason = 'no reason' end
sendToDiscord(_source, 'nsac - violation', reason)
print(json.encode(GetPlayerIdentifiers(_source)))
end)
--[[Credits to ElNelyo: https://github.com/ElNelyo/esx_discord_bot/blob/master/server/main.lua]]
sendToDiscord = function(_source, name, message)
if message == nil or message == '' then
print('message not set, therefore it wasn\'t sent')
return
end
if discord_webhook == nil and discord_webhook == '' then
print('discord_webhook not set, therefore it wasn\'t sent')
return
end
local uselessIdentifiers = ''
local text = ''
--[[FiveM Wiki is veri cool men]]
if _source then
for k,v in pairs(GetPlayerIdentifiers(_source)) do
if string.sub(v, 1, string.len('steam:')) == 'steam:' then
uselessIdentifiers = uselessIdentifiers..'\n'..v
elseif string.sub(v, 1, string.len('license:')) == 'license:' then
uselessIdentifiers = uselessIdentifiers..'\n'..v
elseif string.sub(v, 1, string.len('xbl:')) == 'xbl:' then
uselessIdentifiers = uselessIdentifiers..'\n'..v
elseif string.sub(v, 1, string.len('ip:')) == 'ip:' then
uselessIdentifiers = uselessIdentifiers..'\n'..v
elseif string.sub(v, 1, string.len('discord:')) == 'discord:' then
uselessIdentifiers = uselessIdentifiers..'\n'..v
elseif string.sub(v, 1, string.len('live:')) == 'live:' then
uselessIdentifiers = uselessIdentifiers..'\n'..v
end
end
end
if _source then
text = uselessIdentifiers
else
text = ''
end
local embeds = { {
['title'] = 'NSAC',
['type'] = 'rich',
['description'] = message..text,
['color'] = 16711680, --[[Red]]
['footer'] = {
['text'] = 'Nertigel\'s Simple Anti-Cheat',
}, }
}
PerformHttpRequest(discord_webhook, function(err, text, headers) end, 'POST', json.encode({ username = name, embeds = embeds}), { ['Content-Type'] = 'application/json' })
end
sendToDiscord(false, 'Nertigel\'s Simple Anti-Cheat', 'Resource has been started')
--[[
Ban list credits to nekler/de_way / Good old AlphaVeta
]]
local bansList = ''
AddEventHandler('onServerResourceStart', function(resource_name)
if resource_name == GetCurrentResourceName() then
local path = GetResourcePath(resource_name)
local file = io.open(path..'/bans.txt', 'r')
if file then
file:seek('set', 0)
bansList = file:read('*a')
file:close()
else
print('Couldn\'t find bans.txt in: '..path..' | '..GetCurrentResourceName())
end
while true do
file = io.open(path..'/bans.txt', 'w')
if file then
file:seek('set', 0)
file:write(bansList)
file:close()
else
print('Couldnt write in: '..path..'/bans.txt')
end
Wait(15000) --[[Save banlist every x amount]]
end
end
end)
AddEventHandler('playerConnecting', function(name, shouldDrop, deferrals)
local num = GetNumPlayerIdentifiers(source)
local _i = 0
while _i < num-1 do
local identifier = GetPlayerIdentifier(source, _i)
if string.find(bansList, identifier) then
banUser(source)
shouldDrop(' Nertigel\'s Simple Anti-Cheat \n You have been banned from this server for cheating.\n github.com/nertigel/NSAC')
CancelEvent()
end
_i = _i + 1
end
end)
banUser = function(player)
local num = GetNumPlayerIdentifiers(player)
for _i = 0, num-1 do
local identifier = GetPlayerIdentifier(player, _i)
if not string.find(bansList, identifier) then
bansList = bansList..identifier..'\n'
end
end
end