protocol

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Packets is a map to translate message purposes to their corresponding packets.

Functions

This section is empty.

Types

type CommandRequest

type CommandRequest struct {
	// CommandLine is the full raw command line to be executed. The command line must not include the leading
	// slash. For example 'tell player this was sent using ws'.
	CommandLine string `json:"commandLine"`
	// Version is the version of the packet. Currently this is 1.
	Version int `json:"version"`
}

CommandRequest is used to send a raw command line to the client. The client itself will do the processing of its arguments.

type CommandResponse

type CommandResponse json.RawMessage

CommandResponse is a merely a JSON raw message, because its value depends on what command was executed.

type EncryptResponse

type EncryptResponse struct {
	// PublicKey is the client's public key.
	PublicKey string `json:"publicKey"`
}

EncryptResponse is sent by the client on connection to deliver the public key.

type ErrorResponse

type ErrorResponse struct {
	// StatusMessage is a string explaining the error that occurred.
	StatusMessage string `json:"statusMessage"`
	// StatusCode is the type of the error that occurred.
	StatusCode int `json:"statusCode"`
}

ErrorResponse is sent by the client when an error occurs during the process of communicating.

type EventRequest

type EventRequest struct {
	// EventName is the name of the event, for example 'BlockPlaced'.
	EventName event.Name `json:"eventName"`
}

EventRequest is sent by the server to request the client to start sending events of a particular type to the server.

type EventResponse

type EventResponse json.RawMessage

EventResponse is sent by the client. It holds information about a particular event listened on by the sever.

type Header struct {
	// RequestID is a UUID specific to the request.
	RequestID string `json:"requestId"`
	// MessagePurpose is the purpose of the request. To subscribe to an event, this is 'subscribe'. To
	// unsubscribe from an event, this is 'unsubscribe'. For an event response, this is 'event'.
	MessagePurpose MessagePurpose `json:"messagePurpose"`
	// Version is the version of the request. Currently 1.
	Version int `json:"version"`
	// EventName is the name of the event for EventResponse headers.
	EventName event.Name `json:"eventName"`
}

Header describes the header of a packet. Each packet shares the same header.

type MessagePurpose

type MessagePurpose string

MessagePurpose is the purpose a JSON message was sent.

const (
	Subscribe   MessagePurpose = "subscribe"
	Unsubscribe MessagePurpose = "unsubscribe"
	Event       MessagePurpose = "event"
	Error       MessagePurpose = "error"
	Command     MessagePurpose = "commandRequest"
	Response    MessagePurpose = "commandResponse"
	Encrypt     MessagePurpose = "ws:encrypt"
)

type Packet

type Packet struct {
	Header Header      `json:"header"`
	Body   interface{} `json:"body"`
}

Packet is the main struct that describes every packet sent between client and server to communicate. Each packet shares the same header, but a different body.

func NewCommandRequest

func NewCommandRequest(commandLine string) Packet

NewCommandRequest returns a packet for a raw command to be executed.

func NewEventRequest

func NewEventRequest(eventName event.Name, purpose MessagePurpose) Packet

NewEventRequest returns an event request for a particular event name and action.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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