gorcon

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: MIT Imports: 7 Imported by: 0

README

gorcon

RCON client implementation in Go

Documentation

Index

Constants

View Source
const (
	PacketTypeCommand  PacketType = 2
	PacketTypeLogin    PacketType = 3
	PacketTypeResponse PacketType = 0
	PayloadChunkLength int        = 4096
)
View Source
const (
	RequestIDStart int32 = 6516583
)

Variables

View Source
var (
	MCEndian           binary.ByteOrder = binary.LittleEndian
	ErrInvalidPassword error            = errors.New("invalid RCON password")
)
View Source
var (
	DefaultChecker RCONPasswordChecker = func(*RCONContext, string) bool {
		return false
	}
	DefaultCommandHandler RCONCommandHandler = func(*RCONCommandContext) []string {
		return []string{}
	}
	DefaultErrorHandler RCONErrorHandler = func(_ *RCONCommandContext, _ *RCONContext, _ error) {

	}
)

Functions

func Collect added in v1.2.0

func Collect(s string) []string

func WriteBinaryPacket added in v1.2.0

func WriteBinaryPacket(w io.Writer, packet BinaryPacket) (int, error)

func WritePacket added in v1.2.0

func WritePacket(w io.Writer, packet Packet) (int, error)

Types

type BinaryPacket added in v1.2.0

type BinaryPacket struct {
	RequestID int32
	Type      PacketType
	Body      []byte
}

func ReadBinaryPacket added in v1.2.0

func ReadBinaryPacket(r io.Reader) (*BinaryPacket, error)

func (*BinaryPacket) Text added in v1.2.0

func (bp *BinaryPacket) Text() (*Packet, error)

type Packet

type Packet struct {
	RequestID int32
	Type      PacketType
	Body      string
}

func ReadPacket added in v1.2.0

func ReadPacket(r io.Reader) (*Packet, error)

type PacketType

type PacketType int32

type RCONClient

type RCONClient struct {
	Address    string
	RequestID  int32
	Connection net.Conn
}

func NewRCONClient

func NewRCONClient() *RCONClient

func (*RCONClient) Close

func (client *RCONClient) Close() error

func (*RCONClient) Connect added in v1.2.0

func (client *RCONClient) Connect(address string) error

func (*RCONClient) Login

func (client *RCONClient) Login(password string) error

func (*RCONClient) RecvPacket

func (client *RCONClient) RecvPacket() (*Packet, error)

func (*RCONClient) SendCommand

func (client *RCONClient) SendCommand(command string) (string, error)

func (*RCONClient) SendPacket

func (client *RCONClient) SendPacket(packet Packet) error

type RCONCommandContext added in v1.2.0

type RCONCommandContext struct {
	Command   string
	Context   *RCONContext
	RequestID int32
	UserData  interface{}
}

func NewCommandContext added in v1.2.0

func NewCommandContext(context *RCONContext, packet *Packet) *RCONCommandContext

func (*RCONCommandContext) Reply added in v1.2.2

func (cctx *RCONCommandContext) Reply(payload string) error

type RCONCommandHandler added in v1.2.0

type RCONCommandHandler interface{}

type RCONContext added in v1.2.0

type RCONContext struct {
	Closed     bool
	Connection net.Conn
	RequestID  int32
	Server     *RCONServer
	UserData   interface{}
}

func NewContext added in v1.2.0

func NewContext(conn net.Conn, server *RCONServer) *RCONContext

func (*RCONContext) Close added in v1.2.0

func (ctx *RCONContext) Close() *RCONContext

func (*RCONContext) RawSend added in v1.2.2

func (ctx *RCONContext) RawSend(requestID int32, payload string) error

func (*RCONContext) RecvBinaryPacket added in v1.2.0

func (ctx *RCONContext) RecvBinaryPacket() (*BinaryPacket, error)

func (*RCONContext) RecvPacket added in v1.2.0

