peer

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: 8 Imported by: 0

Documentation

Overview

Package peer implements a mocked Warcraft III client that can be used to manage peer connections in lobbies.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFirstPacket = errors.New("peer: Invalid first packet")
	ErrUnknownPeerID      = errors.New("peer: Unknown ID")
	ErrDupPeerID          = errors.New("peer: Duplicate peer ID")
	ErrAlreadyConnected   = errors.New("peer: Already connected")
	ErrInvalidEntryKey    = errors.New("peer: Wrong entry key")
	ErrInvalidJoinCounter = errors.New("peer: Wrong join counter")
)

Errors

Functions

This section is empty.

Types

type Chat

type Chat struct {
	Event
	Content string
}

Chat event

type Connected

type Connected struct {
	Event
	Dial bool
}

Connected event

type Deregistered

type Deregistered Event

Deregistered event

type Disconnected

type Disconnected Event

Disconnected event

type Event

type Event struct {
	Peer *Player
}

Event root struct

type Host

type Host struct {
	network.EventEmitter

	// Set once before ListenAndServe(), read-only after that
	Encoding     w3gs.Encoding
	PlayerInfo   w3gs.PlayerInfo
	EntryKey     uint32
	PingInterval time.Duration
	// contains filtered or unexported fields
}

Host manages (incoming/outgoing) peer connections in a game lobby Public methods/fields are thread-safe unless explicitly stated otherwise

func (*Host) Accept

func (h *Host) Accept(conn net.Conn) (*Player, error)

Accept a new connection from known player

func (*Host) Close

func (h *Host) Close()

Close closes all connections to peers

func (*Host) Deregister

func (h *Host) Deregister(playerID uint8)

Deregister (and disconnect) player

func (*Host) Dial

func (h *Host) Dial(playerID uint8) (*Player, error)

Dial opens a new connection to player

func (*Host) GameTicks

func (h *Host) GameTicks() uint32

GameTicks state sent to peers

func (*Host) IncGameTicks

func (h *Host) IncGameTicks(t uint32)

IncGameTicks increments the GameTicks state with t

func (*Host) ListenAndServe

func (h *Host) ListenAndServe() error

ListenAndServe opens a new TCP listener on InternalAddr and serves incoming peer connections On success, listening address overrides InternalAddr/ExternalAddr Not safe for concurrent invocation

func (*Host) Peer

func (h *Host) Peer(playerID uint8) *Player

Peer returns registered Player for playerID

func (*Host) PeerSet

func (h *Host) PeerSet() protocol.BitSet32

PeerSet of connected peers

func (*Host) Register

func (h *Host) Register(info *w3gs.PlayerInfo) (*Player, error)

Register new player info

func (*Host) Say

func (h *Host) Say(s string) []uint8

Say sends a chat message to peers, returns failed PIDs

func (*Host) Wait

func (h *Host) 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
	// 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) InitDefaultHandlers

func (p *Player) InitDefaultHandlers()

InitDefaultHandlers adds the default callbacks for relevant packets

func (*Player) PeerSet

func (p *Player) PeerSet() protocol.BitSet32

PeerSet of connected peers

func (*Player) RTT

func (p *Player) RTT() uint32

RTT to host

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 added in v1.5.0

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

SendOrClose sends pkt to player, closes connection on failure

type Registered

type Registered Event

Registered event

Jump to

Keyboard shortcuts

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