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 clientRatelimit[Identifier](#data) then
|
||||
for _, unpacked in data do
|
||||
UnreliableEvent:FireServer(Buffer.write(unpacked))
|
||||
UnreliableEvent:FireServer(Buffer.revert(Identifier), Buffer.write(unpacked))
|
||||
end
|
||||
end
|
||||
unreliableClientQueue[Identifier] = nil
|
||||
|
@ -149,7 +149,7 @@ function ClientProcess.start()
|
|||
if #data > 0 then
|
||||
if clientRatelimit[Identifier](#data) then
|
||||
for _, unpacked in data do
|
||||
ReliableEvent:FireServer(Buffer.write(unpacked))
|
||||
ReliableEvent:FireServer(Buffer.revert(Identifier), Buffer.write(unpacked))
|
||||
end
|
||||
end
|
||||
clientQueue[Identifier] = nil
|
||||
|
@ -230,12 +230,14 @@ function ClientProcess.start()
|
|||
end
|
||||
end
|
||||
end)
|
||||
local function onClientNetworkReceive(data: buffer)
|
||||
if not data then return end
|
||||
local function onClientNetworkReceive(Identifier: buffer | string, data: buffer)
|
||||
if not Identifier or not data then return end
|
||||
Identifier = Buffer.convert(Identifier :: buffer)
|
||||
local read = Buffer.read(data)
|
||||
if not read then return end
|
||||
for Identifier: string in registeredIdentifier do
|
||||
local callback = clientCallback[Identifier] or nil
|
||||
for idx: string in registeredIdentifier do
|
||||
if idx ~= Identifier then continue end
|
||||
local callback = clientCallback[idx] or nil
|
||||
if not callback then continue end
|
||||
for _, fn: any in callback do
|
||||
Spawn(fn, table.unpack(read))
|
||||
|
|
|
@ -191,7 +191,7 @@ function ServerProcess.start()
|
|||
for player: Player, content: any in players do
|
||||
if #content == 0 then continue end
|
||||
for _, unpacked in content do
|
||||
UnreliableEvent:FireClient(player, Buffer.write(unpacked))
|
||||
UnreliableEvent:FireClient(player, Buffer.revert(Identifier), Buffer.write(unpacked))
|
||||
end
|
||||
unreliableServerQueue[Identifier][player] = nil
|
||||
end
|
||||
|
@ -202,7 +202,7 @@ function ServerProcess.start()
|
|||
for player, content: any in contents do
|
||||
if #content > 0 and queueOut[player] then
|
||||
for _, unpacked in content do
|
||||
ReliableEvent:FireClient(player, Buffer.write(unpacked))
|
||||
ReliableEvent:FireClient(player, Buffer.revert(Identifier), Buffer.write(unpacked))
|
||||
end
|
||||
end
|
||||
serverQueue[Identifier][player] = nil
|
||||
|
@ -303,12 +303,14 @@ function ServerProcess.start()
|
|||
end
|
||||
end
|
||||
end)
|
||||
local function onServerNetworkReceive(player: Player, data: buffer)
|
||||
if not data then return end
|
||||
local function onServerNetworkReceive(player: Player, Identifier: buffer | string, data: buffer)
|
||||
if not Identifier or not data then return end
|
||||
Identifier = Buffer.convert(Identifier :: buffer)
|
||||
local read = Buffer.read(data)
|
||||
if not read then return end
|
||||
for Identifier: string in registeredIdentifier do
|
||||
local callback = serverCallback[Identifier] or nil
|
||||
for idx: string in registeredIdentifier do
|
||||
if idx ~= Identifier then continue end
|
||||
local callback = serverCallback[idx] or nil
|
||||
if not callback then continue end
|
||||
for _, fn: any in callback do
|
||||
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
|
||||
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(typeof(arrays) == "table", "[Warp]: Array must be a table type, got {typeof(arrays)}")
|
||||
local copy = {}
|
||||
for param1: any, param2: any in arrays do
|
||||
local copy: { [string]: Type.Server } = {}
|
||||
for param1, param2: string | Type.ServerConf in arrays do
|
||||
if typeof(param2) == "table" then
|
||||
copy[param1] = Index.Server(param1, param2)
|
||||
else
|
||||
copy[param2] = Index.Server(param2)
|
||||
end
|
||||
end
|
||||
return copy :: typeof(copy)
|
||||
return copy
|
||||
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(typeof(arrays) == "table", `[Warp]: Array must be a table type, got {typeof(arrays)}`)
|
||||
local copy = {}
|
||||
for param1: any, param2: any in arrays do
|
||||
for param1, param2: string | Type.ClientConf in arrays do
|
||||
if typeof(param2) == "table" then
|
||||
copy[param1] = Index.Client(param1, param2)
|
||||
else
|
||||
copy[param2] = Index.Client(param2)
|
||||
end
|
||||
end
|
||||
return copy :: typeof(copy)
|
||||
return copy
|
||||
end
|
||||
|
||||
function Index.Signal(Identifier: string)
|
||||
|
|
Loading…
Reference in a new issue