cloudlink

package
v0.0.0-...-9d4b0a8 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ServerVersion string = "0.1.0-golang"

Functions

func CL4MethodHandler

func CL4MethodHandler(client *Client, message *PacketUPL)

CL4MethodHandler is a method that s created when a CL-formatted message gets handled by MessageHandler.

func CL4ProtocolDetect

func CL4ProtocolDetect(client *Client)

func GatherSnowflakeIDs

func GatherSnowflakeIDs(clientstore interface{}) map[interface{}]*Client

Gathers a map of all Snowflake IDs representing Clients in a Room or Manager.

func GatherUUIDs

func GatherUUIDs(clientstore interface{}) map[interface{}]*Client

Gathers a map of all UUIDs representing Clients in a Room or Manager.

func GatherUserObjects

func GatherUserObjects(clientstore interface{}) map[interface{}]*Client

Gathers a map of all UserObjects representing Clients in a Room or Manager.

func GatherUsernames

func GatherUsernames(clientstore interface{}) map[interface{}][]*Client

Gathers a map of all Usernames representing multiple Clients in a Room or Manager.

func GetValue

func GetValue(slice []interface{}, target interface{}) int

func JSONDump

func JSONDump(message any) []byte

func MulticastMessage

func MulticastMessage(clients map[snowflake.ID]*Client, message any)

MulticastMessage broadcasts a payload to multiple clients.

func RemoveValue

func RemoveValue(slice []interface{}, indexRemove int) []interface{}

func ScratchMethodHandler

func ScratchMethodHandler(client *Client, message *Scratch)

ScratchMethodHandler is a method that gets created when a Scratch-formatted message gets handled by MessageHandler.

func ScratchProtocolDetect

func ScratchProtocolDetect(client *Client)

func SessionHandler

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

SessionHandler is the root function that makes CloudLink work. As soon as a client request gets upgraded to the websocket protocol, this function should be called.

func TempCopyRooms

func TempCopyRooms(origin map[interface{}]*Room) map[interface{}]*Room

Creates a temporary deep copy of a client's rooms map attribute.

func UnicastMessage

func UnicastMessage(client *Client, message any)

UnicastMessageAny broadcasts a payload to a singular client.

Types

type Client

type Client struct {

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

The client struct serves as a template for handling websocket sessions. It stores a client's UUID, Snowflake ID, manager and websocket connection pointer(s).

func NewClient

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

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

func (*Client) CloseWithMessage

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

func (*Client) GenerateUserObject

func (client *Client) GenerateUserObject() *UserObject

Generates a value for client identification.

func (*Client) HandleIDSet

func (client *Client) HandleIDSet(message *PacketUPL) bool

func (*Client) MessageHandler

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

func (*Client) RequireIDBeingSet

func (client *Client) RequireIDBeingSet(message *PacketUPL) bool

func (*Client) TempCopy

func (client *Client) TempCopy() *Client

Make a temporary-use copy of a client with RWMutex read locks. This is to safely permit multiple reads from a client.

type Manager

type Manager struct {

	// Configuration settings
	Config struct {
		RejectClients    bool
		CheckIPAddresses bool
		EnableMOTD       bool
		MOTDMessage      string
	}

	// Used for generating Snowflake IDs
	SnowflakeIDNode *snowflake.Node

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

func DummyManager

func DummyManager(name interface{}) *Manager

Dummy Managers function identically to a normal manager. However, they are used for selecting specific clients to multicast to.

func New

func New(name string) *Manager

func (*Manager) AddClient

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

func (*Manager) CreateRoom

func (manager *Manager) CreateRoom(name interface{}) *Room

func (*Manager) DeleteRoom

func (manager *Manager) DeleteRoom(name interface{})

func (*Manager) RemoveClient

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

type PacketUPL

type PacketUPL struct {
	Cmd      string      `json:"cmd"`
	Name     interface{} `json:"name,omitempty"`
	Val      interface{} `json:"val,omitempty"`
	ID       interface{} `json:"id,omitempty"`
	Rooms    interface{} `json:"rooms,omitempty"`
	Listener interface{} `json:"listener,omitempty"`
	Code     string      `json:"code,omitempty"`
	CodeID   int         `json:"code_id,omitempty"`
	Mode     string      `json:"mode,omitempty"`
	Origin   *UserObject `json:"origin,omitempty"`
	Details  string      `json:"details,omitempty"`
}

This structure represents the JSON formatting used for the current CloudLink formatting scheme. Values that are not specific to one type are represented with interface{}.

type Room

type Room struct {

	// Locks states before subscribing/unsubscribing clients
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Room) BroadcastGmsg

func (room *Room) BroadcastGmsg(value interface{})

func (*Room) BroadcastGvar

func (room *Room) BroadcastGvar(name interface{}, value interface{})

func (*Room) BroadcastUserlistEvent

func (room *Room) BroadcastUserlistEvent(event string, client *Client, exclude bool)

func (*Room) FindClient

func (room *Room) FindClient(query interface{}) interface{}

Takes a UUID, Snowflake ID, Username, or UserObject query and returns either a single Client (UUID, Snowflake, UserObject) or multiple Clients (username).

func (*Room) GenerateUserList

func (room *Room) GenerateUserList() []*UserObject

Gathers all user objects in a room, and generates a userlist.

func (*Room) SubscribeClient

func (room *Room) SubscribeClient(client *Client)

func (*Room) UnsubscribeClient

func (room *Room) UnsubscribeClient(client *Client)

type Scratch

type Scratch struct {
	Method    string      `json:"method"`
	ProjectID interface{} `json:"project_id,omitempty"`
	Username  string      `json:"user,omitempty"`
	Value     interface{} `json:"value"`
	Name      interface{} `json:"name,omitempty"`
	NewName   interface{} `json:"new_name,omitempty"`
}

This structure represents the JSON formatting the Scratch cloud variable protocol uses. Values that are not specific to one type are represented with interface{}.

type UserObject

type UserObject struct {
	Id       string      `json:"id,omitempty"`
	Username interface{} `json:"username,omitempty"`
	Uuid     string      `json:"uuid,omitempty"`
}

Jump to

Keyboard shortcuts

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