master

package
v1.0.304 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

A master is an index of public Q2 servers. Servers need to be instructed to report to a specific master. All versions of R1Q2 and Q2Pro have `master.q2servers.com` hard coded as the default master. Servers will not report to a master unless they are set as public: `set public 1`

A server will send a heartbeat every few minutes to announce it's still alive.

Server commands:

`listmasters` - Show the currently configured masters.
`setmaster`   - Sets a comma-separated list of masters to use. To remove
                a master, issue this command again minus the server to
                remove.

Servers can typically support up to 8 different masters.

Index

Constants

View Source
const (
	DefaultListenPort    = 27900
	DefaultListenAddr    = "[::]" // Any IPv4/IPv6
	DefaultThinkInterval = 360    // secs
	DefaultPingInterval  = 360    // secs
)

Variables

This section is empty.

Functions

func Ack added in v1.0.298

func Ack(m *MasterServer, from *net.Addr)

A client sends us an Ack when we "ping" them (from management)

func ClientList added in v1.0.298

func ClientList(m *MasterServer, recip *net.Addr)

Someone requested a list of all Q2 servers we know about.

func Heartbeat added in v1.0.298

func Heartbeat(m *MasterServer, from *net.Addr, info map[string]string)

Sent from client to us every 5-10ish or so minutes.

func RemoveClient added in v1.0.298

func RemoveClient(m *MasterServer, from *net.Addr)

Removes a client from the client slice.

func Send added in v1.0.298

func Send(cmd string, m *MasterServer, recip *net.Addr)

For sending simple "ack"s and "ping"s

func Shutdown added in v1.0.298

func Shutdown(m *MasterServer, from *net.Addr)

Clients issue Shutdown msgs when they quit or go non-public

func Think added in v1.0.298

func Think(ctx context.Context, m *MasterServer)

Periodically checks in on each client, pruning dead ones. This should be run concurrently.

Types

type Client added in v1.0.298

type Client struct {
	Host string
	Port int
}

type MasterClient

type MasterClient struct {
	Active       bool
	Address      net.Addr // ip and port (192.0.2.1:27910)
	Country      string   // 2 letter code, e.g. "US", "AU", "IE"
	CurrentMap   string
	FirstContact time.Time
	GameDir      string
	Heartbeats   int
	Hostname     string
	Info         map[string]string
	IP           net.IP
	LastContact  time.Time
	MaxPlayers   int
	Missedbeats  int
	Passworded   bool
	PendingAcks  int
	Players      []MasterClientPlayer
	Port         int
	Software     string
}

A public Q2 server, also a client for the master

func ParseMasterResponse added in v1.0.298

func ParseMasterResponse(data *message.Buffer) []MasterClient

ParseMasterResponse will break up the bytes returned from the master server into a slice of MasterClient structs. The only the `IP` and `Port` fields will be populated.

Currently only IPv4 responses are supported. Adding support for IPv6 will mostly likely require a protocol change so clients will know weather to read 4 or 16 bytes.

func Ping added in v1.0.298

func Ping(m *MasterServer, from *net.Addr) *MasterClient

An unfamiliar server started talking to us. Start tracking it.

func (*MasterClient) Marshal

func (cl *MasterClient) Marshal() *message.Buffer

Write this MasterClient's IP and port in a format that can be sent as a response

type MasterClientPlayer

type MasterClientPlayer struct {
	ConnectTime time.Time // first seen
	Country     string    // 2 char code
	Name        string    // 15 chars max
	Ping        int       // in milliseconds
	Score       int       // specs will be 0
}

type MasterServer

type MasterServer struct {
	AckFunc        func(m *MasterServer, from *net.Addr)
	Address        string // IP or DNS name
	ClientListFunc func(m *MasterServer, recip *net.Addr)
	Clients        []MasterClient  // our known q2 server
	Conn           *net.PacketConn // the socket
	GeoIPs         *state.GeoIPList
	HeartbeatFunc  func(m *MasterServer, from *net.Addr, info map[string]string)
	PingFunc       func(m *MasterServer, from *net.Addr) *MasterClient
	PingInterval   int
	Port           int // default 27900
	ProcessFunc    func(m *MasterServer)
	Refresh        bool // fetch players every minute or so
	ShutdownFunc   func(m *MasterServer, from *net.Addr)
	Stats          MasterServerStats
	ThinkFunc      func(ctx context.Context, m *MasterServer)
	ThinkInterval  int // seconds between thinks
}

the all-knowning master server

func NewMaster added in v1.0.87

func NewMaster() *MasterServer

Setup a new server struct with default function calls and values

func (*MasterServer) DetailRefresher added in v1.0.300

func (m *MasterServer) DetailRefresher(ctx context.Context)

Once a minute, issue an out-of-band "info" request to each server to fetch the map and status for of the players. This should be run as a concurrent goroutine.

func (*MasterServer) FetchPublicServers added in v1.0.298

func (m *MasterServer) FetchPublicServers() ([]MasterClient, error)

FetchPublicServers will ask a master server for the list of servers sending heartbeats to it. The master server knows nothing more about these game servers than their IP and port and that they're alive and active.

func (MasterServer) FetchServers

func (m MasterServer) FetchServers() ([]MasterClient, error)

Grab all servers

func (*MasterServer) FindClient

func (m *MasterServer) FindClient(cl net.Addr) *MasterClient

Get a pointer to the client struct related to this IP address

func (*MasterServer) HeartbeatCount

func (m *MasterServer) HeartbeatCount() int

Calculate the total number of heartbeats this server has seen from all clients.

func (*MasterServer) MarshalClients

func (m *MasterServer) MarshalClients() *message.Buffer

Write all MasterClient's info to a buffer for responding

func (*MasterServer) Run added in v1.0.87

func (m *MasterServer) Run(ctx context.Context)

start the actual server

type MasterServerStats

type MasterServerStats struct {
	GetServerHits int       // how many times GetServers/query was issued
	PlayerCount   int       // how many players are known?
	ServerCount   int       // how many q2 servers are registered
	StartTime     time.Time // when the server started
}

Jump to

Keyboard shortcuts

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