wg: github.com/jakecoffman/wg Index | Files

package wg

import "github.com/jakecoffman/wg"

Index

Package Files

conn.go fakeconn.go games.go player.go web.go

Constants

const COOKIE_NAME = "PLAYER_COOKIE"

Variables

var AllGames = NewGames()

func GenId Uses

func GenId() string

func NewWsConn Uses

func NewWsConn(ws *websocket.Conn) *wsConn

func ProcessPlayerCommands Uses

func ProcessPlayerCommands(NewGame func(string) *Game) func(Connector, string)

func WsHandler Uses

func WsHandler(cmdHandler PlayerCommandHandler) websocket.Handler

WsHandler handles player web connections

type Command Uses

type Command struct {
    PlayerId string
    Ws       Connector
    Type     string
    Version  int
    Data     json.RawMessage
}

type Connector Uses

type Connector interface {
    Send(v interface{})
    Recv(v interface{}) error

    SendRaw(v []byte)
    RecvRaw(v []byte) error

    Close() error

    Ip() string
    Cookie(string) (*http.Cookie, error)
}

Connector wraps connections so tests are easier

type FakeConn Uses

type FakeConn struct {
    FakeIp string
    Closed bool

    Msgs chan interface{}
}

func NewFakeConn Uses

func NewFakeConn(ip string) *FakeConn

func (*FakeConn) Close Uses

func (c *FakeConn) Close() error

func (*FakeConn) Cookie Uses

func (c *FakeConn) Cookie(name string) (*http.Cookie, error)

func (*FakeConn) Ip Uses

func (c *FakeConn) Ip() string

func (*FakeConn) Recv Uses

func (c *FakeConn) Recv(v interface{}) error

func (*FakeConn) RecvRaw Uses

func (c *FakeConn) RecvRaw(v []byte) error

func (*FakeConn) Send Uses

func (c *FakeConn) Send(v interface{})

func (*FakeConn) SendRaw Uses

func (c *FakeConn) SendRaw(v []byte)

type Game Uses

type Game struct {
    Class interface{}   `json:"-"`
    Cmd   chan *Command `json:"-"`

    Id      string
    Version int
    Created time.Time `json:"-"`
    Updated time.Time `json:"-"`
}

func NewGame Uses

func NewGame(class interface{}, id string) *Game

type Games Uses

type Games struct {
    sync.RWMutex
    // contains filtered or unexported fields
}

func NewGames Uses

func NewGames() *Games

func (*Games) Delete Uses

func (g *Games) Delete(id string)

func (*Games) Find Uses

func (g *Games) Find(pid string) *Game

func (*Games) Get Uses

func (g *Games) Get(id string) *Game

func (*Games) Ids Uses

func (g *Games) Ids() []string

func (*Games) Set Uses

func (g *Games) Set(game *Game, pid string)

type PlayerCommandHandler Uses

type PlayerCommandHandler func(Connector, string)

Package wg imports 8 packages (graph). Updated 2019-06-25. Refresh now. Tools for package owners.