base

package
v0.0.0-...-b083768 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TYPE_BOT    = "bot"
	TYPE_ENGINE = "engine"
	TYPE_VIEWER = "viewer"
)
View Source
const (
	PLAYER_PREFIX = "{[(___"
	PLAYER_SUFFIX = "___)]}"
)

Variables

View Source
var (
	CLIENT_TYPES   = []string{TYPE_BOT, TYPE_ENGINE, TYPE_VIEWER}
	CLIENT_COUNTER util.SafeCounter
)
View Source
var (
	GAME_COUNTER util.SafeCounter
)

Functions

This section is empty.

Types

type Client

type Client struct {
	sync.RWMutex
	Id   int    `json:"id"`
	Type string `json:"type"`
	Name string `json:"name"`
	Game string `json:"game"` // used for bots to specify which game they want to play
	// contains filtered or unexported fields
}

func NewClient

func NewClient(lobby *Lobby, connection *Connection) *Client

func (*Client) GetConnection

func (this *Client) GetConnection() *Connection

func (*Client) GetGame

func (this *Client) GetGame() string

func (*Client) GetId

func (this *Client) GetId() int

func (*Client) GetName

func (this *Client) GetName() string

func (*Client) GetType

func (this *Client) GetType() string

func (*Client) HandleDisconnect

func (this *Client) HandleDisconnect()

func (*Client) HandleMessage

func (this *Client) HandleMessage(raw []byte)

func (*Client) IsConnected

func (this *Client) IsConnected() bool

func (*Client) MarshalJSON

func (this *Client) MarshalJSON() ([]byte, error)

func (*Client) SendError

func (this *Client) SendError(message string)

func (*Client) SendMessage

func (this *Client) SendMessage(message interface{})

func (*Client) SetConnection

func (this *Client) SetConnection(connection *Connection)

func (*Client) Transfer

func (this *Client) Transfer(client *Client)

type Connection

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

func NewConnection

func NewConnection(conn *websocket.Conn) *Connection

func (*Connection) HandleDisconnect

func (this *Connection) HandleDisconnect()

func (*Connection) HandleMessage

func (this *Connection) HandleMessage(raw []byte)

func (*Connection) SendMessage

func (this *Connection) SendMessage(message interface{}) error

func (*Connection) SetClient

func (this *Connection) SetClient(client *Client)

func (*Connection) StartPinging

func (this *Connection) StartPinging()

func (*Connection) StopPinging

func (this *Connection) StopPinging()

type Game

type Game struct {
	Room
	Id      int       `json:"id"`
	Engine  *Client   `json:"engine"`
	Players []*Player `json:"players"`
	History *History  `json:"-"`
	Started bool      `json:"started"`
	Stopped bool      `json:"stopped"`
}

func NewGame

func NewGame(name string, engine *Client) *Game

func (*Game) AddPlayer

func (this *Game) AddPlayer(client *Client)

func (*Game) GetHistory

func (this *Game) GetHistory() *History

func (*Game) GetId

func (this *Game) GetId() int

func (*Game) GetNextPlayerId

func (this *Game) GetNextPlayerId() int

func (*Game) GetPlayerByKey

func (this *Game) GetPlayerByKey(key string) *Player

func (*Game) GetPlayerIds

func (this *Game) GetPlayerIds() []int

func (*Game) GetStarted

func (this *Game) GetStarted() bool

func (*Game) GetStopped

func (this *Game) GetStopped() bool

func (*Game) HandleActionMessage

func (this *Game) HandleActionMessage(message *msg.ActionMessage)

func (*Game) HandleReconnect

func (this *Game) HandleReconnect(client *Client)

func (*Game) HandleStateMessage

func (this *Game) HandleStateMessage(message *msg.StateMessage)

func (*Game) MarshalJSON

func (this *Game) MarshalJSON() ([]byte, error)

func (*Game) RemovePlayer

func (this *Game) RemovePlayer(player *Player)

func (*Game) Start

func (this *Game) Start() error

func (*Game) Stop

func (this *Game) Stop() error

type History

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

func NewHistory

func NewHistory() *History

func (*History) Add

func (this *History) Add(message *msg.StateMessage)

func (*History) AddConverted

func (this *History) AddConverted(message *msg.StateMessageOut)

func (*History) GetLatest

func (this *History) GetLatest() *msg.StateMessage

func (*History) SendAllToViewer

func (this *History) SendAllToViewer(client *Client)

func (*History) SendTurnToViewer

func (this *History) SendTurnToViewer(client *Client, turn int)

unused

func (*History) SendTurnsToViewer

func (this *History) SendTurnsToViewer(client *Client, from int, to int)

unused

type JClient

type JClient Client

type JGame

type JGame Game

type JLobby

type JLobby Lobby

type JPlayer

type JPlayer Player

type JRoom

type JRoom Room

type Lobby

type Lobby struct {
	Room
	Games []*Game `json:"games"`
	// contains filtered or unexported fields
}

func NewLobby

func NewLobby() *Lobby

func (*Lobby) AddGame

func (this *Lobby) AddGame(game *Game)

func (*Lobby) GetGameById

func (this *Lobby) GetGameById(id int) *Game

func (*Lobby) HandleConnect

func (this *Lobby) HandleConnect(connection *Connection)

func (*Lobby) HandleDisconnect

func (this *Lobby) HandleDisconnect(client *Client)

func (*Lobby) HandleReconnect

func (this *Lobby) HandleReconnect(new *Client, old *Client)

func (*Lobby) MarshalJSON

func (this *Lobby) MarshalJSON() ([]byte, error)

func (*Lobby) RemoveGame

func (this *Lobby) RemoveGame(game *Game)

func (*Lobby) SendMessage

func (this *Lobby) SendMessage(clientId int, message interface{})

func (*Lobby) TriggerUpdated

func (this *Lobby) TriggerUpdated()

type Player

type Player struct {
	sync.RWMutex
	Id     int     `json:"id"`
	Client *Client `json:"client"`
	// contains filtered or unexported fields
}

func NewPlayer

func NewPlayer(id int, client *Client) *Player

func (*Player) GetClient

func (this *Player) GetClient() *Client

func (*Player) GetId

func (this *Player) GetId() int

func (*Player) GetKey

func (this *Player) GetKey() string

func (*Player) MarshalJSON

func (this *Player) MarshalJSON() ([]byte, error)

type Room

type Room struct {
	sync.RWMutex
	Name    string    `json:"name"`
	Clients []*Client `json:"clients"`
	// contains filtered or unexported fields
}

func NewRoom

func NewRoom(name string) *Room

func (*Room) AddClient

func (this *Room) AddClient(client *Client)

func (*Room) Broadcast

func (this *Room) Broadcast(senderId int, message interface{})

func (*Room) BroadcastToType

func (this *Room) BroadcastToType(Type string, message interface{})

func (*Room) FindDuplicateUnconnectedClient

func (this *Room) FindDuplicateUnconnectedClient(client *Client) *Client

func (*Room) GetClientById

func (this *Room) GetClientById(id int) *Client

func (*Room) GetName

func (this *Room) GetName() string

func (*Room) MarshalJSON

func (this *Room) MarshalJSON() ([]byte, error)

func (*Room) RemoveClient

func (this *Room) RemoveClient(client *Client)

Jump to

Keyboard shortcuts

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