Skip to content

Commit

Permalink
refactor(server/queue): organize code
Browse files Browse the repository at this point in the history
  • Loading branch information
D4isDAVID committed Dec 15, 2023
1 parent b451307 commit 290c784
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions server/queue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ local maxPlayers = GlobalState.MaxPlayers
local playerPositions = {}
local queueSize = 0

---@param license string
local function enqueue(license)
queueSize += 1
playerPositions[license] = queueSize
end

---@param license string
local function dequeue(license)
local pos = playerPositions[license]

queueSize -= 1
playerPositions[license] = nil

-- decrease the positions of players who are after the current player in queue
for k, v in pairs(playerPositions) do
if v > pos then
playerPositions[k] -= 1
end
end
end

---Map of player licenses that passed the queue and are downloading server content.
---Needs to be saved because these players won't be part of regular player counts such as `GetNumPlayerIndices`.
---@type table<string, true>
Expand All @@ -46,27 +67,6 @@ local function removePlayerJoining(license)
joiningPlayers[license] = nil
end

---@param license string
local function enqueue(license)
queueSize += 1
playerPositions[license] = queueSize
end

---@param license string
local function dequeue(license)
local pos = playerPositions[license]

queueSize -= 1
playerPositions[license] = nil

-- decrease the positions of players who are after the current player in queue
for k, v in pairs(playerPositions) do
if v > pos then
playerPositions[k] -= 1
end
end
end

---@param source Source
---@param license string
---@param deferrals Deferrals
Expand Down

0 comments on commit 290c784

Please sign in to comment.