mirror of
https://github.com/imezx/Warp.git
synced 2025-06-19 21:29:17 +00:00
v1.0.10-test
This commit is contained in:
parent
0fb349fe0f
commit
598c30c147
14 changed files with 96 additions and 49 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,3 +2,5 @@ node_modules
|
||||||
docs/.vitepress/dist
|
docs/.vitepress/dist
|
||||||
docs/.vitepress/cache
|
docs/.vitepress/cache
|
||||||
wally.lock
|
wally.lock
|
||||||
|
TestEZ
|
||||||
|
test.project.json
|
BIN
Warp.rbxm
BIN
Warp.rbxm
Binary file not shown.
|
@ -76,8 +76,11 @@ function ClientProcess.insertRequest(Identifier: string, timeout: number, ...: a
|
||||||
return coroutine.yield()
|
return coroutine.yield()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ClientProcess.add(Identifier: any, originId: string)
|
function ClientProcess.add(Identifier: any, originId: string, conf: Type.ClientConf)
|
||||||
if not clientQueue[Identifier] then
|
if not clientQueue[Identifier] then
|
||||||
|
if conf.logging then
|
||||||
|
ClientProcess.logger(Identifier, conf.logging.store, conf.logging.opt)
|
||||||
|
end
|
||||||
if not clientRatelimit[Identifier] then
|
if not clientRatelimit[Identifier] then
|
||||||
clientRatelimit[Identifier] = RateLimit.create(originId)
|
clientRatelimit[Identifier] = RateLimit.create(originId)
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,29 +7,32 @@ Client.__index = Client
|
||||||
local Players = game:GetService("Players")
|
local Players = game:GetService("Players")
|
||||||
local Util = script.Parent.Parent.Util
|
local Util = script.Parent.Parent.Util
|
||||||
|
|
||||||
|
local Type = require(script.Parent.Parent.Type)
|
||||||
local ClientProcess = require(script.Parent.ClientProcess)
|
local ClientProcess = require(script.Parent.ClientProcess)
|
||||||
local Assert = require(Util.Assert)
|
local Assert = require(Util.Assert)
|
||||||
local Key = require(Util.Key)
|
local Key = require(Util.Key)
|
||||||
local Serdes = require(Util.Serdes)
|
local Serdes = require(Util.Serdes)
|
||||||
local Buffer = require(Util.Buffer)
|
local Buffer = require(Util.Buffer)
|
||||||
|
|
||||||
function Client.new(Identifier: string, yieldWait: number?)
|
function Client.new(Identifier: string, conf: Type.ClientConf?)
|
||||||
local self = setmetatable({}, Client)
|
local self = setmetatable({}, Client)
|
||||||
|
|
||||||
self._buffer = Buffer.new()
|
self._buffer = Buffer.new()
|
||||||
self._buffer:wu8(Serdes(Identifier, yieldWait))
|
self._buffer:wu8(Serdes(Identifier, conf and conf.yieldWait))
|
||||||
self.id = Buffer.convert(self._buffer:build())
|
self.id = Buffer.convert(self._buffer:build())
|
||||||
self.fn = {}
|
self.fn = {}
|
||||||
|
self._conf = table.freeze(conf or {})
|
||||||
self.IsConnected = false
|
self.IsConnected = false
|
||||||
ClientProcess.add(self.id, Identifier)
|
|
||||||
|
ClientProcess.add(self.id, Identifier, conf or { yieldWait = 10, logging = { store = false, opt = false } })
|
||||||
self._buffer:remove()
|
self._buffer:remove()
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
function Client:Logging(store: boolean, opt: boolean)
|
function Client:logs()
|
||||||
ClientProcess.logger(self.id, store, opt)
|
Assert(self._conf.logging, "[Client]: Event is not configured with logging.")
|
||||||
return function()
|
return ClientProcess.getlogs(self.id)
|
||||||
return ClientProcess.getlogs(self.id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Client:Fire(reliable: boolean,...: any)
|
function Client:Fire(reliable: boolean,...: any)
|
||||||
|
|
|
@ -14,23 +14,25 @@ local Key = require(Util.Key)
|
||||||
local Serdes = require(Util.Serdes)
|
local Serdes = require(Util.Serdes)
|
||||||
local Buffer = require(Util.Buffer)
|
local Buffer = require(Util.Buffer)
|
||||||
|
|
||||||
function Server.new(Identifier: string, rateLimit: Type.rateLimitArg?)
|
function Server.new(Identifier: string, conf: Type.ServerConf?)
|
||||||
local self = setmetatable({}, Server)
|
local self = setmetatable({}, Server)
|
||||||
|
|
||||||
self._buffer = Buffer.new()
|
self._buffer = Buffer.new()
|
||||||
self._buffer:wu8(Serdes(Identifier))
|
self._buffer:wu8(Serdes(Identifier))
|
||||||
self.id = Buffer.convert(self._buffer:build())
|
self.id = Buffer.convert(self._buffer:build())
|
||||||
self.fn = {}
|
self.fn = {}
|
||||||
|
self._conf = table.freeze(conf or {})
|
||||||
self.IsConnected = false
|
self.IsConnected = false
|
||||||
ServerProcess.add(self.id, Identifier, rateLimit or { maxEntrance = 200, interval = 2 })
|
|
||||||
|
ServerProcess.add(self.id, Identifier, conf or { rateLimit = { maxEntrance = 200, interval = 2 } })
|
||||||
self._buffer:remove()
|
self._buffer:remove()
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
function Server:Logging(store: boolean, opt: boolean)
|
function Server:logs()
|
||||||
ServerProcess.logger(self.id, store, opt)
|
Assert(self._conf.logging, "[Server]: Event is not configured with logging.")
|
||||||
return function()
|
return ServerProcess.getlogs(self.id)
|
||||||
return ServerProcess.getlogs(self.id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Server:Fire(reliable: boolean, player: Player, ...: any)
|
function Server:Fire(reliable: boolean, player: Player, ...: any)
|
||||||
|
@ -50,6 +52,13 @@ function Server:FireExcept(reliable: boolean, except: { Player }, ...: any)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Server:FireIn(reliable: boolean, range: number, from: Vector3, data: { any }, except: { Player }?)
|
||||||
|
for _, player: Player in ipairs(Players:GetPlayers()) do
|
||||||
|
if (except and table.find(except, player)) or not player.Character or not player.Character.PrimaryPart or (player.Character.PrimaryPart.Position - from).Magnitude < range then continue end
|
||||||
|
ServerProcess.insertQueue(self.id, reliable, player, table.unpack(data))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Server:Invoke(timeout: number, player: Player, ...: any): any
|
function Server:Invoke(timeout: number, player: Player, ...: any): any
|
||||||
return ServerProcess.insertRequest(self.id, timeout, player, ...)
|
return ServerProcess.insertRequest(self.id, timeout, player, ...)
|
||||||
end
|
end
|
||||||
|
|
|
@ -123,9 +123,12 @@ function ServerProcess.insertRequest(Identifier: string, timeout: number, player
|
||||||
return coroutine.yield()
|
return coroutine.yield()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ServerProcess.add(Identifier: string, originId: string, ratelimit: Type.rateLimitArg)
|
function ServerProcess.add(Identifier: string, originId: string, conf: Type.ServerConf)
|
||||||
if not serverQueue[Identifier] then
|
if not serverQueue[Identifier] then
|
||||||
RateLimit.create(originId, ratelimit.maxEntrance or 200, ratelimit.interval or 2)
|
RateLimit.create(originId, conf.rateLimit and conf.rateLimit.maxEntrance or 200, conf.rateLimit and conf.rateLimit.interval or 2)
|
||||||
|
if conf.logging then
|
||||||
|
ServerProcess.logger(Identifier, conf.logging.store, conf.logging.opt)
|
||||||
|
end
|
||||||
if not serverQueue[Identifier] then
|
if not serverQueue[Identifier] then
|
||||||
serverQueue[Identifier] = {}
|
serverQueue[Identifier] = {}
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,24 @@
|
||||||
--!strict
|
--!strict
|
||||||
export type rateLimitArg = {
|
type rateLimitArg = {
|
||||||
maxEntrance: number?,
|
maxEntrance: number?,
|
||||||
interval: number?,
|
interval: number?,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type logging = {
|
||||||
|
store: boolean,
|
||||||
|
opt: boolean,
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ServerConf = {
|
||||||
|
rateLimit: rateLimitArg?,
|
||||||
|
logging: logging?,
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ClientConf = {
|
||||||
|
yieldWait: number?,
|
||||||
|
logging: logging?,
|
||||||
|
}
|
||||||
|
|
||||||
export type Client = {
|
export type Client = {
|
||||||
Fire: (self: Client, reliable: boolean, ...any) -> (),
|
Fire: (self: Client, reliable: boolean, ...any) -> (),
|
||||||
Invoke: (self: Client, timeout: number, ...any) -> any,
|
Invoke: (self: Client, timeout: number, ...any) -> any,
|
||||||
|
@ -11,9 +26,9 @@ export type Client = {
|
||||||
Once: (self: Client, callback: (player: Player, ...any) -> ()) -> string,
|
Once: (self: Client, callback: (player: Player, ...any) -> ()) -> string,
|
||||||
Disconnect: (self: Client, key: string) -> (),
|
Disconnect: (self: Client, key: string) -> (),
|
||||||
DisconnectAll: (self: Client) -> (),
|
DisconnectAll: (self: Client) -> (),
|
||||||
Destroy: (self: Client) -> (),
|
|
||||||
Wait: (self: Client) -> number,
|
Wait: (self: Client) -> number,
|
||||||
Logging: (self: Client, store: boolean, opt: boolean) -> (),
|
Destroy: (self: Client) -> (),
|
||||||
|
logs: (self: Client) -> any,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Server = {
|
export type Server = {
|
||||||
|
@ -24,9 +39,9 @@ export type Server = {
|
||||||
Once: (self: Server, callback: (player: Player, ...any) -> ()) -> string,
|
Once: (self: Server, callback: (player: Player, ...any) -> ()) -> string,
|
||||||
Disconnect: (self: Server, key: string) -> (),
|
Disconnect: (self: Server, key: string) -> (),
|
||||||
DisconnectAll: (self: Server) -> (),
|
DisconnectAll: (self: Server) -> (),
|
||||||
Destroy: (self: Server) -> (),
|
|
||||||
Wait: (self: Server) -> number,
|
Wait: (self: Server) -> number,
|
||||||
Logging: (self: Server, store: boolean, opt: boolean) -> (),
|
Destroy: (self: Server) -> (),
|
||||||
|
logs: (self: Server) -> any,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Signal = {
|
export type Signal = {
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
--!strict
|
--!strict
|
||||||
|
--!native
|
||||||
|
--!optimize 2
|
||||||
return function(condition: (any), errorMessage: string?): ()
|
return function(condition: (any), errorMessage: string?): ()
|
||||||
if not (condition) then error(`Warp: {errorMessage}`, 2) end
|
if not (condition) then error(`Warp: {errorMessage}`, 2) end
|
||||||
end
|
end
|
|
@ -1,4 +1,6 @@
|
||||||
--!strict
|
--!strict
|
||||||
|
--!native
|
||||||
|
--!optimize 2
|
||||||
return function(): number?
|
return function(): number?
|
||||||
return tonumber(string.sub(tostring(Random.new():NextNumber()), 3, 6)) -- 4 digits
|
return tonumber(string.sub(tostring(Random.new():NextNumber()), 3, 6)) -- 4 digits
|
||||||
end
|
end
|
|
@ -26,7 +26,7 @@ function RateLimit.create(Identifier: string, entrance: number?, interval: numbe
|
||||||
entrances = 0
|
entrances = 0
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
entrances += incoming and incoming or 1
|
entrances += incoming or 1
|
||||||
return (entrances <= entrance :: number)
|
return (entrances <= entrance :: number)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,16 +15,19 @@ return function(Identifier: string, timeout: number?): number
|
||||||
--Event:SetAttribute(Identifier, string.pack("I1", SerInt)) -- I1 -> 255 max, I2 -> ~ 6.5e4 max. (SerInt), removed/disabled for buffer migration.
|
--Event:SetAttribute(Identifier, string.pack("I1", SerInt)) -- I1 -> 255 max, I2 -> ~ 6.5e4 max. (SerInt), removed/disabled for buffer migration.
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local retreived = false
|
local yieldThread: thread = coroutine.running()
|
||||||
task.delay(timeout or 10, function()
|
local cancel = task.delay(timeout or 10, function() -- yield cancelation (timerout)
|
||||||
if retreived then return end
|
task.spawn(yieldThread, nil)
|
||||||
retreived = true
|
|
||||||
error(`Serdes: {Identifier} is taking too long to retrieve, seems like not replicated on server.`, 2)
|
error(`Serdes: {Identifier} is taking too long to retrieve, seems like not replicated on server.`, 2)
|
||||||
end)
|
end)
|
||||||
while (not retreived) and (not Event:GetAttribute(Identifier)) do
|
while coroutine.status(cancel) ~= "dead" and task.wait(0.5) do -- let it loop for yields!
|
||||||
task.wait(0.5)
|
if (Event:GetAttribute(Identifier)) then
|
||||||
|
task.cancel(cancel)
|
||||||
|
task.spawn(yieldThread, Event:GetAttribute(Identifier))
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
retreived = true
|
return coroutine.yield() -- yield
|
||||||
end
|
end
|
||||||
return Event:GetAttribute(Identifier)
|
return Event:GetAttribute(Identifier)
|
||||||
end
|
end
|
|
@ -1,4 +1,5 @@
|
||||||
--!strict
|
--!strict
|
||||||
|
--!native
|
||||||
--!optimize 2
|
--!optimize 2
|
||||||
local Index = {}
|
local Index = {}
|
||||||
|
|
||||||
|
@ -20,20 +21,20 @@ else
|
||||||
require(Client.ClientProcess).start()
|
require(Client.ClientProcess).start()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Index.Server(Identifier: string, rateLimit: Type.rateLimitArg?): Type.Server
|
function Index.Server(Identifier: string, conf: Type.ServerConf?): Type.Server
|
||||||
Assert(IsServer, `[Warp]: Calling .Server({Identifier}) on client side (expected server side)`)
|
Assert(IsServer, `[Warp]: Calling .Server({Identifier}) on client side (expected server side)`)
|
||||||
Assert(typeof(Identifier) == "string", `[Warp]: Identifier must be a string type, got {typeof(Identifier)}`)
|
Assert(typeof(Identifier) == "string", `[Warp]: Identifier must be a string type, got {typeof(Identifier)}`)
|
||||||
return require(Server.Index)(Identifier, rateLimit) :: Type.Server
|
return require(Server.Index)(Identifier, conf) :: Type.Server
|
||||||
end
|
end
|
||||||
function Index.Client(Identifier: string, yieldWait: number?): Type.Client
|
function Index.Client(Identifier: string, conf: Type.ClientConf?): Type.Client
|
||||||
Assert(not IsServer, `[Warp]: Calling .Client({Identifier}) on server side (expected client side)`)
|
Assert(not IsServer, `[Warp]: Calling .Client({Identifier}) on server side (expected client side)`)
|
||||||
Assert(typeof(Identifier) == "string", `[Warp]: Identifier must be a string type, got {typeof(Identifier)}`)
|
Assert(typeof(Identifier) == "string", `[Warp]: Identifier must be a string type, got {typeof(Identifier)}`)
|
||||||
return require(Client.Index)(Identifier, yieldWait) :: Type.Client
|
return require(Client.Index)(Identifier, conf) :: Type.Client
|
||||||
end
|
end
|
||||||
|
|
||||||
function Index.fromServerArray(arrays: { any }): Type.fromServerArray
|
function Index.fromServerArray(arrays: { any }): 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")
|
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: any, param2: any in arrays do
|
||||||
if typeof(param2) == "table" then
|
if typeof(param2) == "table" then
|
||||||
|
@ -42,17 +43,21 @@ function Index.fromServerArray(arrays: { any }): Type.fromServerArray
|
||||||
copy[param2] = Index.Server(param2)
|
copy[param2] = Index.Server(param2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return table.freeze(copy) :: typeof(copy)
|
return copy :: typeof(copy)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Index.fromClientArray(arrays: { any }): Type.fromClientArray
|
function Index.fromClientArray(arrays: { any }): 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 _, identifier: string in arrays do
|
for param1: any, param2: any in arrays do
|
||||||
copy[identifier] = Index.Client(identifier)
|
if typeof(param2) == "table" then
|
||||||
|
copy[param1] = Index.Client(param1, param2)
|
||||||
|
else
|
||||||
|
copy[param2] = Index.Client(param2)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return table.freeze(copy) :: typeof(copy)
|
return copy :: typeof(copy)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Index.Signal(Identifier: string)
|
function Index.Signal(Identifier: string)
|
||||||
|
@ -65,7 +70,7 @@ function Index.fromSignalArray(arrays: { any })
|
||||||
for _, identifier: string in arrays do
|
for _, identifier: string in arrays do
|
||||||
copy[identifier] = Index.Signal(identifier)
|
copy[identifier] = Index.Signal(identifier)
|
||||||
end
|
end
|
||||||
return table.freeze(copy) :: typeof(copy)
|
return copy :: typeof(copy)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Index.buffer()
|
function Index.buffer()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
-- Warp Library (@Eternity_Devs)
|
-- Warp Library (@Eternity_Devs)
|
||||||
-- version 1.0.9
|
-- version 1.0.10
|
||||||
--!strict
|
--!strict
|
||||||
--!native
|
--!native
|
||||||
--!optimize 2
|
--!optimize 2
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
[package]
|
[package]
|
||||||
name = "imezx/warp"
|
name = "imezx/warp"
|
||||||
version = "1.0.9"
|
version = "1.0.10"
|
||||||
registry = "https://github.com/UpliftGames/wally-index"
|
registry = "https://github.com/UpliftGames/wally-index"
|
||||||
realm = "shared"
|
realm = "shared"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
exclude = ["node_modules", "docs", ".github", "*.rbxl", "*.rbxmx", "*.rbxml"]
|
exclude = ["node_modules", "docs", ".github", "*.rbxl", "*.rbxmx", "*.rbxml", "TestEZ", "test.project.json"]
|
||||||
description = "A very-fast & powerful networking library for Roblox."
|
description = "A very-fast & powerful networking library for Roblox."
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
Loading…
Reference in a new issue