Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
patch rc9 0.9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
imezx committed Oct 1, 2023
1 parent 9ab5ca0 commit 6216938
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 48 deletions.
5 changes: 5 additions & 0 deletions CHANGELOGS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
[Refresh]
- Reupdate existing version

[RC9 - 0.9.5]
- Fixed Wait-Event Connected (built-in feature)
- Support for using multiple :Wait
- Other minor fix??

[RC9 - 0.9.4]
- Fixed Creating twice "Event" Instance
- Fixed requestId on Client/Server Pull (function)
Expand Down
Binary file modified FastNet2_Rewrite.rbxm
Binary file not shown.
17 changes: 10 additions & 7 deletions src/Client/Process.luau
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ClientProcess.processLimit = 500 -- max rate process limit (default: 250)
ClientProcess.rateLimit = 500 -- max rate limit (default: 150)
ClientProcess.maxFreeze = 1 -- max duration freezing reaching rate limit (default: 1)

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Identifiers = require(script.Parent.Identifier)
local FastSpawn = require(script.Parent.Parent.FastSpawn)
Expand All @@ -19,7 +20,7 @@ function ClientProcess.reg(Identifier: string)
if Identifiers.reg(Identifier) then
Collections[Identifier] = {
OutgoingOrder = 0,
_ping = nil,
_ping = {},
returnRequest = {},
re_req_i = 0,
requests = {},
Expand Down Expand Up @@ -62,10 +63,10 @@ end
function ClientProcess._ping(Identifier: string): number
local thread = coroutine.running()
local clock = os.clock()
Collections[Identifier]._ping = function(x: number)
table.insert(Collections[Identifier]._ping, function(x: number)
Collections[Identifier]._ping = nil
task.spawn(thread, x - clock)
end
end)
return coroutine.yield()
end

Expand Down Expand Up @@ -168,14 +169,16 @@ function ClientProcess.__start()
net.returnRequest = {}
end
-- Ping :Wait()
if net._ping then
FastSpawn(net._ping, os.clock())
if #net._ping > 0 then
for _, func in net._ping do
FastSpawn(func, os.clock())
end
end
end
debug.profileend()
end)
if not script.Parent.Parent:WaitForChild("Event"):GetAttribute(game:GetService("Players").LocalPlayer.Name) then
Event:FireServer("2", game:GetService("Players").LocalPlayer)
if Players.LocalPlayer and not script.Parent.Parent:WaitForChild("Event"):GetAttribute(Players.LocalPlayer.Name) then
Event:FireServer("2", Players.LocalPlayer.Name)
end
end

Expand Down
17 changes: 9 additions & 8 deletions src/Client/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ local Collections = {}

function Client.new(Identifier: string)
Debug.new(typeof(Identifier) == "string", "[FastNet2]: Identifier must be string", 0)
Debug.new(not Identifiers.find(Util.ser(Identifier)), string.format("[FastNet2]: %s already exist", Identifier), 0)
Process.reg(Util.ser(Identifier))
Collections[Util.ser(Identifier)] = setmetatable({
Identifier = Util.ser(Identifier),
func = function(...: any): (...any) end,
Connected = false,
flag = {},
}, Client)
if not Identifiers.find(Util.ser(Identifier)) then
Process.reg(Util.ser(Identifier))
Collections[Util.ser(Identifier)] = setmetatable({
Identifier = Util.ser(Identifier),
func = function(...: any): (...any) end,
Connected = false,
flag = {},
}, Client)
end
return Collections[Util.ser(Identifier)]
end

