server

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NoteMsg

type NoteMsg string

NoteMsg is a message that is sent to the client when a message is added to the game.

type Player

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

Player is a player in a chess game who belongs to a room, has a ssh session and a bubble tea program.

func (*Player) Close

func (p *Player) Close() error

Close closes the the bubble tea program and deletes the player from the room.

func (*Player) Position

func (p *Player) Position() string

Position returns the player's board FEN position.

func (*Player) Send

func (p *Player) Send(m tea.Msg)

Send sends a message to the bubble tea program.

func (*Player) StartGame

func (p *Player) StartGame()

StartGame starts the bubble tea program.

func (*Player) String

func (p *Player) String() string

String implements the Stringer interface.

func (*Player) Write

func (p *Player) Write(b []byte) (int, error)

Write writes data to the ssh session.

func (*Player) WriteString

func (p *Player) WriteString(s string) (int, error)

WriteString writes a string to the ssh session.

type PlayerType

type PlayerType int

PlayerType is the type of a player in a chess game.

func (PlayerType) String

func (pt PlayerType) String() string

String implements the Stringer interface.

type PublicKey

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

PublicKey wraps ssh.PublicKey.

func (PublicKey) String

func (pk PublicKey) String() string

String implements the Stringer interface.

type Room

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

Room is a game room with a unique id, password, and a list of players.

func NewRoom

func NewRoom(id, password string, finish chan string) *Room

NewRoom creates a new room with a unique id and password.

func (*Room) AddPlayer

func (r *Room) AddPlayer(s ssh.Session) (*Player, error)

AddPlayer adds a player to the room.

func (*Room) Close

func (r *Room) Close()

Close closes the room and deletes the room from the server memory.

func (*Room) FindPlayer

func (r *Room) FindPlayer(pub PublicKey) *Player

FindPlayer returns the player for the given public key.

func (*Room) Listen

func (r *Room) Listen()

Listen listens for messages from players in the room and other events.

func (*Room) MakePlayer

func (r *Room) MakePlayer(pt PlayerType, s ssh.Session) *Player

MakePlayer creates a new player with the given type and session.

func (*Room) ObserversCount

func (r *Room) ObserversCount() int

ObserversCount returns the number of observer players in the room.

func (*Room) P1

func (r *Room) P1() *Player

P1 returns the player with the first turn.

func (*Room) P2

func (r *Room) P2() *Player

P2 returns the player with the second turn.

func (*Room) Position

func (r *Room) Position() string

Position returns the FEN position of the game in the room.

func (*Room) SendMsg

func (r *Room) SendMsg(m tea.Msg)

SendMsg sends a bubble tea message to all players in the room.

func (*Room) String

func (r *Room) String() string

String implements the Stringer interface.

func (*Room) Write

func (r *Room) Write(b []byte) (n int, err error)

Write writes data to all players in the room.

func (*Room) WriteString

func (r *Room) WriteString(s string) (int, error)

WriteString writes a string to all players in the room.

type Server

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

Server is a server that manages chess games.

func NewServer

func NewServer(keyPath, host string, port int) (*Server, error)

NewServer creates a new server.

func (*Server) FindRoom

func (s *Server) FindRoom(id string) *Room

FindRoom finds a room with the given id.

func (*Server) NewRoom

func (s *Server) NewRoom(id, password string) *Room

NewRoom creates a new room with the given id and password.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown shuts down the server.

func (*Server) Start

func (s *Server) Start() error

Start starts the Gambit ssh server.

type SharedGame

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

SharedGame is a game that is shared between players. It wraps gambit bubble tea model and synchronizes messages among players and server.

func NewSharedGame

func NewSharedGame(p *Player, sync chan tea.Msg, roomTurn *bool, turn, observer bool, pos string) *SharedGame

NewSharedGame creates a new shared game for a player.

func (*SharedGame) Init

func (r *SharedGame) Init() tea.Cmd

Init implements bubble tea model.

func (*SharedGame) SendMsg

func (r *SharedGame) SendMsg(msg tea.Msg)

SendMsg sends a message to the room.

func (*SharedGame) Update

func (r *SharedGame) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements bubble tea model.

func (*SharedGame) View

func (r *SharedGame) View() string

View implements bubble tea model.

Jump to

Keyboard shortcuts

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