pks

package
v0.0.0-...-8016c1d Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IDConnectionOne = iota
	IDConnectionRequest
	IDConnectionResponse
	IDIncompatibleProtocol
	IDBadRequest
	IDDisconnectionNotification
	IDErrorMessage
	IDRequestProgramList
	IDResponseProgramList
	IDStartProgram
	IDStopProgram
	IDProgramStatus
	IDRequestConsoleList
	IDResponseConsoleList
	IDJoinConsole
	IDQuitConsole
	IDConsoleMessages
	IDSendCommands
)

Variables

Functions

This section is empty.

Types

type BadRequest

type BadRequest struct {
	BasePacket

	Message string
}

BadRequest is a error packet It notifies that a request received client had problems for some reasons If a client is received, the connection is closed. Server -> Client

func (*BadRequest) Decode

func (pk *BadRequest) Decode() error

func (*BadRequest) Encode

func (pk *BadRequest) Encode() error

func (BadRequest) ID

func (BadRequest) ID() byte

func (BadRequest) New

func (BadRequest) New() Packet

type BasePacket

type BasePacket struct {
	Packet

	binary.Stream
}

BasePacket is a basic implement for Packet

func (*BasePacket) Bytes

func (bpk *BasePacket) Bytes() []byte

Bytes returns encoded bytes

func (*BasePacket) Decode

func (bpk *BasePacket) Decode(pk Packet) error

Decode decodes a packet

func (*BasePacket) Encode

func (bpk *BasePacket) Encode(pk Packet) error

Encode encodes a packet

func (*BasePacket) GetConsole

func (bpk *BasePacket) GetConsole() (con *Console, err error)

GetConsole reads a console from buffer

func (*BasePacket) GetProgram

func (bpk *BasePacket) GetProgram() (p *Program, err error)

GetProgram reads a program from buffer

func (*BasePacket) GetUUID

func (bpk *BasePacket) GetUUID() (uuid.UUID, error)

UUID reads a uuid from buffer's bytes

func (*BasePacket) PutConsole

func (bpk *BasePacket) PutConsole(con *Console) error

PutConsole writes a console to buffer

func (*BasePacket) PutProgram

func (bpk *BasePacket) PutProgram(p *Program) error

PutProgram writes a program to buffer

func (*BasePacket) PutString

func (bpk *BasePacket) PutString(str string) error

PutString writes a string to bytes Format: 2bytes(len) + xbytes(string)

func (*BasePacket) PutUUID

func (bpk *BasePacket) PutUUID(uid uuid.UUID) error

PutUUID writes a uuid to buffer

func (*BasePacket) SetBytes

func (bpk *BasePacket) SetBytes(b []byte)

SetBytes returns encoded bytes

func (*BasePacket) String

func (bpk *BasePacket) String() (string, error)

String reads a string from bytes Format: 2bytes(bytes len) + xbytes(string)

type ConnectionOne

type ConnectionOne struct {
	BasePacket

	UUID uuid.UUID // Server's UUID
	Time int64     // Connected Time format: unix timestamp (second)
}

ConnectionOne is a first packet sent from server It notifies that connected with server

func (*ConnectionOne) Decode

func (pk *ConnectionOne) Decode() error

func (*ConnectionOne) Encode

func (pk *ConnectionOne) Encode() error

func (ConnectionOne) ID

func (ConnectionOne) ID() byte

func (ConnectionOne) New

func (ConnectionOne) New() Packet

type ConnectionRequest

type ConnectionRequest struct {
	BasePacket

	ClientProtocol byte
	ClientUUID     uuid.UUID
}

ConnectionRequest is a connection packet sent by client Client -> Server

func (*ConnectionRequest) Decode

func (pk *ConnectionRequest) Decode() error

func (*ConnectionRequest) Encode

func (pk *ConnectionRequest) Encode() error

func (ConnectionRequest) ID

func (ConnectionRequest) ID() byte

func (ConnectionRequest) New

func (ConnectionRequest) New() Packet

type ConnectionResponse

