Skip to content

Commit

Permalink
v1.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
imezx committed May 11, 2024
1 parent acb08a3 commit 839a7af
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 35 deletions.
2 changes: 2 additions & 0 deletions src/Index/Client/ClientProcess/Logger.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
--!strict
--!native
--!optimize 2
local Logger = {}
local Logs: {
[string]: {
Expand Down
40 changes: 24 additions & 16 deletions src/Index/Client/ClientProcess/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/Index/Event.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
--!strict
--!native
--!optimize 2
local RunService = game:GetService("RunService")
local Type = require(script.Parent.Type)

Expand Down
2 changes: 2 additions & 0 deletions src/Index/Server/ServerProcess/Logger.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
--!strict
--!native
--!optimize 2
local Logger = {}
local Logs: {
[string]: {
Expand Down
48 changes: 29 additions & 19 deletions src/Index/Server/ServerProcess/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/Index/Util/RateLimit.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
--!strict
--!native
--!optimize 2
local RateLimit = {}

local RunService = game:GetService("RunService")
Expand Down
2 changes: 2 additions & 0 deletions src/Index/Util/Serdes.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
--!strict
--!native
--!optimize 2
local RunService = game:GetService("RunService")
local SerInt = 0

Expand Down

0 comments on commit 839a7af

Please sign in to comment.