mirror of
https://github.com/imezx/Warp.git
synced 2026-06-02 12:18:32 +00:00
rewrite(phase5): add docstring
This commit is contained in:
parent
85f6aa8b77
commit
c4a7934bc4
3 changed files with 459 additions and 404 deletions
|
|
@ -29,8 +29,13 @@ local eventSchemas: { [number]: Buffer.SchemaType } = {}
|
|||
local pendingInvokes: { [string]: thread } = {}
|
||||
local invokeId = 0
|
||||
|
||||
--@optional
|
||||
-- Yields the current thread until the client has successfully initialized and synchronized with the server's replication data (identifier). Its optionally, but highly recommended to call this before firing or connecting to any events to ensure the network is fully ready.
|
||||
Client.awaitReady = Replication.wait_for_ready
|
||||
|
||||
--@remoteName string
|
||||
--@schema Buffer.SchemaType
|
||||
-- Define a schema for strict data packing on a specific event.
|
||||
Client.useSchema = function(remoteName: string, schema: Buffer.SchemaType)
|
||||
local id = Replication.get_id(remoteName)
|
||||
if not id then
|
||||
|
|
@ -40,6 +45,9 @@ Client.useSchema = function(remoteName: string, schema: Buffer.SchemaType)
|
|||
eventSchemas[id] = schema
|
||||
end
|
||||
|
||||
--@remoteName string
|
||||
--@fn function
|
||||
-- Connect to an event to receive incoming data from the server.
|
||||
Client.Connect = function(remoteName: string, fn: (Player, ...any?) -> ...any?): Connection
|
||||
local id = Replication.get_id(remoteName)
|
||||
if not id then
|
||||
|
|
@ -66,6 +74,9 @@ Client.Connect = function(remoteName: string, fn: (Player, ...any?) -> ...any?):
|
|||
} :: Connection
|
||||
end
|
||||
|
||||
--@remoteName string
|
||||
--@fn function
|
||||
-- Similar to :Connect but automatically disconnects after the first firing.
|
||||
Client.Once = function(remoteName: string, fn: (...any?) -> ()): Connection
|
||||
local connection
|
||||
connection = Client.Connect(remoteName, function(...: any?)
|
||||
|
|
@ -77,6 +88,8 @@ Client.Once = function(remoteName: string, fn: (...any?) -> ()): Connection
|
|||
return connection
|
||||
end
|
||||
|
||||
--@remoteName string
|
||||
-- Wait for an event to be triggered. Yields the current thread.
|
||||
Client.Wait = function(remoteName: string): (number, ...any?)
|
||||
local thread, t = coroutine.running(), os.clock()
|
||||
Client.Once(remoteName, function(...: any?)
|
||||
|
|
@ -85,6 +98,8 @@ Client.Wait = function(remoteName: string): (number, ...any?)
|
|||
return coroutine.yield()
|
||||
end
|
||||
|
||||
--@remoteName string
|
||||
-- Disconnect all connections for a specific event.
|
||||
Client.DisconnectAll = function(remoteName: string)
|
||||
local id = Replication.get_id(remoteName)
|
||||
if not id then
|
||||
|
|
@ -97,8 +112,13 @@ Client.DisconnectAll = function(remoteName: string)
|
|||
end
|
||||
end
|
||||
|
||||
--@remoteName string
|
||||
-- Disconnect all connections and remove the event.
|
||||
Client.Destroy = Client.DisconnectAll
|
||||
|
||||
--@remoteName string
|
||||
--@reliable boolean
|
||||
-- Fire an event to the server.
|
||||
Client.Fire = function(remoteName: string, reliable: boolean, ...: any?)
|
||||
local id = Replication.get_id(remoteName)
|
||||
if id then
|
||||
|
|
@ -109,6 +129,9 @@ Client.Fire = function(remoteName: string, reliable: boolean, ...: any?)
|
|||
end
|
||||
end
|
||||
|
||||
--@remoteName string
|
||||
--@timeout number?
|
||||
-- Invoke the server with timeout support. Yields the current thread. Returns nil if timeout occurs.
|
||||
Client.Invoke = function(remoteName: string, timeout: number?, ...: any?): ...any?
|
||||
local id = Replication.get_id(remoteName)
|
||||
if not id then
|
||||
|
|
|
|||
|
|
@ -86,7 +86,6 @@ if RunService:IsClient() or RunService:IsRunMode() then
|
|||
if not obj then
|
||||
warn(`[Replication] timeout: could not find identifier '{name}' after {timeout}s.`)
|
||||
end
|
||||
|
||||
return obj
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -37,16 +37,25 @@ local players_ready: { Player }, player_bytes: { [Player]: number } = {}, {}
|
|||
local pendingInvokes: { [string]: thread } = {}
|
||||
local invokeId = 0
|
||||
|
||||
--@namespaces { string }
|
||||
--@optional
|
||||
-- Register namespaces to ensure all of the namespaces is being registered earlier on the server to prevent any unexpected issues on the client.
|
||||
Server.reg_namespaces = function(namespaces: { string })
|
||||
for _, name: string in namespaces do
|
||||
Identifier.get_id(name)
|
||||
end
|
||||
end
|
||||
|
||||
--@remoteName string
|
||||
--@schema Buffer.SchemaType
|
||||
-- Define a schema for strict data packing on a specific event.
|
||||
Server.useSchema = function(remoteName: string, schema: Buffer.SchemaType)
|
||||
eventSchemas[Identifier.get_id(remoteName)] = schema
|
||||
end
|
||||
|
||||
--@remoteName string
|
||||
--@fn function
|
||||
-- Connect to an event to receive incoming data from clients.
|
||||
Server.Connect = function(remoteName: string, fn: (Player, ...any?) -> ...any?): Connection
|
||||
local detail = {
|
||||
i = Identifier.get_id(remoteName),
|
||||
|
|
@ -68,6 +77,9 @@ Server.Connect = function(remoteName: string, fn: (Player, ...any?) -> ...any?):
|
|||
} :: Connection
|
||||
end
|
||||
|
||||
--@remoteName string
|
||||
--@fn function
|
||||
-- Similar to :Connect but automatically disconnects after the first firing.
|
||||
Server.Once = function(remoteName: string, fn: (...any?) -> ()): Connection
|
||||
local connection
|
||||
connection = Server.Connect(remoteName, function(...: any?)
|
||||
|
|
@ -79,6 +91,8 @@ Server.Once = function(remoteName: string, fn: (...any?) -> ()): Connection
|
|||
return connection
|
||||
end
|
||||
|
||||
--@remoteName string
|
||||
-- Wait for an event to be triggered. Yields the current thread.
|
||||
Server.Wait = function(remoteName: string): (number, ...any?)
|
||||
local thread, t = coroutine.running(), os.clock()
|
||||
Server.Once(remoteName, function(...: any?)
|
||||
|
|
@ -87,6 +101,8 @@ Server.Wait = function(remoteName: string): (number, ...any?)
|
|||
return coroutine.yield()
|
||||
end
|
||||
|
||||
--@remoteName string
|
||||
-- Disconnect all connections for a specific event.
|
||||
Server.DisconnectAll = function(remoteName: string)
|
||||
local id = Identifier.get_id(remoteName)
|
||||
if not id then
|
||||
|
|
@ -99,8 +115,14 @@ Server.DisconnectAll = function(remoteName: string)
|
|||
end
|
||||
end
|
||||
|
||||
--@remoteName string
|
||||
-- Disconnect all connections and remove the event.
|
||||
Server.Destroy = Server.DisconnectAll
|
||||
|
||||
--@remoteName string
|
||||
--@reliable boolean
|
||||
--@player Player
|
||||
-- Fire an event to a specific player.
|
||||
Server.Fire = function(remoteName: string, reliable: boolean, player: Player, ...: any?)
|
||||
local targetQueue = reliable and queueEvent or queueUnreliableEvent
|
||||
if not targetQueue[player] then
|
||||
|
|
@ -112,12 +134,19 @@ Server.Fire = function(remoteName: string, reliable: boolean, player: Player, ..
|
|||
})
|
||||
end
|
||||
|
||||
--@remoteName string
|
||||
--@reliable boolean
|
||||
-- Fire an event to all connected players.
|
||||
Server.Fires = function(remoteName: string, reliable: boolean, ...: any?)
|
||||
for _, player: Player in players_ready do
|
||||
Server.Fire(remoteName, reliable, player, ...)
|
||||
end
|
||||
end
|
||||
|
||||
--@remoteName string
|
||||
--@reliable boolean
|
||||
--@except { Player }
|
||||
-- Fire an event to all players except specified ones.
|
||||
Server.FireExcept = function(remoteName: string, reliable: boolean, except: { Player }, ...: any?)
|
||||
for _, player: Player in players_ready do
|
||||
if table.find(except, player) then continue end
|
||||
|
|
@ -125,6 +154,10 @@ Server.FireExcept = function(remoteName: string, reliable: boolean, except: { Pl
|
|||
end
|
||||
end
|
||||
|
||||
--@remoteName string
|
||||
--@player Player
|
||||
--@timeout number?
|
||||
-- Invoke a client with timeout support. Yields the current thread. Returns nil if timeout occurs.
|
||||
Server.Invoke = function(remoteName: string, player: Player, timeout: number?, ...: any?): ...any?
|
||||
invokeId += 1
|
||||
local reqId, thread = `{invokeId}`, coroutine.running()
|
||||
|
|
|
|||
Loading…
Reference in a new issue