NetworkMessageHandler

Abstract base class and generic implementation for handling incoming network messages. Each handler is identified by a handlerId string and manages a set of typed callbacks. The generic subclass NetworkMessageHandler<TMessage> deserializes incoming messages, checks client targeting, invokes registered callbacks, and — on the server — relays messages to remaining target clients.

Definition

Namespace: Paragon.Core.Network Assembly: Paragon.dll

public abstract class NetworkMessageHandler
public class NetworkMessageHandler<TMessage> : NetworkMessageHandler

Remarks

The handler is the middle layer of the Messenger subsystem:

  1. NetworkMessenger routes an incoming unnamed message to the correct handler by handlerId.

  2. The handler reads the target client IDs and message header from the buffer.

  3. If the local client is among the targets, it looks up and invokes the matching callback.

  4. If the local peer is the server and other targets remain, it relays the message to those clients via the NetworkMessenger.

Callbacks are keyed by the payload type's AssemblyQualifiedName (the "message header"), allowing a single handler to support multiple message types under the same handler ID.

Quick Lookup

Goal
How

Register a callback

handler.AddMessageCallback(myCallback) (on generic subclass)

Handle incoming data

Automatic — ReceiveMessage() is called by NetworkMessenger

Create a handler

Typically done internally by NetworkMessenger.SubscribeToMessage()


NetworkMessageHandler (Abstract Base)

Fields

handlerId

The unique identifier for this handler, used as a lookup key in the NetworkMessenger.

Constructor

Parameter
Type
Description

handlerId

string

Unique handler identifier

Methods

ReceiveMessage

Processes an incoming message from the network buffer. Abstract — implemented by the generic subclass.

Parameter
Type
Description

clientId

ulong

The Netcode client ID of the sender

reader

FastBufferReader

The buffer containing the message data


NetworkMessageHandler<TMessage> (Generic)

Constructor

Parameter
Type
Description

handlerId

string

Unique handler identifier

Methods

AddMessageCallback

Registers a callback to be invoked when a message of type TMessage is received. Multiple callbacks can be registered for the same message type — they are combined as a multicast delegate.

Parameter
Type
Description

callback

Action<TMessage>

The callback to invoke with the deserialized payload

ReceiveMessage

Reads target client IDs and the message header from the buffer, deserializes the NetworkMessage<TPayload>, and:

  1. If the local client is in the target list → invokes the registered callback.

  2. If the local peer is the server and other targets remain → relays the message to those clients.

Parameter
Type
Description

clientId

ulong

The Netcode client ID of the sender

reader

FastBufferReader

The buffer containing target IDs, header, and payload

Receive Flow

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation

See Also

Last updated