rcon

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: MIT Imports: 10 Imported by: 1

README

csgo-rcon

Go Report Card GitHub release (latest by date) PkgGoDev

Golang package for CS:GO (or other Source Dedicated Server) RCON Protocol client.

For the protocol specification, go to Source RCON Protocol from Valve

Need a web-based admin panel? Check it out at forewing/webrcon-server!

Usage

  1. Import the package
import "github.com/forewing/csgo-rcon"
  1. Create a client with rcon.New(address, password string, timeout time.Duration), assuming your server rcon are hosted at 10.114.51.41:27015, with password password, and you want the connection timeout to be 2 seconds.
c := rcon.New("10.114.51.41:27015", "password", time.Seconds * 2)
  1. Execute commands use *Client.Execute(cmd string). Execute once if no "\n" provided. Return result message and nil on success, empty string and an error on failure.

    If cmd includes "\n", it is treated as a script file. Splitted and trimmed into lines. Line starts with "//" will be treated as comment and ignored. When all commands seccess, concatted messages and nil will be returned. Once failed, concatted previous succeeded messages and an error will be returned.

Command Line Tool

Install
go get -u github.com/forewing/csgo-rcon/cmd/csgo-rcon

Or download from release page.

Usage
Usage of csgo-rcon:
  -a address
        address of the server RCON, in the format of HOST:PORT. (default "127.0.0.1:27015")
  -c file
        load configs from file instead of flags.
  -f file
        read commands from file, "-" for stdin. From arguments if not set.
  -i    interact with the console.
  -m  file
        read completions from file
  -p password
        password of the RCON.
  -t timeout
        timeout of the connection (seconds). (default 1)
  1. From arguments
$ csgo-rcon -c config.json mp_warmuptime 999
L **/**/20** - **:**:**: rcon from "**.**.**.**:***": command "mp_warmuptime 999"
  1. From file (- for stdin)
$ csgo-rcon -c config.json -f commands.cfg
  1. Interactive
$ csgo-rcon -c config.json -i
>>> bot_add_ct
L **/**/20** - **:**:**: "Derek<4><BOT><>" connected, address ""
L **/**/20** - **:**:**: "Derek<4><BOT>" switched from team <Unassigned> to <CT>
L **/**/20** - **:**:**: "Derek<4><BOT><>" entered the game
L **/**/20** - **:**:**: rcon from "**.**.**.**:***": command "bot_add_ct"
>>> users
<slot:userid:"name">
0 users
L **/**/20** - **:**:**: rcon from "**.**.**.**:***": command "users"
>>> ^C

4 .Completion

# First download the completion file from your server
csgo-rcon -c config.json cvarlist > cmds.txt
# and remove top 2 and bottom 2 lines
tail -n +3 cmds.txt | head -n -2 > cmds.txt.bak && mv cmds.txt.bak cmds.txt
# then use -m flag to specify the completion file
csgo-rcon -c config.json -i -m cmds.txt

Documentation

Overview

Package rcon provides a golang interface of Source Remote Console (RCON) client, let server operators to administer and interact with their servers remotely in the same manner as the console provided by srcds. Based on http://developer.valvesoftware.com/wiki/Source_RCON_Protocol

Index

Constants

View Source
const (
	// DefaultAddress of the srcds RCON
	DefaultAddress = "127.0.0.1:27015"

	// DefaultPassword is empty
	DefaultPassword = ""

	// DefaultTimeout of the connection
	DefaultTimeout = time.Second * 1
)

Variables

View Source
var (
	ErrNoConnection     = errors.New("no connection")
	ErrDialTCPFail      = errors.New("dial TCP fail")
	ErrConnectionClosed = errors.New("connection closed")
	ErrBadPassword      = errors.New("bad password")
	ErrInvalidResponse  = errors.New("invalid response")
	ErrCrapBytes        = errors.New("response contains crap bytes")
	ErrWaitingTimeout   = errors.New("timeout while waiting for reply")
)

Functions

This section is empty.

Types

type Client

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

A Client of RCON protocol to srcds Remember to set Timeout, it will block forever when not set

func New

func New(address, password string, timeout time.Duration) *Client

New return pointer to a new client, it's safe for concurrency use

func (*Client) Execute

func (c *Client) Execute(cmd string) (string, error)

Execute the command. Execute once if no "\n" provided. Return result message and nil on success, empty string and an error on failure. If cmd includes "\n", it is treated as a script file. Splitted and trimmed into lines. Line starts with "//" will be treated as comment and ignored. When all commands seccess, concatted messages and nil will be returned. Once failed, concatted previous succeeded messages and an error will be returned.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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