Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/packets/packet.luau
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,20 @@ return function(props: types.packetProps<types.dataTypeInterface<any>>, id: numb

function exported.wait()
-- define it up here so we can use it to disconnect
local index: number

local runningThread = coroutine.running()
table.insert(listeners, function(data, player)
local Callback: (any,Player) -> ()
Callback = function(data, player)
task.spawn(runningThread, data, player)

-- Disconnects the listener
table.remove(listeners, index)
end)

-- we connected, time to set the index for when we need to disconnect.
index = #listeners

-- the listener will resume the thread
table.remove(listeners,table.find(listeners,Callback))
end
table.insert(listeners, Callback)
return coroutine.yield()
end

function exported.listen(callback)
table.insert(listeners, callback)
return function()
table.remove(listeners,table.find(listeners, callback))
end
end

function exported.getListeners()
Expand Down
10 changes: 9 additions & 1 deletion src/process/read.luau
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ return function(incomingBuffer: buffer, references: { [number]: unknown }?, play
readRefs.set(references)

while readCursor < length do
local packet = ref[buffer.readu8(incomingBuffer, readCursor)]
local packet
while true do
packet = ref[buffer.readu8(incomingBuffer, readCursor)]
if not packet then
task.wait()
else
break
end
end
readCursor += 1

local value, valueLength = packet.reader(incomingBuffer, readCursor)
Expand Down
5 changes: 4 additions & 1 deletion src/process/server.luau
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ function serverProcess.start()
end

Players.PlayerAdded:Connect(playerAdded)

Players.PlayerRemoving:Connect(function(Player)
perPlayerReliable[Player] = nil
perPlayerUnreliable[Player] = nil
end)
RunService.Heartbeat:Connect(function()
-- Check if the channel has anything before trying to send it
if globalReliable.cursor > 0 then
Expand Down