match

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2024 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MatchStatus_Normal = iota
	MatchStatus_AfterRegDeadline
)

Variables

View Source
var (
	ErrNotFoundTable          = errors.New("match: not found table")
	ErrNotFoundAvailableTable = errors.New("match: not found available table")
	ErrAfterRegDealline       = errors.New("match: the final registration time has passed")
	ErrMaxPlayersReached      = errors.New("match: the current number of players has reached the maximum limit")
)

Functions

This section is empty.

Types

type DispatchRequest added in v0.0.2

type DispatchRequest struct {
	PlayerID               string `json:"player_id"`
	HighestNumberOfPlayers bool   `json:"highest_number_of_players"`
}

type Dispatcher

type Dispatcher interface {
	Start() error
	Close() error
	GetPendingCount() int64
	Dispatch(playerID string, highestNumberOfPlayers bool) error
	OnFailure(func(err error, playerID string))
}

func NewDispatcher

func NewDispatcher(m Match) Dispatcher

type Match

type Match interface {
	Options() *Options
	Dispatcher() Dispatcher
	WaitingRoom() WaitingRoom
	QueueManager() QueueManager
	TableBackend() TableBackend
	Runner() Runner
	TableMap() TableMap
	Close() error

	GetStatus() MatchStatus
	DisableRegistration()
	IsLastTableStage() bool
	Register(playerID string) error
	BreakTable(tableID string) error
	ApplySeatChanges(tableID string, sc *SeatChanges) error
	GetPlayerCount() int64
	PrintTables()
	AllocateTableWithPlayers(players []string) error

	OnPlayerJoined(fn func(Match, *Table, int, string))
	OnTableBroken(fn func(Match, *Table))
}

func NewMatch

func NewMatch(options *Options, opts ...MatchOpt) Match

type MatchOpt

type MatchOpt func(*match)

func WithPlayerJoinedCallback

func WithPlayerJoinedCallback(fn func(Match, *Table, int, string)) MatchOpt

func WithQueueManager

func WithQueueManager(qm QueueManager) MatchOpt

func WithRunner

func WithRunner(r Runner) MatchOpt

func WithTableBackend

func WithTableBackend(tb TableBackend) MatchOpt

func WithTableBrokenCallback

func WithTableBrokenCallback(fn func(Match, *Table)) MatchOpt

type MatchStatus

type MatchStatus int

type NativeQueueManager

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

func (*NativeQueueManager) AssertQueue

func (nqm *NativeQueueManager) AssertQueue(queueName string, subject string) (Queue, error)

func (*NativeQueueManager) Close

func (nqm *NativeQueueManager) Close() error

func (*NativeQueueManager) Conn

func (nqm *NativeQueueManager) Conn() *nats.Conn

func (*NativeQueueManager) Connect

func (nqm *NativeQueueManager) Connect() error

type NativeRunner

type NativeRunner struct {
}

func NewNativeRunner

func NewNativeRunner() *NativeRunner

func (*NativeRunner) DismissTable

func (nr *NativeRunner) DismissTable(m Match, table *Table) error

func (*NativeRunner) DrainWaitingRoomPlayers

func (nr *NativeRunner) DrainWaitingRoomPlayers(m Match, players []string) error

func (*NativeRunner) ShouldBeSplit

func (nr *NativeRunner) ShouldBeSplit(m Match, table *Table) bool

type NativeTableBackend

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

func NewDummyTableBackend

func NewDummyTableBackend() *NativeTableBackend

func (*NativeTableBackend) Activate

func (tb *NativeTableBackend) Activate(tableID string) error

func (*NativeTableBackend) Allocate

func (tb *NativeTableBackend) Allocate(maxSeats int) (*Table, error)

func (*NativeTableBackend) GetTable

func (tb *NativeTableBackend) GetTable(tableID string) (*Table, error)

func (*NativeTableBackend) OnTableUpdated

func (tb *NativeTableBackend) OnTableUpdated(fn func(tableID string, sc *SeatChanges))

func (*NativeTableBackend) Release

func (tb *NativeTableBackend) Release(tableID string) error

func (*NativeTableBackend) Reserve

func (tb *NativeTableBackend) Reserve(tableID string, seatID int, playerID string) error

func (*NativeTableBackend) UpdateTable

func (tb *NativeTableBackend) UpdateTable(tableID string, sc *SeatChanges) error

type Options

type Options struct {
	ID                string `json:"id"`
	WaitingPeriod     int    `json:"waiting_period"`
	MinInitialPlayers int    `json:"min_initial_player"`
	MaxSeats          int    `json:"max_seats"`
	MaxTables         int    `json:"max_tables"`
	Joinable          bool   `json:"joinable"`
	BreakThreshold    int    `json:"break_threshold"`
}

func NewOptions

func NewOptions(id string) *Options

type Queue

