lobby

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package lobby handles players connecting to games and communication between games and players

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Debug is a flag that causes the game to log the types messages that are read.
	Debug bool
}

Config contiains the properties to create a lobby

func (Config) NewLobby

func (cfg Config) NewLobby(log log.Logger, socketRunner SocketRunner, gameRunner GameRunner) (*Lobby, error)

NewLobby creates a new game lobby.

type GameRunner

type GameRunner interface {
	Run(ctx context.Context, wg *sync.WaitGroup, in <-chan message.Message) <-chan message.Message
}

GameRunner handles running and managing games.

type Lobby

type Lobby struct {
	Config
	// contains filtered or unexported fields
}

Lobby is the place users can create, join, and participate in games. It is a middleman between the socket runner and game runner. It also handles communication from the server to add and remove sockets.

func (*Lobby) AddUser

func (l *Lobby) AddUser(username string, w http.ResponseWriter, r *http.Request) error

AddUser adds a user to the lobby, it opens a new websocket (player) for the username.

func (*Lobby) RemoveUser

func (l *Lobby) RemoveUser(username string)

RemoveUser removes all sockets for the user from the lobby.

func (*Lobby) Run

func (l *Lobby) Run(ctx context.Context, wg *sync.WaitGroup)

Run runs the lobby until the context is closed.

type SocketRunner

type SocketRunner interface {
	Run(ctx context.Context, wg *sync.WaitGroup, in <-chan message.Message, inSM <-chan message.Socket) <-chan message.Message
}

SocketRunner handles running and managing sockets.

Jump to

Keyboard shortcuts

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