server

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ad *ActionDispatcher, s *Store, opt Options) error

Types

type ActionDispatcher

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

ActionDispatcher is in charge of dispatching actions to the application dispatcher

func NewActionDispatcher

func NewActionDispatcher(d *flux.Dispatcher, l *slog.Logger, s *Store, ws WSConnector) *ActionDispatcher

NewActionDispatcher initializes the action dispatcher with the give dispatcher

func (*ActionDispatcher) Dispatch

func (ac *ActionDispatcher) Dispatch(a *action.Action)

Dispatch is a helper to access to the internal dispatch directly with an action. This should only be used from the WS Handler to forward server actions directly

func (*ActionDispatcher) IncomeTick

func (ac *ActionDispatcher) IncomeTick(rooms *RoomsStore)

func (*ActionDispatcher) SyncState

func (ac *ActionDispatcher) SyncState(rooms *RoomsStore)

func (*ActionDispatcher) SyncUsers

func (ac *ActionDispatcher) SyncUsers(users *UsersStore)

func (*ActionDispatcher) SyncWaitingRoom

func (ac *ActionDispatcher) SyncWaitingRoom(rooms *RoomsStore)

func (*ActionDispatcher) UserSignIn

func (ac *ActionDispatcher) UserSignIn(un, ra string, ws *websocket.Conn)

func (*ActionDispatcher) UserSignOut

func (ac *ActionDispatcher) UserSignOut(un string)

func (*ActionDispatcher) UserSignUp

func (ac *ActionDispatcher) UserSignUp(un string)

func (*ActionDispatcher) WaitRoomCountdownTick

func (ac *ActionDispatcher) WaitRoomCountdownTick()

type Game

type Game struct {
	*store.Store
}

func NewGame

func NewGame(d *flux.Dispatcher, l *slog.Logger) *Game

type Options

type Options struct {
	Port    string
	Verbose bool
}

type PlayerConn

type PlayerConn struct {
	Conn       *websocket.Conn
	RemoteAddr string
}

type Room

type Room struct {
	Name string

	Players map[string]PlayerConn

	Connections map[string]string

	Size      int
	Countdown int

	Game *Game
}

type RoomsState

type RoomsState struct {
	Rooms              map[string]*Room
	CurrentWaitingRoom string
}

type RoomsStore

type RoomsStore struct {
	*flux.ReduceStore

	Store *Store
	// contains filtered or unexported fields
}

func NewRoomsStore

func NewRoomsStore(d *flux.Dispatcher, s *Store, l *slog.Logger) *RoomsStore

func (*RoomsStore) FindCurrentWaitingRoom

func (rs *RoomsStore) FindCurrentWaitingRoom() *Room

func (*RoomsStore) GetNextID

func (rs *RoomsStore) GetNextID(room string) int

func (*RoomsStore) List

func (rs *RoomsStore) List() []*Room

func (*RoomsStore) Reduce

func (rs *RoomsStore) Reduce(state, a interface{}) interface{}

type Store

type Store struct {
	Rooms *RoomsStore
	Users *UsersStore
}

func NewStore added in v1.0.3

func NewStore(d *flux.Dispatcher, l *slog.Logger) *Store

type User

type User struct {
	ID       string
	Username string

	Conn       *websocket.Conn
	RemoteAddr string

	CurrentRoomID string
}

type UsersState

type UsersState struct {
	Users map[string]*User
}

type UsersStore

type UsersStore struct {
	*flux.ReduceStore

	Store *Store
	// contains filtered or unexported fields
}

func NewUsersStore

func NewUsersStore(d *flux.Dispatcher, s *Store) *UsersStore

func (*UsersStore) FindByRemoteAddress

func (us *UsersStore) FindByRemoteAddress(ra string) (User, bool)

func (*UsersStore) FindByUsername

func (us *UsersStore) FindByUsername(un string) (User, bool)

func (*UsersStore) List

func (us *UsersStore) List() []*User

func (*UsersStore) Reduce

func (us *UsersStore) Reduce(state, a interface{}) interface{}

type WS added in v1.0.3

type WS struct{}

func NewWS added in v1.0.3

func NewWS() *WS

func (*WS) Read added in v1.0.3

func (ws *WS) Read(ctx context.Context, conn *websocket.Conn, d interface{}) error

func (*WS) Write added in v1.0.3

func (ws *WS) Write(ctx context.Context, conn *websocket.Conn, d interface{}) error

type WSConnector added in v1.0.3

type WSConnector interface {
	Write(context.Context, *websocket.Conn, interface{}) error
	Read(context.Context, *websocket.Conn, interface{}) error
}

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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