type ConnectionResponse struct {
	BasePacket

	Time int64
}

ConnectionResponse is a packet notifying it is established connection with server Client -> Server

func (*ConnectionResponse) Decode

func (pk *ConnectionResponse) Decode() error

func (*ConnectionResponse) Encode

func (pk *ConnectionResponse) Encode() error

func (ConnectionResponse) ID

func (ConnectionResponse) ID() byte

func (ConnectionResponse) New

func (ConnectionResponse) New() Packet

type Console

type Console struct {
	UUID    uuid.UUID
	Program *Program
}

Console is data for console

type ConsoleMessages

type ConsoleMessages struct {
	BasePacket

	MessagesLen byte
	Messages    []string // older sorted
}

ConsoleMessages is a packet sent a console message by server to a client joing the console Server -> Client

func (*ConsoleMessages) Decode

func (pk *ConsoleMessages) Decode() error

func (*ConsoleMessages) Encode

func (pk *ConsoleMessages) Encode() error

func (ConsoleMessages) ID

func (ConsoleMessages) ID() byte

func (ConsoleMessages) New

func (ConsoleMessages) New() Packet

type DisconnectionNotification

type DisconnectionNotification struct {
	BasePacket
}

DisconnectionNotification is a packet Client -> Server or Server -> Client

func (*DisconnectionNotification) Decode

func (pk *DisconnectionNotification) Decode() error

func (*DisconnectionNotification) Encode

func (pk *DisconnectionNotification) Encode() error

func (DisconnectionNotification) ID

func (DisconnectionNotification) New

type ErrorMessage

type ErrorMessage struct {
	BasePacket

	Error int `json:"error"`
}

ErrorMessage is a packet notifying a server is happened errors Server -> Client

func (*ErrorMessage) Decode

func (pk *ErrorMessage) Decode() error

func (*ErrorMessage) Encode

func (pk *ErrorMessage) Encode() error

func (ErrorMessage) ID

func (ErrorMessage) ID() byte

func (ErrorMessage) New

func (ErrorMessage) New() Packet

type IncompatibleProtocol

type IncompatibleProtocol struct {
	BasePacket

	Protocol byte
}

IncompatibleProtocol is a error packet It notifies that client's protocol is incompatible with server's protocol. If a client is received, the connection is closed. Server -> Client

func (*IncompatibleProtocol) Decode

func (pk *IncompatibleProtocol) Decode() error

func (*IncompatibleProtocol) Encode

func (pk *IncompatibleProtocol) Encode() error

func (IncompatibleProtocol) ID

func (IncompatibleProtocol) New

type JoinConsole

type JoinConsole struct {
	BasePacket

	ConsoleUUID uuid.UUID
}

JoinConsole is a packet joining a console Client -> Server

func (*JoinConsole) Decode

func (pk *JoinConsole) Decode() error

func (*JoinConsole) Encode

func (pk *JoinConsole) Encode() error

func (JoinConsole) ID

func (JoinConsole) ID() byte

func (JoinConsole) New

func (JoinConsole) New() Packet

type Packet

type Packet interface {

	// ID returns a packet ID
	ID() byte

	// Encode encodes a packet
	Encode() error

	// Decode decodes a packet
	Decode() error

	// Bytes returns encoded bytes
	Bytes() []byte

	// SetBytes sets bytes into buffer
	SetBytes([]byte)

	// New returns new instance of the packet
	New() Packet
}

Packet is a simple packet interface

func GetPacket

func GetPacket(id byte) (Packet, bool)

GetPacket returns a packet registered by Protocol

type Program

type Program struct {
	Name       string
	LoaderName string
}

Program is data for program

type ProgramStatus

type ProgramStatus struct {
	BasePacket

	ProgramName string
	ConsoleUUID uuid.UUID
	Running     bool
}

ProgramStatus is sended back when a server is received Program packets Server -> Client

func (*ProgramStatus) Decode

func (pk *ProgramStatus) Decode() error

func (*ProgramStatus) Encode

