Documentation
¶
Index ¶
- Constants
- func NewTaiXiuMatch() runtime.Match
- type BetAckResponse
- type BetRequest
- type PlayerBet
- type PlayerPayout
- type RoundResultBroadcast
- type StateUpdateBroadcast
- type TaiXiuMatch
- func (m *TaiXiuMatch) MatchInit(ctx context.Context, logger runtime.Logger, db *sql.DB, ...) (interface{}, int, string)
- func (m *TaiXiuMatch) MatchJoin(ctx context.Context, logger runtime.Logger, db *sql.DB, ...) interface{}
- func (m *TaiXiuMatch) MatchJoinAttempt(ctx context.Context, logger runtime.Logger, db *sql.DB, ...) (interface{}, bool, string)
- func (m *TaiXiuMatch) MatchLeave(ctx context.Context, logger runtime.Logger, db *sql.DB, ...) interface{}
- func (m *TaiXiuMatch) MatchLoop(ctx context.Context, logger runtime.Logger, db *sql.DB, ...) interface{}
- func (m *TaiXiuMatch) MatchSignal(ctx context.Context, logger runtime.Logger, db *sql.DB, ...) (interface{}, string)
- func (m *TaiXiuMatch) MatchTerminate(ctx context.Context, logger runtime.Logger, db *sql.DB, ...) interface{}
- type TaiXiuState
Constants ¶
const ( OpCodeBet int64 = 1 // Client -> Server: Place a bet OpCodeStateUpdate int64 = 2 // Server -> Client: Match state update / timer tick broadcast OpCodeBetAck int64 = 3 // Server -> Client: Bet acknowledgement / status response OpCodeRoundResult int64 = 4 // Server -> Client: Round dice result & win/loss payout notification )
OpCodes for WebSocket / MatchData messages
const ( ChoiceTai = "TAI" // Sum 11 - 17 (Over) ChoiceXiu = "XIU" // Sum 4 - 10 (Under) ChoiceTriple = "TRIPLE" // 3 of a kind (1-1-1 or 6-6-6) )
Bet Choice Constants
const ( PhaseBetting = "BETTING" PhaseRolling = "ROLLING" PhaseResult = "RESULT" PhaseIntermission = "INTERMISSION" )
Phase Constants
Variables ¶
This section is empty.
Functions ¶
func NewTaiXiuMatch ¶
NewTaiXiuMatch creates a new instance of the match handler.
Types ¶
type BetAckResponse ¶
type BetAckResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty"`
Choice string `json:"choice,omitempty"`
Amount int64 `json:"amount,omitempty"`
Balance int64 `json:"balance,omitempty"`
}
BetAckResponse payload sent to client in OpCodeBetAck
type BetRequest ¶
type BetRequest struct {
Choice string `json:"choice"` // "TAI" or "XIU"
Amount int64 `json:"amount"` // Bet amount in coins/chips
}
BetRequest payload sent from client in OpCodeBet
type PlayerBet ¶
type PlayerBet struct {
UserID string `json:"user_id"`
SessionID string `json:"session_id"`
Choice string `json:"choice"` // TAI or XIU
Amount int64 `json:"amount"`
}
PlayerBet stores an individual player's bet for the current round.
type PlayerPayout ¶
type PlayerPayout struct {
UserID string `json:"user_id"`
Choice string `json:"choice"`
BetAmount int64 `json:"bet_amount"`
Payout int64 `json:"payout"` // Total payout credited (0 if lost)
NetProfit int64 `json:"net_profit"` // Payout - BetAmount
NewBalance int64 `json:"new_balance"`
}
PlayerPayout summary included in round result
type RoundResultBroadcast ¶
type RoundResultBroadcast struct {
RoundNumber int64 `json:"round_number"`
Dice [3]int `json:"dice"`
Sum int `json:"sum"`
WinningSide string `json:"winning_side"` // "TAI", "XIU", or "TRIPLE"
Payouts []PlayerPayout `json:"payouts"`
}
RoundResultBroadcast payload sent to all players in OpCodeRoundResult
type StateUpdateBroadcast ¶
type StateUpdateBroadcast struct {
Phase string `json:"phase"`
RoundNumber int64 `json:"round_number"`
RemainingTicks int `json:"remaining_ticks"`
TotalPoolTai int64 `json:"total_pool_tai"`
TotalPoolXiu int64 `json:"total_pool_xiu"`
ActivePlayers int `json:"active_players"`
}
StateUpdateBroadcast payload sent to all players in OpCodeStateUpdate
type TaiXiuMatch ¶
type TaiXiuMatch struct{}
TaiXiuMatch implements runtime.Match for the Tài-Xỉu game room.
func (*TaiXiuMatch) MatchInit ¶
func (m *TaiXiuMatch) MatchInit(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.RuntimeModule, params map[string]interface{}) (interface{}, int, string)
MatchInit initializes match state when the room is created.
func (*TaiXiuMatch) MatchJoin ¶
func (m *TaiXiuMatch) MatchJoin(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.RuntimeModule, dispatcher interface{}, tick int64, state interface{}, presences []runtime.Presence) interface{}
MatchJoin records newly joined presences.
func (*TaiXiuMatch) MatchJoinAttempt ¶
func (m *TaiXiuMatch) MatchJoinAttempt(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.RuntimeModule, dispatcher interface{}, tick int64, state interface{}, presence runtime.Presence, metadata map[string]string) (interface{}, bool, string)
MatchJoinAttempt approves or denies player join requests.
func (*TaiXiuMatch) MatchLeave ¶
func (m *TaiXiuMatch) MatchLeave(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.RuntimeModule, dispatcher interface{}, tick int64, state interface{}, presences []runtime.Presence) interface{}
MatchLeave handles presences departing from the match room.
func (*TaiXiuMatch) MatchLoop ¶
func (m *TaiXiuMatch) MatchLoop(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.RuntimeModule, dispatcher interface{}, tick int64, state interface{}, messages []runtime.MatchData) interface{}
MatchLoop is the tick loop driving the game state machine.
func (*TaiXiuMatch) MatchSignal ¶
func (m *TaiXiuMatch) MatchSignal(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.RuntimeModule, dispatcher interface{}, tick int64, state interface{}, data string) (interface{}, string)
MatchSignal handles external control signals.
func (*TaiXiuMatch) MatchTerminate ¶
func (m *TaiXiuMatch) MatchTerminate(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.RuntimeModule, dispatcher interface{}, tick int64, state interface{}, graceSeconds int) interface{}
MatchTerminate cleans up the room.
type TaiXiuState ¶
type TaiXiuState struct {
sync.RWMutex
RoundNumber int64 `json:"round_number"`
Phase string `json:"phase"`
PhaseTicks int `json:"phase_ticks"`
BettingTicks int `json:"betting_ticks"`
RollingTicks int `json:"rolling_ticks"`
ResultTicks int `json:"result_ticks"`
IntermissionTicks int `json:"intermission_ticks"`
Presences map[string]runtime.Presence `json:"-"`
Bets map[string]*PlayerBet `json:"bets"` // key: userID
TotalPoolTai int64 `json:"total_pool_tai"`
TotalPoolXiu int64 `json:"total_pool_xiu"`
LastDice [3]int `json:"last_dice"`
LastSum int `json:"last_sum"`
LastWinning string `json:"last_winning"`
LastPayouts []PlayerPayout `json:"last_payouts"`
// contains filtered or unexported fields
}
TaiXiuState holds the authoritative state of a Tài-Xỉu match room.