Categorygithub.com/gorcon/rcon
modulepackage
1.4.0
Repository: https://github.com/gorcon/rcon.git
Documentation: pkg.go.dev

# README

Rcon

GitHub Build Go Coverage Go Report Card GoDoc

Source RCON Protocol implementation in Go.

Protocol Specifications

RCON Protocol described in the valve documentation.

Supported Games

Open pull request if you have successfully used a package with another game with rcon support and add it to the list.

Install

go get github.com/gorcon/rcon

See Changelog for release details.

Usage

package main

import (
	"fmt"
	"log"

	"github.com/gorcon/rcon"
)

func main() {
	conn, err := rcon.Dial("127.0.0.1:16260", "password")
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	response, err := conn.Execute("help")
	if err != nil {
		log.Fatal(err)
	}
	
	fmt.Println(response)	
}

With an existing net.Conn

If you wish to initialize a RCON connection with an already initialized net.Conn, you can use the Open function:

package main

import (
	"fmt"
	"log"
	"net"

	"github.com/gorcon/rcon"
)

func main() {
	netConn, err := net.Dial("tcp", "127.0.0.1:16260")
	if err != nil {
		// Failed to open TCP connection to the server.
		log.Fatalf("expected nil got error: %s", err)
	}
	defer netConn.Close()
	
	conn, err := rcon.Open(netConn, "password")
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	response, err := conn.Execute("help")
	if err != nil {
		log.Fatal(err)
	}
	
	fmt.Println(response)	
}

Requirements

Go 1.15 or higher

Contribute

Contributions are more than welcome!

If you think that you have found a bug, create an issue and publish the minimum amount of code triggering the bug, so it can be reproduced.

If you want to fix the bug then you can create a pull request. If possible, write a test that will cover this bug.

License

MIT License, see LICENSE

# Packages

Package rcontest contains RCON server for RCON client testing.

# Functions

Dial creates a new authorized Conn tcp dialer connection.
NewPacket creates and initializes a new Packet using packetType, packetID and body as its initial contents.
Open creates a new authorized Conn from an existing net.Conn.
SetDeadline injects read/write Timeout to Settings.
SetDialTimeout injects dial Timeout to Settings.

# Constants

DefaultDeadline provides default deadline to tcp read/write operations.
DefaultDialTimeout provides default auth timeout to remote server.
MaxCommandLen is an artificial restriction, but it will help in case of random large queries.
Packet sizes definitions.
Packet sizes definitions.
Size of Packet's header.
Size of Packet's padding.
SERVERDATA_AUTH is the first packet sent by the client, which is used to authenticate the conn with the server.
SERVERDATA_AUTH_ID is any positive integer, chosen by the client (will be mirrored back in the server's response).
SERVERDATA_AUTH_RESPONSE packet is a notification of the conn's current auth status.
SERVERDATA_EXECCOMMAND packet type represents a command issued to the server by a client.
SERVERDATA_EXECCOMMAND_ID is any positive integer, chosen by the client (will be mirrored back in the server's response).
SERVERDATA_RESPONSE_VALUE packet is the response to a SERVERDATA_EXECCOMMAND request.

# Variables

DefaultSettings provides default deadline settings to Conn.
ErrAuthFailed is returned when the package id from authentication response is -1.
ErrAuthNotRCON is returned when got auth response with negative size.
ErrCommandEmpty is returned when executed command length equal 0.
ErrCommandTooLong is returned when executed command length is bigger than MaxCommandLen characters.
ErrInvalidAuthResponse is returned when we didn't get an auth packet back for second read try after discard empty SERVERDATA_RESPONSE_VALUE from authentication response.
ErrInvalidPacketID is returned when the package id from server response was not mirrored back from request.
ErrInvalidPacketPadding is returned when the bytes after type field from response is not equal to null-terminated ASCII strings.
ErrMultiErrorOccurred is returned when close connection failed with error after auth failed.
ErrResponseTooSmall is returned when the server response is smaller than 10 bytes.

# Structs

Conn is source RCON generic stream-oriented network connection.
Packet is a rcon packet.
Settings contains option to Conn.

# Type aliases

Option allows to inject settings to Settings.