lobby

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2020 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package lobby implements a mocked Warcraft III game server that can be used to host lobbies.

Index

Constants

View Source
const LagDelay = 2 * time.Second

LagDelay timeout before showing lag screen

View Source
const LagRecoverDelay = 1 * time.Second

LagRecoverDelay timeout before ending lag screen

View Source
const ObsDisabled uint8 = 0xFF

ObsDisabled constant

Variables

View Source
var (
	ErrFull            = errors.New("lobby: Lobby is full")
	ErrLocked          = errors.New("lobby: Lobby is locked")
	ErrInvalidArgument = errors.New("lobby: Invalid argument")
	ErrInvalidSlot     = errors.New("lobby: Invalid slot")
	ErrInvalidPacket   = errors.New("lobby: Invalid packet")
	ErrMapUnavailable  = errors.New("lobby: Map unavailable")
	ErrNotReady        = errors.New("lobby: Player was not ready")
	ErrPlayersOccupied = errors.New("lobby: No player slots left")
	ErrSlotOccupied    = errors.New("lobby: Slot occupied")
	ErrColorOccupied   = errors.New("lobby: Color occupied")
	ErrHighPing        = errors.New("lobby: Ping exceeds lag recovery delay")
	ErrStraggling      = errors.New("lobby: Player was straggling")
	ErrDesync          = errors.New("lobby: Timeslot checksum mismatch")
)

Errors

Functions

This section is empty.

Types

type Game

type Game struct {
	Lobby

	// Set once before Run(), read-only after that
	LoadTimeout  time.Duration
	LagTimeout   time.Duration
	LagObservers bool
	TurnRate     int
	// contains filtered or unexported fields
}

Game represents a game host

func NewGame

func NewGame(encoding w3gs.Encoding, slotInfo w3gs.SlotInfo, mapInfo w3gs.MapCheck) *Game

NewGame initializes a new Game struct

func (*Game) EnqueueAction

func (g *Game) EnqueueAction(a *w3gs.PlayerAction)

EnqueueAction for next TimeSlot

func (*Game) InitDefaultHandlers

func (g *Game) InitDefaultHandlers()

InitDefaultHandlers adds the default callbacks for relevant packets

func (*Game) Stage

func (g *Game) Stage() Stage

Stage of game

func (*Game) Start

func (g *Game) Start() error

Start game

func (*Game) Tick

func (g *Game) Tick() Tick

Tick counter

type Lobby

type Lobby struct {
	network.EventEmitter

	// Set once before Run(), read-only after that
	w3gs.Encoder
	w3gs.MapCheck
	ObsTeam      uint8
	ColorSet     protocol.BitSet32
	ReadyTimeout time.Duration
	ShareAddr    bool
	// contains filtered or unexported fields
}

Lobby represents a mocked game lobby Public methods/fields are thread-safe unless explicitly stated otherwise

func NewLobby

func NewLobby(encoding w3gs.Encoding, slotInfo w3gs.SlotInfo, mapInfo w3gs.MapCheck) *Lobby

NewLobby initializes a new Lobby struct

func (*Lobby) Accept

func (l *Lobby) Accept(conn net.Conn) (*Player, error)

Accept a new player connection

func (*Lobby) ChangeColor

func (l *Lobby) ChangeColor(sid int, c uint8) error

ChangeColor to c for sid

func (*Lobby) ChangeComputer

func (l *Lobby) ChangeComputer(sid int, ai w3gs.AI) error

ChangeComputer to ai for sid

func (*Lobby) ChangeHandicap

func (l *Lobby) ChangeHandicap(sid int, h uint8) error

ChangeHandicap to h for sid

func (*Lobby) ChangeRace

func (l *Lobby) ChangeRace(sid int, r w3gs.RacePref) error

ChangeRace to r for sid

func (*Lobby) ChangeTeam

func (l *Lobby) ChangeTeam(sid int, t uint8) error

ChangeTeam to t for sid

func (*Lobby) Close

func (l *Lobby) Close()

Close closes all connections to players

func (*Lobby) CloseAllSlots

func (l *Lobby) CloseAllSlots() error

CloseAllSlots closes all open slots

func (*Lobby) CloseSlot

func (l *Lobby) CloseSlot(sid int, kick bool) error

CloseSlot by sid, optionally kick if occupied

func (*Lobby) CountPlayers

func (l *Lobby) CountPlayers() int

