-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.lua
225 lines (201 loc) · 6.52 KB
/
main.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
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
-- Don't change code in here.
-- All values you need to modify are in the config.lua file provided.
Queue = {}
Queue.Current = {}
Queue.GetDiscordIdentifier = function(source)
local identifiers = GetPlayerIdentifiers(source)
for i=1,5 do
for _,id in next,identifiers,nil do
if id:find("discord") then
return id
end
end
Wait(1000)
end
return false
end
Queue.GetDiscordMember = function(identifier)
local res,ret = false,false
PerformHttpRequest(string.format('https://discordapp.com/api/guilds/%s/members/%s',Config.Tokens.Discord,identifier),function(err,data)
if data then
ret = json.decode(data)
else
ret = false
end
res = true
end,'GET','',{['Content-Type'] = 'application/json', ['Authorization'] = Config.Tokens.Bot})
while not res do Wait(0); end
return ret
end
Queue.CheckDiscordRole = function(member,id)
for _,role in ipairs(member.roles) do
if role == id then
return true
end
end
return false
end
Queue.CheckInfront = function(source)
local staff,priority,members = 0,0,0
for k,v in ipairs(Queue.Current) do
if v.source == source then
return staff,priority,members
else
if v.queue == 1 then
staff = staff + 1
elseif v.queue == 2 then
priority = priority + 1
else
members = members + 1
end
end
end
return staff,priority,members
end
Queue.Add = function(source,queue)
if queue == 1 then
for k,v in ipairs(Queue.Current) do
if v.queue == 1 then
last = k
end
if v.queue > 1 then
table.insert(Queue.Current,k,{source = source, queue = queue})
return
end
end
table.insert(Queue.Current,1,{source = source, queue = queue})
elseif queue == 2 then
local last = 0
for k,v in ipairs(Queue.Current) do
if v.queue == 1 or v.queue == 2 then
last = k
end
if v.queue > 2 then
table.insert(Queue.Current,k,{source = source, queue = queue})
return
end
end
table.insert(Queue.Current,last+1,{source = source, queue = queue})
elseif queue == 3 then
local last = 0
for k,v in ipairs(Queue.Current) do
if v.queue == 1 or v.queue == 2 or v.queue == 3 then
last = k
end
if v.queue > 3 then
table.insert(Queue.Current,k,{source = source, queue = queue})
return
end
end
table.insert(Queue.Current,last+1,{source = source, queue = queue})
elseif queue == 4 then
table.insert(Queue.Current,{source = source, queue = queue})
end
end
Queue.Remove = function(source)
for k,v in ipairs(Queue.Current) do
if v.source == source then
table.remove(Queue.Current,k)
return
end
end
end
Queue.Ready = function(source)
for k,v in ipairs(Queue.Current) do
if v.source == source then
if not GetPlayerName(source) then
return false,false
else
return true,k
end
end
end
end
Queue.Connect = function(name,setKickReason,deferrals)
local _source = source
deferrals.defer()
Wait(0)
local identifier = Queue.GetDiscordIdentifier(_source)
if identifier then
deferrals.update("Checking discord identifier.")
local id = identifier:gsub("discord:","")
local member = Queue.GetDiscordMember(id)
if member then
if Config.Tokens.StaffRole and Queue.CheckDiscordRole(member,Config.Tokens.StaffRole) then
deferrals.update("Connecting to server as staff.")
Queue.Add(_source,1)
elseif Config.Tokens.PriorityRole and Queue.CheckDiscordRole(member,Config.Tokens.PriorityRole) then
deferrals.update("Connecting to server as priority.")
Queue.Add(_source,2)
elseif Config.Tokens.WhitelistRole and Queue.CheckDiscordRole(member,Config.Tokens.WhitelistRole) then
deferrals.update("Connecting to server as whitelisted.")
Queue.Add(_source,3)
else
if Config.Whitelisted then
deferrals.done("You are not whitelisted.")
return
else
deferrals.update("Connecting to server as unlisted.")
Queue.Add(_source,4)
end
end
local tick = 0
while GetNumPlayerIndices() >= (Config.MaxPlayers-Config.ReserveSlots) do
local connected,queue = Queue.Ready(_source)
if not connected then
Queue.Remove(_source)
return
else
tick = tick + 1
if tick > 3 then
tick = 1
end
if GetNumPlayerIndices() < (Config.MaxPlayers) then
if Config.Tokens.StaffRole and Queue.CheckDiscordRole(member,Config.Tokens.StaffRole) then
break
elseif Config.Tokens.PriorityRole and Queue.CheckDiscordRole(member,Config.Tokens.PriorityRole) then
break
else
deferrals.update(string.format("Server full. Please wait%s",string.rep(".",tick)))
end
else
deferrals.update(string.format("Server full. Please wait%s",string.rep(".",tick)))
end
Wait(1000)
end
end
tick = 0
local connected,queue = Queue.Ready(_source)
while queue ~= 1 do
if not connected then
Queue.Remove(_source)
return
else
local staff,priority,members = Queue.CheckInfront(_source)
tick = tick + 1
if tick > 3 then
tick = 1
end
if Config.ShowStaffQueue and Config.ShowPriorityQueue then
deferrals.update(string.format("%i staff, %i priority, %i member%s ahead of you in the queue%s",staff,priority,members,(members == 1 and "" or "s"),string.rep(".",tick)))
elseif Config.ShowStaffQueue then
deferrals.update(string.format("%i staff, %i member%s ahead of you in the queue%s",staff,members,(members == 1 and "" or "s"),string.rep(".",tick)))
elseif Config.ShowPriorityQueue then
deferrals.update(string.format("%i priority, %i member%s ahead of you in the queue%s",priority,members,(members == 1 and "" or "s"),string.rep(".",tick)))
else
deferrals.update(string.format("%i member%s ahead of you in the queue",queue-1,(queue-1 == 1 and "" or "s"),string.rep(".",tick)))
end
Wait(1000)
end
end
Queue.Remove(_source)
deferrals.done()
else
deferrals.done("You are not apart of the discord.")
end
else
deferrals.done("You are not connected to discord.")
end
end
RegisterNetEvent("playerConnecting")
AddEventHandler("playerConnecting",Queue.Connect)