-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwhitelist.lua
More file actions
121 lines (88 loc) · 3.35 KB
/
Copy pathwhitelist.lua
File metadata and controls
121 lines (88 loc) · 3.35 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
-- Created by Flagship - 𝕕𝕖𝕧#1001 and Kirta#9173 for their server LeyendasRP || https://discord.gg/wwbxcC8Qp4
-- Maximum attempts for players
local attempts = 2 -- How many attempts
--[[
When player connects to server:
- Checks whitelist, if the steam ID is on the whitelist array, let him in.
- If he is not on the whitelist, check if the IP has more than the variable "attemps", if attempts > Nº IPs, then let him in.
- If he is not whitelisted, and he connected more than "attempts", drop from the server.
]]
AddEventHandler("playerConnecting", function(playerName, setKickReason, deferrals)
-- Array Whitelist
local whitelistArray = {}
-- Read whitelist.txt
local data = LoadResourceFile(GetCurrentResourceName(), "whitelist.txt")
-- If there are new steamids on the .txt, add them to the array.
if data then
for s in string.gmatch(data,"[^\r\n]+") do
table.insert(whitelistArray, s)
end
print("Loaded " .. #whitelistArray .. " whitelisted identifiers")
end
-- Same to ips.log
local ipArray = {}
local dataIp = LoadResourceFile(GetCurrentResourceName(), "ips.log")
if dataIp then
for s in string.gmatch(dataIp, "[^\r\n]+") do
table.insert(ipArray, s)
end
print("Loaded " .. #ipArray .. "IPs")
end
-- Stop conection to check the stuff
deferrals.defer()
-- Save source.
local s = source
-- Boolean to join or not
local joined = false
-- Say to the user, that we are checking whitelist
deferrals.update("👽 Wait, we are checking the whitelist -- Discord = https://discord.gg/wwbxcC8Qp4👽")
-- Necessary
Wait(100)
-- Variables
local totalInWhitelist = #whitelistArray
local noIdentifiers = #GetPlayerIdentifiers(s)
local currentId = 0
local totalChecksNeeded = totalInWhitelist * noIdentifiers
local ipcount = 0
-- Get player identifiers
for myIdx,identifier in pairs(GetPlayerIdentifiers(s)) do
-- Checks steam IDs
for wIdx,i in ipairs(whitelistArray) do
-- Check if the steam ID is on the whitelist
if(string.lower(i) == string.lower(identifier))then
deferrals.done() -- Dejarles conectar
joined = true
break -- Stop loop
end
-- Say to user the % of checking
deferrals.update(string.format("🍸 Checking whitelist: %.2f%% -- Discord! https://discord.gg/prqmx8P🍸", (currentId / totalChecksNeeded)*100))
Wait(1)
currentId = currentId +1
end
end
-- If he is not whitelist, then:
if(joined == false)then
-- Get his IP
local ipv4 = GetPlayerEndpoint(s)
-- Check the number of connections with that IP
for k,j in ipairs(ipArray) do
if(string.lower(j) == string.lower(ipv4))then
ipcount = ipcount + 1
end
end
end
-- Stop resource if he is already joined
if joined then
return
-- Not whitelist + More than "attempts" then:
elseif((joined == false) and (ipcount>=attempts))then
deferrals.done("🌙 You have finished the trial period! -- https://discord.gg/prqmx8P🌙")
-- No whitelist, but he is already on trial period:
else
-- Save his IP on logs
local file = LoadResourceFile(GetCurrentResourceName(), "ips.log")
SaveResourceFile(GetCurrentResourceName(), "ips.log", file .. GetPlayerEndpoint(s) .. "\n", -1)
-- Let them in
deferrals.done()
end
end)