### Install RbxNet for TypeScript from GitHub Source: https://rbxnet.australis.dev/docs/3.0/install Installs the latest master build of RbxNet directly from its GitHub repository. This method is an alternative to using NPM. ```bash npm install github:roblox-aurora/rbx-net ``` ```typescript import Net from "@rbxts/net"; ``` -------------------------------- ### RbxNet Installation Source: https://rbxnet.australis.dev/docs/3.0/index Instructions for installing RbxNet for both TypeScript and Luau environments. This guide helps developers set up the networking library in their Roblox projects. ```TypeScript Install for TypeScript: https://rbxnet.australis.dev/docs/3.0/install ``` ```Luau Install for Luau: https://rbxnet.australis.dev/docs/3.0/install-luau ``` -------------------------------- ### Install RbxNet via Studio (RBXMX) Source: https://rbxnet.australis.dev/docs/3.0/install-luau Instructions for installing RbxNet in Roblox Studio using an RBXMX model file. This involves downloading the file from the releases page and placing it in ReplicatedStorage. ```text Download the appropriate .rbxmx file from the releases page. Drag the file into Studio. Ensure the library is under ReplicatedStorage. ``` -------------------------------- ### RbxNet Installation for Luau Source: https://rbxnet.australis.dev/docs/3.0/middleware/custom Instructions for installing RbxNet for use in a Luau project. ```bash npm install rbxnet-luau # or yarn add rbxnet-luau ``` -------------------------------- ### RbxNet Installation for Luau Source: https://rbxnet.australis.dev/docs/3.0/definitions/starting Instructions for installing RbxNet for use in a Luau project. This may involve cloning the repository or using a specific package manager for Luau. ```bash git clone https://github.com/roblox-aurora/rbx-net.git -- or -- -- Instructions for Luau package manager if available -- ``` -------------------------------- ### Install RbxNet for TypeScript via NPM Source: https://rbxnet.australis.dev/docs/3.0/install Installs the RbxNet module into your TypeScript project using the Node Package Manager (NPM). This is the recommended installation method. ```bash npm install @rbxts/net ``` ```typescript import Net from "@rbxts/net"; ``` -------------------------------- ### RbxNet Installation for TypeScript Source: https://rbxnet.australis.dev/docs/3.0/middleware/custom Instructions for installing RbxNet for use in a TypeScript project. ```bash npm install rbxnet-ts # or yarn add rbxnet-ts ``` -------------------------------- ### Install RbxNet for TypeScript Source: https://rbxnet.australis.dev/docs/3.0/install-luau This section provides instructions for installing RbxNet in a TypeScript environment for Roblox development. It links to a separate installation guide. ```typescript // See: https://rbxnet.australis.dev/docs/3.0/install ``` -------------------------------- ### RbxNet Installation for TypeScript Source: https://rbxnet.australis.dev/docs/3.0/definitions/starting Instructions for installing RbxNet for use in a TypeScript project. This typically involves using a package manager like npm or yarn. ```bash npm install rbxnet # or yarn add rbxnet ``` -------------------------------- ### Install rbxts-transform-guid Source: https://rbxnet.australis.dev/docs/3.0/uuid Installs the rbxts-transform-guid package as a development dependency. ```bash npm i -D rbxts-transform-guid ``` -------------------------------- ### Install RbxNet via Wally (Luau) Source: https://rbxnet.australis.dev/docs/3.0/install-luau This snippet shows how to add RbxNet as a dependency in your Luau project using Wally. It requires Wally to be installed and specifies the RbxNet package and version. ```toml [dependencies] # ... Net="vorlias/net@3.0.1" ``` ```bash wally install ``` -------------------------------- ### Create RbxNet Definitions (Luau) Source: https://rbxnet.australis.dev/docs/3.0/definitions Shows how to create a definition script for RbxNet remotes using Luau. This script should be placed in ReplicatedStorage and made accessible to both server and client scripts. ```luau localNet=require(ReplicatedStorage.Net) localRemotes=Net.CreateDefinitions({ -- Definitions for the actual remotes will go here }) returnRemotes ``` -------------------------------- ### TypeScript: Client Remote Example Source: https://rbxnet.australis.dev/docs/3.0/api/definitions An example demonstrating how to get a client remote named 'TestRemote' using the `Client` type from `shared/remotes.ts`. ```typescript import { Client as ClientRemotes } from "shared/remotes.ts"; const TestRemote = ClientRemotes.Get("TestRemote"); ``` -------------------------------- ### Create RbxNet Definitions (TypeScript) Source: https://rbxnet.australis.dev/docs/3.0/definitions Demonstrates how to create a definition script for RbxNet remotes using TypeScript. This script serves as a central source of truth for networking objects. ```typescript importNetfrom"@rbxts/net"; constRemotes=Net.CreateDefinitions({ // Definitions for the actual remotes will go here }); export=Remotes; ``` -------------------------------- ### TypeScript: Server Remote Example Source: https://rbxnet.australis.dev/docs/3.0/api/definitions An example demonstrating how to get a server remote named 'TestRemote' using the `Server` type from `shared/remotes.ts`. ```typescript import { Server as ServerRemotes } from "shared/remotes.ts"; const TestRemote = ServerRemotes.Get("TestRemote"); ``` -------------------------------- ### Define Remotes in TypeScript Source: https://rbxnet.australis.dev/docs/3.0/definitions/starting This snippet shows how to define various types of remotes (ServerAsyncFunction, ServerToClientEvent, ClientToServerEvent) using the Net library in TypeScript. It includes examples for getting player inventory, equipped items, and handling item updates and unequips. ```typescript importNet,{Definitions}from"@rbxts/net"; constRemotes=Net.CreateDefinitions({ GetPlayerInventory:Definitions.ServerAsyncFunction<()=>SerializedPlayerInventory>(), GetPlayerEquipped:Definitions.ServerAsyncFunction<()=>SerializedPlayerEquipped>(), PlayerInventoryUpdated:Definitions.ServerToClientEvent<[event:InventoryUpdatedEvent]>(), PlayerEquippedUpdated:Definitions.ServerToClientEvent<[event:EquippedUpdatedEvent]>(), PlayerUnequipItem:Definitions.ClientToServerEvent<[itemId:number]>(), PlayerEquipItem:Definitions.ClientToServerEvent<[itemId:number]>(), }); export=Remotes; ``` -------------------------------- ### Luau Custom Middleware Example Source: https://rbxnet.australis.dev/docs/3.0/middleware/custom An example of a custom middleware function in Luau. This middleware forwards the call to the next function in the middleware pipeline, illustrating the fundamental structure for creating custom middleware. ```luau function MyMiddleware(next, instance) return function(player, ...) return next(player, ...) end end return{ MyMiddleware = MyMiddleware } ``` -------------------------------- ### Define Remotes in Luau Source: https://rbxnet.australis.dev/docs/3.0/definitions/using This snippet demonstrates defining server-to-client, client-to-server, and server functions using RbxNet's Definitions API in Luau. It sets up the communication channels for the game. ```luau local Net =require(ReplicatedStorage.Net) local Remotes = Net.CreateDefinitions({ GetPlayerInventory = Net.Definitions.ServerFunction(), GetPlayerEquipped = Net.Definitions.ServerFunction(), PlayerInventoryUpdated = Net.Definitions.ServerToClientEvent(), PlayerEquippedUpdated = Net.Definitions.ServerToClientEvent(), PlayerUnequipItem = Net.Definitions.ClientToServerEvent(), PlayerEquipItem = Net.Definitions.ClientToServerEvent(), }) return Remotes ``` -------------------------------- ### Server Namespace Usage (TypeScript) Source: https://rbxnet.australis.dev/docs/3.0/definitions/namespacing Demonstrates how to get server-side namespaces for 'Inventory' and 'Equipped' remotes using Roblox-TS. ```typescript import Remotes from "shared/remotes"; // This will contain all the server inventory remotes const InventoryRemotes = Remotes.Server.GetNamespace("Inventory"); // This will contain all the server equipped remotes const equippedRemotes = Remotes.Server.GetNamespace("Equipped"); ``` -------------------------------- ### TypeScript Custom Middleware Example Source: https://rbxnet.australis.dev/docs/3.0/middleware/custom An example of a custom middleware function in TypeScript. This middleware simply passes control to the next middleware in the chain, demonstrating the basic structure required for custom middleware. ```typescript exportconst MyMiddleware:Net.Middleware=( nextMiddleware, instance )=>{ return( sender, ...args )=>{ return nextMiddleware(sender, ...args); }; }; ``` -------------------------------- ### RbxNet Definitions API Documentation Source: https://rbxnet.australis.dev/docs/3.0/api/definitions Provides comprehensive documentation for the Net.Definitions namespace, including functions for creating various types of remote definitions. It details parameters, return types, and usage examples for functions like Definitions.Create, Definitions.ServerFunction, Definitions.ServerToClientEvent, Definitions.ClientToServerEvent, Definitions.BidirectionalEvent, and Definitions.ServerAsyncFunction. ```APIDOC Net.Definitions Namespace This namespace is for the Definitions feature. Definitions.Create(definitions) - Creates a new set of remote definitions. - Parameters: - `remotes`: An object of remote definitions. See [definitions](https://rbxnet.australis.dev/docs/3.0/api/definitions#definitions-oh-my) for usage. - `globalMiddleware` (optional): A collection of _global middleware_ to apply to all remotes in this definition. - Returns a [DefinitionsCreateResult](https://rbxnet.australis.dev/docs/3.0/api/definitions/#definitionscreateresultt). Example: ```typescript import Net from "@rbxts/net"; const MyDefinitions = Net.Definitions.Create({ TestRemote: Net.Definitions.AsyncFunction<(name: string) => boolean>() }); ``` Definitions.ServerFunction(...) - Definition function for creating a `FunctionDefinition`. Definitions.ServerToClientEvent(...) - Definition function for creating an `ServerEventDeclaration`. Definitions.ClientToServerEvent(...) - Definition function for creating an `ClientEventDeclaration`. Definitions.BidirectionalEvent(...) - Definition function for creating an `BidirectionalEventDeclaration`. Definitions.ServerAsyncFunction(...) - Definition function for creating an `ServerAsyncFunctionDefinition`. ``` -------------------------------- ### Define Remotes in Luau Source: https://rbxnet.australis.dev/docs/3.0/definitions/starting This snippet demonstrates how to define remotes using the Net library in Luau. It includes examples for ServerFunction, ServerToClientEvent, and ClientToServerEvent, covering player inventory, equipped items, and item updates. ```luau local Net =require(ReplicatedStorage.Net) local Remotes = Net.CreateDefinitions({ GetPlayerInventory = Net.Definitions.ServerFunction(), GetPlayerEquipped = Net.Definitions.ServerFunction(), PlayerInventoryUpdated = Net.Definitions.ServerToClientEvent(), PlayerEquippedUpdated = Net.Definitions.ServerToClientEvent(), PlayerUnequipItem = Net.Definitions.ClientToServerEvent(), PlayerEquipItem = Net.Definitions.ClientToServerEvent(), }) return Remotes ``` -------------------------------- ### Server Handling Client Events in Luau Source: https://rbxnet.australis.dev/docs/3.0/definitions/using This Luau code snippet shows how a server can listen for and handle a client-to-server event ('PlayerEquipItem'). It connects a function to the event that prints a message when the event is received. ```luau local Remotes =require(ReplicatedStorage.Shared.Remotes) Remotes.Server:Get("PlayerEquipItem"):Connect(function(player: Player, text: string) print("Received "..text.." from "..player.Name) end) ``` -------------------------------- ### APIDOC: ServerDefinitionBuilder Methods Source: https://rbxnet.australis.dev/docs/3.0/api/definitions Provides methods for interacting with server-side definitions. It allows getting specific events or functions, accessing child namespaces, and setting up callbacks for events and functions. ```APIDOC ServerDefinitionBuilder Contains all the definition builders for server-side events and functions. class ServerDefinitionBuilder{ Get(name:string):ServerEvent|ServerAsyncFunction|ServerFunction; GetNamespace(name:K):SeverDefinitionBuilder; OnEvent(name:string, callback:Callback):void; OnFunction(name:string, callback:Callback):void; } Get(name) Will get the specified event by name, and return it. The returned object will be the type provided in the definition. OnFunction(name, callback) Similar to `Get` but only works on events, and is pretty much a shortcut for `Get(name).SetCallback(callback)` OnEvent(name, callback) Similar to `Get` but only works on events, and is pretty much a shortcut for `Get(name).Connect(callback)` GetNamespace(name) Gets a child namespace under this namespace ``` -------------------------------- ### Luau Administrator Middleware Example Source: https://rbxnet.australis.dev/docs/3.0/middleware/custom A Luau example of middleware that enforces administrator privileges. It checks the sender's group rank, proceeding with the next middleware only if the rank meets the specified threshold; otherwise, the request is dropped. ```luau local GROUP_ID = 2664663 -- group id would go here function MyMiddleware(next, instance) return function(sender, ...) if sender:GetRankInGroup(GROUP_ID) >= 250 then -- This would continue the remote execution return next(sender, ...) end -- Otherwise the remote request is ignored since the next middleware is never called end end return{ MyMiddleware = MyMiddleware } ``` -------------------------------- ### TypeScript Administrator Middleware Example Source: https://rbxnet.australis.dev/docs/3.0/middleware/custom An example of a TypeScript middleware that restricts access to administrators based on their group rank. If the sender's rank is 250 or higher, the next middleware is called; otherwise, the request is ignored. ```typescript const GROUP_ID = 2664663; exportconst AdministratorMiddleware:Net.Middleware=( nextMiddleware, instance )=>{ return( sender, ...args )=>{ if (sender.GetRankInGroup(GROUP_ID) >= 250) { // This would continue the remote execution return nextMiddleware(sender, ...args); } // Otherwise the remote request is ignored }; }; ``` -------------------------------- ### APIDOC: ClientDefinitionBuilder Methods Source: https://rbxnet.australis.dev/docs/3.0/api/definitions Provides methods for interacting with client-side definitions. It allows getting specific events or functions, accessing child namespaces, and setting up callbacks for events and functions. ```APIDOC ClientDefinitionBuilder Contains all the definition builders for server-side events and functions. class ClientDefinitionBuilder{ Get(name:string):ServerEvent|ServerAsyncFunction|ServerFunction; GetNamespace(name:K):ClientDefinitionBuilder; OnEvent(name:string, callback:Callback):void; OnFunction(name:string, callback:Callback):void; } Get(name) Will get the specified event by name, and return it. The returned object will be the type provided in the definition. Gets the specified remote definition and gets the client version of the event/function/asyncfunction OnEvent(name, callback) Similar to `Get` but only works on events, and is pretty much a shortcut for `Get(name).Connect(callback)` OnFunction(name, callback) Similar to `Get` but only works on events, and is pretty much a shortcut for `Get(name).SetCallback(callback)` ``` -------------------------------- ### Define Remotes in TypeScript Source: https://rbxnet.australis.dev/docs/3.0/definitions/using This snippet shows how to define server-to-client, client-to-server, and server-async functions using RbxNet's Definitions API in TypeScript. It includes type safety for arguments and return values. ```typescript import Net,{Definitions}from"@rbxts/net"; const Remotes=Net.CreateDefinitions({ GetPlayerInventory:Definitions.ServerAsyncFunction<()=>SerializedPlayerInventory>(), GetPlayerEquipped:Definitions.ServerAsyncFunction<()=>SerializedPlayerEquipped>(), PlayerInventoryUpdated:Definitions.ServerToClientEvent<[event:InventoryUpdatedEvent]>(), PlayerEquippedUpdated:Definitions.ServerToClientEvent<[event:EquippedUpdatedEvent]>(), PlayerUnequipItem:Definitions.ClientToServerEvent<[itemId:number]>(), PlayerEquipItem:Definitions.ClientToServerEvent<[itemId:number]>(), }); export=Remotes; ``` -------------------------------- ### Client Sending Events to Server in Luau Source: https://rbxnet.australis.dev/docs/3.0/definitions/using This Luau code snippet demonstrates how a client can send a client-to-server event ('PlayerEquipItem') to the server. It uses the Remotes object to send a string payload. ```luau local Remotes =require(ReplicatedStorage.Shared.Remotes) Remotes.Client:Get("PlayerEquipItem"):SendToServer("Hey!") ``` -------------------------------- ### TypeScript Rate Limit Middleware Configuration Source: https://rbxnet.australis.dev/docs/3.0/middleware/rate-limit Example of configuring the RateLimit middleware with a custom error handler. This limits requests to 1 per minute and uses the `analyticRateLimitError` function for handling errors. ```typescript const Remotes = Net.Definitions.Create({ Example: Net.Definitions.AsyncFunction([ Net.Middleware.RateLimit({ MaxRequestsPerMinute: 1, ErrorHandler: analyticRateLimitError }) ]) }) ``` -------------------------------- ### Luau Rate Limit Middleware Configuration Source: https://rbxnet.australis.dev/docs/3.0/middleware/rate-limit Example of configuring the RateLimit middleware in Luau with a custom error handler. This limits requests to 1 per minute and uses the `analyticRateLimitError` function for handling errors. ```luau local Remotes = Net.Definitions.Create({ Example = Net.Definitions.AsyncFunction({ Net.Middleware.RateLimit({ MaxRequestsPerMinute = 1, ErrorHandler = analyticRateLimitError }) }) }) ``` -------------------------------- ### RbxNet Client API Documentation Source: https://rbxnet.australis.dev/docs/3.0/api/client This section provides detailed API documentation for the Net.Client namespace. It outlines the classes and methods available for client-server communication, including events, functions, and asynchronous functions. Specific details on how to send data to the server, connect callbacks, and manage asynchronous calls are provided. ```APIDOC Net.Client Namespace This contains all the client-related code relating to Net. Event class ClientEvent { constructor(name: string); SendToServer(...args: CallArguments): void; Connect(callback: (...args: ConnectArgs) => void): RBXScriptConnection; } SendToServer Connect Function class ClientFunction { constructor(name: string); CallServerAsync(...args: CallArgs): Promise; } CallServerAsync AsyncFunction class ClientAsyncFunction { constructor(name: string); CallServerAsync(...args: CallArgs): Promise; SetCallback(callback: (...args: CallbackArgs) => any): void; SetCallTimeout(timeout: number): void; GetCallTimeout(): number; } CallServerAsync SetCallback SetCallTimeout GetCalllTimeout CrossServerEvent class CrossServerEvent { constructor(name: string); Connect(callback: (...args: unknown[]) => void): void; } ``` -------------------------------- ### RbxNet API Overview Source: https://rbxnet.australis.dev/docs/3.0/middleware/custom Provides an overview of the RbxNet API, detailing its components for server, client, definitions, and middleware interactions. ```APIDOC Net.Server: // Methods for server-side operations // Example: Send data to clients // Parameters: // - target: The player or group of players to send data to // - eventName: The name of the event to fire // - data: The data to send // Returns: void Send(target: Player | Player[], eventName: string, data: any): void Net.Client: // Methods for client-side operations // Example: Receive data from the server // Parameters: // - eventName: The name of the event to listen for // - callback: The function to execute when the event is received // Returns: void On(eventName: string, callback: (data: any) => void): void Net.Definitions: // Methods for managing and using definitions // Example: Define a remote event // Parameters: // - name: The name of the definition // - schema: The schema for the definition // Returns: void DefineEvent(name: string, schema: any): void Net.Middleware: // Methods for applying middleware to network events // Example: Apply rate limiting middleware // Parameters: // - middleware: The middleware function to apply // Returns: void Use(middleware: (request: any, response: any, next: () => void) => void): void ``` -------------------------------- ### RbxNet API Overview Source: https://rbxnet.australis.dev/docs/3.0/index Provides an overview of the RbxNet API, including server, client, definitions, and middleware modules. This section details how to interact with the networking library for Roblox development. ```APIDOC Net.Server: Handles server-side networking operations. Net.Client: Handles client-side networking operations. Net.Definitions: Manages remote definitions for auto-generated remotes. Net.Middleware: Provides functionality for adding custom behaviors to remotes, including rate limiting and type checking. ``` -------------------------------- ### Create Namespaces in Luau Source: https://rbxnet.australis.dev/docs/3.0/definitions/namespacing Illustrates the creation of namespaces for inventory and equipping remotes in Luau using RbxNet. It showcases the usage of Net.Definitions.Namespace, ServerToClientEvent, ServerFunction, and ClientToServerEvent. ```luau local Net =require(ReplicatedStorage.Net) local Remotes = Net.CreateDefinitions({ -- These are all remotes relating to the inventory Inventory = Net.Definitions.Namespace({ PlayerInventoryUpdated = Net.Definitions.ServerToClientEvent(), GetPlayerInventory = Net.Definitions.ServerFunction(), }), -- These are all the remotes relating to equipping Equipped = Net.Definitions.Namespace({ GetPlayerEquipped = Net.Definitions.ServerFunction(), PlayerEquippedUpdated = Net.Definitions.ServerToClientEvent(), PlayerUnequipItem = Net.Definitions.ClientToServerEvent(), PlayerEquipItem = Net.Definitions.ClientToServerEvent(), }), }) return Remotes ``` -------------------------------- ### Server API Documentation Source: https://rbxnet.australis.dev/docs/3.0/api/server Provides a comprehensive overview of the server-side API functionalities, including event handling, function calls, asynchronous operations, and cross-server communication. ```apidoc GetInstance - Retrieves an instance of a server-side object or service. SetCallback - Sets a callback function for a specific server-side event or operation. CallPlayerAsync - Calls a function on a specific player's client asynchronously. CrossServerEvent: constructor(name: string) - Initializes a new CrossServerEvent with a given name. SendToAllServers(...args: unknown[]): void - Sends data to all connected servers. SendToServer(jobId: string, ...args: unknown[]): void - Sends data to a specific server identified by its jobId. SendToPlayer(userId: number, ...args: unknown[]): void - Sends data to a specific player identified by their userId. SendToPlayers(userIds: number[], ...args: unknown[]): void - Sends data to multiple players identified by their userIds. Disconnect(): void - Disconnects the event or connection. ``` -------------------------------- ### Net.Client Namespace API Documentation Source: https://rbxnet.australis.dev/docs/3.0/api/client Provides documentation for the Net.Client namespace, including methods for connecting, sending data, and managing asynchronous calls. This section details events like SendToServer and Connect, functions like CallServerAsync, and async functions including SetCallback and timeout management. ```APIDOC Net.Client Namespace: Events: SendToServer: Description: Event triggered when data is sent to the server. Usage: Connect a function to this event to handle outgoing data. Connect: Description: Event triggered when the client successfully connects to the server. Usage: Connect a function to this event to perform actions upon successful connection. Functions: CallServerAsync: Description: Asynchronously calls a function on the server. Parameters: - functionName: The name of the function to call on the server. - args: Arguments to pass to the server function. Returns: A Promise that resolves with the server's response. AsyncFunctions: CallServerAsync: Description: Asynchronously calls a function on the server, with an alias. Parameters: - functionName: The name of the function to call on the server. - args: Arguments to pass to the server function. Returns: A Promise that resolves with the server's response. SetCallback: Description: Sets a callback function to be executed when a specific event occurs. Parameters: - eventName: The name of the event to listen for. - callback: The function to execute when the event is triggered. SetCallTimeout: Description: Sets the timeout duration for asynchronous server calls. Parameters: - timeout: The timeout duration in seconds. GetCalllTimeout: Description: Retrieves the current timeout duration for asynchronous server calls. Returns: The current timeout duration in seconds. CrossServerEvent: Connect: Description: Connects to a cross-server event. Usage: Allows clients to subscribe to events broadcast across different servers. ``` -------------------------------- ### Server Namespace Usage (Luau) Source: https://rbxnet.australis.dev/docs/3.0/definitions/namespacing Shows how to access server-side namespaces for 'Equipped' and 'Inventory' remotes in Luau. ```luau local Remotes = require(ReplicatedStorage.Shared.Remotes) -- This will contain all the server inventory remotes local EquippedRemotes = Remotes.Server:GetNamespace("Equipped") -- This will contain all the client inventory remotes local InventoryRemotes = Remotes.Server:GetNamespace("Inventory") ``` -------------------------------- ### RbxNet API Namespaces Source: https://rbxnet.australis.dev/docs/3.0/api Overview of the main namespaces in the RbxNet API. These namespaces organize the framework's functionalities for server, client, definitions, and middleware. ```APIDOC Net.Server: Description: Base namespace for the server. Link: https://rbxnet.australis.dev/docs/3.0/api/server Net.Client: Description: Base namespace for the client. Link: https://rbxnet.australis.dev/docs/3.0/api/client Net.Definitions: Description: The namespace for the definitions feature. Link: https://rbxnet.australis.dev/docs/3.0/api/definitions Net.Middleware: Description: The namespace for built-in middleware. Link: https://rbxnet.australis.dev/docs/3.0/api/middleware ``` -------------------------------- ### RbxNet API Documentation Source: https://rbxnet.australis.dev/docs/3.0/middleware/logging Provides an overview of the RbxNet API, including server, client, definitions, and middleware functionalities. This section details the available modules and their respective capabilities for network communication in Roblox. ```APIDOC Net.Server: Methods for server-side network operations. Net.Client: Methods for client-side network operations. Net.Definitions: Manages and utilizes network definitions for data serialization and validation. Net.Middleware: Provides a framework for integrating custom middleware, including logging and rate limiting. ``` -------------------------------- ### Create Namespaces in TypeScript Source: https://rbxnet.australis.dev/docs/3.0/definitions/namespacing Demonstrates how to create nested namespaces for organizing inventory and equipping remotes using RbxNet's Definitions API in TypeScript. It shows the structure for ServerAsyncFunction and ServerToClientEvent. ```typescript importNet,{Definitions}from"@rbxts/net"; constRemotes=Net.CreateDefinitions({ // These are all remotes relating to the inventory Inventory:Definitions.Namespace({ GetPlayerInventory:Definitions.ServerAsyncFunction<()=>SerializedPlayerInventory>(), PlayerInventoryUpdated:Definitions.ServerToClientEvent<[event:InventoryUpdatedEvent]>(), }), // These are all the remotes relating to equipping Equipping:Definitions.Namespace({ GetPlayerEquipped:Definitions.ServerAsyncFunction<()=>SerializedPlayerEquipped>(), PlayerEquippedUpdated:Definitions.ServerToClientEvent<[event:EquippedUpdatedEvent]>(), PlayerUnequipItem:Definitions.ClientToServerEvent<[itemId:number]>(), PlayerEquipItem:Definitions.ClientToServerEvent<[itemId:number]>(), }) }); export=Remotes; ``` -------------------------------- ### RbxNet Features Source: https://rbxnet.australis.dev/docs/3.0/index Details the key features of RbxNet, including identifier-based remotes, explicit APIs (Net.Server, Net.Client), auto-generated remotes via Net.Definitions, asynchronous functions, promises, middleware, and GameMessagingEvent for cross-server communication. ```TypeScript Features: - Creation and usage of remotes through "identifiers". - Explicit, contextual APIs: `Net.Server` and `Net.Client`. - Remote definitions through `Net.Definitions` for auto-generated remotes. - Asynchronous functions: `Net.*.AsyncFunction`. - Asynchronous callbacks and methods supporting promises. - Middleware for custom behaviors (e.g., runtime type checker, rate limiter). - `Net.*.GameMessagingEvent` for cross-server communication using `MessagingService`. ``` -------------------------------- ### Apply withPlayerEntity Wrapper to Remotes (Luau) Source: https://rbxnet.australis.dev/docs/3.0/custom-player-objects Applies the `withPlayerEntity` wrapper to remote events and callbacks in Luau. This shows how the wrapper simplifies handling player-specific data for `PlayerEquipItem`, `PlayerUnequipItem`, and `GetPlayerEquipped` remotes by providing the `PlayerEntity` directly. ```lua local PlayerService = require(ServerScriptService.Services.PlayerService) local Remotes = require(ReplicatedStorage.Remotes) local withPlayerEntity = require(ServerScriptService.Wrappers.withPlayerEntity) local PlayerEquipItem = Remotes.Server:Get("PlayerEquipItem") PlayerEquipItem:Connect( withPlayerEntity(function(entity, itemId) entity:EquipItem(itemId) end) ) local PlayerUnequipItem = Remotes.Server:Get("PlayerUnequipItem") PlayerUnequipItem:Connect( withPlayerEntity(function(player, itemId) entity:UnequipItem(itemId) end) ) local GetPlayerEquipped = Remotes.Server:Get("GetPlayerEquipped") GetPlayerEquipped:SetCallback( withPlayerEntity(function(player) return entity:GetEquippedItems() end) ) ``` -------------------------------- ### Definitions API Source: https://rbxnet.australis.dev/docs/3.0/api/definitions Provides methods for creating and managing definitions for server and client communication, including functions, events, and namespaces. ```APIDOC Definitions: Create(definitions) Creates definitions for server and client communication. Parameters: definitions: The definitions to create. ServerFunction(name, callback) Defines a server-side function. Parameters: name: The name of the function. callback: The callback function to execute. ServerToClientEvent(name, callback) Defines a server-to-client event. Parameters: name: The name of the event. callback: The callback function to execute. ClientToServerEvent(name, callback) Defines a client-to-server event. Parameters: name: The name of the event. callback: The callback function to execute. BidirectionalEvent(name, callback) Defines a bidirectional event. Parameters: name: The name of the event. callback: The callback function to execute. ServerAsyncFunction(name, callback) Defines a server-side asynchronous function. Parameters: name: The name of the function. callback: The callback function to execute. Namespace(definitions) Creates a namespace for definitions. Parameters: definitions: The definitions to include in the namespace. DefinitionsCreateResult: Server Client ServerDefinitionBuilder: Get(name) Retrieves a definition by name. Parameters: name: The name of the definition. OnFunction(name, callback) Registers a callback for a function. Parameters: name: The name of the function. callback: The callback function. OnEvent(name, callback) Registers a callback for an event. Parameters: name: The name of the event. callback: The callback function. GetNamespace(name) Gets a child namespace. Parameters: name: The name of the child namespace. ClientDefinitionBuilder: Get(name) Retrieves a definition by name. Parameters: name: The name of the definition. OnEvent(name, callback) Registers a callback for an event. Parameters: name: The name of the event. callback: The callback function. OnFunction(name, callback) Registers a callback for a function. Parameters: name: The name of the function. callback: The callback function. GetNamespace(name) Gets a child namespace. Parameters: name: The name of the child namespace. ``` -------------------------------- ### RbxNet Remote Definition API Source: https://rbxnet.australis.dev/docs/3.0/definitions/starting Provides an overview of the functions available in Net.Definitions for creating different types of remote objects in RbxNet. This includes Events, AsyncFunctions, and Functions, outlining their specific use cases and behaviors. ```APIDOC Net.Definitions: Event(name: string, callback: (player: Player, ...args: any[]) => void) - Creates a remote event that can send data to the server or players. - Parameters: - name: The unique name for the event. - callback: The function to execute when the event is received. AsyncFunction(name: string, callback: (player: Player, ...args: any[]) => Promise) - Creates an asynchronous remote function that handles timeouts and runs non-yieldingly. - Rejects if no response is received from the receiver. - Parameters: - name: The unique name for the async function. - callback: An async function that returns a Promise with the result. Function(name: string, callback: (player: Player, ...args: any[]) => any) - Creates a remote function similar to RemoteFunction but restricted to server-to-player calls for security. - Parameters: - name: The unique name for the function. - callback: The function to execute when the remote function is called. ``` -------------------------------- ### Applying Rate Limiter to Definitions Source: https://rbxnet.australis.dev/docs/3.0/middleware/rate-limit Demonstrates how to apply the configured RateLimit middleware to specific remote definitions (like AsyncFunctions) within RbxNet. This allows granular control over which remotes are rate-limited. ```typescript const Remotes = Net.Definitions.Create({ Example:Net.Definitions.AsyncFunction([ Net.Middleware.RateLimit({ MaxRequestsPerMinute:1 }) ]) }) ``` ```luau local Remotes = Net.Definitions.Create({ Example = Net.Definitions.AsyncFunction({ Net.Middleware.RateLimit({ MaxRequestsPerMinute =1 }) }) }) ``` -------------------------------- ### APIDOC: Definitions Namespace and Create Result Source: https://rbxnet.australis.dev/docs/3.0/api/definitions Defines the structure for creating and managing namespaces of definitions. It returns a `DeclarationNamespace` and provides `DefinitionsCreateResult` which contains builders for server and client-side definitions. ```APIDOC Definitions.Namespace(definitions) Creates a group of definitions (returns `DeclarationNamespace`) DefinitionsCreateResult Contains the definition builders for a given definition (returned using [`Create`](https://rbxnet.australis.dev/docs/3.0/api/definitions/definitions#definitionscreatedefinitions) in Net.Definitions) interface DefinitionsCreateResult{ readonly Server: ServerDefinitionBuilder; readonly Client: ClientDefinitionBuilder; } ``` -------------------------------- ### Net.Server Function API Source: https://rbxnet.australis.dev/docs/3.0/api/server Manages server-side functions for RbxNet. Allows setting a callback function that clients can invoke and retrieving the underlying Roblox RemoteFunction instance. ```APIDOC class ServerFunction: constructor(name: string, middleware?: Middleware) name: The name of the function. middleware: Optional middleware to apply to the function. GetInstance(): RemoteFunction Returns the underlying Roblox RemoteFunction instance. SetCallback(callback: (player: Player, ...args: CallbackArgs) => Returns): void Sets the callback function that will be executed when a client invokes this function. Parameters: callback: The function to execute. It receives the player who invoked the function and any arguments passed. ``` -------------------------------- ### Define withPlayerEntity Wrapper (Luau) Source: https://rbxnet.australis.dev/docs/3.0/custom-player-objects Defines a `withPlayerEntity` wrapper function in Luau. This function accepts a callback and returns a new function that retrieves the `PlayerEntity` using `PlayerService` before executing the callback with the entity and any additional arguments. ```lua local PlayerService = require(ServerScriptService.Services.PlayerService) local function withPlayerEntity(fn) return function(player, ...) local entity = playerService:GetEntity(player) if entity then return fn(entity, ...) end end end return withPlayerEntity ``` -------------------------------- ### RateLimit Middleware Source: https://rbxnet.australis.dev/docs/3.0/api/middleware The built-in rate limiting middleware for RbxNet. It allows you to configure the maximum number of requests per minute and provide a custom error handler. ```APIDOC interfaceRateLimitError{ Message:string; UserId:number; RemoteId:string; MaxRequestsPerMinute:number; } interfaceRateLimitOptions{ MaxRequestsPerMinute:number; ErrorHandler?:(error:RateLimitError)=>void; } functionRateLimit(options:RateLimitOptions):RateLimitingMiddleware * Parameters: * `options` The options for the rate limiter ``` -------------------------------- ### Net.Server Event API Source: https://rbxnet.australis.dev/docs/3.0/api/server Manages server-side events for RbxNet. Allows connecting callbacks to events, sending events to all players, specific players, or all players except a blacklist. It uses Roblox's RemoteEvent instances. ```APIDOC class ServerEvent: constructor(name: string, middleware?: Middleware) name: The name of the event. middleware: Optional middleware to apply to the event. GetInstance(): RemoteEvent Returns the underlying Roblox RemoteEvent instance. Connect(callback: (player: Player, ...args: ConnectArgs) => void): RBXScriptConnection Connects a callback function to the event. The callback receives the player who triggered the event and any arguments passed. Parameters: callback: The function to call when the event is received. Returns: An RBXScriptConnection object that can be used to disconnect the callback. SendToAllPlayers(...args: CallArgs): void Sends the event with the given arguments to all players. Parameters: args: The arguments to send with the event. SendToAllPlayersExcept(blacklist: Player | Player[], ...args: CallArgs): void Sends the event with the given arguments to all players except those in the blacklist. Parameters: blacklist: A single Player or an array of Players to exclude. args: The arguments to send with the event. SendToPlayer(player: Player, ...args: CallArgs): void Sends the event with the given arguments to a specific player. Parameters: player: The player to send the event to. args: The arguments to send with the event. SendToPlayers(players: Player[], ...args: CallArgs): void Sends the event with the given arguments to a list of players. Parameters: players: An array of players to send the event to. args: The arguments to send with the event. ``` -------------------------------- ### TypeChecking Middleware Source: https://rbxnet.australis.dev/docs/3.0/api/middleware Provides a basic type checker for remote function arguments. It takes a series of type checking functions as arguments, which are applied in order to the arguments passed to the remote. ```APIDOC functionTypeChecking(...checks:TypeCheck[]):TypeCheckingMiddleware * Parameters: * `...checks` Type checking functions in order of the arguments passed to the remote ``` -------------------------------- ### Net.Server AsyncFunction API Source: https://rbxnet.australis.dev/docs/3.0/api/server Manages server-side asynchronous functions for RbxNet. Allows setting a callback that returns a Promise, and clients can asynchronously call these functions. It uses Roblox's RemoteEvent instances. ```APIDOC class ServerAsyncFunction: constructor(name: string, middleware?: Middleware) name: The name of the asynchronous function. middleware: Optional middleware to apply to the function. GetInstance(): RemoteEvent Returns the underlying Roblox RemoteEvent instance. SetCallback(callback: (player: Player, ...args: CallbackArgs) => any): void Sets the callback function that will be executed when a client invokes this asynchronous function. The callback can return any value, which will be serialized and sent back to the client. Parameters: callback: The function to execute. It receives the player who invoked the function and any arguments passed. CallPlayerAsync(player: Player, ...args: CallArgs): Promise Asynchronously calls the server-side function for a specific player and returns the result. Parameters: player: The player to call the function for. args: The arguments to pass to the server-side callback. Returns: A Promise that resolves with the return value from the server-side callback. ```