improvements

This commit is contained in:
EternityDev 2024-11-30 23:49:37 +07:00
parent f3b674b377
commit 925df47d4c
6 changed files with 18 additions and 20 deletions

View file

@ -231,17 +231,16 @@ function ClientProcess.start()
end end
end) end)
local function onClientNetworkReceive(Identifier: buffer | string, data: buffer, ref: { any }?) local function onClientNetworkReceive(Identifier: buffer | string, data: buffer, ref: { any }?)
if not Identifier or not data then return end if not Identifier or typeof(Identifier) ~= "buffer" or not data or typeof(data) ~= "buffer" then return end
Identifier = Buffer.convert(Identifier :: buffer) Identifier = Buffer.convert(Identifier :: buffer)
local idx: string = registeredIdentifier[Identifier]
if not idx then return end
local read = Buffer.read(data, ref) local read = Buffer.read(data, ref)
if not read then return end if not read then return end
for idx: string in registeredIdentifier do local callback = clientCallback[idx]
if idx ~= Identifier then continue end if not callback then return end
local callback = clientCallback[idx] or nil for _, fn: any in callback do
if not callback then continue end Spawn(fn, table.unpack(read))
for _, fn: any in callback do
Spawn(fn, table.unpack(read))
end
end end
end end
ReliableEvent.OnClientEvent:Connect(onClientNetworkReceive) ReliableEvent.OnClientEvent:Connect(onClientNetworkReceive)

View file

@ -304,17 +304,16 @@ function ServerProcess.start()
end end
end) end)
local function onServerNetworkReceive(player: Player, Identifier: buffer | string, data: buffer, ref: { any }?) local function onServerNetworkReceive(player: Player, Identifier: buffer | string, data: buffer, ref: { any }?)
if not Identifier or not data then return end if not Identifier or typeof(Identifier) ~= "buffer" or not data or typeof(data) ~= "buffer" then return end
Identifier = Buffer.convert(Identifier :: buffer) Identifier = Buffer.convert(Identifier :: buffer)
local idx: string = registeredIdentifier[Identifier]
if not idx then return end
local read = Buffer.read(data, ref) local read = Buffer.read(data, ref)
if not read then return end if not read then return end
for idx: string in registeredIdentifier do local callback = serverCallback[idx]
if idx ~= Identifier then continue end if not callback then return end
local callback = serverCallback[idx] or nil for _, fn: any in callback do
if not callback then continue end Spawn(fn, player, table.unpack(read))
for _, fn: any in callback do
Spawn(fn, player, table.unpack(read))
end
end end
end end
ReliableEvent.OnServerEvent:Connect(onServerNetworkReceive) ReliableEvent.OnServerEvent:Connect(onServerNetworkReceive)

View file

@ -36,7 +36,7 @@ function DedicatedBuffer.alloc(self: any, byte: number)
local b: buffer = self.buffer local b: buffer = self.buffer
while self.next + byte >= size do while self.next + byte >= size do
size = math.floor(size * 1.2) size = math.floor(size * 1.25) -- +25% increase
end end
local newBuffer: buffer = create(size) local newBuffer: buffer = create(size)
copy(newBuffer, 0, b) copy(newBuffer, 0, b)

View file

@ -15,7 +15,7 @@ function RateLimit.create(Identifier: string, entrance: number?, interval: numbe
Event:SetAttribute(Identifier.."_int", interval) Event:SetAttribute(Identifier.."_int", interval)
else else
while (not Event:GetAttribute(Identifier.."_ent")) or (not Event:GetAttribute(Identifier.."_int")) do while (not Event:GetAttribute(Identifier.."_ent")) or (not Event:GetAttribute(Identifier.."_int")) do
task.wait(0.25) task.wait(0.1)
end end
entrance = tonumber(Event:GetAttribute(Identifier.."_ent")) entrance = tonumber(Event:GetAttribute(Identifier.."_ent"))
interval = tonumber(Event:GetAttribute(Identifier.."_int")) interval = tonumber(Event:GetAttribute(Identifier.."_int"))

View file

@ -24,7 +24,7 @@ function SerDes.increment(Identifier: string, timeout: number?): number
error(`Serdes: {Identifier} is taking too long to retrieve, seems like it's not replicated on server.`, 2) error(`Serdes: {Identifier} is taking too long to retrieve, seems like it's not replicated on server.`, 2)
end) end)
task.spawn(function() task.spawn(function()
while coroutine.status(cancel) ~= "dead" and task.wait(0.25) do -- let it loop for yields! while coroutine.status(cancel) ~= "dead" and task.wait(0.04) do -- let it loop for yields! 1/24
if Event:GetAttribute(Identifier) then if Event:GetAttribute(Identifier) then
task.cancel(cancel) task.cancel(cancel)
task.spawn(yieldThread, Event:GetAttribute(Identifier)) task.spawn(yieldThread, Event:GetAttribute(Identifier))