source

package module
v0.0.0-...-cb29ef5 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

Source Go Report Card License GoDoc Build Status

go-source is a Go client for the Source RCON Protocol.

Features

Supports

Installation

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

Examples

Using go-source is simple just create a client, login and then send commands e.g.

package main

import (
	"log"

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

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

	if s, err := c.Exec("status"); err != nil {
		log.Fatal(err)
	} else {
		log.Println("server status:", s)
	}
}

Documentation

License

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

Documentation

Overview

Package source provides a client which can talk to game servers which support the source RCON protocol: https://developer.valvesoftware.com/wiki/Source_RCON_Protocol

Index

Constants

View Source
const (
	// DefaultPort is the default source RCON port.
	DefaultPort = 27015
)

Variables

View Source
var (
	// ErrNilOption is returned by NewClient if an option is nil.
	ErrNilOption = errors.New("source: nil option")

	// ErrNonASCII is returned if a command with non-ASCII characters is attempted.
	ErrNonASCII = errors.New("source: non-ascii body")

	// ErrAuthFailure is returned if the client failed to authenticate.
	ErrAuthFailure = errors.New("source: authentication failure")
)
View Source
var (
	// DefaultTimeout is the default read / write / dial timeout for Clients.
	DefaultTimeout = time.Second * 10
)

Functions

func DisableMultiPacket

func DisableMultiPacket() func(*Client) error

DisableMultiPacket disables multi-packet support, which not all servers support. This is required for Minecraft and Starbound servers.

func Password

func Password(pwd string) func(*Client) error

Password sets authentication password for a source rcon Client.

func Timeout

func Timeout(timeout time.Duration) func(*Client) error

Timeout sets read / write / dial timeout for a source rcon Client.

Types

type Client

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

Client is a source rcon client.

func NewClient

func NewClient(addr string, options ...func(c *Client) error) (c *Client, err error)

NewClient returns a new source rcon client connected to addr. If addr doesn't include a port the DefaultPort will be used.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection to the server.

func (*Client) Exec

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

Exec creates a new Cmd from cmd and calls ExecCmd with it. If cmd contains non-ASCII characters it returns ErrNonASCII.

func (*Client) ExecCmd

func (c *Client) ExecCmd(cmd *Cmd) (resp string, err error)

ExecCmd executes cmd on the server and returns the response. If cmd contains non-ASCII characters it returns ErrNonASCII.

type Cmd

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

Cmd represents a source rcon command.

func NewCmd

func NewCmd(cmd string) *Cmd

NewCmd creates a new Cmd.

func (*Cmd) String

func (c *Cmd) String() string

func (*Cmd) WithArgs

func (c *Cmd) WithArgs(args ...interface{}) *Cmd

WithArgs sets the command Args.

type ErrMalformedResponse

type ErrMalformedResponse string

ErrMalformedResponse is returned if the response from the server is malformed.

func (ErrMalformedResponse) Error

func (e ErrMalformedResponse) Error() string

Jump to

Keyboard shortcuts

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