state

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: 10 Imported by: 3

Documentation

Overview

These functions relate to figuring out the physical location of a particular player. The current granularity is limited to the country.

This functionlity depends on the IP-to-Country Lite CSV list downloaded from: https://db-ip.com/db/download/ip-to-country-lite. Any list will work really, but each record is expected to be in the following format:

x.x.x.x,y.y.y.y,zz

Where x.x.x.x is the first IP in a range, y.y.y.y is the last IP in a range and zz is the Alpha-2 ISO 3166 country code.

Note: these are not CIDR ranges and not even expected to be within the appropriate byte-boundaries for them. Converting these into actual CIDR ranges will in many cases result in a single record resolving to multiple CIDR ranges and possibly include some unintended top-end space. Just keep them as literal ranges of addresses.

Example 63.254.184.0 to 64.4.0.1 overlaps two different class As and various byte boundaries. This range would resolve to:

[
 63.254.184.0/21,
 63.254.192.0/18,
 63.255.0.0/16,
 64.0.0.0/14,
 64.4.0.0/31,
]

Not only is this a mega-bitch to caculate it'll result in 4 extra lookups to match an IP. Don't even get me started on doing this for IPv6 🤮

Index

Constants

View Source
const (
	CmdBad = iota
	CmdNoOp
	CmdMove
)
View Source
const (
	GZipMagic = 35615 // 0x1f 0x8b
)

Variables

This section is empty.

Functions

func ParseInfoString

func ParseInfoString(info string) map[string]string

Parse and info string (in the format of: "\key1\val1\key2\val2\key3\val3\" into a key/value map)

Types

type GeoIP added in v1.0.303

type GeoIP struct {
	First   net.IP
	Last    net.IP
	Country string // 2 character country code
}

A mapping of an IP range to a particular country. We can't use a *net.IPNet because first and last addresses aren't necessarily in the same CIDR range.

Supports IPv4 and IPv6

type GeoIPList added in v1.0.303

type GeoIPList []GeoIP

Make the list a type for use as a func receiver.

func LoadGeoIPData added in v1.0.303

func LoadGeoIPData(data []byte) (GeoIPList, error)

Create the list of GeoIPs from raw bytes. Also determines if the data is compressed and handles that situation transparently. Only Gzip compression is supported.

func LoadGeoIPFile added in v1.0.303

func LoadGeoIPFile(inputFile string) (GeoIPList, error)

Read each line of the ip-to-country database file into memory. This file should be in the format:

func (*GeoIPList) Lookup added in v1.0.303

func (n *GeoIPList) Lookup(addr string) string

Get the country code for a particular IP address string. Output of "zz" is considered country-less (think RFC1918). This is also used for any address not found in the list.

type Rcon

type Rcon struct {
	Serverinfo *Server
	Input      string
	Output     string
}

type Server

type Server struct {
	Address  string // IP or DNS name
	Port     int
	Password string // rcon
}

func NewServer added in v1.0.242

func NewServer(srv string) (Server, error)

func (*Server) DoRcon

func (s *Server) DoRcon(str string) (Rcon, error)

func (*Server) FetchInfo

func (s *Server) FetchInfo() (ServerInfo, error)

type ServerInfo

type ServerInfo struct {
	Server  map[string]string
	Players []struct {
		Name  string
		Score int
		Ping  int
	}
}

type UserCmd added in v1.0.87

type UserCmd struct {
	Msec         byte
	Buttons      byte
	Angles       client.Angles // viewangles
	MoveForward  int16
	MoveSideways int16
	MoveUp       int16
	Impulse      byte
	LightLevel   byte
}

Jump to

Keyboard shortcuts

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