CountPlayers that are not observing

func (*Lobby) JoinAndServe

func (l *Lobby) JoinAndServe(conn net.Conn, join *w3gs.Join) (*Player, error)

JoinAndServe player connection

func (*Lobby) Lock

func (l *Lobby) Lock()

Lock lobby, disabling joins and slot changes

func (*Lobby) OpenAllSlots

func (l *Lobby) OpenAllSlots() error

OpenAllSlots opens all closed slots

func (*Lobby) OpenSlot

func (l *Lobby) OpenSlot(sid int, kick bool) error

OpenSlot by sid, optionally kick if occupied

func (*Lobby) Player

func (l *Lobby) Player(id uint8) *Player

Player returns Player for id

func (*Lobby) SendToAll

func (l *Lobby) SendToAll(pkt w3gs.Packet)

SendToAll players

func (*Lobby) ShuffleSlots

func (l *Lobby) ShuffleSlots(shuffleTeams bool) error

ShuffleSlots randomizes slots and teams

func (*Lobby) SlotInfo

func (l *Lobby) SlotInfo() *w3gs.SlotInfo

SlotInfo in current state

func (*Lobby) SlotsAvailable

func (l *Lobby) SlotsAvailable() int

SlotsAvailable counts open slots

func (*Lobby) SlotsUsed

func (l *Lobby) SlotsUsed() int

SlotsUsed counts occupied+closed slots

func (*Lobby) SwapSlots

func (l *Lobby) SwapSlots(slotA int, slotB int) error

SwapSlots slotA and slotB

func (*Lobby) Unlock

func (l *Lobby) Unlock()

Unlock lobby, enabling joins and slot changes

func (*Lobby) Wait

func (l *Lobby) Wait()

Wait for all goroutines to finish

type Player

type Player struct {
	network.EventEmitter
	network.W3GSConn

	// Set once before Run(), read-only after that
	PlayerInfo   w3gs.PlayerInfo
	StartTime    time.Time
	PingInterval time.Duration
	// contains filtered or unexported fields
}

Player represents a (real) player in game Public methods/fields are thread-safe unless explicitly stated otherwise

func NewPlayer

func NewPlayer(info *w3gs.PlayerInfo) *Player

NewPlayer initializes a new Player struct

func (*Player) BattleTag

func (p *Player) BattleTag() string

BattleTag for player

func (*Player) DequeueAck

func (p *Player) DequeueAck() (checksum uint32, ok bool, more bool)

DequeueAck from queue

func (*Player) InitDefaultHandlers

func (p *Player) InitDefaultHandlers()

InitDefaultHandlers adds the default callbacks for relevant packets

func (*Player) Kick

func (p *Player) Kick(reason w3gs.LeaveReason)

Kick from lobby

func (*Player) Lag

func (p *Player) Lag() bool

Lag in receiving packets

func (*Player) LeaveReason

func (p *Player) LeaveReason() w3gs.LeaveReason

LeaveReason from lobby

func (*Player) RTT

func (p *Player) RTT() uint32

RTT to host

func (*Player) Ready

func (p *Player) Ready() bool

Ready to start the game (ping and map packets received)

func (*Player) Run

func (p *Player) Run() error

Run reads packets and emits an event for each received packet Not safe for concurrent invocation

func (*Player) SendOrClose

func (p *Player) SendOrClose(pkt w3gs.Packet) (int, error)

SendOrClose sends pkt to player, closes connection on failure

func (*Player) Tick

func (p *Player) Tick() Tick

Tick counter

type PlayerChat

type PlayerChat struct {
	*Player
	*w3gs.Message
}

PlayerChat event

type PlayerJoined

type PlayerJoined struct {
	*Player
}

PlayerJoined event

type PlayerLeft

type PlayerLeft struct {
	*Player
}

PlayerLeft event

type Ready

type Ready struct{}

Ready event

type Stage

type Stage uint32

Stage enum

const (
	StageLobby Stage = iota
	StageLoading
	StagePlaying
	StageDone
)

Stage enums

func (Stage) String

func (s Stage) String() string

type StageChanged

type StageChanged struct {
	Old Stage
	New Stage
}

StageChanged event

type StartLag

type StartLag struct{}

StartLag event

type StopLag

type StopLag struct{}

StopLag event

type Tick

type Tick uint32

Tick counter

Jump to

Keyboard shortcuts

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