services

package
v0.0.0-...-0097a70 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CREATE_ROOM = "CREATE_ROOM"
	JOIN_ROOM   = "JOIN_ROOM"
	LEAVE_ROOM  = "LEAVE_ROOM"
	SET_NAME    = "SET_NAME"
	START_GAME  = "START_GAME"
	MOVE        = "MOVE"
	END_GAME    = "END_GAME"
)
View Source
const ONGOING = "ONGOING"
View Source
const (
	REGISTER = "REGISTER"
)

Variables

This section is empty.

Functions

func ActionHandler

func ActionHandler(player *Player, action string, payload json.RawMessage) error

func MapIntToRank

func MapIntToRank(rankInt int) string

func ServerFailMsg

func ServerFailMsg[V any](action string, payload V) ([]byte, error)

func ServerSuccessMsg

func ServerSuccessMsg[V any](action string, payload V) ([]byte, error)

Types

type Card

type Card struct {
	Suit string
	Rank int
}

func MapIntToCard

func MapIntToCard(num int) (*Card, error)

S: 0 -> 12 D: 13 -> 25 C: 26 -> 38 H: 39 -> 51

func NewCard

func NewCard(suitIndex, rank int) (*Card, error)

func (*Card) String

func (c *Card) String() string

type ClientMessage

type ClientMessage struct {
	Action  string          `json:"action"`
	Payload json.RawMessage `json:"payload"`
}

type CreateRoomPayload

type CreateRoomPayload struct {
	TimeoutInSeconds int       `json:"timeoutSeconds"`
	PlayerId         uuid.UUID `json:"playerId"`
}

type CreateRoomResponse

type CreateRoomResponse struct {
	RoomId uuid.UUID `json:"roomId"`
}

type Game

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

func NewGame

func NewGame() *Game

type GameStack

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

func NewGameStack

func NewGameStack() *GameStack

func (*GameStack) GetAllGames

func (g *GameStack) GetAllGames() []*Game

func (*GameStack) Len

func (g *GameStack) Len() int

func (*GameStack) Peek

func (g *GameStack) Peek() *Game

func (*GameStack) Pop

func (g *GameStack) Pop() *Game

func (*GameStack) Push

func (g *GameStack) Push(game *Game)

type GenericErrorResponse

type GenericErrorResponse struct {
	Error string `json:"error"`
}

type Hub

type Hub struct {
	Store      HubStore
	Register   chan *websocket.Conn
	Unregister chan uuid.UUID
	SetName    chan SetNamePayload
	CreateRoom chan CreateRoomPayload
	JoinRoom   chan RoomPayload
	LeaveRoom  chan RoomPayload
	StartGame  chan RoomPayload
	MakeMove   chan MakeMovePayload
}

func NewHub

func NewHub(store HubStore) *Hub

func (*Hub) Run

func (h *Hub) Run()

type HubStore

type HubStore interface {
	RegisterPlayer(player *Player)
	GetPlayerById(id uuid.UUID) (*Player, error)
	UnregisterPlayer(id uuid.UUID) error
	SetPlayerName(id uuid.UUID, name string) error
	CreateRoom(room *Room)
	GetRoomById(id uuid.UUID) (*Room, error)
	DeleteRoom(id uuid.UUID) error
	JoinRoom(id uuid.UUID, playerId uuid.UUID) error
	LeaveRoom(id uuid.UUID, playerId uuid.UUID) error
}

type JoinRoomResponse

type JoinRoomResponse struct {
	RoomId           uuid.UUID `json:"roomId"`
	TimeoutInSeconds int       `json:"timeoutInSeconds"`
	NewPlayer        string    `json:"newPlayer"`
	Players          []string  `json:"players"`
}

type LeaveRoomResponse

type LeaveRoomResponse struct {
	RoomId     uuid.UUID `json:"roomId"`
	LeftPlayer string    `json:"leftPlayer"`
	Players    []string  `json:"players"`
}

type MakeMovePayload

type MakeMovePayload struct {
	RoomId   uuid.UUID `json:"roomId"`
	Move     int       `json:"move"`
	PlayerId uuid.UUID `json:"playerId"`
}

type Player

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

func NewPlayer

func NewPlayer(id uuid.UUID, conn *websocket.Conn, hub *Hub) *Player

func (*Player) Run

func (p *Player) Run()

func (*Player) SetName

func (p *Player) SetName(name string)

type PlayerWithMove

type PlayerWithMove struct {
	Player *Player
	Move   int
}

type PlayerWithScore

type PlayerWithScore struct {
	Player string `json:"player"`
	Guess  string `json:"guess"`
	Score  int    `json:"score"`
}

type RegisterPlayerResponse

type RegisterPlayerResponse struct {
	PlayerId uuid.UUID `json:"playerId"`
}

type ResultResponse

type ResultResponse struct {
	RoomId  uuid.UUID         `json:"roomId"`
	GameId  uuid.UUID         `json:"gameId"`
	Target  string            `json:"target"`
	Results []PlayerWithScore `json:"results"`
}

type Room

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

func NewRoom

func NewRoom(timeout int, hub *Hub) *Room

func (*Room) Run

func (r *Room) Run()

type RoomPayload

type RoomPayload struct {
	RoomId   uuid.UUID `json:"roomId"`
	PlayerId uuid.UUID `json:"playerId"`
}

type ServerMessage

type ServerMessage[V any] struct {
	Action  string `json:"action"`
	Status  string `json:"status"`
	Payload V      `json:"payload"`
}

type SetNamePayload

type SetNamePayload struct {
	Name     string    `json:"name"`
	PlayerId uuid.UUID `json:"playerId"`
}

type StartGameResponse

type StartGameResponse struct {
	RoomId uuid.UUID `json:"roomId"`
	GameId uuid.UUID `json:"gameId"`
}

type Store

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

func NewStore

func NewStore() *Store

func (*Store) CreateRoom

func (s *Store) CreateRoom(room *Room)

func (*Store) DeleteRoom

func (s *Store) DeleteRoom(id uuid.UUID) error

func (*Store) GetPlayerById

func (s *Store) GetPlayerById(id uuid.UUID) (*Player, error)

func (*Store) GetRoomById

func (s *Store) GetRoomById(id uuid.UUID) (*Room, error)

func (*Store) JoinRoom

func (s *Store) JoinRoom(id uuid.UUID, playerId uuid.UUID) error

func (*Store) LeaveRoom

func (s *Store) LeaveRoom(id uuid.UUID, playerId uuid.UUID) error

func (*Store) RegisterPlayer

func (s *Store) RegisterPlayer(player *Player)

func (*Store) SetPlayerName

func (s *Store) SetPlayerName(id uuid.UUID, name string) error

func (*Store) UnregisterPlayer

func (s *Store) UnregisterPlayer(id uuid.UUID) error

Jump to

Keyboard shortcuts

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