gorcon

package module
v0.0.0-...-88c621d Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2014 License: MPL-2.0 Imports: 6 Imported by: 0

README

gorcon

gorcon package contains the essential functions needed for, connecting to & running commands on, BF2CC based Rcon servers.

EXAMPLES:

Basic:

package main

import (
	"fmt"
	"github.com/lee8oi/gorcon"
)

func main() {
	var r gorcon.Rcon
	if err := r.Connect("ADDRESS:PORT"); err != nil {
		fmt.Println(err)
		return
	}
	if err := r.Login(ADMINNAME, PASSWORD); err != nil {
		fmt.Println(err)
		return
	}
	result, err := r.Send("RCON COMMAND")
	if err != nil {
		fmt.Println(err)
	}
	if len(result) > 1 {
		fmt.Println(result)
	}
}

Command console including Reconnect & Config:

package main

import (
	"bufio"
	"fmt"
	"github.com/lee8oi/gorcon"
	"os"
)

var config = gorcon.Config{
	Admin:    "Gorcon",
	Address:  "123.123.123.123",
	Pass:     "SeCrEtPaSsWoRd",
	RconPort: "18666",
}

func main() {
	var r gorcon.Rcon
	if err := r.Connect(config.Address + ":" + config.Port); err != nil {
		fmt.Println(err)
		return
	}
	if err := r.Login(config.Admin, config.Pass); err != nil {
		fmt.Println(err)
		return
	}
	r.AutoReconnect("30s") //see time.ParseDuration for valid time units
	go r.Init()
	go r.Handler(handle)
	for {
		in := bufio.NewReader(os.Stdin)
		line, err := in.ReadString('\n')
		if err != nil {
			fmt.Println(err)
			return
		}
		if len(line) > 1 {
			r.Enqueue(line)
		}
	}
}
func handle(s string) {
	fmt.Println(s)
}

Documentation

Overview

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

gorcon version 14.1.13 (lee8oi)

gorcon package contains the essential functions needed for, connecting to & running commands on, BF2CC based Rcon servers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Admin, Address, Port, Pass string
}

type Rcon

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

func (*Rcon) AutoReconnect

func (r *Rcon) AutoReconnect(wait string)

AutoReconnect enables reconnection. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h" (see time.ParseDuration doc).

func (*Rcon) Connect

func (r *Rcon) Connect(address string) (err error)

Connect establishes connection to specified address and stores encryption seed used by Login().

func (*Rcon) Enqueue

func (r *Rcon) Enqueue(line string)

Enqueue adds a command line to the Queue to be written to the Rcon connection via Writer.

func (*Rcon) Handler

func (r *Rcon) Handler(f func(string))

Handler listens on the receive channel for data from the Reader. Runs the given function on the resulting string data.

func (*Rcon) Init

func (r *Rcon) Init()

Init initializes Reader & Writer routines. Also initializes necessary channels and starts the Queue for handling outgoing commands with Enqueue().

func (*Rcon) Login

func (r *Rcon) Login(admin, pass string) (err error)

Login encrypts seed & pass, performs authentication with Rcon server.

func (*Rcon) Queue

func (r *Rcon) Queue(dur time.Duration)

Queue sequentially handles outgoing commands being sent to the Rcon connection. Waits duration before processing next item in queue.

func (*Rcon) Reader

func (r *Rcon) Reader()

Reader reads all incoming socket data and sends it to the receiving channel. Includes reconnection on connect errors.

func (*Rcon) Reconnect

func (r *Rcon) Reconnect() error

Reconnect attempts to re-establish Rcon connection. Waiting duration & trying again on failure.

func (*Rcon) Scan

func (r *Rcon) Scan(str string) (s string)

Scan parses incoming socket data for specified string & returns the data found.

func (*Rcon) Send

func (r *Rcon) Send(command string) (string, error)

Send is a synchronous style function, independant of the Reader & Writer, used to write a command to the socket and returning the resulting data as a string. Includes reconnection on connect errors.

func (*Rcon) Write

func (r *Rcon) Write(message string)

Write sends a message to Rcon.send channel to be written out by Writer().

func (*Rcon) Writer

func (r *Rcon) Writer()

Writer handles writing send channel data to the socket. Waits if connection is not authenticated.

Directories

Path Synopsis
The log package is used to log messages to the web via gorilla websocket.
The log package is used to log messages to the web via gorilla websocket.
track is used for tracking player stats & chat messages.
track is used for tracking player stats & chat messages.

Jump to

Keyboard shortcuts

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