ts3

package module
v0.0.0-...-63d6426 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2016 License: MIT Imports: 9 Imported by: 0

README

#GO TS3 TeamSpeak 3 Server Query interface for Go

##Quick Start ###Connecting to a server It's as simple as

client, err := ts3.Dial("ts.example.com:10011")
defer client.Close()

###Sending a command - part 1

client.Command("clientlist")

###Sending a command - part 2

client.Commandf("login %s %s", "serveradmin", "12345")

###Sending a command - part 3

client.DoCommand(ts3command.GlobalMessage("TS3 is da bom"))

##Reading Responses For example, if I wanted to log all the names of connected clients

r, err := client.Command("clientlist")
arr := r.Array()

for _, c := range arr {
    log.Println(c["client_nickname"])
}

Or if I wanted to get my current client id

r, err := client.Command("whoami")
data := r.Map()

clid := data["client_id"]

Documentation

Overview

Package ts3 makes it easier to use with the TeamSpeak 3's Server Query interface

Index

Constants

View Source
const (
	// WelcomeMessage is used to match the welcome message received from the server
	WelcomeMessage = "TS3"
)

Variables

View Source
var (
	// ErrNoResponse is returned when the server doesn't response
	ErrNoResponse = errors.New("No response from the server query. Make sure your IP address is whitelisted.")
	// ErrBadResponseFormat is returned when the server returns a malformed response
	ErrBadResponseFormat = errors.New("The response is in the wrong format. Make sure your server software is up to date.")
	// ErrBadWelcome is returned when the server sends an unexpected welcome message
	ErrBadWelcome = errors.New("Got an unexpected welcome message.  Make sure you're connecting to a TeamSpeak 3 server.")
)
View Source
var (
	// WelcomeTimeout is the longest time to wait for
	// before assuming that the server will not respond
	WelcomeTimeout = 5 * time.Second
	// ResponseBufferSize is the largest number
	// of lines to hold in the receiving buffer
	ResponseBufferSize = 10
)

Functions

This section is empty.

Types

type Client

type Client struct {

	// NotifyFunc is called whenever a notify-prefixed
	// message is received from the server
	NotifyFunc func(response ServerResponse) error
	// DisconnectFunc is called when the client is disconnected
	// from the server and not does not try to reconnect
	DisconnectFunc func()
	// contains filtered or unexported fields
}

A Client interfaces with TeamSpeak 3's Server Query interface

func Dial

func Dial(address string) (*Client, error)

Dial opens a new connection to a TeamSpeak 3's Server Query

func DialTimeout

func DialTimeout(address string, timeout time.Duration) (*Client, error)

DialTimeout opens a new connection to a TeamSpeak 3's Server Query with a specific timeout.

func (*Client) Close

func (c *Client) Close() error

Close cuts the connection to the server

func (*Client) Command

func (c *Client) Command(command string) (ServerResponse, error)

Command sends a string command to the Server Query

func (*Client) Commandf

func (c *Client) Commandf(format string, a ...interface{}) (ServerResponse, error)

Commandf formats a string according to a format specifier and sends it to the Server Query.

func (*Client) DoCommand

func (c *Client) DoCommand(cmd Command) (ServerResponse, error)

DoCommand sends a command to the Server Query

type Command

type Command interface {
	Command() string
}

A Command is a wrapper for Server Query commands

type Error

type Error struct {
	Code    string
	Message string
}

A Error holds an error received from the Server Query

func (*Error) Error

func (err *Error) Error() string

Error formats and returns the error

type ServerResponse

type ServerResponse string

A ServerResponse is a wrapper for raw responses received from the server query

func (ServerResponse) Array

func (r ServerResponse) Array() []map[string]string

Array parses and returns the response data into an array when there is more than one set of data in the response.

func (ServerResponse) Header

func (r ServerResponse) Header() string

Header returns the first word of the raw response. Includes but is not limited to notify callbacks and error responses. Does not include words that are part of the response data.

func (ServerResponse) Map

func (r ServerResponse) Map() map[string]string

Map parses and returns the response data into a map when there is only one set of data in the response.

func (ServerResponse) String

func (r ServerResponse) String() string

String returns the raw response

Directories

Path Synopsis
Package ts3command binds to various TeamSpeak 3 Server Query commands
Package ts3command binds to various TeamSpeak 3 Server Query commands
Package ts3util contains helper functions for the ts3 package
Package ts3util contains helper functions for the ts3 package

Jump to

Keyboard shortcuts

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