rcon

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

rcon package implements the minecraft rcon protocol (based on the source rcon protocol). This package is strictly compliant with the following documentation : https://wiki.vg/RCON.

Index

Constants

View Source
const (
	PacketSizeEmptyPayload       int = 14
	MaximumResponsePayloadLength int = 4096
	MaximumRequestPayloadLength  int = 1446
	LoginRequestType             int = 3
	CommandRequestType           int = 2
	WrongPasswordResponseType    int = 2
	CommandResponseType          int = 0
	InvalidRequestType           int = 4
)

Variables

View Source
var (
	ErrNotAuthenticated error = errors.New("authentication hasn't been realised or has failed. Call Authenticate method to authenticate")
	ErrCommandTooLong   error = errors.New("command length must be 1446 or less")
)
View Source
var (
	ErrWrongPassword error = errors.New("wrong password")
)

Functions

func Rcon

func Rcon(hostname string, port int, password string, command string) (string, error)

Rcon executes a command on a minecraft server, and returns the response of that command. If the password is wrong, the error will be of type ErrWrongPassword.

Types

type RCONClient

type RCONClient struct {

	// options
	SkipSRVLookup bool
	DialTimeout   time.Duration
	ReadTimeout   time.Duration
	// contains filtered or unexported fields
}

RCONClient is the RCON client.

func NewClient

func NewClient(hostname string, port int) *RCONClient

NewClient returns a well-formed *RCONClient.

func (*RCONClient) Authenticate

func (client *RCONClient) Authenticate(password string) (bool, error)

Authenticate sends an authentication packet to the server. If connection is successful it returns true, if not it returns false. If the communication didn't go wrong, err will be nil. This means that (false, nil) is a perfectly fine return if the password was wrong but he communication went well.

func (*RCONClient) Command

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

Command sends a command packet to the server. Command length cannot be over MaximumRequestPayloadLength. This is a limitation of the source RCON protocol.

func (*RCONClient) Connect

func (client *RCONClient) Connect() error

Connect establishes a connection via TCP.

func (*RCONClient) Disconnect

func (client *RCONClient) Disconnect() error

Disconnect closes the connection. This also means the authentication isn't valid anymore, even if a call to the Connect method is made. Connection is made not usable anymore no matter if the it closed properly or not.

Jump to

Keyboard shortcuts

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