-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathserver.lua
More file actions
84 lines (77 loc) · 3.89 KB
/
server.lua
File metadata and controls
84 lines (77 loc) · 3.89 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
--------------------------------------------------------------------------------------------
-- Guardian- A Far More Advanced FiveM Script Than DiscordWhitelist, Made By Jordan.#2139 --
--------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
-- !WARNING! !WARNING! !WARNING! !WARNING! !WARNING! --
-- DO NOT TOUCH THIS FILE OR YOU /WILL/ FUCK SHIT UP! EDIT THE CONFIG.LUA --
-- DO NOT BE STUPID AND WHINE TO ME ABOUT THIS BEING BROKEN IF YOU TOUCHED THE LINES BELOW. --
----------------------------------------------------------------------------------------------
function ExtractIdentifiers(src)
local identifiers = {
discord = ""
}
--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, "discord") then
identifiers.discord = id
end
end
return identifiers
end
roleList = Config.WhitelistRoles;
AddEventHandler("playerConnecting", function(name, setCallback, deferrals)
local Config = Config
deferrals.defer()
local src = source
local identifierDiscord = "";
local identifierSteam = nil;
deferrals.update("Checking Whitelist Permissions For " .. Config.ServerName)
Citizen.Wait(0); -- Necessary Citizen.Wait() before deferrals.done()
for k, v in ipairs(GetPlayerIdentifiers(src)) do
if string.sub(v, 1, string.len("discord:")) == "discord:" then
identifierDiscord = v
end
if string.sub(v, 1, string.len("steam:")) == "steam:" then
identifierSteam = v
end
end
local isWhitelisted = false;
if identifierDiscord then
local roleIDs = exports.Badger_Discord_API:GetDiscordRoles(src)
if not (roleIDs == false) then
for i = 1, #roleList do
for j = 1, #roleIDs do
if exports.Badger_Discord_API:CheckEqual(roleList[i], roleIDs[j]) then
print("[Guardian] (playerConnecting) Allowing " .. GetPlayerName(src) .. " to join with the role " .. roleList[i])
print("[Guardian] (playerConnecting) Player " .. GetPlayerName(src) .. " Attempted to connect with Guardian, They were allowed entry")
isWhitelisted = true;
else
if isWhitelisted == false then
isWhitelisted = false;
end
end
end
end
else
print("[Guardian] (playerConnecting) Player " .. GetPlayerName(src) or identifierSteam or "NO ID FOUND" .. " Could not connect because role id\'s were not present")
print("[Guardian] (playerConnecting) Player " .. GetPlayerName(src) or identifierSteam or "NO ID FOUND" .. " Attempted to connect with Guardian, however they failed")
deferrals.done(Config.RoleIdsYeet)
CancelEvent()
return;
end
else
print("[Guardian] (playerConnecting) Declined connection from " .. GetPlayerName(src) or identifierSteam or "NO ID FOUND" .. " because they did not have Discord open")
print("[Guardian] (playerConnecting) Player " .. GetPlayerName(src) or identifierSteam or "NO ID FOUND" .. " Attempted to connect with Guardian, however they failed")
deferrals.done(Config.DiscordYeet)
CancelEvent()
return;
end
if isWhitelisted then
deferrals.done();
else
deferrals.done(Config.WhitelistYeet);
CancelEvent()
end
end)