rcon

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: MIT Imports: 12 Imported by: 1

README

Valve RCON server implementation

Simple server implementation for the RCON protocol.

Example usage

package main

import (
	"log"

	rcon "github.com/crossworth/valve-rcon"
)

const (
	host     = "0.0.0.0"
	port     = rcon.DefaultPort
	password = "test"
)

func main() {
	server := rcon.NewRCON(host, port, password)
	server.SetBanList([]string{
		"192.168.0.10",
		// ...
	})

	// echo server
	server.OnCommand(func(command string, client rcon.Client) {
		log.Printf("command: %s", command)
		_ = client.Write("server: " + command)
	})

	err := server.ListenAndServe()
	if err != nil {
		log.Fatalln(err)
	}
}

Documentation

Index

Constants

View Source
const (
	ServerDataAuth          = PacketType(3) // Authentication packet
	ServerDataAuthResponse  = PacketType(2) // Authentication response packet
	ServerDataExecCommand   = PacketType(2) // Command packet
	ServerDataResponseValue = PacketType(0) // Response packet
)
View Source
const (
	DefaultPort = 27015
)
View Source
const MaxPacketSize = 4096

Variables

This section is empty.

Functions

func EncodePacket

func EncodePacket(p Packet) ([]byte, error)

EncodePacket convert the packet to a binary representation expected by the RCON protocol, it will return an error if the packet exceeds the maximum packet size.

if you need to send a lot of data you should send multiple packets https://developer.valvesoftware.com/wiki/Source_RCON_Protocol#Multiple-packet_Responses

Types

type Client

type Client interface {
	Write(content string) error
	Close() error
}

func NewClient

func NewClient(conn io.WriteCloser, lastPacket Packet) Client

type Packet

type Packet struct {
	Size int32
	ID   int32
	Type PacketType
	Body string
}

Packet represents an RCON packet

func ParsePacket

func ParsePacket(input io.Reader) (Packet, error)

ParsePacket return the packet parsed from the input or an error if the packet could not be parsed

type PacketType

type PacketType int32

PacketType represents an RCON packet type

func (PacketType) Stringer

func (p PacketType) Stringer() string

type RCON

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

func NewRCON

func NewRCON(host string, port int, password string) *RCON

func (*RCON) CloseOnProgramEnd

func (server *RCON) CloseOnProgramEnd()

func (*RCON) ListenAndServe

func (r *RCON) ListenAndServe() error

func (*RCON) OnCommand

func (r *RCON) OnCommand(handle func(command string, client Client))

func (*RCON) SetBanList

func (r *RCON) SetBanList(banList []string)

Jump to

Keyboard shortcuts

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