type Queue interface {
	Assert() error
	Destroy() error
	Subject() string
	Publish(msg []byte) error
	Subscribe(fn func(*nats.Msg)) error
	Unsubscribe() error
}

func NewQueue

func NewQueue(qm QueueManager, queueName string, subject string) Queue

type QueueManager

type QueueManager interface {
	Connect() error
	Close() error
	Conn() *nats.Conn
	AssertQueue(queueName string, subject string) (Queue, error)
}

func NewNativeQueueManager

func NewNativeQueueManager() QueueManager

type Runner

type Runner interface {
	ShouldBeSplit(m Match, table *Table) bool
	DismissTable(m Match, table *Table) error
	DrainWaitingRoomPlayers(m Match, players []string) error
}

type SeatChanges

type SeatChanges struct {
	Dealer int            `json:"dealer"` // The seat number of the dealer
	SB     int            `json:"sb"`     // The seat number of small blind
	BB     int            `json:"bb"`     // The seat number of big blind
	Seats  map[int]string `json:"seats"`  // Seat states (eg: left)
}

func NewSeatChanges

func NewSeatChanges() *SeatChanges

type Stack

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

func NewStack

func NewStack() *Stack

func (*Stack) Empty

func (stack *Stack) Empty() bool

func (*Stack) Len

func (stack *Stack) Len() int

func (*Stack) List

func (stack *Stack) List() *list.List

func (*Stack) Peek

func (stack *Stack) Peek() interface{}

func (*Stack) Pop

func (stack *Stack) Pop() interface{}

func (*Stack) Push

func (stack *Stack) Push(value interface{})

type Table

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

func NewTable

func NewTable(maxSeats int) *Table

func (*Table) ApplySeatChanges

func (t *Table) ApplySeatChanges(sc *SeatChanges) error

func (*Table) GetAvailableSeatCount

func (t *Table) GetAvailableSeatCount() int

func (*Table) GetPlayerCount

func (t *Table) GetPlayerCount() int

func (*Table) GetPlayers

func (t *Table) GetPlayers() ([]string, error)

func (*Table) GetSeatCount

func (t *Table) GetSeatCount() int

func (*Table) GetStatus

func (t *Table) GetStatus() TableStatus

func (*Table) ID

func (t *Table) ID() string

func (*Table) Join

func (t *Table) Join(seatID int, playerID string) error

func (*Table) OnPlayerDrained

func (t *Table) OnPlayerDrained(fn func(string, int))

func (*Table) OnPlayerJoined

func (t *Table) OnPlayerJoined(fn func(string, int))

func (*Table) OnPlayerLeft

func (t *Table) OnPlayerLeft(fn func(string, int))

func (*Table) PrintState

func (t *Table) PrintState()

func (*Table) Release

func (t *Table) Release() error

func (*Table) SeatManager

func (t *Table) SeatManager() *seat_manager.SeatManager

func (*Table) SetID

func (t *Table) SetID(id string)

func (*Table) SetStatus

func (t *Table) SetStatus(status TableStatus) error

type TableBackend

type TableBackend interface {
	Allocate(maxSeats int) (*Table, error)
	Release(tableID string) error
	Activate(tableID string) error
	Reserve(tableID string, seatID int, playerID string) error
	GetTable(tableID string) (*Table, error)
	UpdateTable(tableID string, sc *SeatChanges) error
	OnTableUpdated(func(tableID string, sc *SeatChanges))
}

type TableCondition

type TableCondition struct {
	HighestNumberOfPlayers bool `json:"highest_number_of_players"`
	MinAvailableSeats      int  `json:"min_available_seats"`
}

type TableMap

type TableMap interface {
	GetTables() (map[string]*Table, error)
	CreateTable(players []string) (*Table, error)
	BreakTable(tableID string) error
	GetTable(tableID string) (*Table, error)
	ApplySeatChanges(tableID string, sc *SeatChanges) error
	FindAvailableTable(condition *TableCondition) (*Table, error)
	DispatchPlayer(condition *TableCondition, playerID string) error
	Count() int64

	OnTableBroken(func(*Table))
	OnPlayerLeft(func(table *Table, seatID int, playerID string))
	OnPlayerJoined(func(table *Table, seatID int, playerID string))
}

func NewTableMap

func NewTableMap(m Match) TableMap

type TableStatus

type TableStatus int
const (
	TableStatus_Preparing TableStatus = iota
	TableStatus_Ready
	TableStatus_Busy
	TableStatus_Broken
	TableStatus_Suspend
)

type WaitingRoom

type WaitingRoom interface {
	Count() (int, error)
	Enter(playerID string) error
	Leave(playerID string) error
	Drain() error
	Match() error
	Flush() error
}

func NewWaitingRoom

func NewWaitingRoom(m Match) WaitingRoom

Jump to

Keyboard shortcuts

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