mirror of
https://github.com/imezx/Warp.git
synced 2025-06-19 21:29:17 +00:00
fix & improved array type
This commit is contained in:
parent
43c4a1594f
commit
1d67954ef9
3 changed files with 24 additions and 20 deletions
|
@ -139,7 +139,7 @@ function ClientProcess.start()
|
||||||
if #data == 0 then continue end
|
if #data == 0 then continue end
|
||||||
if clientRatelimit[Identifier](#data) then
|
if clientRatelimit[Identifier](#data) then
|
||||||
for _, unpacked in data do
|
for _, unpacked in data do
|
||||||
UnreliableEvent:FireServer(Buffer.write(unpacked))
|
UnreliableEvent:FireServer(Buffer.revert(Identifier), Buffer.write(unpacked))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
unreliableClientQueue[Identifier] = nil
|
unreliableClientQueue[Identifier] = nil
|
||||||
|
@ -149,7 +149,7 @@ function ClientProcess.start()
|
||||||
if #data > 0 then
|
if #data > 0 then
|
||||||
if clientRatelimit[Identifier](#data) then
|
if clientRatelimit[Identifier](#data) then
|
||||||
for _, unpacked in data do
|
for _, unpacked in data do
|
||||||
ReliableEvent:FireServer(Buffer.write(unpacked))
|
ReliableEvent:FireServer(Buffer.revert(Identifier), Buffer.write(unpacked))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
clientQueue[Identifier] = nil
|
clientQueue[Identifier] = nil
|
||||||
|
@ -230,12 +230,14 @@ function ClientProcess.start()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
local function onClientNetworkReceive(data: buffer)
|
local function onClientNetworkReceive(Identifier: buffer | string, data: buffer)
|
||||||
if not data then return end
|
if not Identifier or not data then return end
|
||||||
|
Identifier = Buffer.convert(Identifier :: buffer)
|
||||||
local read = Buffer.read(data)
|
local read = Buffer.read(data)
|
||||||
if not read then return end
|
if not read then return end
|
||||||
for Identifier: string in registeredIdentifier do
|
for idx: string in registeredIdentifier do
|
||||||
local callback = clientCallback[Identifier] or nil
|
if idx ~= Identifier then continue end
|
||||||
|
local callback = clientCallback[idx] or nil
|
||||||
if not callback then continue end
|
if not callback then continue end
|
||||||
for _, fn: any in callback do
|
for _, fn: any in callback do
|
||||||
Spawn(fn, table.unpack(read))
|
Spawn(fn, table.unpack(read))
|
||||||
|
|
|
@ -191,7 +191,7 @@ function ServerProcess.start()
|
||||||
for player: Player, content: any in players do
|
for player: Player, content: any in players do
|
||||||
if #content == 0 then continue end
|
if #content == 0 then continue end
|
||||||
for _, unpacked in content do
|
for _, unpacked in content do
|
||||||
UnreliableEvent:FireClient(player, Buffer.write(unpacked))
|
UnreliableEvent:FireClient(player, Buffer.revert(Identifier), Buffer.write(unpacked))
|
||||||
end
|
end
|
||||||
unreliableServerQueue[Identifier][player] = nil
|
unreliableServerQueue[Identifier][player] = nil
|
||||||
end
|
end
|
||||||
|
@ -202,7 +202,7 @@ function ServerProcess.start()
|
||||||
for player, content: any in contents do
|
for player, content: any in contents do
|
||||||
if #content > 0 and queueOut[player] then
|
if #content > 0 and queueOut[player] then
|
||||||
for _, unpacked in content do
|
for _, unpacked in content do
|
||||||
ReliableEvent:FireClient(player, Buffer.write(unpacked))
|
ReliableEvent:FireClient(player, Buffer.revert(Identifier), Buffer.write(unpacked))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
serverQueue[Identifier][player] = nil
|
serverQueue[Identifier][player] = nil
|
||||||
|
@ -229,7 +229,7 @@ function ServerProcess.start()
|
||||||
end
|
end
|
||||||
queueOutRequest[2][Identifier] = nil
|
queueOutRequest[2][Identifier] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
for Identifier: string in registeredIdentifier do
|
for Identifier: string in registeredIdentifier do
|
||||||
if serverRequestQueue[Identifier] then
|
if serverRequestQueue[Identifier] then
|
||||||
for player, content in serverRequestQueue[Identifier] do
|
for player, content in serverRequestQueue[Identifier] do
|
||||||
|
@ -303,12 +303,14 @@ function ServerProcess.start()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
local function onServerNetworkReceive(player: Player, data: buffer)
|
local function onServerNetworkReceive(player: Player, Identifier: buffer | string, data: buffer)
|
||||||
if not data then return end
|
if not Identifier or not data then return end
|
||||||
|
Identifier = Buffer.convert(Identifier :: buffer)
|
||||||
local read = Buffer.read(data)
|
local read = Buffer.read(data)
|
||||||
if not read then return end
|
if not read then return end
|
||||||
for Identifier: string in registeredIdentifier do
|
for idx: string in registeredIdentifier do
|
||||||
local callback = serverCallback[Identifier] or nil
|
if idx ~= Identifier then continue end
|
||||||
|
local callback = serverCallback[idx] or nil
|
||||||
if not callback then continue end
|
if not callback then continue end
|
||||||
for _, fn: any in callback do
|
for _, fn: any in callback do
|
||||||
Spawn(fn, player, table.unpack(read))
|
Spawn(fn, player, table.unpack(read))
|
||||||
|
|
|
@ -32,32 +32,32 @@ function Index.Client(Identifier: string, conf: Type.ClientConf?): Type.Client
|
||||||
return require(Client.Index)(Identifier, conf) :: Type.Client
|
return require(Client.Index)(Identifier, conf) :: Type.Client
|
||||||
end
|
end
|
||||||
|
|
||||||
function Index.fromServerArray(arrays: { any }): Type.fromServerArray
|
function Index.fromServerArray(arrays: { string } | { [string]: Type.ServerConf }): Type.fromServerArray
|
||||||
Assert(IsServer, `[Warp]: Calling .fromServerArray({arrays}) on client side (expected server side)`)
|
Assert(IsServer, `[Warp]: Calling .fromServerArray({arrays}) on client side (expected server side)`)
|
||||||
Assert(typeof(arrays) == "table", "[Warp]: Array must be a table type, got {typeof(arrays)}")
|
Assert(typeof(arrays) == "table", "[Warp]: Array must be a table type, got {typeof(arrays)}")
|
||||||
local copy = {}
|
local copy: { [string]: Type.Server } = {}
|
||||||
for param1: any, param2: any in arrays do
|
for param1, param2: string | Type.ServerConf in arrays do
|
||||||
if typeof(param2) == "table" then
|
if typeof(param2) == "table" then
|
||||||
copy[param1] = Index.Server(param1, param2)
|
copy[param1] = Index.Server(param1, param2)
|
||||||
else
|
else
|
||||||
copy[param2] = Index.Server(param2)
|
copy[param2] = Index.Server(param2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return copy :: typeof(copy)
|
return copy
|
||||||
end
|
end
|
||||||
|
|
||||||
function Index.fromClientArray(arrays: { any }): Type.fromClientArray
|
function Index.fromClientArray(arrays: { string } | { [string]: Type.ClientConf }): Type.fromClientArray
|
||||||
Assert(not IsServer, `[Warp]: Calling .fromClientArray({arrays}) on server side (expected client side)`)
|
Assert(not IsServer, `[Warp]: Calling .fromClientArray({arrays}) on server side (expected client side)`)
|
||||||
Assert(typeof(arrays) == "table", `[Warp]: Array must be a table type, got {typeof(arrays)}`)
|
Assert(typeof(arrays) == "table", `[Warp]: Array must be a table type, got {typeof(arrays)}`)
|
||||||
local copy = {}
|
local copy = {}
|
||||||
for param1: any, param2: any in arrays do
|
for param1, param2: string | Type.ClientConf in arrays do
|
||||||
if typeof(param2) == "table" then
|
if typeof(param2) == "table" then
|
||||||
copy[param1] = Index.Client(param1, param2)
|
copy[param1] = Index.Client(param1, param2)
|
||||||
else
|
else
|
||||||
copy[param2] = Index.Client(param2)
|
copy[param2] = Index.Client(param2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return copy :: typeof(copy)
|
return copy
|
||||||
end
|
end
|
||||||
|
|
||||||
function Index.Signal(Identifier: string)
|
function Index.Signal(Identifier: string)
|
||||||
|
|
Loading…
Reference in a new issue