From 839a7af6675134a03d873a394fc3d728b5dcedf3 Mon Sep 17 00:00:00 2001 From: EternityDev Date: Sat, 11 May 2024 09:29:53 +0700 Subject: [PATCH] v1.0.10 --- src/Index/Client/ClientProcess/Logger.luau | 2 + src/Index/Client/ClientProcess/init.luau | 40 ++++++++++-------- src/Index/Event.luau | 2 + src/Index/Server/ServerProcess/Logger.luau | 2 + src/Index/Server/ServerProcess/init.luau | 48 +++++++++++++--------- src/Index/Util/RateLimit.luau | 2 + src/Index/Util/Serdes.luau | 2 + 7 files changed, 63 insertions(+), 35 deletions(-) diff --git a/src/Index/Client/ClientProcess/Logger.luau b/src/Index/Client/ClientProcess/Logger.luau index b6de03d..29b0208 100644 --- a/src/Index/Client/ClientProcess/Logger.luau +++ b/src/Index/Client/ClientProcess/Logger.luau @@ -1,4 +1,6 @@ --!strict +--!native +--!optimize 2 local Logger = {} local Logs: { [string]: { diff --git a/src/Index/Client/ClientProcess/init.luau b/src/Index/Client/ClientProcess/init.luau index 7901f39..a09f623 100644 --- a/src/Index/Client/ClientProcess/init.luau +++ b/src/Index/Client/ClientProcess/init.luau @@ -70,6 +70,9 @@ function ClientProcess.insertQueue(Identifier: string, reliable: boolean, ...: a end function ClientProcess.insertRequest(Identifier: string, timeout: number, ...: any) + if not clientRequestQueue[Identifier] then + clientRequestQueue[Identifier] = {} + end local yieldThread: thread, start = coroutine.running(), os.clock() local cancel = task.delay(timeout, function() task.spawn(yieldThread, nil) @@ -168,15 +171,15 @@ function ClientProcess.start() end clientQueue[Identifier] = nil end - if #clientRequestQueue[Identifier] > 0 then + if clientRequestQueue[Identifier] then for _, requestData in clientRequestQueue[Identifier] do if not requestData[3] then continue end if not queueOutRequest[1][Identifier] then queueOutRequest[1][Identifier] = {} end table.insert(queueOutRequest[1][Identifier], { requestData[1], requestData[3] }) - table.remove(requestData, #requestData) end + clientRequestQueue[Identifier] = nil end if callback then if incoming_cache[Identifier] then @@ -187,8 +190,8 @@ function ClientProcess.start() Spawn(fn, table.unpack(packet[i] or {})) end end - incoming_cache[Identifier] = nil end + incoming_cache[Identifier] = nil end if queueIn[Identifier] then for _, packedDatas: any in queueIn[Identifier] do @@ -221,16 +224,18 @@ function ClientProcess.start() queueInRequest[1][Identifier] = nil end if queueInRequest[2][Identifier] then - for _, packetDatas: any in queueInRequest[2][Identifier] do - for _, packetData in packetDatas do - if #packetData == 1 then continue end - for y=1,#clientRequestQueue[Identifier] do - local clientRequest = clientRequestQueue[Identifier][y] - if not clientRequest then continue end - if clientRequest[1] == packetData[1] then - Spawn(clientRequest[2], table.unpack(packetData[2])) - table.remove(clientRequestQueue[Identifier], y) - break + if clientRequestQueue[Identifier] then + for _, packetDatas: any in queueInRequest[2][Identifier] do + for _, packetData in packetDatas do + if #packetData == 1 then continue end + for y=1,#clientRequestQueue[Identifier] do + local clientRequest = clientRequestQueue[Identifier][y] + if not clientRequest then continue end + if clientRequest[1] == packetData[1] then + Spawn(clientRequest[2], table.unpack(packetData[2])) + table.remove(clientRequestQueue[Identifier], y) + break + end end end end @@ -262,17 +267,20 @@ function ClientProcess.start() if not queueIn[Identifier] then queueIn[Identifier] = {} end - if logger[Identifier] then - task.defer(Logger.write, Identifier, `state: in -> net -> {#data} data.`) - end if not clientCallback[Identifier] then if not incoming_cache[Identifier] then incoming_cache[Identifier] = {} end table.insert(incoming_cache[Identifier], data) + if logger[Identifier] then + task.defer(Logger.write, Identifier, `state: cache -> net -> {#data} data.`) + end return end table.insert(queueIn[Identifier], data) + if logger[Identifier] then + task.defer(Logger.write, Identifier, `state: in -> net -> {#data} data.`) + end end ReliableEvent.OnClientEvent:Connect(onClientNetworkReceive) UnreliableEvent.OnClientEvent:Connect(onClientNetworkReceive) diff --git a/src/Index/Event.luau b/src/Index/Event.luau index 0f8fb13..fd09c6e 100644 --- a/src/Index/Event.luau +++ b/src/Index/Event.luau @@ -1,4 +1,6 @@ --!strict +--!native +--!optimize 2 local RunService = game:GetService("RunService") local Type = require(script.Parent.Type) diff --git a/src/Index/Server/ServerProcess/Logger.luau b/src/Index/Server/ServerProcess/Logger.luau index b6de03d..29b0208 100644 --- a/src/Index/Server/ServerProcess/Logger.luau +++ b/src/Index/Server/ServerProcess/Logger.luau @@ -1,4 +1,6 @@ --!strict +--!native +--!optimize 2 local Logger = {} local Logs: { [string]: { diff --git a/src/Index/Server/ServerProcess/init.luau b/src/Index/Server/ServerProcess/init.luau index 8ce6a32..20f0481 100644 --- a/src/Index/Server/ServerProcess/init.luau +++ b/src/Index/Server/ServerProcess/init.luau @@ -109,6 +109,9 @@ function ServerProcess.insertRequest(Identifier: string, timeout: number, player if not serverQueue[Identifier][player] then serverQueue[Identifier][player] = {} end + if not serverRequestQueue[Identifier] then + serverRequestQueue[Identifier] = {} + end local yieldThread: thread, start = coroutine.running(), os.clock() local cancel = task.delay(timeout, function() task.spawn(yieldThread, nil) @@ -201,30 +204,45 @@ function ServerProcess.start() end for Identifier: string, contents: { [Player]: { any } } in serverQueue do + + for player: Player, requestsData: any in queueOutRequest[1][Identifier] do + if #requestsData > 0 then + RequestEvent:FireClient(player, Buffer.revert(Identifier), "\1", requestsData) + if logger[Identifier] then + task.defer(Logger.write, Identifier, `state: out -> request -> {#requestsData} data.`) + end + end + queueOutRequest[1][Identifier][player] = nil + end + + for player: Player, toReturnDatas: any in queueOutRequest[2][Identifier] do + if #toReturnDatas > 0 then + RequestEvent:FireClient(player, Buffer.revert(Identifier), "\0", toReturnDatas) + if logger[Identifier] then + task.defer(Logger.write, Identifier, `state: out -> return request -> {#toReturnDatas} data.`) + end + end + queueOutRequest[2][Identifier][player] = nil + end + local callback = serverCallback[Identifier] or nil for player, content: any in contents do if #content > 0 and queueOut[player] then ReliableEvent:FireClient(player, Buffer.revert(Identifier), content) - serverQueue[Identifier][player] = nil end - if #serverRequestQueue[Identifier][player] > 0 then + serverQueue[Identifier][player] = nil + + if serverRequestQueue[Identifier][player] then for _, requestData in serverRequestQueue[Identifier][player] do if not requestData[3] then continue end if not queueOutRequest[1][Identifier][player] then queueOutRequest[1][Identifier][player] = {} end table.insert(queueOutRequest[1][Identifier][player], { requestData[1], requestData[3] }) - serverRequestQueue[Identifier][player] = nil - end - end - for player: Player, requestsData: any in queueOutRequest[1][Identifier] do - if #requestsData == 0 then continue end - RequestEvent:FireClient(player, Buffer.revert(Identifier), "\1", requestsData) - if logger[Identifier] then - task.defer(Logger.write, Identifier, `state: out -> request -> {#requestsData} data.`) end - queueOutRequest[1][Identifier][player] = nil + serverRequestQueue[Identifier][player] = nil end + if callback then local requestIn1: any = queueInRequest[1][Identifier][player] local requestIn2: any = queueInRequest[2][Identifier][player] @@ -283,14 +301,6 @@ function ServerProcess.start() queueInRequest[2][Identifier][player] = nil end end - for player: Player, toReturnDatas: any in queueOutRequest[2][Identifier] do - if #toReturnDatas == 0 then continue end - RequestEvent:FireClient(player, Buffer.revert(Identifier), "\0", toReturnDatas) - if logger[Identifier] then - task.defer(Logger.write, Identifier, `state: out -> return request -> {#toReturnDatas} data.`) - end - queueOutRequest[2][Identifier][player] = nil - end end end end) diff --git a/src/Index/Util/RateLimit.luau b/src/Index/Util/RateLimit.luau index cf16ba3..9b8177e 100644 --- a/src/Index/Util/RateLimit.luau +++ b/src/Index/Util/RateLimit.luau @@ -1,4 +1,6 @@ --!strict +--!native +--!optimize 2 local RateLimit = {} local RunService = game:GetService("RunService") diff --git a/src/Index/Util/Serdes.luau b/src/Index/Util/Serdes.luau index a38a0a4..c028357 100644 --- a/src/Index/Util/Serdes.luau +++ b/src/Index/Util/Serdes.luau @@ -1,4 +1,6 @@ --!strict +--!native +--!optimize 2 local RunService = game:GetService("RunService") local SerInt = 0