server

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 18 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, s *Store) *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) TPS

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

func (*ActionDispatcher) UserSignIn

func (ac *ActionDispatcher) UserSignIn(un string)

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) *Game

type Options

type Options struct {
	Port string
}

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) *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
}

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{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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