cluster

package
v2.6.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 2 Imported by: 13

Documentation

Overview

Package cluster defines the kinds, states, events, hooks and message arguments shared by the gate, node and mesh components.

Index

Constants

View Source
const (
	Random             = def.Random             // Random dispatches messages randomly
	RoundRobin         = def.RoundRobin         // RoundRobin dispatches messages in turn
	WeightedRoundRobin = def.WeightedRoundRobin // WeightedRoundRobin dispatches messages in turn by weight
)

The dispatch strategies of stateless route messages.

Variables

This section is empty.

Functions

This section is empty.

Types

type BroadcastArgs added in v2.1.0

type BroadcastArgs struct {
	Kind       session.Kind // Kind is the session kind, either session.Conn or session.User
	Message    *Message     // Message is the message to broadcast
	Disconnect bool         // Disconnect reports whether to gracefully close the connection after pushing
	Ack        bool         // Ack reports whether the push result should be acknowledged
}

BroadcastArgs is the arguments of broadcasting a message.

type DeliverArgs added in v2.1.0

type DeliverArgs struct {
	NID     string   // NID is the receiving node. When it is set, the message is delivered to that node directly; otherwise the system locates the node the user belongs to and delivers the message there
	UID     int64    // UID is the user ID
	Message *Message // Message is the message to deliver
}

DeliverArgs is the arguments of delivering a message.

type DisconnectArgs added in v2.1.0

type DisconnectArgs struct {
	GID    string       // GID is the gate ID, it may be omitted when the session kind is user
	Kind   session.Kind // Kind is the session kind, either session.Conn or session.User
	Target int64        // Target is the session target, either a CID or a UID
	Force  bool         // Force reports whether to force the disconnection
}

DisconnectArgs is the arguments of disconnecting a session.

type Dispatch added in v2.3.0

type Dispatch = def.Dispatch

Dispatch is the dispatch strategy of stateless route messages.

type Event

type Event int

Event is the event of a cluster instance.

const (
	Connect    Event = iota + 1 // Connect is emitted when a connection is opened
	Reconnect                   // Reconnect is emitted when a connection reconnects after a break
	Disconnect                  // Disconnect is emitted when a connection is closed
)

The events of a cluster instance.

func (Event) String

func (e Event) String() string

type GetIPArgs added in v2.1.0

type GetIPArgs struct {
	GID    string       // GID is the gate ID, it may be omitted when the session kind is user
	Kind   session.Kind // Kind is the session kind, either session.Conn or session.User
	Target int64        // Target is the session target, either a CID or a UID
}

GetIPArgs is the arguments of getting the client IP.

type Hook added in v2.1.0

type Hook int

Hook is a lifecycle hook of a component.

const (
	Init    Hook = iota // Init initializes the component
	Start               // Start starts the component
	Close               // Close closes the component
	Destroy             // Destroy destroys the component
)

The lifecycle hooks of a component.

func (Hook) String added in v2.1.0

func (h Hook) String() string

type IsOnlineArgs added in v2.1.0

type IsOnlineArgs struct {
	GID    string       // GID is the gate ID, it may be omitted when the session kind is user
	Kind   session.Kind // Kind is the session kind, either session.Conn or session.User
	Target int64        // Target is the session target, either a CID or a UID
}

IsOnlineArgs is the arguments of checking whether a session is online.

type Kind

type Kind int

Kind is the type of a cluster instance.

const (
	Gate   Kind = iota + 1 // Gate is the gate server
	Node                   // Node is the node server
	Mesh                   // Mesh is the mesh service
	Master                 // Master is the master server
)

The kinds of a cluster instance.

func (Kind) String

func (k Kind) String() string

type Message added in v2.1.0

type Message struct {
	Seq   int32 // Seq is the sequence number
	Route int32 // Route is the route ID
	Data  any   // Data is the message payload, which accepts json, proto or []byte
}

Message is a cluster message.

type MulticastArgs added in v2.1.0

type MulticastArgs struct {
	GID        string       // GID is the gate ID, it may be omitted when the session kind is user
	Kind       session.Kind // Kind is the session kind, either session.Conn or session.User
	Targets    []int64      // Targets are the session targets, either CIDs or UIDs
	Message    *Message     // Message is the message to multicast
	Disconnect bool         // Disconnect reports whether to gracefully close the connection after pushing
	Ack        bool         // Ack reports whether the push result should be acknowledged
}

MulticastArgs is the arguments of multicasting a message.

type PublishArgs added in v2.3.0

type PublishArgs struct {
	Channel    string   // Channel is the channel name
	Message    *Message // Message is the message to publish
	Disconnect bool     // Disconnect reports whether to gracefully close the connection after pushing
	Ack        bool     // Ack reports whether the push result should be acknowledged
}

PublishArgs is the arguments of publishing a message to a channel.

type PushArgs added in v2.1.0

type PushArgs struct {
	GID        string       // GID is the gate ID, it may be omitted when the session kind is user
	Kind       session.Kind // Kind is the session kind, either session.Conn or session.User
	Target     int64        // Target is the session target, either a CID or a UID
	Message    *Message     // Message is the message to push
	Disconnect bool         // Disconnect reports whether to gracefully close the connection after pushing
	Ack        bool         // Ack reports whether the push result should be acknowledged
}

PushArgs is the arguments of pushing a message.

type State

type State int

State is the state of a cluster instance.

const (
	Shut State = iota // Shut means the node is shut down and cannot be accessed
	Work              // Work means the node is healthy and more players may be assigned to it
	Busy              // Busy means the node is low on resources and should not receive more players
	Hang              // Hang means the node is about to be destroyed and is reclaiming resources
)

The states of a cluster instance.

func (State) String

func (s State) String() string

type SubscribeArgs added in v2.3.0

type SubscribeArgs struct {
	GID     string       // GID is the gate ID, it may be omitted when the session kind is user
	Kind    session.Kind // Kind is the session kind, either session.Conn or session.User
	Targets []int64      // Targets are the session targets, either CIDs or UIDs
	Channel string       // Channel is the channel name
}

SubscribeArgs is the arguments of subscribing to a channel.

type TriggerArgs added in v2.1.0

type TriggerArgs struct {
	Event int   // Event is the event type
	CID   int64 // CID is the connection ID
	UID   int64 // UID is the user ID
}

TriggerArgs is the arguments of triggering an event.

type UnsubscribeArgs added in v2.3.0

type UnsubscribeArgs struct {
	GID     string       // GID is the gate ID, it may be omitted when the session kind is user
	Kind    session.Kind // Kind is the session kind, either session.Conn or session.User
	Targets []int64      // Targets are the session targets, either CIDs or UIDs
	Channel string       // Channel is the channel name
}

UnsubscribeArgs is the arguments of unsubscribing from a channel.

Directories

Path Synopsis
Package gate implements the gate server component.
Package gate implements the gate server component.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL