battleye

package module
v0.0.0-...-5c3fa7b Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2017 License: BSD-2-Clause Imports: 9 Imported by: 0

README

BattlEye Go Report Card License GoDoc Build Status

go-battleye is a Go client for the BattlEye RCON Protocol.

Features

  • Full BattlEye RCON support.
  • Multi-packet response support.
  • Auto keep-alive support.

Installation

go get -u github.com/multiplay/go-battleye

Examples

Using go-battleye is simple, just create a client then execute commands e.g.

package main

import (
	"log"

	battleye "github.com/multiplay/go-battleye"
)

func main() {
	c, err := battleye.NewClient("192.168.1.102:2301", "mypass")
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()

	resp, err := c.Exec("version")
	if err != nil {
		log.Fatal(err)
	}
	log.Println("server version:", resp)
}

Server broadcast messages arrive in a buffered read-only channel. By default, there is room for 100 messages. You can get more by using the MessageBuffer option in the client constructor:

battleye.NewClient("192.168.1.102:2301", "mypass", battleye.MessageBuffer(500))

If the channel gets full, new messages will be dropped. It is your responsibility to drain the channel, e.g.:

func LogServerMessages(c *battleye.Client) {
	for {
		switch {
		case msg := <-c.Messages():
			log.Println(msg)

		// Another case to exit the for loop.
		// ...
		}
	}
}

Run integration test using your own BattlEye server:

go test -v -tags=integration -run=Integration -address=<BattlEye server address> -password=<admin password>

Documentation

License

go-battleye is available under the BSD 2-Clause License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidMessageBufferSize is returned if MessageBuffer Option is used with a size less than 1.
	ErrInvalidMessageBufferSize = errors.New("battleye: invalid message buffer size")

	// ErrInvalidPacketSize is returned if the packet size is less than the minimum size.
	ErrInvalidPacketSize = errors.New("battleye: invalid packet size")

	// ErrInvalidHeader is returned if packet does not start with 0x42, 0x45 (BE).
	ErrInvalidHeader = errors.New("battleye: invalid header")

	// ErrInvalidChecksum is returned the checksum in the packet header is invalid.
	ErrInvalidChecksum = errors.New("battleye: invalid checksum")

	// ErrInvalidEndOfHeader is returned if the last byte of the header is not 0xff.
	ErrInvalidEndOfHeader = errors.New("battleye: invalid end of header")

	// ErrUnknownPacketType is returned if packet type cannot be determined.
	ErrUnknownPacketType = errors.New("battleye: unknown packet type")

	// ErrInvalidLoginResponse is returned if the response byte in the login response is invalid.
	ErrInvalidLoginResponse = errors.New("battleye: invalid login response")

	// ErrNilOption is returned by NewClient if an Option is nil.
	ErrNilOption = errors.New("battleye: nil option")

	// ErrLoginFailed is returned by NewClient if it was unable to connect to the server due to auth failure.
	ErrLoginFailed = errors.New("battleye: login failed")

	// ErrTimeout is returned after the timeout period elapsed while waiting for response or error from the BattlEye server.
	ErrTimeout = errors.New("battleye: timeout")
)

Functions

This section is empty.

Types

type Client

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

Client represents a BattlEye client.

func NewClient

func NewClient(addr string, pwd string, options ...Option) (*Client, error)

NewClient returns a new BattlEye client connected to address.

func (*Client) Close

func (c *Client) Close() error

Close gracefully closes the connection.

func (*Client) Exec

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

Exec executes the cmd on the BattlEye server and returns its response. Executing is retried for 45 seconds after which the Client is considered to be disconnected and ErrTimeout is returned. A disconnected Client is unlikely to get any more responses from the BattlEye server, so a new Client should be created.

func (*Client) Messages

func (c *Client) Messages() <-chan string

Messages returns a buffered channel containing the console messages sent by the server. If the channel is full new messages will be dropped. It is the user's responsibility to drain the channel and handle these messages.

type Option

type Option func(c *Client) error

Option is a Client configuration Option type.

func KeepAlive

func KeepAlive(interval time.Duration) Option

KeepAlive sets the keep-alive message interval for a Client.

func MessageBuffer

func MessageBuffer(size int) Option

MessageBuffer sets the size of the Messages channel buffer.

func Timeout

func Timeout(timeout time.Duration) Option

Timeout sets the connection read / write timeout for a Client.

Jump to

Keyboard shortcuts

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