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
- func MakeCommandResponsePacket(seq uint8, data []byte) []byte
- func MakeLoginResponsePacket(responseType LoginResponseType) []byte
- func MakeServerMessagePacket(seq uint8, data []byte) []byte
- func NewChecksum(data []byte) uint32
- func ParseCommand(input io.Reader) (string, error)
- func ParseSequenceNumber(input io.Reader) (byte, error)
- func VerifyChecksum(data []byte, checksum uint32) bool
- type Logger
- type LoginResponseType
- type PacketHeader
- type PacketType
- type RCON
- func (r *RCON) Broadcast(data []byte)
- func (r *RCON) Clients() []net.Addr
- func (r *RCON) ListenAndServe() error
- func (r *RCON) NextSequenceNumber() uint8
- func (r *RCON) OnCommand(handle func(seq uint8, command string, from net.Addr))
- func (r *RCON) SendResponse(to net.Addr, data []byte) error
- func (r *RCON) SetIPBanList(ipBanList []string)
Constants ¶
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 )
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 ¶
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 ¶
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 ¶
NewChecksum creates a checksum for the bytes provided
func ParseCommand ¶
ParseCommand tries to read the rest of the input and extract an command or string
func ParseSequenceNumber ¶
ParseSequenceNumber tries to decode the packet sequence number of the provided input
func VerifyChecksum ¶
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 ¶
NewRCON create a new RCON server with the host (IP/interface), port and password provided, it will not start the server.
func (*RCON) Broadcast ¶
Broadcast send an message to all the connected clients it will handle the retry and acknowledgement of messages
func (*RCON) ListenAndServe ¶
ListenAndServe start the server on the udp ip/port provided and start handling packets
func (*RCON) NextSequenceNumber ¶
NextSequenceNumber returns the Next sequence number to be used on the MakeServerMessagePacket call
func (*RCON) OnCommand ¶
OnCommand can be used to register a callback to be executed once the server receives a command
func (*RCON) SendResponse ¶
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 ¶
SetIPBanList defines the ip ban list to be used to avoid certain ips