rcon

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2020 License: MIT Imports: 13 Imported by: 0

README

BattlEye RCon Server Protocol v2

Implementation of the RCON protocol for servers.

This project implements the server protocol without the fragmentation/multiple packets part.

It will handle the client state and brute-force attacks.

You can download an BattlEye RCon client at https://www.battleye.com/downloads/.

Example simple UDP server

package main

import (
	"fmt"
	"log"
	"net"

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

func main() {
	server := rcon.NewRCON("", 2301, "test")

	server.OnCommand(func(seq uint8, command string, from net.Addr) {
		fmt.Println("command", command, seq, from.String())
		resp := rcon.MakeCommandResponsePacket(seq, []byte("echo "+command))
		server.SendResponse(from, resp)

		server.Broadcast(rcon.MakeServerMessagePacket(server.NextSequenceNumber(), []byte("GLOBAL: echo "+command)))
	})

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

Server Server

Client Client

Documentation

Overview

Package RCON provides an implementation of the BattlEye RCon Protocol Specification v2 server side.

It can be used to talk with RCON clients over a remote console

Reference: https://www.battleye.com/downloads/BERConProtocol.txt https://de.wikipedia.org/wiki/BattleEye_RCon_Protocol

Index

Constants

View Source
const (
	LoginPacketType         = PacketType(0x00) // LoginPacketType used during the login process
	CommandPacketType       = PacketType(0x01) // CommandPacketType used every time the client sends a packet
	ServerMessagePacketType = PacketType(0x02) // ServerMessagePacketType used when the server broadcast a packet for the client
	UnknownPacketType       = PacketType(0xff) // UnknownPacketType when the application cannot figure out the packet type

	FragmentationPacketType = PacketType(0x00) // FragmentationPacketType, a packet used when the server response has a lot of data, we dont implement it
)
View Source
const (
	LoginSuccessful = LoginResponseType(0x01) // LoginSuccessful when the password provided matches the password of the server
	LoginFailed     = LoginResponseType(0x00) // LoginFailed when the password is incorrect
)

Variables

This section is empty.

Functions

func MakeCommandResponsePacket

func MakeCommandResponsePacket(seq uint8, data []byte) []byte

MakeCommandResponsePacket creates a new CommandResponsePacket encoded as byte slice Note that you should provide the sequence number for the command that you are "answering" the data is the payload that you want to send

func MakeLoginResponsePacket

func MakeLoginResponsePacket(responseType LoginResponseType) []byte

MakeLoginResponsePacket creates a new LoginResponsePacket already encoded as byte slice

func MakeServerMessagePacket

func MakeServerMessagePacket(seq uint8, data []byte) []byte

MakeServerMessagePacket creates a new ServerMessagePacket and encode it as a byte slice You must provide an sequence number, you can get an valid sequence number from the RCON struct calling the NextSequenceNumber, the data is the payload that you want to send

func NewChecksum

func NewChecksum(data []byte) uint32

NewChecksum creates a checksum for the bytes provided

func ParseCommand

func ParseCommand(input io.Reader) (string, error)

ParseCommand tries to read the rest of the input and extract an command or string

func ParseSequenceNumber

func ParseSequenceNumber(input io.Reader) (byte, error)

ParseSequenceNumber tries to decode the packet sequence number of the provided input

func VerifyChecksum

func VerifyChecksum(data []byte, checksum uint32) bool

VerifyChecksum check if the bytes matches the checksum provided

Types

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

Logger is a simple interface that defines a logger used on the implementation, you can create your custom logger and set the Logger for the RCON struct

type LoginResponseType

type LoginResponseType byte

LoginResponseType defines the possible login results

type PacketHeader

type PacketHeader struct {
	Magic    []byte // 2 byte magic, always BE
	Checksum uint32 // 4 bytes crc32 checksum of the following bytes (including the end)
	End      byte   // 1 byte, always 0xff
}

PacketHeader defines a basic struct used on every packet

func NewPacketHeader

func NewPacketHeader(checksum uint32) PacketHeader

NewPacketHeader creates a new packet with the checksum provided

func ParseHeader

func ParseHeader(input io.Reader) (PacketHeader, error)

ParseHeader parse an input trying to "discovery" the needed data to decode the payload

func (*PacketHeader) Encode

func (ph *PacketHeader) Encode() []byte

Encode encodes the packet header in a byte slice representation

type PacketType

type PacketType byte

PacketType defines possible packets types for the BattlEye RCon protocol

func ParsePacketType

func ParsePacketType(input io.Reader) (PacketType, error)

ParsePacketType tries to decode the packet type of the provided input

func (PacketType) Stringer

func (p PacketType) Stringer() string

Stringer returns the string representation for the packet

type RCON

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

RCON is the RCON server implementation it manages state about the clients, blocked and banned ips and server messages acknowledges.

func NewRCON

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

NewRCON create a new RCON server with the host (IP/interface), port and password provided, it will not start the server.

func (*RCON) Broadcast

func (r *RCON) Broadcast(data []byte)

Broadcast send an message to all the connected clients it will handle the retry and acknowledgement of messages

func (*RCON) Clients

func (r *RCON) Clients() []net.Addr

Clients return an slice containing all the clients addresses authenticated

func (*RCON) ListenAndServe

func (r *RCON) ListenAndServe() error

ListenAndServe start the server on the udp ip/port provided and start handling packets

func (*RCON) NextSequenceNumber

func (r *RCON) NextSequenceNumber() uint8

NextSequenceNumber returns the Next sequence number to be used on the MakeServerMessagePacket call

func (*RCON) OnCommand

func (r *RCON) OnCommand(handle func(seq uint8, command string, from net.Addr))

OnCommand can be used to register a callback to be executed once the server receives a command

func (*RCON) SendResponse

func (r *RCON) SendResponse(to net.Addr, data []byte) error

SendResponse sends an packet to a client The packet can be created using MakeCommandResponsePacket be aware that most of times you will only use this to send and response

func (*RCON) SetIPBanList

func (r *RCON) SetIPBanList(ipBanList []string)

SetIPBanList defines the ip ban list to be used to avoid certain ips

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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