gorcon

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2020 License: MIT Imports: 7 Imported by: 0

README

gorcon

Source Remote Console Specification Implemented in Go

Goal

I couldn't find a decently accurate go lib that matched the specification of the Source RCON client. So I quickly implemented one.

Documentation

Index

Constants

View Source
const (
	// PacketTerminatorSize is the number of bytes the terminator (0x00) at the end of the packet uses.
	PacketTerminatorSize int32 = 2

	// PacketHeaderSize is the number of bytes the ID and Type fields use in bytes, both of which are 32-bit signed integers.
	PacketHeaderSize int32 = 8 //ID and Type, both 32-bit signed integers

	// PacketMaximumBodySize is the number of bytes the Body of the packet uses in bytes, it's 4096 minus the header and terminator.
	PacketMaximumBodySize int32 = 4096 - PacketHeaderSize - PacketTerminatorSize

	// PacketMaximumSize is the total number of bytes a full packet may contain.
	PacketMaximumSize int32 = 4 + PacketHeaderSize + PacketMaximumBodySize + PacketTerminatorSize
)
View Source
const (
	// DefaultDialTimeout is the timeout set for a zero value timeout, disabling it requires it be set to -1.
	DefaultDialTimeout = 5 * time.Second

	// DefaultReadDeadline is the deadline for reading from the socket, disabling it requires it be set to -1.
	DefaultReadDeadline = 5 * time.Second

	// DefaultWriteDeadline is the deadline for writing to the socket, disabling it requires it be set to -1.
	DefaultWriteDeadline = 5 * time.Second
)

Variables

View Source
var (
	ErrInvalidPacketTerminator     = errors.New("the packet was not terminated correctly")
	ErrInvalidResponseToAuthPacket = errors.New("the server responded with an invalid packet type for a auth packet")
	ErrAuthPacketFailed            = errors.New("the authentication attempt with the server failed")
	ErrInvalidPacketIDInResponse   = errors.New("the server replied with a packet ID not in our request")
	ErrCommandEmpty                = errors.New("the command must not be a blank string")
	ErrCommandTooLong              = errors.New("the supplied command was too long")
	ErrInvalidPacketType           = errors.New("packet type is invalid")
	ErrInvalidPacketTypeRust       = errors.New("packet type is invalid (rust undocumented)")
	ErrAlreadyConnected            = errors.New("remote console is already connected")
	ErrAlreadyAuthenticated        = errors.New("remote console is already authenticated")
)

Functions

This section is empty.

Types

type ClientPacket

type ClientPacket struct {
	ID   int32
	Type ClientPacketType
	Body string
}

ClientPacket represents an outgoing packet from the client to the remote server.

func (*ClientPacket) Size

func (cp *ClientPacket) Size() int32

Size calculates the size of the packet.

func (*ClientPacket) WriteTo

func (cp *ClientPacket) WriteTo(rc *RemoteConsole) (n int64, err error)

WriteTo writes this packet to the underlying connection.

type ClientPacketType

type ClientPacketType int32

ClientPacketType represents the packet types that can be sent by the client to the server.

const (
	// TODO: Implement this response check.
	// CheckResponse is a SERVERDATA_RESPONSE_VALUE packet type, used for multi-packet response checking.
	CheckResponse ClientPacketType = 0

	// ExecuteCommand represents the SERVERDATA_EXECCOMMAND packet type.
	ExecuteCommand ClientPacketType = 2

	// Auth represents the SERVERDATA_AUTH packet type.
	Auth ClientPacketType = 3
)

type RemoteConsole

type RemoteConsole struct {
	// contains filtered or unexported fields
}

func NewRemoteConsole

func NewRemoteConsole(address string, password string, settings RemoteConsoleSettings) (rc *RemoteConsole, err error)

NewRemoteConsole creates a new remote console, dials it, and authenticates it.

func (*RemoteConsole) Authenticate

func (rc *RemoteConsole) Authenticate(password string) (err error)

Authenticate sends the authentication packet.

func (*RemoteConsole) Close

func (rc *RemoteConsole) Close() (err error)

Close forwards the Close() method from the underlying net.Conn.

func (*RemoteConsole) Dial

func (rc *RemoteConsole) Dial(address string) (err error)

Dial sets up the connection and dials it.

func (*RemoteConsole) Execute

func (rc *RemoteConsole) Execute(command string) (response string, err error)

Execute runs a command on the remote console.

func (*RemoteConsole) LocalAddr

func (rc *RemoteConsole) LocalAddr() (addr net.Addr)

LocalAddr returns the LocalAddr() from the underlying net.Conn.

func (*RemoteConsole) RemoteAddr

func (rc *RemoteConsole) RemoteAddr() (addr net.Addr)

RemoteAddr returns the RemoteAddr() from the underlying net.Conn.

type RemoteConsoleSettings

type RemoteConsoleSettings struct {
	DialTimeout   time.Duration
	ReadDeadline  time.Duration
	WriteDeadline time.Duration
}

type ServerPacket

type ServerPacket struct {
	Size      int32
	ID        int32
	Type      ServerPacketType
	BodyBytes []byte
}

ServerPacket represents packets received from the server.

func NewServerPacketFromRemoteConsole

func NewServerPacketFromRemoteConsole(rc *RemoteConsole) (n int64, packet *ServerPacket, err error)

NewServerPacketFromRemoteConsole reads the data from the socket and decodes it into a ServerPacket.

func (*ServerPacket) Body

func (sp *ServerPacket) Body() string

Body converts the BodyBytes into a string.

type ServerPacketType

type ServerPacketType int32

ServerPacketType represents the packet types that can be received by the client from the server.

const (
	// ResponseValue represents the SERVERDATA_RESPONSE_VALUE packet type.
	ResponseValue ServerPacketType = 0

	// AuthResponse represents the SERVERDATA_AUTH_RESPONSE packet type.
	AuthResponse ServerPacketType = 2

	// RustUndocumentedPacket represents the unknown packet type from Rust with an ID of 4.
	RustUndocumentedPacket ServerPacketType = 4
)

Jump to

Keyboard shortcuts

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