valve

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

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 9 Imported by: 0

README

Go A2S

An implementation of Source A2S Queries

Guides

Installing

go get -u github.com/oxxzz/valve

Querying

package main

import (
 "fmt"
 "time"

 "github.com/oxxzz/valve"
)

func main() {
 servers := []string{
  "62.234.169.62:26666",
  // ....
 }

 for i := 0; i < len(servers); i++ {
  c, err := valve.NewClient(servers[i], 3*time.Second)
  if err != nil {
   fmt.Printf("server %s => error: %v\n", servers[i], err)
   continue
  }
  // Ping
  fmt.Println(c.Ping())
  fmt.Println(c.Players())
  fmt.Println(c.Info())
  fmt.Println(c.Rules())

  c.Close()
 }
}

TODO

  • RCON

Documentation

Index

Constants

View Source
const PingReply = 0x6a
View Source
const PingRequest = 0x69

Variables

View Source
var ErrBadPacketHeader = errors.New("bad packet header")
View Source
var ErrUnknownInfoVersion = errors.New("unknown A2S_INFO version")

Functions

func Try

func Try(fn func() error) error

Types

type Client

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

Client is a client for the Valve source query protocol

func NewClient

func NewClient(addr string, timeout time.Duration) (*Client, error)

NewClient creates a new client

func (*Client) Close

func (c *Client) Close() error

Close closes the underlying socket

func (*Client) Connect

func (c *Client) Connect() error

func (*Client) Info

func (c *Client) Info() (*types.Server, error)

Info gets the server info

func (*Client) Ping

func (c *Client) Ping() (uint, error)

Ping gets the server ping in milliseconds

func (*Client) Players

func (c *Client) Players() (*types.PlayerList, error)

Players gets the server players

func (*Client) Reconnect

func (c *Client) Reconnect() error

func (*Client) Rules

func (c *Client) Rules() (map[string]string, error)

type MultiPacketHeader

type MultiPacketHeader struct {
	// Size of the packet header itself.
	Size int

	// Packet sequence id.
	Id uint32

	// Packet number out of Total Packets.
	PacketNumber uint8

	// Total number of packets to receive.
	TotalPackets uint8

	// Packet size (0 if not present).
	PacketSize uint16

	// Compression information.
	Compressed bool

	Payload []byte
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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