Documentation ¶
Overview ¶
Package lobby implements a mocked Warcraft III game server that can be used to host lobbies.
Index ¶
- Constants
- Variables
- type Game
- type Lobby
- func (l *Lobby) Accept(conn net.Conn) (*Player, error)
- func (l *Lobby) ChangeColor(sid int, c uint8) error
- func (l *Lobby) ChangeComputer(sid int, ai w3gs.AI) error
- func (l *Lobby) ChangeHandicap(sid int, h uint8) error
- func (l *Lobby) ChangeRace(sid int, r w3gs.RacePref) error
- func (l *Lobby) ChangeTeam(sid int, t uint8) error
- func (l *Lobby) Close()
- func (l *Lobby) CloseAllSlots() error
- func (l *Lobby) CloseSlot(sid int, kick bool) error
- func (l *Lobby) CountPlayers() int
- func (l *Lobby) JoinAndServe(conn net.Conn, join *w3gs.Join) (*Player, error)
- func (l *Lobby) Lock()
- func (l *Lobby) OpenAllSlots() error
- func (l *Lobby) OpenSlot(sid int, kick bool) error
- func (l *Lobby) Player(id uint8) *Player
- func (l *Lobby) SendToAll(pkt w3gs.Packet)
- func (l *Lobby) ShuffleSlots(shuffleTeams bool) error
- func (l *Lobby) SlotInfo() *w3gs.SlotInfo
- func (l *Lobby) SlotsAvailable() int
- func (l *Lobby) SlotsUsed() int
- func (l *Lobby) SwapSlots(slotA int, slotB int) error
- func (l *Lobby) Unlock()
- func (l *Lobby) Wait()
- type Player
- func (p *Player) BattleTag() string
- func (p *Player) DequeueAck() (checksum uint32, ok bool, more bool)
- func (p *Player) InitDefaultHandlers()
- func (p *Player) Kick(reason w3gs.LeaveReason)
- func (p *Player) Lag() bool
- func (p *Player) LeaveReason() w3gs.LeaveReason
- func (p *Player) RTT() uint32
- func (p *Player) Ready() bool
- func (p *Player) Run() error
- func (p *Player) SendOrClose(pkt w3gs.Packet) (int, error)
- func (p *Player) Tick() Tick
- type PlayerChat
- type PlayerJoined
- type PlayerLeft
- type Ready
- type Stage
- type StageChanged
- type StartLag
- type StopLag
- type Tick
Constants ¶
const LagDelay = 2 * time.Second
LagDelay timeout before showing lag screen
const LagRecoverDelay = 1 * time.Second
LagRecoverDelay timeout before ending lag screen
const ObsDisabled uint8 = 0xFF
ObsDisabled constant
Variables ¶
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") 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 (*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
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 // contains filtered or unexported fields }
Lobby represents a mocked game lobby Public methods/fields are thread-safe unless explicitly stated otherwise
func (*Lobby) ChangeColor ¶
ChangeColor to c for sid
func (*Lobby) ChangeComputer ¶
ChangeComputer to ai for sid
func (*Lobby) ChangeHandicap ¶
ChangeHandicap to h for sid
func (*Lobby) ChangeRace ¶
ChangeRace to r for sid
func (*Lobby) ChangeTeam ¶
ChangeTeam to t for sid
func (*Lobby) CloseAllSlots ¶
CloseAllSlots closes all open slots
func (*Lobby) JoinAndServe ¶
JoinAndServe player connection
func (*Lobby) OpenAllSlots ¶
OpenAllSlots opens all closed slots
func (*Lobby) ShuffleSlots ¶
ShuffleSlots randomizes slots and teams
func (*Lobby) SlotsAvailable ¶
SlotsAvailable counts open slots
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) DequeueAck ¶
DequeueAck from queue
func (*Player) InitDefaultHandlers ¶
func (p *Player) InitDefaultHandlers()
InitDefaultHandlers adds the default callbacks for relevant packets
func (*Player) Run ¶
Run reads packets and emits an event for each received packet Not safe for concurrent invocation
func (*Player) SendOrClose ¶
SendOrClose sends pkt to player, closes connection on failure