cloudlinkOmega

package
v0.0.0-...-d01bcee Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Managers = map[string]*Manager{}
View Source
var Opcodes = map[string]int{
	"VIOLATION":         0,
	"KEEPALIVE":         1,
	"INIT":              2,
	"INIT_OK":           3,
	"CONFIG_HOST":       4,
	"CONFIG_PEER":       5,
	"ACK_HOST":          6,
	"ACK_PEER":          7,
	"NEW_HOST":          8,
	"NEW_PEER":          9,
	"MAKE_OFFER":        10,
	"MAKE_ANSWER":       11,
	"ICE":               12,
	"ABORT_OFFER":       13,
	"ABORT_ANSWER":      14,
	"SHUTDOWN":          15,
	"LOBBY_EXISTS":      16,
	"LOBBY_NOTFOUND":    17,
	"LOBBY_FULL":        18,
	"LOBBY_LOCKED":      19,
	"LOBBY_CLOSE":       20,
	"HOST_GONE":         21,
	"PEER_GONE":         22,
	"HOST_RECLAIM":      23,
	"CLAIM_HOST":        24,
	"TRANSFER_HOST":     25,
	"ABANDON":           26,
	"LOCK":              27,
	"UNLOCK":            28,
	"SIZE":              29,
	"KICK":              30,
	"PASSWORD_REQUIRED": 31,
	"PASSWORD_ACK":      32,
	"PASSWORD_FAIL":     33,
	"PEER_INVALID":      34,
	"NEW_CHANNEL":       35,
}

See https://github.com/MikeDev101/cloudlink-omega/blob/main/backend/docs/protocol.md

View Source
var ServerVersion string = "0.1.0"
View Source
var VerboselyLogLocks bool = true

Functions

func JSONDump

func JSONDump(message any) []byte

func MulticastMessage

func MulticastMessage(clients map[uuid.UUID]*Client, message []byte, ignoreOrigin *Client)

MulticastMessage broadcasts a payload to multiple clients.

func MulticastMessageArray

func MulticastMessageArray(clients []*Client, message []byte, ignoreOrigin *Client)

MulticastMessageArray broadcasts a payload to multiple clients.

func New

func New(manager *Manager, con *websocket.Conn)

func NewHost

func NewHost(lobbyID string, client *Client, manager *Manager, AllowHostReclaim bool, AllowPeersToClaimHost bool, MaxPeers int, Password string) bool

func NewPeer

func NewPeer(lobbyID string, client *Client, manager *Manager) bool

func NotifyPeersOfStateChange

func NotifyPeersOfStateChange(eventType int, lobbyID string, manager *Manager, client *Client)

func Remove

func Remove(manager *Manager)

func SessionCleanup

func SessionCleanup(manager *Manager, client *Client)

func SignalingOpcode

func SignalingOpcode(message []byte, manager *Manager, client *Client)

Handles incoming messages from the websocket server

func UnicastMessage

func UnicastMessage(client *Client, message []byte, ignoreOrigin *Client)

UnicastMessageAny broadcasts a payload to a singular client.

Types

type ChannelConfig

type ChannelConfig struct {
	Opcode  int `json:"opcode"`
	Payload struct {
		Id      int    `json:"id"`
		Name    string `json:"name"`
		Ordered bool   `json:"ordered"`
	} `json:"payload"`
}

type ChannelDetails

type ChannelDetails struct {
	Id      int    `json:"id"`
	Name    string `json:"name"`
	Ordered bool   `json:"ordered"`
}

type Client

type Client struct {

	// Lock state for rooms
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewClient

func NewClient(conn *websocket.Conn, manager *Manager) *Client

NewClient assigns a UUID to a websocket client, and returns a initialized Client struct for use with a manager's AddClient.

func (*Client) CloseConnectionOnError

func (client *Client) CloseConnectionOnError(opcode int, message string, errorcode int)

func (*Client) CloseWithMessage

func (client *Client) CloseWithMessage(statuscode int, closeMessage string)

func (*Client) MessageHandler

func (client *Client) MessageHandler(manager *Manager)

type HostConfig

type HostConfig struct {
	Opcode  int `json:"opcode"`
	Payload struct {
		LobbyID             string `json:"lobby_id"`
		AllowHostReclaim    bool   `json:"allow_host_reclaim"`
		AllowPeersToReclaim bool   `json:"allow_peers_to_claim_host"`
		MaxPeers            int    `json:"max_peers"`
		Password            string `json:"password"`
	} `json:"payload"`
}

type HostDetails

type HostDetails struct {
	Id               string `json:"id"`
	Username         string `json:"username"`
	LobbyID          string `json:"lobby_id"`
	MaxPeers         int    `json:"max_peers"`
	PasswordRequired bool   `json:"password_required"`
}

type Lobby

type Lobby struct {
	Host                  *Client
	Peers                 []*Client
	AllowHostReclaim      bool
	AllowPeersToClaimHost bool
	MaxPeers              int
	Password              string
	Locked                bool
}

type Manager

type Manager struct {
	// Friendly Name for manager
	Name string

	// Locks states before registering sessions
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewManager

func NewManager(name string) *Manager

func (*Manager) AbandonLobbies

func (manager *Manager) AbandonLobbies(client *Client)

func (*Manager) AcquireAccessLock

func (manager *Manager) AcquireAccessLock(lock *sync.RWMutex, something string)

Verbosely log RWMutex lock requests

func (*Manager) AddClient

func (manager *Manager) AddClient(client *Client)

func (*Manager) BroadcastDiscovery

func (manager *Manager) BroadcastDiscovery(lobbyID string, Host *Client, Peer *Client)

Loop through all peers in a lobby, notify peer (*Client) of all other peers ([]*Peer) while excluding host (*Client) and itself (*Client)

func (*Manager) FreeAccessLock

func (manager *Manager) FreeAccessLock(lock *sync.RWMutex, something string)

Verbosely log RWMutex unlock requests

func (*Manager) RemoveClient

func (manager *Manager) RemoveClient(client *Client)

type Packet

type Packet struct {
	Opcode  int          `json:"opcode"`
	Payload interface{}  `json:"payload,omitempty"`
	Tx      *PeerDetails `json:"tx,omitempty"`
	Rx      string       `json:"rx,omitempty"`
}

type PacketHost

type PacketHost struct {
	Opcode  int          `json:"opcode"`
	Payload *HostDetails `json:"payload"`
}

type PacketPeer

type PacketPeer struct {
	Opcode  int          `json:"opcode"`
	Payload *PeerDetails `json:"payload"`
}

type PeerConfig

type PeerConfig struct {
	Opcode  int `json:"opcode"`
	Payload struct {
		LobbyID  string `json:"lobby_id"`
		Password string `json:"password"`
	} `json:"payload"`
}

type PeerDetails

type PeerDetails struct {
	Id       string `json:"id"`
	Username string `json:"username"`
}

type ReclaimHost

type ReclaimHost struct {
	LobbyID  string `json:"lobby_id"`
	Id       string `json:"id"`
	Username string `json:"username"`
}

type ReclaimHostConfig

type ReclaimHostConfig struct {
	Opcode  int          `json:"opcode"`
	Payload *ReclaimHost `json:"payload"`
}

Jump to

Keyboard shortcuts

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