diff --git a/Warp.rbxm b/Warp.rbxm
index 8c4a37e..71ee703 100644
Binary files a/Warp.rbxm and b/Warp.rbxm differ
diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts
index 3d49b9b..e99b142 100644
--- a/docs/.vitepress/config.mts
+++ b/docs/.vitepress/config.mts
@@ -33,14 +33,12 @@ function side() {
text: 'Feature',
items: [
{ text: 'Rate Limit', link: '/api/1.0/ratelimit' },
- { text: 'Middleware', link: '/api/1.0/middleware' },
]
},
{
text: 'Utilities',
items: [
{ text: 'Signal', link: '/api/1.0/signal' },
- { text: 'Buffer', link: '/api/1.0/buffer' },
]
},
]
diff --git a/docs/api/1.0/buffer.md b/docs/api/1.0/buffer.md
deleted file mode 100644
index 4b5f49a..0000000
--- a/docs/api/1.0/buffer.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# Buffer
-
-A Additional buffer.
\ No newline at end of file
diff --git a/docs/api/1.0/middleware.md b/docs/api/1.0/middleware.md
deleted file mode 100644
index b0b79d0..0000000
--- a/docs/api/1.0/middleware.md
+++ /dev/null
@@ -1,64 +0,0 @@
-# Middleware
-
-::: code-group
-```lua [Server]
-local Event1 = Warp.Server("Remote1")
-
-local storeC = Event1:Connect(function(player: Player, arg1: string, arg2: number, arg3: boolean)
- print(player, arg1, arg2, arg3)
-end):middleware(function(player: Player, arg1: string, arg2: number, arg3: boolean)
- assert(type(player) == "userdata" and player:IsA("Player"), "player must be a Player.")
- assert(typeof(arg1) == "string", "arg1 must be a string.")
- assert(typeof(arg2) == "number", "arg2 must be a number.")
- assert(typeof(arg3) == "boolean", "arg3 must be a boolean.")
-end)
-
-print(storeC:key())
-
-task.delay(15, function()
- Event1:Disconnect(storeC:key())
-end)
-
-for _=1,5 do
- print("send incorrect values")
- Event1:Fires(true, 1e9, "hello world!")
- task.wait(0.5)
-end
-
-for _=1,5 do
- print("send correct values")
- Event1:Fires(true, "hello world!", 1e9)
- task.wait(0.5)
-end
-```
-
-```lua [Client]
-local Event1 = Warp.Client("Remote1")
-
-local storeC = Event1:Connect(function(arg1: boolean, arg2: string, arg3: number)
- print(arg1, arg2, arg3)
-end):middleware(function(arg1: boolean, arg2: string, arg3: number)
- assert(typeof(arg1) == "boolean", "arg1 must be a boolean.")
- assert(typeof(arg2) == "string", "arg2 must be a string.")
- assert(typeof(arg3) == "number", "arg3 must be a number.")
-end)
-
-print(storeC:key())
-
-task.delay(15, function()
- Event1:Disconnect(storeC:key())
-end)
-
-for _=1,5 do
- print("send incorrect values")
- Event1:Fires("hello world!", false, 1e9)
- task.wait(0.5)
-end
-
-for _=1,5 do
- print("send correct values")
- Event1:Fires("hello world!", 1e9, false)
- task.wait(0.5)
-end
-```
-:::
\ No newline at end of file
diff --git a/docs/guide/installation.md b/docs/guide/installation.md
index 4ac6dc5..1efb80b 100644
--- a/docs/guide/installation.md
+++ b/docs/guide/installation.md
@@ -8,7 +8,7 @@
::: code-group
```toml [wally.toml]
[dependencies]
-warp = "imezx/warp@1.0.12"
+warp = "imezx/warp@1.0.13"
```
3. Run `wally install` in command.
diff --git a/src/Index/Server/ServerProcess/init.luau b/src/Index/Server/ServerProcess/init.luau
index 0c687f9..d217409 100644
--- a/src/Index/Server/ServerProcess/init.luau
+++ b/src/Index/Server/ServerProcess/init.luau
@@ -55,7 +55,7 @@ local function initializeEachPlayer(player: Player)
queueOut[player] = {}
end
- for _, Identifier: string in registeredIdentifier do
+ for Identifier: string in registeredIdentifier do
if not player then break end
if not queueOut[player][Identifier] then
queueOut[player][Identifier] = {}
diff --git a/src/Index/Util/Buffer/Dedicated.luau b/src/Index/Util/Buffer/Dedicated.luau
index 475c81e..da6050d 100644
--- a/src/Index/Util/Buffer/Dedicated.luau
+++ b/src/Index/Util/Buffer/Dedicated.luau
@@ -19,8 +19,8 @@ local writestring = buffer.writestring
local default: { [string]: number } = {
point = 0,
next = 0,
- size = 32,
- bufferSize = 32,
+ size = 128,
+ bufferSize = 128,
}
function DedicatedBuffer.copy(self: any, offset: number, b: buffer?, src: buffer?, srcOffset: number?, count: number?)
@@ -65,51 +65,51 @@ function DedicatedBuffer.buildAndRemove(self: any): buffer
return build
end
-function DedicatedBuffer.wi8(self: any, val: number)
+function DedicatedBuffer.wi8(self: any, val: number, alloc: number?)
if not val then return end
- self:alloc(1)
+ self:alloc(alloc or 1)
writei8(self.buffer, self.point, val)
end
-function DedicatedBuffer.wi16(self: any, val: number)
+function DedicatedBuffer.wi16(self: any, val: number, alloc: number?)
if not val then return end
- self:alloc(2)
+ self:alloc(alloc or 2)
writei16(self.buffer, self.point, val)
end
-function DedicatedBuffer.wi32(self: any, val: number)
+function DedicatedBuffer.wi32(self: any, val: number, alloc: number?)
if not val then return end
- self:alloc(4)
+ self:alloc(alloc or 4)
writei32(self.buffer, self.point, val)
end
-function DedicatedBuffer.wu8(self: any, val: number)
+function DedicatedBuffer.wu8(self: any, val: number, alloc: number?)
if not val then return end
- self:alloc(1)
+ self:alloc(alloc or 1)
writeu8(self.buffer, self.point, val)
end
-function DedicatedBuffer.wu16(self: any, val: number)
+function DedicatedBuffer.wu16(self: any, val: number, alloc: number?)
if not val then return end
- self:alloc(2)
+ self:alloc(alloc or 2)
writeu16(self.buffer, self.point, val)
end
-function DedicatedBuffer.wu32(self: any, val: number)
+function DedicatedBuffer.wu32(self: any, val: number, alloc: number?)
if not val then return end
- self:alloc(4)
+ self:alloc(alloc or 4)
writeu32(self.buffer, self.point, val)
end
-function DedicatedBuffer.wf32(self: any, val: number)
+function DedicatedBuffer.wf32(self: any, val: number, alloc: number?)
if not val then return end
- self:alloc(4)
+ self:alloc(alloc or 4)
writef32(self.buffer, self.point, val)
end
-function DedicatedBuffer.wf64(self: any, val: number)
+function DedicatedBuffer.wf64(self: any, val: number, alloc: number?)
if not val then return end
- self:alloc(8)
+ self:alloc(alloc or 8)
writef64(self.buffer, self.point, val)
end
@@ -119,14 +119,15 @@ function DedicatedBuffer.wstring(self: any, val: string)
writestring(self.buffer, self.point, val)
end
-function DedicatedBuffer.wType(self: any, typeByte: number)
- self:alloc(1)
- writeu8(self.buffer, self.point, typeByte)
+function DedicatedBuffer.wType(self: any, ref: number)
+ writeu8(self.buffer, self.point, ref)
self.point += 1
end
function DedicatedBuffer.pack(self: any, data: {any})
- if typeof(data) == "number" then
+ if typeof(data) == "nil" then
+ self:wi8(0)
+ elseif typeof(data) == "number" then
if math.floor(data) == data then -- Integer
if data >= 0 and data <= 255 then
self:wi8(1) -- u8 marker
@@ -149,26 +150,37 @@ function DedicatedBuffer.pack(self: any, data: {any})
self:wi8(5) -- boolean marker
self:wu8(data and 1 or 0)
elseif typeof(data) == "string" then
- self:wi8(6) -- string marker
local length = #data
- if length < 255 then
- --self:wi8(7) -- small string marker
- self:wu8(length) -- use 1 byte for length if small
+ if length <= 255 then
+ self:wi8(6)
+ self:wu8(length)
+ elseif length <= 65535 then
+ self:wi8(7)
+ self:wu16(length)
else
- --self:wi8(8) -- large string marker
- self:wi32(length) -- 32-bit for larger strings
+ self:wi8(8)
+ self:wi32(length)
end
self:wstring(data)
elseif typeof(data) == "Vector3" then
- self:wi8(7) -- Vector3 marker
+ self:wi8(9) -- Vector3 marker
self:wf32(data.X)
self:wf32(data.Y)
self:wf32(data.Z)
+ elseif typeof(data) == "Vector2" then
+ self:wi8(10) -- Vector2 marker
+ self:wf32(data.X)
+ self:wf32(data.Y)
elseif typeof(data) == "CFrame" then
- self:wi8(8) -- CFrame marker
+ self:wi8(11) -- CFrame marker
for _, v in {data:GetComponents()} do
self:wf32(v)
end
+ elseif typeof(data) == "Color3" then
+ self:wi8(12) -- Color3 marker
+ self:wu8(data.R * 255)
+ self:wu8(data.G * 255)
+ self:wu8(data.B * 255)
elseif typeof(data) == "table" then
--local isArray = (next(data) ~= nil and #data > 0) and true or false
local isArray = true
@@ -180,21 +192,26 @@ function DedicatedBuffer.pack(self: any, data: {any})
end
end
if isArray then
- self:wi8(9) -- array marker
- self:wi32(count) -- use 32-bit length
+ self:wi8(13) -- array marker
+ self:wu16(count) -- use 32-bit length
for _, v in data do
self:pack(v)
end
else
- self:wi8(10) -- dictionary marker
- self:wi32(count) -- number of key-value pairs
+ self:wi8(14) -- dictionary marker
+ self:wu16(count) -- number of key-value pairs
for k, v in data do
self:pack(k) -- pack the key
self:pack(v) -- pack the value
end
end
+ elseif typeof(data) == "Instance" then
+ self:wi8(15) -- Instance marker
+ self:pack(data.ClassName) -- Serialize ClassName
+ self:pack(data.Name) -- Serialize Name
+ self:pack(data:GetAttributes())
else
- error("Unsupported data type: " .. typeof(data))
+ warn(`Unsupported data type: {typeof(data)} value: {data}`)
end
end
diff --git a/src/Index/Util/Buffer/init.luau b/src/Index/Util/Buffer/init.luau
index a21116a..e1ee3ef 100644
--- a/src/Index/Util/Buffer/init.luau
+++ b/src/Index/Util/Buffer/init.luau
@@ -21,13 +21,15 @@ local len = buffer.len
local function readValue(b: buffer, position: number): (any, number)
local typeByte = readu8(b, position)
position += 1
- if typeByte == 1 then -- u8
+ if typeByte == 0 then -- nil
+ return nil, position
+ elseif typeByte == 1 then -- int u8
local value = readu8(b, position)
return value, position + 1
- elseif typeByte == 2 then -- i16
+ elseif typeByte == 2 then -- int i16
local value = readi16(b, position)
return value, position + 2
- elseif typeByte == 3 then -- i32
+ elseif typeByte == 3 then -- int i32
local value = readi32(b, position)
return value, position + 4
elseif typeByte == 4 then -- f64
@@ -36,33 +38,41 @@ local function readValue(b: buffer, position: number): (any, number)
elseif typeByte == 5 then -- boolean
local value = readu8(b, position) == 1
return value, position + 1
- elseif typeByte == 6 then -- string
- local lengthByte = readu8(b, position)
- position += 1
- local value
- if lengthByte < 255 then
- value = readstring(b, position, lengthByte)
- return value, position + lengthByte
- else
- local length = readi32(b, position)
- position += 4
- value = readstring(b, position, length)
- return value, position + length
- end
- elseif typeByte == 7 then -- Vector3
+ elseif typeByte == 6 then -- string u8
+ local length = readu8(b, position)
+ local value = readstring(b, position + 1, length)
+ return value, position + length + 1
+ elseif typeByte == 7 then -- string u16
+ local length = readu16(b, position)
+ local value = readstring(b, position + 2, length)
+ return value, position + length + 2
+ elseif typeByte == 8 then -- string i32
+ local length = readi32(b, position)
+ local value = readstring(b, position + 4, length)
+ return value, position + length + 4
+ elseif typeByte == 9 then -- Vector3
local x = readf32(b, position)
local y = readf32(b, position + 4)
local z = readf32(b, position + 8)
return Vector3.new(x, y, z), position + 12
- elseif typeByte == 8 then -- CFrame
+ elseif typeByte == 10 then -- Vector2
+ local x = readf32(b, position)
+ local y = readf32(b, position + 8)
+ return Vector2.new(x, y), position + 8
+ elseif typeByte == 11 then -- CFrame
local components = {}
for i = 1, 12 do
table.insert(components, readf32(b, position + (i - 1) * 4))
end
return CFrame.new(unpack(components)), position + 48
- elseif typeByte == 9 then -- array
- local length = readi32(b, position)
- position += 4
+ elseif typeByte == 12 then -- Vector2
+ local r = readu8(b, position)
+ local g = readu8(b, position + 1)
+ local b = readu8(b, position + 2)
+ return Color3.fromRGB(r, g, b), position + 3
+ elseif typeByte == 13 then -- array
+ local length = readu16(b, position)
+ position += 2
local array = {}
for _ = 1, length do
local value
@@ -70,9 +80,9 @@ local function readValue(b: buffer, position: number): (any, number)
table.insert(array, value)
end
return array, position
- elseif typeByte == 10 then -- dictionary
- local length = readi32(b, position)
- position += 4
+ elseif typeByte == 14 then -- dictionary
+ local length = readu16(b, position)
+ position += 2
local dict = {}
for _ = 1, length do
local key, value
@@ -81,6 +91,16 @@ local function readValue(b: buffer, position: number): (any, number)
dict[key] = value
end
return dict, position
+ elseif typeByte == 15 then -- Instance
+ local className, position1 = readValue(b, position)
+ local name, position2 = readValue(b, position1)
+ local properties, position3 = readValue(b, position2)
+ local instance: Instance = Instance.new(className)
+ instance.Name = name
+ for key, value in properties do
+ instance:SetAttribute(key, value)
+ end
+ return instance, position3
end
error(`Unsupported type marker: {typeByte}`)
end
diff --git a/src/Index/Util/Middleware.luau b/src/Index/Util/Middleware.luau
deleted file mode 100644
index 27dd713..0000000
--- a/src/Index/Util/Middleware.luau
+++ /dev/null
@@ -1,46 +0,0 @@
---!strict
---!native
---!optimize 2
-local Middleware = {}
-Middleware.__index = Middleware
-
-local function wrap(middleware: (...any) -> (...any)): (...any) -> boolean
- return function(...): boolean
- local obj: any = { ... }
- local s, r = pcall(function()
- return middleware(table.unpack(obj))
- end)
- if not s and r then
- warn(r)
- r = nil
- table.clear(obj)
- obj = nil
- end
- return s
- end
-end
-
-function Middleware.new(key: string)
- return setmetatable({
- root = key,
- bridge = function(...: any?): any?
- return true
- end,
- }, Middleware)
-end
-
-function Middleware:middleware(middleware: (...any) -> (...any))
- self.bridge = wrap(middleware)
- return self
-end
-
-function Middleware:key(): string
- return self.root
-end
-
-function Middleware:destroy()
- table.clear(self)
- setmetatable(self, nil)
-end
-
-return Middleware.new :: typeof(Middleware.new)
\ No newline at end of file