rcon

package
v0.0.0-...-6a73ad5 Latest Latest
Warning

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

Go to latest
Published: May 1, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package rcon implements the communication protocol for communicating with RCON servers. Tested and working with Valve game servers.

Index

Constants

View Source
const (
	PacketPaddingSize uint8 = 2 // Size of Packet's padding.
	PacketHeaderSize  uint8 = 8 // Size of Packet's header.
)
View Source
const (
	Exec          int32 = 2
	Auth          int32 = 3
	AuthResponse  int32 = 2
	ResponseValue int32 = 0
)

Packet type constants. https://developer.valvesoftware.com/wiki/Source_RCON_Protocol#Packet_Type

View Source
const (
	TerminationSequence = "\x00" // Null empty ASCII string suffix.
)

Variables

View Source
var (
	ErrInvalidWrite        = errors.New("Failed to write the payload corretly to remote connection.")
	ErrInvalidRead         = errors.New("Failed to read the response corretly from remote connection.")
	ErrInvalidChallenge    = errors.New("Server failed to mirror request challenge.")
	ErrUnauthorizedRequest = errors.New("Client not authorized to remote server.")
	ErrFailedAuthorization = errors.New("Failed to authorize to the remote server.")
)

Rcon package errors.

Functions

This section is empty.

Types

type Client

type Client struct {
	Host       string   // The IP address of the remote server.
	Port       int      // The Port the remote server's listening on.
	Authorized bool     // Has the client been authorized by the server?
	Connection net.Conn // The TCP connection to the server.
}

func NewClient

func NewClient(host string, port int) (client *Client, err error)

NewClient creates a new Client type, creating the connection to the server specified by the host and port arguments. If the connection fails, an error is returned.

func (*Client) Authorize

func (c *Client) Authorize(password string) (response *Packet, err error)

Authorize calls Send with the appropriate command type and the provided password. The response packet is returned if authorization is successful or a potential error.

func (*Client) Execute

func (c *Client) Execute(command string) (response *Packet, err error)

Execute calls Send with the appropriate command type and the provided command. The response packet is returned if the command executed successfully or a potential error.

func (*Client) Send

func (c *Client) Send(typ int32, command string) (response *Packet, err error)

Sends accepts the commands type and its string to execute to the clients server, creating a packet with a random challenge id for the server to mirror, and compiling its payload bytes in the appropriate order. The resonse is decompiled from its bytes into a Packet type for return. An error is returned if send fails.

type Header struct {
	Size      int32 // The size of the payload.
	Challenge int32 // The challenge ths server should mirror.
	Type      int32 // The type of request being sent.
}

type Packet

type Packet struct {
	Header Header // Packet header.
	Body   string // Body of packet.
}

func NewPacket

func NewPacket(challenge, typ int32, body string) (packet *Packet)

NewPacket returns a pointer to a new Packet type.

func (Packet) Compile

func (p Packet) Compile() (payload []byte, err error)

Compile converts a packets header and body into its approriate byte array payload, returning an error if the binary packages Write method fails to write the header bytes in their little endian byte order.

Jump to

Keyboard shortcuts

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