rustcon

package module
v0.0.0-...-c7d62d3 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 7 Imported by: 0

README

RustCON Go

RustCON Go is a Go library for interacting with Rust servers via WebSockets (Web RCON)

Installation

go get github.com/rustcon/rustcon-go

Example Usage

package main

import (
    "fmt"
    "log"
    "time"

    "github.com/rustcon/rustcon-go"
)

func main() {
    connection := &rustcon.RconConnection{
        IP:                      "127.0.0.1",
        Port:                    28016,
        Password:                "password",
        OnConnected: func() {
            fmt.Println("Connected to RCON")

            connection.SendCommand("say Hello World!")

            go func() {
                <-time.After(10 * time.Second)
                connection.Disconnect()
            }()
        },
        OnMessage: func(genericMessage *rustcon.GenericMessage) {
            fmt.Println(genericMessage.Message)
        },
        OnChatMessage: func(chatMessage *rustcon.ChatMessage) {
            fmt.Println(chatMessage.Message)
        },
        OnDisconnected: func() {
            fmt.Println("Disconnected from RCON")
        },
    }

    if err := connection.Connect(); err != nil {
        log.Fatal(err)
    }
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatMessage

type ChatMessage struct {
	Channel  int64  `json:"Channel"`
	Message  string `json:"Message"`
	UserId   string `json:"UserId"`
	Username string `json:"Username"`
	Color    string `json:"Color"`
	Time     int64  `json:"Time"`
}

type Command

type Command struct {
	Identifier int    `json:"Identifier"`
	Message    string `json:"Message"`
	Name       string `json:"Name"`
}

type GenericMessage

type GenericMessage struct {
	Message    string `json:"Message"`
	Identifier int    `json:"Identifier"`
	Type       string `json:"Type"`
	Stacktrace string `json:"Stacktrace"`
}

type RconConnection

type RconConnection struct {
	IP       string
	Port     int
	Password string

	OnConnected    func()
	OnMessage      func(*GenericMessage)
	OnChatMessage  func(*ChatMessage)
	OnDisconnected func()
	// contains filtered or unexported fields
}

func NewRconConnection

func NewRconConnection(options RconConnectionOptions) *RconConnection

func (*RconConnection) Connect

func (r *RconConnection) Connect() error

func (*RconConnection) Disconnect

func (r *RconConnection) Disconnect() error

func (*RconConnection) SendCommand

func (r *RconConnection) SendCommand(command string) error

type RconConnectionOptions

type RconConnectionOptions struct {
	IP             string
	Port           int
	Password       string
	OnConnected    func()
	OnMessage      func(*GenericMessage)
	OnChatMessage  func(*ChatMessage)
	OnDisconnected func()
}

Jump to

Keyboard shortcuts

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