func (pk *ProgramStatus) Encode() error

func (ProgramStatus) ID

func (ProgramStatus) ID() byte

func (ProgramStatus) New

func (ProgramStatus) New() Packet

type QuitConsole

type QuitConsole struct {
	BasePacket

	ConsoleUUID uuid.UUID
}

QuitConsole is a packet quiting a console Client -> Server

func (*QuitConsole) Decode

func (pk *QuitConsole) Decode() error

func (*QuitConsole) Encode

func (pk *QuitConsole) Encode() error

func (QuitConsole) ID

func (QuitConsole) ID() byte

func (QuitConsole) New

func (QuitConsole) New() Packet

type RequestConsoleList

type RequestConsoleList struct {
	BasePacket
}

RequestConsoleList is a request packet If it send, it will send ResponseConsoleList packet back by server Client -> Server

func (*RequestConsoleList) Decode

func (pk *RequestConsoleList) Decode() error

func (*RequestConsoleList) Encode

func (pk *RequestConsoleList) Encode() error

func (RequestConsoleList) ID

func (RequestConsoleList) ID() byte

func (RequestConsoleList) New

func (RequestConsoleList) New() Packet

type RequestProgramList

type RequestProgramList struct {
	BasePacket
}

RequestProgramList is a request packet If it send, it's sent a ResponseProgramList packet back Client -> Server

func (*RequestProgramList) Decode

func (pk *RequestProgramList) Decode() error

func (*RequestProgramList) Encode

func (pk *RequestProgramList) Encode() error

func (RequestProgramList) ID

func (RequestProgramList) ID() byte

func (RequestProgramList) New

func (RequestProgramList) New() Packet

type ResponseConsoleList

type ResponseConsoleList struct {
	BasePacket

	ConsolesLen byte
	Consoles    []*Console
}

ResponseConsoleList is a response packet for consoles This is sent back for RequestConsoleList packet Server -> Client

func (*ResponseConsoleList) Decode

func (pk *ResponseConsoleList) Decode() error

func (*ResponseConsoleList) Encode

func (pk *ResponseConsoleList) Encode() error

func (ResponseConsoleList) ID

func (ResponseConsoleList) New

type ResponseProgramList

type ResponseProgramList struct {
	BasePacket

	ProgramsLen byte
	Programs    []*Program
}

ResponseProgramList is a response packet for RequestProgramList packet Server -> Client

func (*ResponseProgramList) Decode

func (pk *ResponseProgramList) Decode() error

func (*ResponseProgramList) Encode

func (pk *ResponseProgramList) Encode() error

func (ResponseProgramList) ID

func (ResponseProgramList) New

type SendCommands

type SendCommands struct {
	BasePacket

	CommandsLen byte
	Commands    []string
}

SendCommands is a packet for sending commands Client -> Server

func (*SendCommands) Decode

func (pk *SendCommands) Decode() error

func (*SendCommands) Encode

func (pk *SendCommands) Encode() error

func (SendCommands) ID

func (SendCommands) ID() byte

func (SendCommands) New

func (SendCommands) New() Packet

type StartProgram

type StartProgram struct {
	BasePacket

	ProgramName string
}

StartProgram is a packet starting a program Client -> Server

func (*StartProgram) Decode

func (pk *StartProgram) Decode() error

func (*StartProgram) Encode

func (pk *StartProgram) Encode() error

func (StartProgram) ID

func (StartProgram) ID() byte

func (StartProgram) New

func (StartProgram) New() Packet

type StopProgram

type StopProgram struct {
	BasePacket

	ProgramName string
	Restart     bool
}

StopProgram is a packet stopping a program If Restart is true, it will restart a program Client -> Server

func (*StopProgram) Decode

func (pk *StopProgram) Decode() error

func (*StopProgram) Encode

func (pk *StopProgram) Encode() error

func (StopProgram) ID

func (StopProgram) ID() byte

func (StopProgram) New

func (StopProgram) New() Packet

Jump to

Keyboard shortcuts

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