server

package
v0.0.0-...-3757f2b Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyToString

func AnyToString(val any) string

func StringToAny

func StringToAny(val string) any

func ValidateAnyType

func ValidateAnyType(name any) error

Types

type Config

type Config struct {
	Designation string

	// Defines the listening address of the metrics/health gateway.
	Address string

	// Defines the logging level that the server will use.
	Log_Level zerolog.Level
}

type Hosts

type Hosts map[*Lobby]*duplex.Peer

type Instance

type Instance struct {
	Self                  string
	Designation           string
	Lobbies               Lobbies
	Hosts                 Hosts
	Members               Peers
	Mutex                 *sync.Mutex
	NameRegistry          Registry
	BridgeRegistry        Registry
	DiscoveryRegistry     Registry
	App                   *fiber.App
	Address               string
	Predisposed_Instances []string
	Logger                *zerolog.Logger
	*duplex.Instance
}

Define Discovery server

func New

func New(server_config *Config, duplex_config *duplex.Config) *Instance

func (*Instance) AutoRegister

func (server *Instance) AutoRegister(peer *duplex.Peer, registry Registry)

func (*Instance) GetState

func (i *Instance) GetState(p *duplex.Peer, emit_warn bool, halt_if_fail bool, packet *duplex.RxPacket) (*Lobby, bool, bool)

GetState returns the current lobby and whether the peer is the host or not. If the peer is not the host and emit_warn is true, it will send a "UNAUTHORIZED" packet to the peer. If the peer is not in a lobby, it will send a "CONFIG_REQUIRED" packet to the peer. If halt_if_fail is true, it will halt execution of the opcode handler if any state checks fail.

func (*Instance) Multiquery

func (i *Instance) Multiquery(username string, peer *duplex.Peer, packet *duplex.RxPacket, streams Registry)

func (*Instance) ResolvePeer

func (i *Instance) ResolvePeer(username string, peer *duplex.Peer, packet *duplex.RxPacket)

ResolvePeer is a function that resolves a peer based on a query string.

@param query - The query string to search for. @param peer - The peer object that sent the query. @param packet - The Rx packet object that contains the query string.

ResolvePeer will reply with a QUERY_ACK packet containing the resolved peer's information. If the query string does not match any peer in the instance's name registry, ResolvePeer will reply with a QUERY_ACK packet containing an empty name and false online status. If the query string matches a peer in the instance's name registry, ResolvePeer will reply with a QUERY_ACK packet containing the resolved peer's information.

func (*Instance) Run

func (i *Instance) Run()

type Lobbies

type Lobbies map[string]*Lobby

Define type aliases

func (Lobbies) ToSlice

func (l Lobbies) ToSlice() []string

type Lobby

type Lobby struct {
	ID               any           `json:"lobby_id"`          // ID of the lobby
	Host             string        `json:"host"`              // Host of the lobby
	CurrentPeers     int64         `json:"current_peers"`     // Number of peers currently in the lobby
	MaxPeers         int64         `json:"max_peers"`         // Maximum number of peers allowed in the lobby
	PasswordRequired bool          `json:"password_required"` // Whether the lobby requires a password
	Hidden           bool          `json:"hidden"`            // Whether the lobby is hidden
	Locked           bool          `json:"locked"`            // Whether the lobby is locked
	Metadata         any           `json:"metadata"`          // Arbitrary, user-defined storage
	Peers            []*PeerObject `json:"peers"`             // List of peers in the lobby (shortcut for querying peers)

	Password    string     `json:"-"` // Password for the lobby
	Instance    *Instance  `json:"-"` // Pointer to the instance
	*sync.Mutex `json:"-"` // Mutex for thread safety
}

Define a struct to hold lobby data

func (*Lobby) ComputeCount

func (l *Lobby) ComputeCount()

func (*Lobby) GetHost

func (l *Lobby) GetHost()

func (*Lobby) GetPeers

func (l *Lobby) GetPeers()

func (*Lobby) PrecomputeTasks

func (l *Lobby) PrecomputeTasks()

func (*Lobby) Remove

func (l *Lobby) Remove(peer *duplex.Peer)

type PeerObject

type PeerObject struct {
	Online        bool   `json:"online"`
	Username      string `json:"username,omitempty"`
	Designation   string `json:"designation,omitempty"`
	InstanceID    string `json:"instance_id,omitempty"`
	IsLobbyMember bool   `json:"is_lobby_member,omitempty"`
	IsLobbyHost   bool   `json:"is_lobby_host,omitempty"`
	IsInLobby     bool   `json:"is_in_lobby,omitempty"`
	LobbyID       string `json:"lobby_id,omitempty"`
	RTT           int64  `json:"rtt,omitempty"`
	IsLegacy      bool   `json:"is_legacy,omitempty"`
	IsRelayed     bool   `json:"is_relayed,omitempty"`
	RelayPeer     string `json:"relay_peer,omitempty"`
	IsBridge      bool   `json:"is_bridge,omitempty"`
	IsDiscovery   bool   `json:"is_discovery,omitempty"`
}

type Peers

type Peers map[*Lobby][]*duplex.Peer

type Registry

type Registry map[string]*duplex.Peer

Jump to

Keyboard shortcuts

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