Skip to content

Commit

Permalink
Fix: QueryResult filter stops iteration, causing packets to not be qu…
Browse files Browse the repository at this point in the history
…eried
  • Loading branch information
YetAnotherClown committed Aug 26, 2024
1 parent 7c609df commit 04632d5
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions lib/QueryResult.luau
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,31 @@ function QueryResult:__iter()
local senders = self._senders
local identifier = self._identifier

local snapshot = self._snapshot
local i = 0
local filteredSnapshot = {}

return function()
-- Tick for new packet
i += 1

local packet = snapshot[i]
for i = 1, #self._snapshot do
local packet = self._snapshot[i]
if not packet then
return
continue
end

-- Return all packets if no Senders are supplied, or filter by Senders
local filterSenders = #senders > 0
local isSenderAllowed = if filterSenders then table.find(senders, packet.sender) else true

-- Don't return packet if filtered
if read(packet.identifier) ~= read(identifier) or not isSenderAllowed then
continue
end

table.insert(filteredSnapshot, packet)
end

local i = 0

return function()
i += 1

local packet = filteredSnapshot[i]
if not packet then
return
end

Expand Down

0 comments on commit 04632d5

Please sign in to comment.