Skip to content

Net

The Net library offers wrapper methods to make working with network messages easier. Its main feature is automatically stringifying messages, removing the need to do so explicitly when using tables.

Additionally, Net.RegisterListener() provides a way to register net listeners with IDE hints for the function parameters. This is done by defining a class with the name of the net message, for example:

---@class EPIPENCOUNTERS_Vanity_ApplyAura : NetMessage, Net_SimpleMessage_NetID
---@field AuraID string
---@field BoneID string

Net.RegisterListener("EPIPENCOUNTERS_Vanity_ApplyAura", function(payload)
    -- The payload variable here will be of the type EPIPENCOUNTERS_Vanity_ApplyAura and offer auto-completion!
end)

Additionally, for purposes of semantic clarity, a NetMessage class exists for denoting net events. Several other net message classes are defined with commonly used fields like CharacterNetID. You may have your net message classes inherit from these to reduce annotation duplication and to clarify the class's purpose as a net message.

NetLib Class

Inherits from Library.

Events and Hooks

MessageReceived (event)

@field Channel string

@field Message `T`|any Will be a primitive if the payload sent wasn't a table.

@field UserID UserId

Methods

Broadcast
function NetLib.Broadcast(channel, message, excludedChar)

Sends a message to all peers.

@param channel `T`

@param message T?

@param excludedChar GUID?

PostToCharacter
function NetLib.PostToCharacter(char, channel, message)

Sends a message to the user that currently controls char. Fails if char is a summon.

@param char Character|GUID|NetId

@param channel `T`

@param message T?

PostToOwner
function NetLib.PostToOwner(char, channel, message)

Sends a message to the owner of char. Use if you suspect the char might be a summon.

@param char Character

@param channel string

@param message any

PostToUser
function NetLib.PostToUser(user, channel, message)

Sends a message to a user.

@param user UserId|Character

@param channel `T`

@param message T?

RegisterListener
function NetLib.RegisterListener(channel, func)

Wrapper for Ext.RegisterNetListener that parses json payloads and fires an event afterwards.

@param channel `T`

@param func fun(payload:`T`)