server

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 24 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) SyncLobbies added in v1.1.0

func (ac *ActionDispatcher) SyncLobbies(s *Store)

SyncLobbies will just sync the info of each lobby to the players on it

func (*ActionDispatcher) SyncState

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

func (*ActionDispatcher) SyncUsers

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

func (*ActionDispatcher) SyncVs1WaitingRoom added in v1.2.0

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

func (*ActionDispatcher) SyncVs6WaitingRoom added in v1.2.0

func (ac *ActionDispatcher) SyncVs6WaitingRoom(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
	Version string
}

type PlayerConn

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

type Room

type Room struct {
	Name string

	Players map[string]PlayerConn

	Connections map[string]string

	Context         context.Context
	ContextCancelFn context.CancelFunc
	Bots            map[string]*bot.Bot

	Size      int
	Countdown int

	Game *Game
}

type RoomsState

type RoomsState struct {
	Rooms                 map[string]*Room
	CurrentVs6WaitingRoom string
	CurrentVs1WaitingRoom 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) FindByID added in v1.1.0

func (rs *RoomsStore) FindByID(rid string) *Room

func (*RoomsStore) FindCurrentVs1WaitingRoom added in v1.2.0

func (rs *RoomsStore) FindCurrentVs1WaitingRoom() *Room

func (*RoomsStore) FindCurrentVs6WaitingRoom added in v1.2.0

func (rs *RoomsStore) FindCurrentVs6WaitingRoom() *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
	Lobbies *store.Lobbies
}

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
	CurrentLobbyID 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