mockgame

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package mockgame is a tiny game that the lobby calls over HTTP, for the lobby's own tests. It serves the hooks of the gamehooks protocol from Go functions, keeps its games in memory, reads the lobby through the game API, and can be told to fail or delay a hook.

  • Its game settings are {"rounds": N}, N from 1 to 5.
  • Its seats are {"level": 1}, named "Mock bot (level 1)".
  • Its member settings are {"color": "<1 to 20 characters>"}, and a person needs them to get ready: ready-check refuses a member without them with the problem type ColorMissingProblemType.
  • start records a game for the lobby's round, once: a second call for the same round returns the same game.
  • POST /finish/{lobby_id} ends the game of the lobby's newest round, so round-ended answers true and the lobby can be reopened.
  • GET /watch/{lobby_id}?player_id=… is a watcher's read: it asks the lobby's game API whether the player may watch, and answers with the lobby's game.

A Game is an http.Handler; serve it with httptest.NewServer and configure the lobby with hooks_url set to the server's URL + HooksPath.

Index

Constants

View Source
const ColorMissingProblemType = "urn:mockgame:problem:color-missing"

ColorMissingProblemType is the ready-check's refusal of a member who has chosen no color.

View Source
const HooksPath = "/hooks"

HooksPath is where a Game serves its hooks.

View Source
const MaxRounds = 5

MaxRounds bounds the rounds setting.

View Source
const SeatName = "Mock bot (level 1)"

SeatName names the mock game's only seat.

Variables

This section is empty.

Functions

This section is empty.

Types

type Game

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

Game is the mock game.

func New

func New(key string, secret []byte) (*Game, error)

New returns a mock game with key, whose hooks verify signatures with secret.

func (*Game) Calls

func (game *Game) Calls(hook string) int

Calls counts the signed calls of hook that reached the game, failed ones included.

func (*Game) Delay

func (game *Game) Delay(hook string, delay time.Duration, times int)

Delay makes the next times calls of hook wait for delay first, or until the call is canceled.

func (*Game) Fail

func (game *Game) Fail(hook string, status, times int)

Fail makes the next times calls of hook answer status, with a problem, without running the hook.

func (*Game) Finish

func (game *Game) Finish(lobbyID string) bool

Finish ends the game of the lobby's newest round, and reports whether there was one.

func (*Game) Games

func (game *Game) Games() []StartedGame

Games returns the recorded games, by lobby and round.

func (*Game) Registration

func (game *Game) Registration() domain.GameRegistration

Registration is the mock game's hooks as Go functions, which NewHandler serves. The key is the game's; its start rules and retention are the lobby configuration's.

func (*Game) ServeHTTP

func (game *Game) ServeHTTP(response http.ResponseWriter, request *http.Request)

func (*Game) UseLobby

func (game *Game) UseLobby(client *gamehooks.GameAPIClient)

UseLobby connects the game to the lobby's game API, for GET /watch.

type StartedGame

type StartedGame struct {
	ID      string
	LobbyID string
	Round   int64
	// Players are the start roster's player IDs, in roster order.
	Players []string
	// Colors are the people's colors by player ID, from their member
	// settings.
	Colors map[string]string
	Ended  bool
}

StartedGame is a game that start recorded for a lobby's round.

type Watch

type Watch struct {
	GameID  string `json:"game_id"`
	LobbyID string `json:"lobby_id"`
	Round   int64  `json:"round"`
	Phase   string `json:"phase"`
}

Watch is the answer of GET /watch/{lobby_id}.

Jump to

Keyboard shortcuts

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