Documentation ¶
Overview ¶
Package dummy implements a mocked Warcraft III game client that can be used to add dummy players to lobbies.
Example ¶
package main import ( "context" "fmt" "time" "github.com/nielsAD/gowarcraft3/network" "github.com/nielsAD/gowarcraft3/network/dummy" "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 } // Join game player, err := dummy.Join(addr, "DummyPlayer", id, secret, -1, w3gs.Encoding{GameVersion: game.Version}) if err != nil { fmt.Println(err) return } defer player.Close() // Print incoming chat messages player.On(&dummy.Chat{}, func(ev *network.Event) { var msg = ev.Arg.(*dummy.Chat) fmt.Printf("[%s] %s\n", msg.Sender.PlayerName, msg.Content) }) // Run() blocks until the connection is closed player.Run() }
Output:
Index ¶
- Variables
- func RejectReasonToError(r w3gs.RejectReason) error
- type Chat
- type Player
- func (p *Player) ChangeColor(c uint8) error
- func (p *Player) ChangeHandicap(h uint8) error
- func (p *Player) ChangeRace(r w3gs.RacePref) error
- func (p *Player) ChangeTeam(t uint8) error
- func (p *Player) Close() error
- func (p *Player) InitDefaultHandlers()
- func (p *Player) Join() error
- func (p *Player) JoinWithConn(conn net.Conn) error
- func (p *Player) Leave(reason w3gs.LeaveReason) error
- func (p *Player) Run() error
- func (p *Player) Say(s string) error
- func (p *Player) SendOrClose(pkt w3gs.Packet) (int, error)
- type Say
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrJoinRejected = errors.New("dummy: Join rejected") ErrGameFull = errors.New("dummy: Join rejected (game full)") ErrGameStarted = errors.New("dummy: Join rejected (game started)") ErrInvalidFirstPacket = errors.New("dummy: Invalid first packet") )
Errors
Functions ¶
func RejectReasonToError ¶
func RejectReasonToError(r w3gs.RejectReason) error
RejectReasonToError converts w3gs.RejectReason to an appropriate error
Types ¶
type Player ¶
type Player struct { peer.Host network.W3GSConn // Set once before Join(), read-only after that HostAddr string HostCounter uint32 DialPeers bool }
Player represents a mocked player that can join a game lobby
func Join ¶
func Join(addr string, name string, hostCounter uint32, entryKey uint32, listenPort int, encoding w3gs.Encoding) (*Player, error)
Join a game lobby as a mocked player
func (*Player) InitDefaultHandlers ¶
func (p *Player) InitDefaultHandlers()
InitDefaultHandlers adds the default callbacks for relevant packets
func (*Player) JoinWithConn ¶ added in v1.6.0
JoinWithConn initializes a connection to host Not safe for concurrent invocation
Click to show internal directories.
Click to hide internal directories.