func (ctx *RCONContext) RecvPacket() (*Packet, error)

func (*RCONContext) Send added in v1.2.2

func (ctx *RCONContext) Send(requestID int32, payload string) error

func (*RCONContext) SendBinaryPacket added in v1.2.0

func (ctx *RCONContext) SendBinaryPacket(packet BinaryPacket) error

func (*RCONContext) SendPacket added in v1.2.0

func (ctx *RCONContext) SendPacket(packet Packet) error

type RCONDispatcher added in v1.2.0

type RCONDispatcher func(*RCONContext, *BinaryPacket) error

type RCONErrorCondition added in v1.2.0

type RCONErrorCondition int
const (
	AtLeast RCONErrorCondition = iota
	Exactly
	Range
	TooLarge
)

type RCONErrorHandler added in v1.2.0

type RCONErrorHandler func(*RCONCommandContext, *RCONContext, error)

type RCONErrorInvalidLength added in v1.2.0

type RCONErrorInvalidLength struct {
	Expected  int
	Expected2 int
	Got       int
	Condition RCONErrorCondition
}

func (*RCONErrorInvalidLength) Error added in v1.2.0

func (e *RCONErrorInvalidLength) Error() string

type RCONErrorNotZeroTerminatedPayload added in v1.2.0

type RCONErrorNotZeroTerminatedPayload struct {
	RequestID int32
	Type      PacketType
	Payload   []byte
}

func (*RCONErrorNotZeroTerminatedPayload) Error added in v1.2.0

type RCONExitHandler added in v1.2.3

type RCONExitHandler func(*RCONContext)

type RCONLoggedHandler added in v1.2.3

type RCONLoggedHandler func(*RCONContext)

type RCONPasswordChecker added in v1.2.0

type RCONPasswordChecker func(*RCONContext, string) bool

func ForPassword added in v1.2.0

func ForPassword(password string) RCONPasswordChecker

type RCONServer added in v1.2.0

type RCONServer struct {
	Config         RCONServerConfig
	Checker        RCONPasswordChecker
	CommandHandler RCONCommandHandler
	ErrorHandler   RCONErrorHandler
	LoggedHandler  RCONLoggedHandler
	ExitHandler    RCONExitHandler
	Listener       net.Listener
	Dispatchers    map[PacketType]RCONDispatcher
}

func NewRCONServer added in v1.2.0

func NewRCONServer(config *RCONServerConfig) *RCONServer

func (*RCONServer) Check added in v1.2.0

func (rs *RCONServer) Check(checker RCONPasswordChecker) *RCONServer

func (*RCONServer) Close added in v1.2.0

func (rs *RCONServer) Close() error

func (*RCONServer) On added in v1.2.0

func (rs *RCONServer) On(pt PacketType, dispatcher RCONDispatcher) *RCONServer

func (*RCONServer) OnCommand added in v1.2.0

func (rs *RCONServer) OnCommand(commandHandler RCONCommandHandler) *RCONServer

func (*RCONServer) OnError added in v1.2.0

func (rs *RCONServer) OnError(errorHandler RCONErrorHandler) *RCONServer

func (*RCONServer) OnExit added in v1.2.3

func (rs *RCONServer) OnExit(exitHandler RCONExitHandler) *RCONServer

func (*RCONServer) OnLogged added in v1.2.3

func (rs *RCONServer) OnLogged(loggedHandler RCONLoggedHandler) *RCONServer

func (*RCONServer) Run added in v1.2.0

func (rs *RCONServer) Run(address string) error

type RCONServerConfig added in v1.2.0

type RCONServerConfig struct {
	Flags RCONServerConfigFlags
}

type RCONServerConfigFlags added in v1.2.0

type RCONServerConfigFlags int
const (
	CommandInGoroutine RCONServerConfigFlags = 1 << iota
)

Jump to

Keyboard shortcuts

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