lan

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2019 License: MPL-2.0 Imports: 18 Imported by: 6

Documentation

Overview

Package lan implements a mocked Warcraft III LAN client that can be used to discover local games.

Example
package main

import (
	"context"
	"fmt"
	"time"

	"github.com/nielsAD/gowarcraft3/network/lan"
	"github.com/nielsAD/gowarcraft3/protocol/w3gs"
)

func main() {
	var game = w3gs.GameVersion{
		Product: w3gs.ProductTFT,
		Version: w3gs.CurrentGameVersion,
	}

	// Find LAN game
	ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
	addr, id, secret, err := lan.FindGame(ctx, game)

	cancel()
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Printf("Found game at %s (id: %d, secret %d)\n", addr, id, secret)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var MulticastGroup = net.UDPAddr{IP: net.IPv4(224, 0, 0, 251), Port: 5353}

MulticastGroup endpoint

View Source
var TypeCacheFlush uint16 = 1 << 15

TypeCacheFlush bit

View Source
var TypeUnicastResponse uint16 = 1 << 15

TypeUnicastResponse bit

Functions

func FindGame

func FindGame(ctx context.Context, gv w3gs.GameVersion) (addr string, hostCounter uint32, entryKey uint32, err error)

FindGame returns entry information for an arbitrary game hosted in LAN

Types

type Advertiser added in v1.5.0

type Advertiser interface {
	network.Listener

	Create() error
	Refresh(slotsUsed uint32, slotsAvailable uint32) error
	Decreate() error

	Run() error
	Close() error
}

Advertiser broadcasts available game information to the Local Area Network Emits events for every received packet, responds to search queries

func NewAdvertiser added in v1.5.0

func NewAdvertiser(info *w3gs.GameInfo) (Advertiser, error)

NewAdvertiser initializes proper Advertiser type for game version

type DNSPacketConn added in v1.5.0

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

DNSPacketConn manages a UDP connection that transfers DNS packets. Public methods/fields are thread-safe unless explicitly stated otherwise

func NewDNSPacketConn added in v1.5.0

func NewDNSPacketConn(conn net.PacketConn) *DNSPacketConn

NewDNSPacketConn returns conn wrapped in DNSPacketConn

func (*DNSPacketConn) Broadcast added in v1.5.0

func (c *DNSPacketConn) Broadcast(pkt *dns.Msg) (int, error)

Broadcast a packet over LAN

func (*DNSPacketConn) Close added in v1.5.0

func (c *DNSPacketConn) Close() error

Close the connection

func (*DNSPacketConn) Conn added in v1.5.0

func (c *DNSPacketConn) Conn() net.PacketConn

Conn returns the underlying net.PacketConn

func (*DNSPacketConn) NextPacket added in v1.5.0

func (c *DNSPacketConn) NextPacket(timeout time.Duration) (*dns.Msg, net.Addr, error)

NextPacket waits for the next packet (with given timeout) and returns its deserialized representation Not safe for concurrent invocation

func (*DNSPacketConn) Run added in v1.5.0

func (c *DNSPacketConn) Run(f network.Emitter, timeout time.Duration) error

Run reads packets (with given max time between packets) from Conn and emits an event for each received packet Not safe for concurrent invocation

func (*DNSPacketConn) Send added in v1.5.0

func (c *DNSPacketConn) Send(addr net.Addr, pkt *dns.Msg) (int, error)

Send pkt to addr over net.PacketConn

func (*DNSPacketConn) SetConn added in v1.5.0

func (c *DNSPacketConn) SetConn(conn net.PacketConn)

SetConn closes the old connection and starts using the new net.PacketConn

type GameList

type GameList interface {
	network.Listener
	Games() map[string]w3gs.GameInfo
	Run() error
	Close() error
}

GameList keeps track of all the hosted games in the Local Area Network Emits events for every received packet and Update{} when the output of Games() changes

func NewGameList

func NewGameList(gv w3gs.GameVersion) (GameList, error)

NewGameList initializes proper GameList type for game version

type MDNSAdvertiser added in v1.5.0

type MDNSAdvertiser struct {
	network.EventEmitter
	DNSPacketConn

	// Set once before Run(), read-only after that
	BroadcastInterval time.Duration
	// contains filtered or unexported fields
}

MDNSAdvertiser advertises a hosted game in the Local Area Network using MDNS (Bonjour)

func NewMDNSAdvertiser added in v1.5.0

func NewMDNSAdvertiser(info *w3gs.GameInfo) (*MDNSAdvertiser, error)

NewMDNSAdvertiser initializes MDNSAdvertiser struct

func (*MDNSAdvertiser) Close added in v1.5.0

func (a *MDNSAdvertiser) Close() error

Close the connection

func (*MDNSAdvertiser) Create added in v1.5.0

func (a *MDNSAdvertiser) Create() error

Create local game

func (*MDNSAdvertiser) Decreate added in v1.5.0

func (a *MDNSAdvertiser) Decreate() error

Decreate game

func (*MDNSAdvertiser) InitDefaultHandlers added in v1.5.0

func (a *MDNSAdvertiser) InitDefaultHandlers()

InitDefaultHandlers adds the default callbacks for relevant packets

func (*MDNSAdvertiser) Refresh added in v1.5.0

func (a *MDNSAdvertiser) Refresh(slotsUsed uint32, slotsAvailable uint32) error

Refresh game info

func (*MDNSAdvertiser) Run added in v1.5.0

func (a *MDNSAdvertiser) Run() error

Run broadcasts gameinfo in Local Area Network

type MDNSGameList added in v1.5.0

type MDNSGameList struct {
	network.EventEmitter
	DNSPacketConn

	// Set once before Run(), read-only after that
	GameVersion       w3gs.GameVersion
	BroadcastInterval time.Duration
	// contains filtered or unexported fields
}

MDNSGameList keeps track of all the hosted games in the Local Area Network using MDNS (Bonjour) Emits events for every received packet and Update{} when the output of Games() changes Public methods/fields are thread-safe unless explicitly stated otherwise

func NewMDNSGameList added in v1.5.0

func NewMDNSGameList(gv w3gs.GameVersion) (*MDNSGameList, error)

NewMDNSGameList opens a new UDP socket to listen for MDNS GameList updates

func (*MDNSGameList) Games added in v1.5.0

func (g *MDNSGameList) Games() map[string]w3gs.GameInfo

Games returns the current list of LAN games. Map key is the remote address.

func (*MDNSGameList) InitDefaultHandlers added in v1.5.0

func (g *MDNSGameList) InitDefaultHandlers()

InitDefaultHandlers adds the default callbacks for relevant packets

func (*MDNSGameList) Run added in v1.5.0

func (g *MDNSGameList) Run() error

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

type UDPAdvertiser added in v1.5.0

type UDPAdvertiser struct {
	network.EventEmitter
	network.W3GSPacketConn

	// Set once before Run(), read-only after that
	BroadcastInterval time.Duration
	// contains filtered or unexported fields
}

UDPAdvertiser advertises a hosted game in the Local Area Network using UDP broadcast

func NewUDPAdvertiser added in v1.5.0

func NewUDPAdvertiser(info *w3gs.GameInfo, port int) (*UDPAdvertiser, error)

NewUDPAdvertiser initializes UDPAdvertiser struct

func (*UDPAdvertiser) Close added in v1.5.0

func (a *UDPAdvertiser) Close() error

Close the connection

func (*UDPAdvertiser) Create added in v1.5.0

func (a *UDPAdvertiser) Create() error

Create local game

func (*UDPAdvertiser) Decreate added in v1.5.0

func (a *UDPAdvertiser) Decreate() error

Decreate game

func (*UDPAdvertiser) InitDefaultHandlers added in v1.5.0

func (a *UDPAdvertiser) InitDefaultHandlers()

InitDefaultHandlers adds the default callbacks for relevant packets

func (*UDPAdvertiser) Refresh added in v1.5.0

func (a *UDPAdvertiser) Refresh(slotsUsed uint32, slotsAvailable uint32) error

Refresh game info

func (*UDPAdvertiser) Run added in v1.5.0

func (a *UDPAdvertiser) Run() error

Run broadcasts gameinfo in Local Area Network

type UDPGameList added in v1.5.0

type UDPGameList struct {
	network.EventEmitter
	network.W3GSPacketConn

	// Set once before Run(), read-only after that
	GameVersion       w3gs.GameVersion
	BroadcastInterval time.Duration
	// contains filtered or unexported fields
}

UDPGameList keeps track of all the hosted games in the Local Area Network using UDP broadcast Emits events for every received packet and Update{} when the output of Games() changes Public methods/fields are thread-safe unless explicitly stated otherwise

func NewUDPGameList added in v1.5.0

func NewUDPGameList(gv w3gs.GameVersion, port int) (*UDPGameList, error)

NewUDPGameList opens a new UDP socket to listen for LAN GameList updates

func (*UDPGameList) Encoding added in v1.5.0

func (g *UDPGameList) Encoding() w3gs.Encoding

Encoding for w3gs packets

func (*UDPGameList) Games added in v1.5.0

func (g *UDPGameList) Games() map[string]w3gs.GameInfo

Games returns the current list of LAN games. Map key is the remote address.

func (*UDPGameList) InitDefaultHandlers added in v1.5.0

func (g *UDPGameList) InitDefaultHandlers()

InitDefaultHandlers adds the default callbacks for relevant packets

func (*UDPGameList) Run added in v1.5.0

func (g *UDPGameList) Run() error

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

type Update

type Update struct{}

Update event for GameList changes

Jump to

Keyboard shortcuts

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