protocol

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderSize = 8
View Source
const MaxDataSize = MaxPacketSize - HeaderSize
View Source
const MaxPacketSize = 1500 // standard packet MTU
View Source
const RequestAllPackets = 0xff
View Source
const Version = 0x10
View Source
const VersionExt = 0x69

Variables

View Source
var ErrorEmptyPacket = errors.New("empty packet received")
View Source
var (
	ErrorPascalStringTooLong = errors.New("pascal string too long")
)
View Source
var ErrorUnknownPacketVersion = errors.New("unknown packet version")

Functions

func Clen

func Clen(n []byte) int

Clen returns the position of the first null byte in a given byte slice for null-terminated c strings, this returns the length of the string function was yanked from a golang stdlib private method.

func NewServersMapFromList added in v1.2.0

func NewServersMapFromList(input []string) map[string]*Server

func ReadCString added in v1.2.0

func ReadCString(input []byte) string

func ReadPascalString added in v1.2.0

func ReadPascalString(input []byte) string

func ReadPascalStringStream added in v1.2.0

func ReadPascalStringStream(input []byte) (string, []byte)

func WriteCString added in v1.2.0

func WriteCString(input string) []byte

func WritePascalString added in v1.2.0

func WritePascalString(input string) ([]byte, error)

Types

type Options added in v1.1.0

type Options struct {
	Search  map[string]*Server
	Timeout time.Duration
	Debug   bool

	MaxServerPacketSize uint16
	PacketKey           uint16
}

type Packet

type Packet struct {
	Version byte
	Type    PacketType
	Number  byte   // packet number out of total; starts at 1
	Total   byte   // total packets of info
	Key     uint16 // used for verification and (transaction) id purposes
	ID      uint16 // master server id (read from config file)
	Data    []byte // MaxSize = (MaxPacketSize - HeaderSize)

	// implements
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
	fmt.Stringer
}

func NewPacket

func NewPacket() *Packet

func NewPacketWithData added in v1.2.0

func NewPacketWithData(data []byte) (*Packet, error)

func (*Packet) MarshalBinary

func (p *Packet) MarshalBinary() ([]byte, error)

func (*Packet) String

func (p *Packet) String() string

func (*Packet) UnmarshalBinary

func (p *Packet) UnmarshalBinary(data []byte) error

type PacketType

type PacketType int
const (
	PingInfoQuery PacketType = iota + 0x03
	PingInfoResponse
	MasterServerHeartbeat
	MasterServerList
	GameInfoQuery
	GameInfoResponse
)

func (PacketType) String

func (p PacketType) String() string

type Server added in v1.2.0

type Server struct {
	Address    *net.UDPAddr
	Connection *net.PacketConn
	LastSeen   time.Time
	TTL        int
	Info       *Packet
}

func NewServerFromString added in v1.2.0

func NewServerFromString(input string, ttl int) (*Server, error)

func (Server) IsExpired added in v1.2.0

func (s Server) IsExpired() bool

func (Server) String added in v1.2.0

func (s Server) String() string

Jump to

Keyboard shortcuts

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