-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
82 lines (75 loc) · 2.64 KB
/
server.lua
File metadata and controls
82 lines (75 loc) · 2.64 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
local Lobbies = {}
local SetPlayerRoutingBucket = SetPlayerRoutingBucket
local GetPlayerName = GetPlayerName
RegisterNetEvent('Lobbies', function(data)
if data.type == 'New Lobby' then
local index = #Lobbies+1
local name = GetPlayerName(source)
if data.Password then
Lobbies[index] = {
Players = {name},
CachedPlayers = {source},
index = index,
Password = data.Password,
Name = data.Name,
source = source,
Creator = name,
Settings = data.Settings
}
else
Lobbies[index] = {
Players = {name},
index = index,
CachedPlayers = {source},
Name = data.Name,
Creator = name,
Settings = data.Settings
}
end
SetPlayerRoutingBucket(source, index)
elseif data.type == 'Leave' then
SetPlayerRoutingBucket(source, 0)
for i = 1, #Lobbies do
local Lobby = Lobbies[i]
if Lobby.Creator == source then
for j = 1, #Lobby.CachedPlayers do
local Player = Lobby.CachedPlayers[j]
SetPlayerRoutingBucket(Player, 0)
TriggerClientEvent('Lobbies', Player, nil)
end
Lobby = nil
end
end
elseif data.type == 'Join Lobby' then
local lobby = Lobbies[data.Lobby]
if lobby.Password then
local pass = lib.callback.await('Lobby:EnterPassword', source)
if lobby.Password == pass then
SetPlayerRoutingBucket(source, data.Lobby)
lobby.Players[#lobby.Players+1] = GetPlayerName(source)
lobby.CachedPlayers[lobby.CachedPlayers+1] = source
end
else
SetPlayerRoutingBucket(source, data.Lobby)
lobby.Players[#lobby.Players+1] = GetPlayerName(source)
lobby.CachedPlayers[lobby.CachedPlayers+1] = source
end
TriggerClientEvent('Lobbies', source, lobby.Settings)
end
end)
lib.callback.register('GetLobbyCount', function()
return Lobbies
end)
AddEventHandler('playerDropped', function ()
for i = 1, #Lobbies do
local Lobby = Lobbies[i]
if Lobby.Creator == source then
for j = 1, #Lobby.CachedPlayers do
local Player = Lobby.CachedPlayers[j]
SetPlayerRoutingBucket(Player, 0)
TriggerClientEvent('Lobbies', Player, nil)
end
Lobby = nil
end
end
end)