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,19 +231,18 @@ function ClientProcess.start()
end
end)
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)
local idx: string = registeredIdentifier[Identifier]
if not idx then return end
local read = Buffer.read(data, ref)
if not read then return end
for idx: string in registeredIdentifier do
if idx ~= Identifier then continue end
local callback = clientCallback[idx] or nil
if not callback then continue end
local callback = clientCallback[idx]
if not callback then return end
for _, fn: any in callback do
Spawn(fn, table.unpack(read))
end
end
end
ReliableEvent.OnClientEvent:Connect(onClientNetworkReceive)
UnreliableEvent.OnClientEvent:Connect(onClientNetworkReceive)
RequestEvent.OnClientEvent:Connect(function(Identifier: any, action: string, data)

View file

@ -304,19 +304,18 @@ function ServerProcess.start()
end
end)
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)
local idx: string = registeredIdentifier[Identifier]
if not idx then return end
local read = Buffer.read(data, ref)
if not read then return end
for idx: string in registeredIdentifier do
if idx ~= Identifier then continue end
local callback = serverCallback[idx] or nil
if not callback then continue end
local callback = serverCallback[idx]
if not callback then return end
for _, fn: any in callback do
Spawn(fn, player, table.unpack(read))
end
end
end
ReliableEvent.OnServerEvent:Connect(onServerNetworkReceive)
UnreliableEvent.OnServerEvent:Connect(onServerNetworkReceive)
RequestEvent.OnServerEvent:Connect(function(player: Player, Identifier: any, action: string, data: any)

View file

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

View file

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