This repository has been archived by the owner on Mar 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.lua
71 lines (64 loc) · 2.9 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
function ExtractIdentifiers(src)
local identifiers = {
discord = ""
}
--Loop Identifiers
for i = 0, GetNumPlayerIdentifiers(src) - 1 do
local id = GetPlayerIdentifier(src, i)
if string.find(id, "discord") then
identifiers.discord = id
end
end
return identifiers
end
roleList = Configure.Whitelisted;
AddEventHandler("playerConnecting", function(name, setCallback, deferrals)
local Configure = Configure
deferrals.defer()
local src = source
local identifierDiscord = "";
deferrals.update("Checking Your Server Permissions For " .. Configure.svname)
Citizen.Wait(0);
for k, v in ipairs(GetPlayerIdentifiers(src)) do
if string.sub(v, 1, string.len("discord:")) == "discord:" then
identifierDiscord = 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("[Raccoon-Whitelist] (playerConnecting) Allowing " .. GetPlayerName(src) .. " to join with the role " .. roleList[i])
print("[Raccoon-Whitelist] (playerConnecting) Player " .. GetPlayerName(src) .. " Attempted to connect with Raccoon-Whitelist, They were allowed entry")
isWhitelisted = true;
else
if isWhitelisted == false then
isWhitelisted = false;
end
end
end
end
else
print("[Raccoon-Whitelist] (playerConnecting) Player " .. GetPlayerName(src) .. " We could not get your Role ID\'s, failed to connect.")
print("[Raccoon-Whitelist] (playerConnecting) Player " .. GetPlayerName(src) .. " Attempted to connect with Raccoon-Whitelist, connection has failed.")
deferrals.done(Configure.RoleIDKick)
CancelEvent()
return;
end
else
print("[Raccoon-Whitelist] (playerConnecting) Declined connection from " .. GetPlayerName(src) .. " because they did not have Discord open")
print("[Raccoon-Whitelist] (playerConnecting) Player " .. GetPlayerName(src) .. " Attempted to connect with Raccoon-Whitelist, connection has failed.")
deferrals.done(Configure.DiscordKick)
CancelEvent()
return;
end
if isWhitelisted then
deferrals.done();
else
deferrals.done(Configure.WhitelistKick);
CancelEvent()
end
end)