servers

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EXT_ACK                    = -1
	EXT_VERSION                = 105
	EXT_NO_ERROR               = 0
	EXT_ERROR                  = 1
	EXT_PLAYERSTATS_RESP_IDS   = -10
	EXT_PLAYERSTATS_RESP_STATS = -11
	EXT_UPTIME                 = 0
	EXT_PLAYERSTATS            = 1
	EXT_TEAMSCORE              = 2
)
View Source
const (
	// How long we wait before pruning an unused server
	SERVER_MAX_IDLE_TIME = time.Duration(10 * time.Minute)
)

Variables

This section is empty.

Functions

func FindIdentity

func FindIdentity() string

TODO this is bad, server identifiers can collide

Types

type ClientExtInfo

type ClientExtInfo struct {
	Client    int
	Ping      int
	Name      string
	Team      string
	Frags     int32
	Flags     int32
	Deaths    int32
	TeamKills int32
	Damage    int32
	Health    int32
	Armour    int32
	GunSelect int32
	Privilege int32
	State     int32
	Ip0       byte
	Ip1       byte
	Ip2       byte
}

func DecodeClientInfo

func DecodeClientInfo(p io.Packet) (*ClientExtInfo, error)

type ClientKick

type ClientKick struct {
	Client ingress.ClientID
	Reason int32
	Text   string
}

type ClientLeave

type ClientLeave struct {
	Client ingress.ClientID
	Num    ClientNum
}

type ClientName

type ClientName struct {
	Client ingress.ClientID
	Name   string
}

type ClientNum

type ClientNum int32

Sauerbraten servers assign each client a number. NOT the same thing as ClientID.

type ClientPacket

type ClientPacket struct {
	Client   ingress.ClientID
	Channel  uint8
	Messages []P.Message
	Server   *GameServer
}

type ENetDatagram

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

func NewENetDatagram

func NewENetDatagram() *ENetDatagram

func (*ENetDatagram) Poll

func (i *ENetDatagram) Poll(ctx context.Context) <-chan PingEvent

func (*ENetDatagram) Serve

func (i *ENetDatagram) Serve(port int) error

func (*ENetDatagram) Shutdown

func (i *ENetDatagram) Shutdown()

type GameServer

type GameServer struct {
	*gameserver.Server

	Id string
	// Another way for the client to refer to this server
	Alias string

	Entities []maps.Entity

	// Whether this map was in our assets (ie can we send it to the client)
	IsBuiltMap bool

	Hidden bool

	// The last time a client connected
	LastEvent time.Time
	Started   time.Time

	Mutex deadlock.RWMutex

	From *P.MessageProxy
	To   *P.MessageProxy
	// contains filtered or unexported fields
}

func (*GameServer) GetClientInfo

func (s *GameServer) GetClientInfo() []*ClientExtInfo

func (*GameServer) GetEntities

func (server *GameServer) GetEntities() []maps.Entity

func (*GameServer) GetFormattedReference

func (server *GameServer) GetFormattedReference() string

func (*GameServer) GetServerInfo

func (s *GameServer) GetServerInfo() *ServerInfo

func (*GameServer) GetTeamInfo

func (s *GameServer) GetTeamInfo() *TeamInfo

func (*GameServer) GetUptime

func (s *GameServer) GetUptime() int

func (*GameServer) IsReference

func (server *GameServer) IsReference(reference string) bool

Whether this string is a reference to this server (either an alias or an id).

func (*GameServer) Logger

func (server *GameServer) Logger() zerolog.Logger

func (*GameServer) Reference

func (server *GameServer) Reference() string

func (*GameServer) Shutdown

func (server *GameServer) Shutdown()

type InfoProvider

type InfoProvider interface {
	GetServerInfo() *ServerInfo
	GetClientInfo() []*ClientExtInfo
	GetTeamInfo() *TeamInfo
	GetUptime() int // seconds
}

type MapRequest

type MapRequest struct {
	Map  string
	Mode int32
}

type PingEvent

type PingEvent struct {
	Request  []byte
	Response chan []byte
}

type ServerInfo

type ServerInfo struct {
	NumClients int32
	GamePaused bool
	GameMode   int32
	// Seconds
	TimeLeft     int32
	MaxClients   int32
	PasswordMode int32
	GameSpeed    int32
	Map          string
	Description  string
}

func DecodeServerInfo

func DecodeServerInfo(p io.Packet) (*ServerInfo, error)

type ServerInfoService

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

func NewServerInfoService

func NewServerInfoService(provider InfoProvider) *ServerInfoService

func (*ServerInfoService) Handle

func (s *ServerInfoService) Handle(request *io.Packet, out chan []byte) error

func (*ServerInfoService) PollMaster

func (s *ServerInfoService) PollMaster(ctx context.Context, port int)

func (*ServerInfoService) Serve

func (s *ServerInfoService) Serve(ctx context.Context, port int, registerMaster bool) error

func (*ServerInfoService) Shutdown

func (s *ServerInfoService) Shutdown()

func (*ServerInfoService) UpdateMaster

func (s *ServerInfoService) UpdateMaster(port int) error

type ServerManager

type ServerManager struct {
	Servers []*GameServer
	Receive chan []byte
	Mutex   sync.Mutex

	Maps *assets.AssetFetcher
	// contains filtered or unexported fields
}

func NewServerManager

func NewServerManager(
	maps *assets.AssetFetcher,
	serverDescription string,
	presets []config.Preset,
) *ServerManager

func (*ServerManager) FindPreset

func (manager *ServerManager) FindPreset(presetName string, isVirtualOk bool) opt.Option[config.Preset]

func (*ServerManager) GetServerInfo

func (manager *ServerManager) GetServerInfo() *ServerInfo

func (*ServerManager) NewServer

func (manager *ServerManager) NewServer(ctx context.Context, presetName string, isVirtualOk bool) (*GameServer, error)

func (*ServerManager) PollMapRequests

func (manager *ServerManager) PollMapRequests(ctx context.Context, server *GameServer)

func (*ServerManager) PruneServers

func (manager *ServerManager) PruneServers(ctx context.Context)

func (*ServerManager) ReadEntities

func (manager *ServerManager) ReadEntities(ctx context.Context, server *GameServer, data []byte) error

func (*ServerManager) ReceiveKicks

func (manager *ServerManager) ReceiveKicks() <-chan ClientKick

func (*ServerManager) ReceivePackets

func (manager *ServerManager) ReceivePackets() <-chan ClientPacket

func (*ServerManager) RemoveServer

func (manager *ServerManager) RemoveServer(server *GameServer)

func (*ServerManager) Shutdown

func (manager *ServerManager) Shutdown()

func (*ServerManager) Start

func (manager *ServerManager) Start() error

type ServerUptime

type ServerUptime struct {
	TimeUp int
}

func DecodeServerUptime

func DecodeServerUptime(p io.Packet) (*ServerUptime, error)

type TeamInfo

type TeamInfo struct {
	IsDeathmatch bool
	GameMode     int
	TimeLeft     int // seconds
	Scores       []TeamScore
}

func DecodeTeamInfo

func DecodeTeamInfo(p io.Packet) (*TeamInfo, error)

type TeamScore

type TeamScore struct {
	Team  string
	Score int
	Bases []int
}

Jump to

Keyboard shortcuts

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