protocol

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: MIT Imports: 13 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) (i 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 ReadCString

func ReadCString(input []byte) string

func ReadPascalString

func ReadPascalString(input []byte) string

func ReadPascalStringStream

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

func WriteCString

func WriteCString(input string) (output []byte)

func WritePascalString

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

Types

type GameInfo

type GameInfo struct {
	GameVersion string // es3a
	Hostname    string // string 1
	VersionInfo string // string 2
}

type Master

type Master struct {
	*Packet    `json:"-" csv:"-"`
	Address    string
	CommonName string
	MOTDJunk   string `json:"-" csv:"-"`
	MOTD       string
	Servers    map[string]*server.Server
	MasterID   uint16
}

func NewMaster

func NewMaster() (output *Master)

func NewMasterWithAddress added in v2.0.1

func NewMasterWithAddress(address string) (output *Master)

func (*Master) GeneratePackets

func (m *Master) GeneratePackets(options *Options, key uint16, laddr net.Addr, raddr net.Addr) [][]byte

func (*Master) MarshalBinaryHeader

func (m *Master) MarshalBinaryHeader() (output []byte)

func (*Master) MarshalBinarySet

func (m *Master) MarshalBinarySet(options *Options, input map[string]*server.Server, laddr net.Addr, raddr net.Addr) (output []byte)

MarshalBinarySet generates the body of a darkstar master packet laddr is the address of the interface the packet came in on raddr is the address of the request

func (*Master) UnmarshalBinary

func (m *Master) UnmarshalBinary(data []byte) (err error)

func (*Master) UnmarshalBinarySet

func (m *Master) UnmarshalBinarySet(data [][]byte) (err error)

type Options

type Options struct {
	Timeout       time.Duration
	LocalNetworks []*net.IPNet
	ExternalIP    net.IP
	Debug         bool

	MaxServerPacketSize  uint16
	MaxNetworkPacketSize uint16
}

type Packet

type Packet struct {
	Version byte
	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)
	Type    PacketType

	// implements
	encoding.BinaryMarshaler   `json:"-" csv:"-"`
	encoding.BinaryUnmarshaler `json:"-" csv:"-"`
	fmt.Stringer               `json:"-" csv:"-"`
}

func NewPacket

func NewPacket() *Packet

func NewPacketWithData

func NewPacketWithData(data []byte) (out *Packet, err 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 PingInfo

type PingInfo struct {
	GameMode    byte          `csv:"-"` // ??
	PlayerCount byte          `csv:"cur_players"`
	MaxPlayers  byte          `csv:"max_players"`
	GameStatus  StatusByte    `csv:"status"`
	Ping        time.Duration `csv:"ping"`
	GameName    []byte        `csv:"-"` // es3a
	GameVersion []byte        `csv:"-"` // V 001.000r
	Name        []byte        `csv:"server_name"`
	Address     string        `csv:"address"`
	*Packet     `json:"-" csv:"-"`
}

func (*PingInfo) MarshalBinary

func (s *PingInfo) MarshalBinary() ([]byte, error)

func (*PingInfo) MarshalJSON added in v2.1.1

func (s *PingInfo) MarshalJSON() ([]byte, error)

func (*PingInfo) String

func (s *PingInfo) String() string

func (*PingInfo) UnmarshalBinary

func (s *PingInfo) UnmarshalBinary(data []byte) error

type StatusBit

type StatusBit int
const (
	Protected StatusBit = 1 << iota
	Dedicated
	AllowOldClients
	Started
	Dynamix
	WON
	Reserved1
	Reserved2
)

type StatusByte

type StatusByte byte

func (StatusByte) MarshalJSON

func (s StatusByte) MarshalJSON() ([]byte, error)

func (StatusByte) String

func (s StatusByte) String() string

func (StatusByte) StringSlice

func (s StatusByte) StringSlice() (statusArr []string)

func (StatusByte) Struct

func (s StatusByte) Struct() (output StatusByteStruct)

type StatusByteStruct

type StatusByteStruct struct {
	Protected       bool
	Dedicated       bool
	AllowOldClients bool
	Started         bool
	Dynamix         bool
	WON             bool
	Reserved1       bool
	Reserved2       bool
}

func (StatusByteStruct) MarshalBinary

func (s StatusByteStruct) MarshalBinary() (output byte)

Jump to

Keyboard shortcuts

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