Documentation
¶
Index ¶
- func AnyToString(val any) string
- func StringToAny(val string) any
- func ValidateAnyType(name any) error
- type Config
- type Hosts
- type Instance
- func (server *Instance) AutoRegister(peer *duplex.Peer, registry Registry)
- func (i *Instance) GetState(p *duplex.Peer, emit_warn bool, halt_if_fail bool, packet *duplex.RxPacket) (*Lobby, bool, bool)
- func (i *Instance) Multiquery(username string, peer *duplex.Peer, packet *duplex.RxPacket, streams Registry)
- func (i *Instance) ResolvePeer(username string, peer *duplex.Peer, packet *duplex.RxPacket)
- func (i *Instance) Run()
- type Lobbies
- type Lobby
- type PeerObject
- type Peers
- type Registry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyToString ¶
func StringToAny ¶
func ValidateAnyType ¶
Types ¶
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 (*Instance) AutoRegister ¶
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 (*Instance) ResolvePeer ¶
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.
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) PrecomputeTasks ¶
func (l *Lobby) PrecomputeTasks()
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"`
}