-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
335 lines (263 loc) · 6.65 KB
/
server.lua
File metadata and controls
335 lines (263 loc) · 6.65 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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
local players = {} -- {id, points, source}
local waiting = {} -- {id}
local connecting = {} -- {id}
local prePoints = Config.Points;
local EmojiList = Config.EmojiList
Citizen.CreateThread(function()
CheckWhitelistUsers()
end)
Citizen.CreateThread(function()
local maxServerSlots = GetConvarInt('sv_maxclients', 128)
while true do
Citizen.Wait(Config.TimerCheckPlaces * 1000)
CheckConnecting()
if #waiting > 0 and #connecting + #GetPlayers() < maxServerSlots then
ConnectFirst()
end
end
end)
Citizen.CreateThread(function()
while true do
UpdatePoints()
Citizen.Wait(Config.TimerUpdatePoints * 1000)
end
end)
RegisterServerEvent("nex_queue:playerKicked")
RegisterServerEvent("nex_queue:playerConnected")
RegisterServerEvent('QueueNex:RefreshList', function() CheckWhitelistUsers() end) -- Used in nex_admin
AddEventHandler("playerConnecting", function(name, reject, def)
local source = source
local userId = (Config.UseSteamID and GetSteamID(source) or GetLicenseID(source))
if not userId then
reject(Config.NoSteam)
CancelEvent()
return
end
if not Rocade(userId, def, source) then
CancelEvent()
end
end)
AddEventHandler("nex_queue:playerKicked", function(src, points)
local sid = (Config.UseSteamID and GetSteamID(src) or GetLicenseID(src))
Purge(sid)
for i,p in ipairs(prePoints) do
if p[1] == sid then
p[2] = p[2] - points
return
end
end
local initialPoints = GetInitialPoints(sid)
table.insert(prePoints, {sid, initialPoints - points})
end)
AddEventHandler("nexQueue:playerConnected", function()
local sid = (Config.UseSteamID and GetSteamID(source) or GetLicenseID(source))
Purge(sid)
end)
AddEventHandler("playerDropped", function(reason)
local steamID = (Config.UseSteamID and GetSteamID(source) or GetLicenseID(source))
Purge(steamID)
end)
function Rocade(userId, def, source)
def.defer()
AntiSpam(def)
Purge(userId)
AddPlayer(userId, source)
table.insert(waiting, userId)
local stop = false
repeat
for i,p in ipairs(connecting) do
if p == userId then
stop = true
break
end
end
for j,sid in ipairs(waiting) do
for i,p in ipairs(players) do
if sid == p[1] and p[1] == userId and (GetPlayerPing(p[3]) == 0) then
Purge(userId)
def.done(Config.Accident)
return false
end
end
end
def.update(GetMessage(userId))
Citizen.Wait(Config.TimerRefreshClient * 1000)
until stop
def.done()
return true
end
function CheckWhitelistUsers()
-- VIPS
MySQL.Async.fetchAll("SELECT users_characters.isVip, users_identifiers.steam FROM users_characters INNER JOIN users_identifiers ON users_characters.identifier = users_identifiers.identifier WHERE users_characters.isVip > 0", {}, function(vipUsers)
for k, v in pairs(vipUsers) do
local data = {steamid = v.steam, points = 5000 }
table.insert(prePoints, data)
end
end)
-- STAFF
MySQL.Async.fetchAll("SELECT users.group, users_identifiers.steam FROM users INNER JOIN users_identifiers ON users.identifier = users_identifiers.identifier WHERE users.group = 'admin'", {}, function(vipUsers)
for k, v in pairs(vipUsers) do
local data = {steamid = v.steam, points = 8000 }
table.insert(prePoints, data)
end
end)
end
function CheckConnecting()
for i,sid in ipairs(connecting) do
for j,p in ipairs(players) do
if p[1] == sid and (GetPlayerPing(p[3]) == 500) then
table.remove(connecting, i)
break
end
end
end
end
function ConnectFirst()
if #waiting == 0 then return end
local maxPoint = 0
local maxSid = waiting[1][1]
local maxWaitId = 1
for i,sid in ipairs(waiting) do
local points = GetPoints(sid)
if points > maxPoint then
maxPoint = points
maxSid = sid
maxWaitId = i
end
end
table.remove(waiting, maxWaitId)
table.insert(connecting, maxSid)
end
function GetPoints(steamID)
for i,p in ipairs(players) do
if p[1] == steamID then
return p[2]
end
end
end
function UpdatePoints()
for i,p in ipairs(players) do
local found = false
for j,sid in ipairs(waiting) do
if p[1] == sid then
p[2] = p[2] + Config.AddPoints
found = true
break
end
end
if not found then
for j,sid in ipairs(connecting) do
if p[1] == sid then
found = true
break
end
end
if not found then
p[2] = p[2] - Config.RemovePoints
if p[2] < GetInitialPoints(p[1]) - Config.RemovePoints then
Purge(p[1])
table.remove(players, i)
end
end
end
end
end
function AddPlayer(steamID, source)
for i,p in ipairs(players) do
if steamID == p[1] then
players[i] = {p[1], p[2], source}
return
end
end
local initialPoints = GetInitialPoints(steamID)
table.insert(players, {steamID, initialPoints, source})
end
function GetInitialPoints(steamID)
local points = Config.RemovePoints + 1
for n,p in ipairs(prePoints) do
if p[1] == steamID then
points = p[2]
break
end
end
return points
end
function GetPlace(steamID)
local points = GetPoints(steamID)
local place = 1
for i,sid in ipairs(waiting) do
for j,p in ipairs(players) do
if p[1] == sid and p[2] > points then
place = place + 1
end
end
end
return place
end
function GetMessage(steamID)
local msg = ""
if GetPoints(steamID) ~= nil then
msg = Config.EnRoute .. " " .. GetPoints(steamID) .." " .. Config.PointsRP ..".\n"
msg = msg .. Config.Position .. GetPlace(steamID) .. "/".. #waiting .. " " .. ".\n"
msg = msg .. "[ " .. Config.EmojiMsg
local e1 = RandomEmojiList()
local e2 = RandomEmojiList()
local e3 = RandomEmojiList()
local emojis = e1 .. e2 .. e3
if( e1 == e2 and e2 == e3 ) then
emojis = emojis .. Config.EmojiBoost
LoterieBoost(steamID)
end
msg = msg .. emojis .. " ]"
else
msg = Config.Error
end
return msg
end
function LoterieBoost(steamID)
for i,p in ipairs(players) do
if p[1] == steamID then
p[2] = p[2] + Config.LoterieBonusPoints
return
end
end
end
function Purge(steamID)
for n,sid in ipairs(connecting) do
if sid == steamID then
table.remove(connecting, n)
end
end
for n,sid in ipairs(waiting) do
if sid == steamID then
table.remove(waiting, n)
end
end
end
function AntiSpam(def)
for i=Config.AntiSpamTimer,0,-1 do
def.update(Config.PleaseWait_1 .. i .. Config.PleaseWait_2)
Citizen.Wait(1000)
end
end
function RandomEmojiList()
randomEmoji = EmojiList[math.random(#EmojiList)]
return randomEmoji
end
function GetSteamID(src)
local sid = GetPlayerIdentifiers(src)[1] or false
if (sid == false or sid:sub(1,5) ~= "steam") then
return false
end
return sid
end
function GetLicenseID(src)
local identifier = false
for k,v in ipairs(GetPlayerIdentifiers(playerId)) do
if string.match(v, 'license:') then
identifier = string.sub(v, 9)
break
end
end
return identifier
end