mirror of
https://github.com/imezx/Warp.git
synced 2025-04-24 15:10:03 +00:00
Compare commits
No commits in common. "master" and "1.0.13" have entirely different histories.
10 changed files with 55 additions and 128 deletions
BIN
Warp.rbxm
BIN
Warp.rbxm
Binary file not shown.
|
@ -230,16 +230,18 @@ function ClientProcess.start()
|
|||
end
|
||||
end
|
||||
end)
|
||||
local function onClientNetworkReceive(Identifier: buffer | string, data: buffer, ref: { any }?)
|
||||
if not Identifier or typeof(Identifier) ~= "buffer" or not data or typeof(data) ~= "buffer" then return end
|
||||
Identifier = Buffer.convert(Identifier)
|
||||
if not registeredIdentifier[Identifier :: string] then return end
|
||||
local read = Buffer.read(data, ref)
|
||||
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
|
||||
local callback = clientCallback[Identifier :: string]
|
||||
if not callback then return end
|
||||
for _, fn: any in callback do
|
||||
Spawn(fn, table.unpack(read))
|
||||
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))
|
||||
end
|
||||
end
|
||||
end
|
||||
ReliableEvent.OnClientEvent:Connect(onClientNetworkReceive)
|
||||
|
|
|
@ -49,13 +49,12 @@ local ReliableEvent = Event.Reliable
|
|||
local UnreliableEvent = Event.Unreliable
|
||||
local RequestEvent = Event.Request
|
||||
|
||||
RateLimit.Protect()
|
||||
|
||||
local function initializeEachPlayer(player: Player)
|
||||
if not player then return end
|
||||
if not queueOut[player] then
|
||||
queueOut[player] = {}
|
||||
end
|
||||
|
||||
for Identifier: string in registeredIdentifier do
|
||||
if not player then break end
|
||||
if not queueOut[player][Identifier] then
|
||||
|
@ -85,29 +84,6 @@ local function initializeEachPlayer(player: Player)
|
|||
end
|
||||
|
||||
Players.PlayerAdded:Connect(initializeEachPlayer)
|
||||
Players.PlayerRemoving:Connect(function(player: Player)
|
||||
if not player then return end
|
||||
if queueOut[player] then
|
||||
queueOut[player] = nil
|
||||
end
|
||||
for _, map in { serverQueue, unreliableServerQueue, serverRequestQueue } do
|
||||
for Identifier: string in map do
|
||||
map[Identifier][player] = nil
|
||||
end
|
||||
end
|
||||
for i=1,2 do
|
||||
for Identifier: string in queueInRequest[i] do
|
||||
if queueInRequest[i][Identifier][player] then
|
||||
queueInRequest[i][Identifier][player] = nil
|
||||
end
|
||||
end
|
||||
for Identifier: string in queueOutRequest[i] do
|
||||
if queueOutRequest[i][Identifier][player] then
|
||||
queueOutRequest[i][Identifier][player] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
function ServerProcess.insertQueue(Identifier: string, reliable: boolean, player: Player, ...: any)
|
||||
if not reliable then
|
||||
|
@ -327,16 +303,18 @@ function ServerProcess.start()
|
|||
end
|
||||
end
|
||||
end)
|
||||
local function onServerNetworkReceive(player: Player, Identifier: buffer | string, data: buffer, ref: { any }?)
|
||||
if not Identifier or typeof(Identifier) ~= "buffer" or not data or typeof(data) ~= "buffer" 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)
|
||||
if not registeredIdentifier[Identifier :: string] then return end
|
||||
local read = Buffer.read(data, ref)
|
||||
local read = Buffer.read(data)
|
||||
if not read then return end
|
||||
local callback = serverCallback[Identifier :: string]
|
||||
if not callback then return end
|
||||
for _, fn: any in callback do
|
||||
Spawn(fn, player, table.unpack(read))
|
||||
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))
|
||||
end
|
||||
end
|
||||
end
|
||||
ReliableEvent.OnServerEvent:Connect(onServerNetworkReceive)
|
||||
|
|
|
@ -36,7 +36,7 @@ function DedicatedBuffer.alloc(self: any, byte: number)
|
|||
local b: buffer = self.buffer
|
||||
|
||||
while self.next + byte >= size do
|
||||
size = math.floor(size * 1.25) -- +25% increase
|
||||
size = math.floor(size * 1.2)
|
||||
end
|
||||
local newBuffer: buffer = create(size)
|
||||
copy(newBuffer, 0, b)
|
||||
|
@ -56,15 +56,13 @@ function DedicatedBuffer.build(self: any): buffer
|
|||
return build
|
||||
end
|
||||
|
||||
function DedicatedBuffer.buildAndRemove(self: any): (buffer, (any)?)
|
||||
function DedicatedBuffer.buildAndRemove(self: any): buffer
|
||||
local p: number = self.next > self.point and self.next or self.point
|
||||
local build: buffer = create(p)
|
||||
local ref = #self.ref > 0 and table.clone(self.ref) or nil
|
||||
|
||||
copy(build, 0, self.buffer, 0, p)
|
||||
|
||||
self:remove()
|
||||
return build, ref
|
||||
return build
|
||||
end
|
||||
|
||||
function DedicatedBuffer.wi8(self: any, val: number, alloc: number?)
|
||||
|
@ -126,21 +124,14 @@ function DedicatedBuffer.wType(self: any, ref: number)
|
|||
self.point += 1
|
||||
end
|
||||
|
||||
function DedicatedBuffer.wRef(self: any, value: any, alloc: number?)
|
||||
if not value then return end
|
||||
self:alloc(alloc or 1)
|
||||
table.insert(self.ref, value)
|
||||
local index = #self.ref
|
||||
writeu8(self.buffer, self.point, index)
|
||||
self.point += 1
|
||||
end
|
||||
|
||||
function DedicatedBuffer.pack(self: any, data: {any})
|
||||
if typeof(data) == "nil" then
|
||||
self:wi8(0)
|
||||
elseif typeof(data) == "Instance" then
|
||||
self:wi8(-1) -- Instance marker
|
||||
self:wRef(data)
|
||||
self:pack(data.ClassName) -- Serialize ClassName
|
||||
self:pack(data.Name) -- Serialize Name
|
||||
self:pack(data:GetAttributes())
|
||||
elseif typeof(data) == "table" then
|
||||
--local isArray = (next(data) ~= nil and #data > 0) and true or false
|
||||
local isArray = true
|
||||
|
@ -241,7 +232,6 @@ function DedicatedBuffer.flush(self: any)
|
|||
self.next = default.next
|
||||
self.size = default.size
|
||||
self.buffer = create(default.bufferSize)
|
||||
table.clear(self.ref)
|
||||
end
|
||||
|
||||
function DedicatedBuffer.new()
|
||||
|
@ -249,8 +239,7 @@ function DedicatedBuffer.new()
|
|||
point = default.point,
|
||||
next = default.next,
|
||||
size = default.size,
|
||||
buffer = create(default.bufferSize),
|
||||
ref = {},
|
||||
buffer = create(default.bufferSize)
|
||||
}, DedicatedBuffer)
|
||||
end
|
||||
|
||||
|
|
|
@ -18,27 +18,28 @@ local readf64 = buffer.readf64
|
|||
local readstring = buffer.readstring
|
||||
local len = buffer.len
|
||||
|
||||
local function readValue(b: buffer, position: number, ref: { any }?): (any, number)
|
||||
local function readValue(b: buffer, position: number): (any, number)
|
||||
local typeByte = readi8(b, position)
|
||||
position += 1
|
||||
if typeByte == 0 then -- nil
|
||||
return nil, position
|
||||
elseif typeByte == -1 then -- Instance
|
||||
if not ref or #ref == 0 then
|
||||
return nil, position + 1
|
||||
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
|
||||
local value = ref[readu8(b, position)]
|
||||
if typeof(value) == "Instance" then
|
||||
return value, position + 1
|
||||
end
|
||||
return nil, position + 1
|
||||
return instance, position3
|
||||
elseif typeByte == -2 then -- array
|
||||
local length = readu16(b, position)
|
||||
position += 2
|
||||
local array = {}
|
||||
for _ = 1, length do
|
||||
local value
|
||||
value, position = readValue(b, position, ref)
|
||||
value, position = readValue(b, position)
|
||||
table.insert(array, value)
|
||||
end
|
||||
return array, position
|
||||
|
@ -48,8 +49,8 @@ local function readValue(b: buffer, position: number, ref: { any }?): (any, numb
|
|||
local dict = {}
|
||||
for _ = 1, length do
|
||||
local key, value
|
||||
key, position = readValue(b, position, ref)
|
||||
value, position = readValue(b, position, ref)
|
||||
key, position = readValue(b, position)
|
||||
value, position = readValue(b, position)
|
||||
dict[key] = value
|
||||
end
|
||||
return dict, position
|
||||
|
@ -128,21 +129,20 @@ function Buffer.revert(s: string): buffer
|
|||
return fromstring(s)
|
||||
end
|
||||
|
||||
function Buffer.write(data: { any }): (buffer, (any)?)
|
||||
function Buffer.write(data: { any }): buffer
|
||||
local newBuffer = Dedicated()
|
||||
newBuffer:pack(data)
|
||||
return newBuffer:buildAndRemove()
|
||||
end
|
||||
|
||||
function Buffer.read(b: buffer, ref: { any }?): any?
|
||||
function Buffer.read(b: buffer): any?
|
||||
local position = 0
|
||||
local result = {}
|
||||
while position < len(b) do
|
||||
local value
|
||||
value, position = readValue(b, position, ref)
|
||||
value, position = readValue(b, position)
|
||||
table.insert(result, value)
|
||||
end
|
||||
ref = nil
|
||||
return table.unpack(result)
|
||||
end
|
||||
|
||||
|
|
|
@ -4,51 +4,21 @@ local RateLimit = {}
|
|||
|
||||
local RunService = game:GetService("RunService")
|
||||
local Assert = require(script.Parent.Assert)
|
||||
local Events = require(script.Parent.Parent.Event)
|
||||
local Reliable, Unreliable, Request = Events.Reliable, Events.Unreliable, Events.Request
|
||||
local Signal = require(script.Parent.Parent.Signal)("Warp_OnSpamSignal")
|
||||
|
||||
local map, activity, meta = {}, {}, {}
|
||||
setmetatable(meta , {
|
||||
__index = map,
|
||||
__newindex = function(self, key, value)
|
||||
if not activity[key] then
|
||||
activity[key] = os.clock()
|
||||
end
|
||||
if (os.clock()-activity[key]) >= 1 then
|
||||
activity[key] = os.clock()
|
||||
map[key] = 1
|
||||
return
|
||||
end
|
||||
if value >= 1e2 then -- 100
|
||||
Signal:Fire(key)
|
||||
return
|
||||
end
|
||||
map[key] = value
|
||||
end,
|
||||
})
|
||||
|
||||
local function onReceived(player: Player)
|
||||
if not meta[player] then
|
||||
meta[player] = 1
|
||||
return
|
||||
end
|
||||
meta[player] += 1
|
||||
end
|
||||
local Event = require(script.Parent.Parent.Event).Reliable
|
||||
|
||||
function RateLimit.create(Identifier: string, entrance: number?, interval: number?)
|
||||
Assert(typeof(Identifier) == "string", "Identifier must a string type.")
|
||||
if RunService:IsServer() then
|
||||
Assert(typeof(entrance) == "number", "entrance must a number type.")
|
||||
Assert(entrance :: number > 0, "entrance must above 0.")
|
||||
Reliable:SetAttribute(Identifier.."_ent", entrance)
|
||||
Reliable:SetAttribute(Identifier.."_int", interval)
|
||||
Event:SetAttribute(Identifier.."_ent", entrance)
|
||||
Event:SetAttribute(Identifier.."_int", interval)
|
||||
else
|
||||
while (not Reliable:GetAttribute(Identifier.."_ent")) or (not Reliable:GetAttribute(Identifier.."_int")) do
|
||||
task.wait(0.1)
|
||||
while (not Event:GetAttribute(Identifier.."_ent")) or (not Event:GetAttribute(Identifier.."_int")) do
|
||||
task.wait(0.25)
|
||||
end
|
||||
entrance = tonumber(Reliable:GetAttribute(Identifier.."_ent"))
|
||||
interval = tonumber(Reliable:GetAttribute(Identifier.."_int"))
|
||||
entrance = tonumber(Event:GetAttribute(Identifier.."_ent"))
|
||||
interval = tonumber(Event:GetAttribute(Identifier.."_int"))
|
||||
end
|
||||
local entrances: number = 0
|
||||
return function(incoming: number?): boolean
|
||||
|
@ -62,14 +32,4 @@ function RateLimit.create(Identifier: string, entrance: number?, interval: numbe
|
|||
end
|
||||
end
|
||||
|
||||
function RateLimit.Protect()
|
||||
if not RunService:IsServer() or Reliable:GetAttribute("Protected") or Unreliable:GetAttribute("Protected") or Request:GetAttribute("Protected") then return end
|
||||
Reliable:SetAttribute("Protected", true)
|
||||
Unreliable:SetAttribute("Protected", true)
|
||||
Request:SetAttribute("Protected", true)
|
||||
Reliable.OnServerEvent:Connect(onReceived)
|
||||
Unreliable.OnServerEvent:Connect(onReceived)
|
||||
Request.OnServerEvent:Connect(onReceived)
|
||||
end
|
||||
|
||||
return RateLimit :: typeof(RateLimit)
|
|
@ -24,7 +24,7 @@ function SerDes.increment(Identifier: string, timeout: number?): number
|
|||
error(`Serdes: {Identifier} is taking too long to retrieve, seems like it's not replicated on server.`, 2)
|
||||
end)
|
||||
task.spawn(function()
|
||||
while coroutine.status(cancel) ~= "dead" and task.wait(0.04) do -- let it loop for yields! 1/24
|
||||
while coroutine.status(cancel) ~= "dead" and task.wait(0.25) do -- let it loop for yields!
|
||||
if Event:GetAttribute(Identifier) then
|
||||
task.cancel(cancel)
|
||||
task.spawn(yieldThread, Event:GetAttribute(Identifier))
|
||||
|
|
|
@ -77,4 +77,4 @@ function Index.buffer()
|
|||
return Buffer.new()
|
||||
end
|
||||
|
||||
return table.freeze(Index) :: typeof(Index)
|
||||
return table.freeze(Index) :: typeof(Index)
|
|
@ -1,5 +1,5 @@
|
|||
-- Warp Library (@Eternity_Devs)
|
||||
-- version 1.0.14
|
||||
-- version 1.0.13
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
|
@ -11,8 +11,6 @@ return {
|
|||
fromServerArray = Index.fromServerArray,
|
||||
fromClientArray = Index.fromClientArray,
|
||||
|
||||
OnSpamSignal = Index.OnSpamSignal,
|
||||
|
||||
Signal = Index.Signal,
|
||||
fromSignalArray = Index.fromSignalArray,
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "imezx/warp"
|
||||
version = "1.0.14"
|
||||
version = "1.0.13"
|
||||
registry = "https://github.com/UpliftGames/wally-index"
|
||||
realm = "shared"
|
||||
license = "MIT"
|
||||
|
|
Loading…
Reference in a new issue