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

Commit

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

[RC9 - 0.9.6]
- Changed :Pull to :Invoke
- Improved Invoking on bandwidth saving (only affect to multiple-events)
- Fix :Once
- Changed entire :Session works
- :Invoke now use :Session for it internal system

[RC9 - 0.9.5]
- Fixed Wait-Event Connected (built-in feature)
- Support for using multiple :Wait
Expand Down
Binary file modified FastNet2_Rewrite.rbxm
Binary file not shown.
6 changes: 3 additions & 3 deletions docs/api/1.0/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ Remote:Fire("Hello World!")
This function have rate limiting to prevent spamming
:::

## `:Pull`
## `:Invoke`

Pull is a function that invoke to server.
Semiliar with :InvokeServer, its for doing Invoke to a Server.

::: code-group
```lua [main]
Expand All @@ -106,7 +106,7 @@ Pull is a function that invoke to server.
```

```lua [Example]
local Request = Remote:Pull(2, "Hello World!")
local Request = Remote:Invoke(2, "Hello World!")
```
:::

Expand Down
6 changes: 3 additions & 3 deletions docs/api/1.0/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ Remote:Fires("Hello World!")
```
:::

## `:Pull`
## `:Invoke`

Pull is a function that invoke to client.
Semiliar with `:InvokeClient`, its for doing Invoke to spesific Client.

::: code-group
```lua [main]
Expand All @@ -120,7 +120,7 @@ Pull is a function that invoke to client.
```

```lua [Example]
local Request = Remote:Pull(2, player, "Hello World!")
local Request = Remote:Invoke(2, player, "Hello World!")
```
:::

Expand Down
14 changes: 8 additions & 6 deletions src/Client/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local FastSpawn = require(script.Parent.FastSpawn)
local Debug = require(script.Parent.Debug)
local Util = require(script.Parent.Util)

local Event = script.Parent:WaitForChild("Event")
local Event: RemoteEvent = script.Parent:WaitForChild("Event")

local Collections = {}

Expand Down Expand Up @@ -92,6 +92,7 @@ function Client:Once(callback: (...any) -> ())
self:Disconnect()
task.spawn(callback, ...)
end
Process.reg_pre_f(self.Identifier, callback)
self.Connected = true
end
end
Expand Down Expand Up @@ -139,23 +140,24 @@ end
@params ... any parameters to sent
**--]]

function Client:Pull(timeout: number, ...: any)
function Client:Invoke(timeout: number, ...: any)
Debug.new(typeof(timeout) == "number", "[FastNet2]: expire argument must be a number.", 0)
Debug.new(timeout > 1, "[FastNet2]: expire argument must be minimum 2.", 0)
Debug.new(#{...} > 0, "[FastNet2]: Unable to invoke without data", 0)
local thread, requestId = coroutine.running(), string.pack("I5", Util.uniqueNum())
local session = task.delay(timeout, function()
local session = Util.Session(timeout)
:After(function(e)
-- session expire
-- removing and clear entire requests point
if Process.verify(self.Identifier, requestId) or self.flag[requestId] then
self.flag[requestId] = nil
end
task.spawn(thread, nil) -- resume thread to finish and return nil as failed to retreive due over-session (expired)
end)
task.spawn(thread, e) -- resume thread to finish and return nil as failed to retreive due over-session (expired)
end, nil)
-- set new flag as checkpoint
self.flag[requestId] = function(...)
self.flag[requestId] = nil
task.cancel(session)
session:Cancel()
task.spawn(thread, ...) -- resume thread to finish and return data as successed
end
-- push new request
Expand Down
30 changes: 22 additions & 8 deletions src/Server/Process.luau
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function ServerProcess.reg(Identifier: string)
Identifier = Identifier,
_ping = {},
returnRequest = {},
re_req_i = 0,
re_req_i = {},
requests = {},
req_i = 0,
packets = {},
Expand Down Expand Up @@ -60,7 +60,7 @@ function ServerProcess.pushback(Identifier: string, player: string, id: number,
Collections[Identifier].returnRequest[player] = {}
end
Collections[Identifier].returnRequest[player][id] = obj
Collections[Identifier].re_req_i += 1
Collections[Identifier].re_req_i[player] = true
end

function ServerProcess._ping(Identifier: string): number
Expand Down Expand Up @@ -100,6 +100,7 @@ end
function ServerProcess.__start()
local outQueue: { [string]: {any} }, outIndex: number = {}, 0
local outSQueue: { [string]: {any} }, outSIndex: number = {}, 0
local outReq: { [string]: {any} }, outRIndex: { [string]: boolean } = {}, {}
RunService.PostSimulation:Connect(function()
-- Sent all data to client (Multiple Players)
if outIndex > 0 then
Expand All @@ -116,6 +117,13 @@ function ServerProcess.__start()
end
end
end
for i, player: Player in Players:GetPlayers() do
if outReq[player.Name] and outRIndex[player.Name] == true then
outRIndex[player.Name] = false
Event:FireClient(player, "1", outReq[player.Name])
table.clear(outReq[player.Name])
end
end
debug.profilebegin("FastNet2.process")
-- Connections Dataset from Collections
for Identifier: string, net in Collections do
Expand Down Expand Up @@ -164,13 +172,19 @@ function ServerProcess.__start()
end
end
-- Return Requests
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)
for player, data in net.returnRequest do
if player and Players:FindFirstChild(player) and net.re_req_i[player] == true and Event:GetAttribute(player) == true then
net.re_req_i[player] = false
if not outReq[player] then
outReq[player] = {}
end
if not outReq[player][net.Identifier] then
outReq[player][net.Identifier] = {}
end
outReq[player][net.Identifier] = table.clone(data)
outRIndex[player] = true
--Event:FireClient(Players[player], "1", {[net.Identifier] = data})
table.clear(data)
end
end
-- Single Players to Queue
Expand Down
15 changes: 9 additions & 6 deletions src/Server/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local Debug = require(script.Parent.Debug)
local Util = require(script.Parent.Util)

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

local Collections = {}

Expand Down Expand Up @@ -52,6 +52,7 @@ end

--[[**
Connect a connection (Luau Parralel)
This only works with Actor Instance
@param callback this must be a function with any arguments
**--]]
Expand Down Expand Up @@ -92,6 +93,7 @@ function Server:Once(callback: (...any) -> ())
self:Disconnect()
task.spawn(callback, ...)
end
Process.reg_pre_f(self.Identifier, callback)
self.Connected = true
end
end
Expand Down Expand Up @@ -148,24 +150,25 @@ end
@params ... any parameters to sent
**--]]

function Server:Pull(timeout: number, player: Player, ...: any)
function Server:Invoke(timeout: number, player: Player, ...: any)
Debug.new(typeof(timeout) == "number", "[FastNet2]: expire argument must be a number.", 0)
Debug.new(timeout > 1, "[FastNet2]: expire argument must be minimum 2.", 0)
Debug.new(player:IsA("Player"), "[FastNet2]: player argument must be a Player.", 0)
Debug.new(#{...} > 0, "[FastNet2]: Unable to invoke without data", 0)
local thread, requestId = coroutine.running(), string.pack("I5", Util.uniqueNum())
local session = task.delay(timeout, function()
local session = Util.Session(timeout)
:After(function(e)
-- session expire
-- removing and clear entire requests point
if Process.verify(self.Identifier, player, requestId) or self.flag[requestId] then
self.flag[requestId] = nil
end
task.spawn(thread, nil) -- resume thread to finish and return nil as failed to retreive due over-session (expired)
end)
task.spawn(thread, e) -- resume thread to finish and return nil as failed to retreive due over-session (expired)
end, nil)
-- set new flag as checkpoint
self.flag[requestId] = function(...)
self.flag[requestId] = nil
task.cancel(session)
session:Cancel()
task.spawn(thread, ...) -- resume thread to finish and return data as successed
end
-- push new request
Expand Down
24 changes: 17 additions & 7 deletions src/Util.luau
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,23 @@ function Util.CreateUUID(): string
return string.gsub(HttpService:GenerateGUID(false), "-", "") :: string
end

-- Create session semiliar with task.wait function (YIELD) (Internal Function)
function Util.Session(timeout: number): number
local thread, n = coroutine.running(), tick()
task.delay(math.max(0.25, timeout), function()
task.spawn(thread, tick() - n)
-- Create session semiliar with task.wait function (Internal Function)
function Util.Session(timeout: number)
local afterSession, arguments, private = nil, {}, {}
local session = task.delay(math.max(0.5, timeout), function()
if afterSession and typeof(afterSession) == "function" then
task.spawn(afterSession, table.unpack(arguments))
end
end)
return coroutine.yield()
function private:After(func: (...any) -> (), ...: any)
afterSession = func
arguments = { ... }
return private
end
function private:Cancel()
task.cancel(session)
end
return private
end

-- Generate a randomized unique number with 8 length num (Internal Function)
Expand All @@ -45,7 +55,7 @@ function Util.ser(identifier: string): string
end
else
while not Event:GetAttribute(identifier) do
Util.Session(0.5)
task.wait(0.5)
end
end
return Event:GetAttribute(identifier)
Expand Down
4 changes: 2 additions & 2 deletions 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.5)
-- version rc9 (0.9.6)

local FastNet2 = {}
FastNet2.__index = FastNet2
Expand Down Expand Up @@ -86,7 +86,7 @@ end
**--]]

function FastNet2.debugLogs()
function FastNet2.debugLogs(): {any}
return Debug.receiveAll()
end

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.5"
version = "0.9.6"
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.5"
version = "0.9.6"
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"
license = "MIT"
Expand Down

0 comments on commit 0b5a737

Please sign in to comment.