Expand Down
39 changes: 22 additions & 17 deletions src/Server/Process.luau
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function ServerProcess.reg(Identifier: string)
if Identifiers.reg(Identifier) then
Collections[Identifier] = {
Identifier = Identifier,
_ping = nil,
_ping = {},
returnRequest = {},
re_req_i = 0,
requests = {},
Expand Down Expand Up @@ -64,12 +64,11 @@ function ServerProcess.pushback(Identifier: string, player: string, id: number,
end

function ServerProcess._ping(Identifier: string): number
local thread = coroutine.running()
local clock = os.clock()
Collections[Identifier]._ping = function(x: number)
local thread, clock = coroutine.running(), os.clock()
table.insert(Collections[Identifier]._ping, function(x: number)
Collections[Identifier]._ping = nil
task.spawn(thread, x - clock)
end
end)
return coroutine.yield()
end

Expand Down Expand Up @@ -155,19 +154,23 @@ function ServerProcess.__start()
net.packets = {}
end
-- Requests to Queue
for player, requests in net.requests do
if net.req_i > 0 and player and Players:FindFirstChild(player.Name) and Event:GetAttribute(player.Name) == true then
net.req_i -= 1
Event:FireClient(player, "0", {[net.Identifier] = requests})
table.clear(requests)
if net.req_i > 0 then
for player, requests in net.requests do
if player and Players:FindFirstChild(player.Name) and Event:GetAttribute(player.Name) == true then
net.req_i -= 1
Event:FireClient(player, "0", {[net.Identifier] = requests})
table.clear(requests)
end
end
end
-- Return Requests
for player, data in net.returnRequest do
if net.re_req_i > 0 and Players:FindFirstChild(player) and Event:GetAttribute(player) == true then
net.re_req_i -= 1
Event:FireClient(Players[player], "1", {[net.Identifier] = data})
table.clear(data)
if net.re_req_i > 0 then
for player, data in net.returnRequest do
if Players:FindFirstChild(player) and Event:GetAttribute(player) == true then
net.re_req_i -= 1
Event:FireClient(Players[player], "1", {[net.Identifier] = data})
table.clear(data)
end
end
end
-- Single Players to Queue
Expand All @@ -185,8 +188,10 @@ function ServerProcess.__start()
end
end
-- Ping :Wait()
if net._ping then
FastSpawn(net._ping, os.clock())
if #net._ping > 0 then
for _, func in net._ping do
FastSpawn(func, os.clock())
end
end
end
debug.profileend()
Expand Down
27 changes: 15 additions & 12 deletions src/Server/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local FastSpawn = require(script.Parent.FastSpawn)
local Debug = require(script.Parent.Debug)
local Util = require(script.Parent.Util)

local Players = game:GetService("Players")
local Event = script.Parent:WaitForChild("Event")

local Collections = {}
Expand All @@ -23,14 +24,16 @@ local Collections = {}

function Server.new(Identifier: string)
Debug.new(typeof(Identifier) == "string", "[FastNet2]: Identifier must be string", 0)
Debug.new(not Identifiers.find(Util.ser(Identifier)), string.format("[FastNet2]: %s already exist", Identifier), 0)
Process.reg(Util.ser(Identifier))
Collections[Util.ser(Identifier)] = setmetatable({
Identifier = Util.ser(Identifier),
func = function(...: any): (...any) end,
Connected = false,
flag = {},
}, Server)
if not Identifiers.find(Util.ser(Identifier)) then
Process.reg(Util.ser(Identifier))
Collections[Util.ser(Identifier)] = setmetatable({
_origin = Identifier,
Identifier = Util.ser(Identifier),
func = function(...: any): (...any) end,
Connected = false,
flag = {},
}, Server)
end
return Collections[Util.ser(Identifier)]
end

Expand All @@ -41,7 +44,7 @@ end
**--]]

function Server:Connect(callback: (...any) -> ())
Debug.new(not self.Connected, string.format("[FastNet2]: %s already connected", self.Identifier), 0)
Debug.new(not self.Connected, string.format("[FastNet2]: %s already connected", self._origin), 0)
self.func = callback
Process.reg_pre_f(self.Identifier, callback)
self.Connected = true
Expand Down Expand Up @@ -208,9 +211,9 @@ Event.OnServerEvent:Connect(function(player: Player, packets: any, secondPackets
end
end
table.clear(secondPackets)
elseif packets == "2" then
if not Event:GetAttribute(tostring(secondPackets)) then
Event:SetAttribute(tostring(secondPackets), true)
elseif packets == "2" and typeof(secondPackets) == "string" then
if Players:FindFirstChild(secondPackets) and not Event:GetAttribute(secondPackets) then
Event:SetAttribute(secondPackets, true)
end
end
end
Expand Down
1 change: 0 additions & 1 deletion src/Util.luau
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ function Util.ser(identifier: string): string
end
else
while not Event:GetAttribute(identifier) do
print("e")
Util.Session(0.5)
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
--!strict
-- FastNet2
-- Author: @EternityDev (Eternity_Devs)
-- version rc9 (0.9.4)
-- version rc9 (0.9.5)

local FastNet2 = {}
FastNet2.__index = FastNet2
Expand Down
2 changes: 1 addition & 1 deletion wally.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ registry = "test"

[[package]]
name = "imezx/fastnet2"
version = "0.9.4"
version = "0.9.5"
dependencies = []
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "imezx/fastnet2"
version = "0.9.4"
version = "0.9.5"
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"
license = "MIT"
Expand Down

0 comments on commit 6216938

Please sign in to comment.