mcr

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2025 License: MIT Imports: 7 Imported by: 3

README

mcr

tests
mcr is a dependency-free remote console (RCon) package written in Golang following the Source protocol.

Usage

import (
	"log"
	"os"

	"github.com/jake-young-dev/mcr"
)

func main() {
	//create new client to server address on port 9876
	client := mcr.NewClient(os.Getenv("rcon_address"), mcr.WithPort(9876))

	//connect to server and authenticate with password
	err := client.Connect(os.Getenv("rcon_password"))
	if err != nil {
		panic(err)
	}
	defer client.Close() //always call close to clean up your connections

	response, err := client.Command("list") //run "list" command on server
	if err != nil {
		panic(err)
	}

	log.Println(response)
}

Default Options

  • Timeout is defaulted 10 seconds
  • Port is defaulted to 61695

Security

  • RCon is an inherently insecure protocol that sends passwords in plaintext. I recommend using a VPN or keeping the connection local when possible.
  • All code is checked with gosec as an added security measure

Documentation

Index

Constants

View Source
const (
	//rcon packet type values
	FailurePacket = int32(-1)
	CommandPacket = int32(2)
	AuthPacket    = int32(3)

	//tcp constants
	Protocol          = "tcp"
	PacketRequestSize = 10 //size of headers plus padding bytes, not including Size header per RCon standard
	PacketHeaderSize  = 8  //size of headers not including Size header per RCon standard
	PacketPaddingSize = 2  //size of padding required after body

	//default values
	ResetID        = 1
	DefaultCap     = 100
	DefaultTimeout = time.Second * 10
	DefaultPort    = 61695
)

Variables

View Source
var (
	ErrClientNotConnected = errors.New("client not connected. The Connect method must be called before commands can be run")
	ErrIntOverflow        = errors.New("integer overflowed 32 bits")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	Connect(password string) error
	Command(cmd string) (string, error)
	CommandNoResponse(cmd string) error
	Close() error
	RequestID() int32
	SetRequestID(id int32)
	Timeout() time.Duration
	Connection() net.Conn
	Port() int
	Address() string
	// contains filtered or unexported methods
}

func NewClient

func NewClient(addr string, opts ...Option) Client

creates a new remote console client configured with the supplied options. The client does not connect to the server until the Connect method is called to authenticate the client. Check the README for information on default values

type Option added in v0.2.0

type Option func(cn *client)

request option func skeleton

func WithCap added in v0.2.1

func WithCap(c int32) Option

option to allow for custom request id max value

func WithConnection added in v1.1.1

func WithConnection(c net.Conn) Option

option to allow for use of custom connections

func WithID added in v1.4.0

func WithID(i int32) Option

option to allow for setting current request ID

func WithPort added in v1.0.1

func WithPort(port int) Option

option to allow for custom port values

func WithTimeout added in v0.2.0

func WithTimeout(timeout time.Duration) Option

option to allow for custom timeout values

Jump to

Keyboard shortcuts

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