///
interface RbxNetConfigItem {
/**
* The throttle reset timer (default: 60 seconds)
*/
ServerThrottleResetTimer: number;
/**
* The message shown when the throttle has been exceeded.
* {player} will be replaced with the player's name!
*/
ServerThrottleMessage: string;
}
/**
* Typescript Networking Library for ROBLOX
*/
export declare namespace Net {
/**
* Sets a configuration value
* @param key The key of the configuration value
* @param value The value of the configuration key
* @rbxts server
*/
function SetConfiguration(key: K, value: RbxNetConfigItem[K]): void;
/**
* Gets a configuration value
* @param key The key of the configuration value
*/
function GetConfiguration(key: K): RbxNetConfigItem[K];
/**
* An event on the server
* @rbxts server
*/
class ServerEvent {
/**
* Creates a new instance of a server event (Will also create the corresponding remote if it does not exist!)
* @param name The name of this server event
* @throws If not created on server
*/
constructor(name: string);
/**
* The RemoteEvent instance
*/
readonly Instance: RemoteEvent;
/**
* The RBXScriptSignal for this RemoteEvent
*/
readonly Event: RBXScriptSignal<(player: Player, ...arguments: unknown[]) => void, false>;
/**
* Connect a fucntion to fire when the event is invoked by the client
* @param callback The function fired when the event is invoked by the client
*/
Connect>(callback: (sourcePlayer: Player, ...args: T) => void): void;
/**
* Sends the specified arguments to all players
* @param args The arguments to send to the players
*/
SendToAllPlayers>(...args: T): void;
/**
* Will send this message to all players except specified players
* @param blacklist The blacklist
* @param args The arguments
*/
SendToAllPlayersExcept>(blacklist: Player | Array, ...args: T): void;
/**
* Sends the specified arguments to a specified player
* @param player The player
* @param args The arguments to send to the player
*/
SendToPlayer>(player: Player, ...args: T): void;
/**
* Sends the specified argumetns to the specified list of players
* @param players The players
* @param args The arugments to send to these players
*/
SendToPlayers>(players: Array, ...args: T): void;
}
/**
* A function on the server
* @rbxts server
*/
class ServerFunction {
/**
* Creates a new instance of a server function (Will also create the corresponding remote if it does not exist!)
* @param name The name of this server function
* @param rateLimit The number of requests allowed per minute per client (0 = none)
* @throws If not created on server
*/
constructor(name: string);
/**
* The callback function
*/
/**
* Set the callback function when called by the client
*/
Callback: Callback;
/**
* The RemoteFunction instance
*/
readonly Instance: RemoteFunction;
/**
* The client cache in seconds
*/
/**
* Sets a client cache timer in seconds
* @param time seconds to cache on client
*/
ClientCache: number;
/**
* Calls the player and returns a promise
* @async returns Promise
* @param player The player to call the function on
* @param args The arguments to call the function with
*/
CallPlayerAsync>(player: Player, ...args: T): Promise;
}
/**
* A server event that can be rate limited
* @rbxts server
*/
class ServerThrottledEvent extends ServerEvent {
private maxRequestsPerMinute;
private clientRequests;
constructor(name: string, rateLimit: number);
/**
* The RBXScriptSignal for this RemoteEvent
*/
readonly Event: RBXScriptSignal<(player: Player, ...arguments: unknown[]) => void, false>;
/**
* Connect a fucntion to fire when the event is invoked by the client
* @param callback The function fired when the event is invoked by the client
*/
Connect>(callback: (sourcePlayer: Player, ...args: T) => void): void;
/**
* The number of requests allowed per minute per user
*/
RateLimit: number;
}
/**
* A server function that can be rate limited
* @rbxts server
*/
class ServerThrottledFunction extends ServerFunction {
private maxRequestsPerMinute;
private clientRequests;
constructor(name: string, rateLimit: number);
Callback: Callback;
/**
* The number of requests allowed per minute per user
*/
RateLimit: number;
}
/**
* An event on the client
* @rbxts client
*/
class ClientEvent {
/**
* Create a new instance of the ClientEvent
* @param name The name of the client event
* @throws If created on server, or does not exist.
*/
constructor(name: string);
static WaitFor(name: string): Promise;
/**
* The RemoteEvent instance
*/
readonly Instance: RemoteEvent;
/**
* The RBXScriptConnection
*/
readonly Event: RBXScriptSignal<(...arguments: unknown[]) => void, true>;
/**
* Connect a function to fire when the event is invoked by the client
* @param callback The function fired when the event is invoked by the client
*/
Connect>(callback: (...args: T) => void): void;
/**
* Sends the specified arguments to the server
* @param args The arguments to send to the server
*/
SendToServer>(...args: T): void;
}
/**
* A function on the client
* @rbxts client
*/
class ClientFunction {
constructor(name: string);
static WaitFor(name: string): Promise>;
/**
* The callback
*/
/**
* Set the callback function when called by the server
*/
Callback: Callback;
/**
* The remoteFunction instance
*/
readonly Instance: RemoteFunction;
/**
* The client cache in seconds
*/
readonly Cache: number;
/**
* Call the server with the specified arguments
* @param args The arguments to call the server with
* @returns the result of the call to the server
*/
CallServer>(...args: T): SR;
/**
* Call the server with the specified arguments asynchronously
* @param args The args to call the server with
* @async Will return a promise
*/
CallServerAsync>(...args: T): Promise;
}
function IsClient(): boolean;
function IsServer(): boolean;
/**
* Create a function
* @param name The name of the function
* @rbxts server
*/
function CreateFunction(name: string): ServerFunction;
/**
* Creates a function that has a limited number of client requests every timeout (default 60 seconds)
* @param name The name of the function
* @param rateLimit The amount of requests allowed by clients in the rate timeout (default 60 seconds)
* @rbxts server
*/
function CreateThrottledFunction(name: string, rateLimit: number): ServerThrottledFunction;
/**
* Creates an event that has a limited number of client requests every timeout (default 60 seconds)
* @param name The name of the event
* @param rateLimit The amount of requests allowed by clients in the rate timeout (default 60 seconds)
* @rbxts server
*/
function CreateThrottledEvent(name: string, rateLimit: number): ServerThrottledEvent;
/**
* Create an event
* @param name The name of the event
* @rbxts server
*/
function CreateEvent(name: string): ServerEvent;
/**
* Wait for a client function specified by `name`
*
* Usage
*
```ts
Net.WaitForClientFunctionAsync("FunctionName").then(func => {
func.Callback = clientCallbackFunction;
}, err => {
warn("Error fetching FunctionName:", err);
});```
*
* Or inside an async function:
```ts
const func = await Net.WaitForClientFunctionAsync("FunctionName");
func.Callback = clientCallbackFunction;
```
*
* @param name The name of the function
* @alias for `Net.ClientFunction.WaitFor(name)`
* @returns `Promise`
* @rbxts client
*/
function WaitForClientFunctionAsync(name: string): Promise>;
/**
* Wait for a client function specified by `name`
*
* Usage
*
```ts
Net.WaitForClientEventAsync("EventName").then(event => {
event.Connect(eventHandler);
}, err => {
warn("Error fetching EventName:", err);
});```
*
* Or inside an async function:
```ts
const event = await Net.WaitForClientEventAsync("EventName");
event.Connect(eventHandler);
```
*
* @param name The name of the function
* @alias for `Net.ClientEvent.WaitFor(name)`
* @returns `Promise`
* @rbxts client
*/
function WaitForClientEventAsync(name: string): Promise;
/** @rbxts server */
function GetServerEventAsync(name: string): Promise;
/** @rbxts server */
function GetServerFunctionAsync(name: string): Promise>;
}
export default Net;