cc_rest_lib

package
v0.0.0-...-a558ee2 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2017 License: MIT Imports: 11 Imported by: 0

README

CookieClicker REST Server

go test \
    --credentials=/path/to/Google/credentials.json \
    --project=some-string-project-id \
    --environment=(dev|prod)

Documentation

Overview

Package cc_rest_lib provides the handlers for managing and mutating CookieClicker games to the Firebase DB.

Index

Constants

This section is empty.

Variables

View Source
var BuildingRegex *regexp.Regexp = regexp.MustCompile(`^/game/(?P<gameID>[\w-]*)/building/(?P<buildingType>[\w-]*)(/)?$`)
View Source
var ClickRegex *regexp.Regexp = regexp.MustCompile(`^/game/(?P<gameID>[\w-]*)/cookie/click(/)?$`)
View Source
var MineRegex *regexp.Regexp = regexp.MustCompile(`^/game/(?P<gameID>[\w-]*)/cookie/mine(/)?$`)
View Source
var NewGameRegex *regexp.Regexp = regexp.MustCompile(`^/game(/)?$`)
View Source
var UpgradeRegex *regexp.Regexp = regexp.MustCompile(`^/game/(?P<gameID>[\w-]*)/upgrade/(?P<upgradeID>[\w-]*)(/)?$`)

Functions

func BuildingHandler

func BuildingHandler(resp http.ResponseWriter, req *http.Request)

BuildingHandler mutates the given game by incrementing the given building by spending cookies. The URL must match BuildingRegex. The only valid method is a POST request with an empty body. A successful POST request will return a 204 NO CONTENT response with an empty body. BuildingHandler will return with 402 PAYMENT REQUIRED in the case the user does not have enough cookies to buy a new building. BuildingHandler may return with 412 PRECONDITION FAILED in the case of a race condition. The caller is responsible for reissuing the request.

func ClickHandler

func ClickHandler(resp http.ResponseWriter, req *http.Request)

ClickHandler mutates the given game by incrementing the number of cookies in the bank by clicking "the cookie" some number of times. The URL must match ClickHandlerRegex. The only valid method is a POST request with a supplied ClickRequest body. A successful POST request will return a 204 NO CONTENT response with an empty body. ClickHandler may return with 412 PRECONDITION FAILED in the case of a race condition. The caller is responsible for reissuing the request.

func GameRouter

func GameRouter(resp http.ResponseWriter, req *http.Request)

GameRouter is responsible for routing all URLs to an appropriate handler.

func MineHandler

func MineHandler(resp http.ResponseWriter, req *http.Request)

MineHandler mutates the given game by incrementing the number of cookies in the bank by a calculated amount scaled since the last time this method was called. The URL must match MineHandlerRegex. The only valid method is a POST request with an empty body. A successful POST request will return a 204 NO CONTENT response with an empty body. MineHandler may return with 412 PRECONDITION FAILED in the case of a race condition. The caller is responsible for reissuing the request.

func NewGameHandler

func NewGameHandler(resp http.ResponseWriter, req *http.Request)

NewGameHandler creates a new game and stores the game state in the database. The URL must match NewGameRegex. The only valid method is a POST request with an empty body. A successful POST request will return a 201 CREATED response with a supplied NewGameResponse.

func UpgradeHandler

func UpgradeHandler(resp http.ResponseWriter, req *http.Request)

UpgradeHandler mutates the given game by incrementing the given upgrade by spending cookies. The URL must match UpgradeRegex. The only valid method is a POST request with an empty body. A successful POST request will return a 204 NO CONTENT response with an empty body. UpgradeHandler will return with 402 PAYMENT REQUIRED in the case the user does not have enough cookies to buy the upgrade. UpgradeHandler will return with 412 PRECONDITION FAILED in the case of a race condition. The caller is responsible for reissuing the request.

Types

type ClickRequest

type ClickRequest struct {
	// List of monotonically increasing click time events,
	// i.e. Events[i] < Events[i + 1].
	Events []time.Time `json:"events"`

	// Byte array of the correct validation SHA256 hash
	// associated with clicking the cookie len(Clicks) times.
	//
	// JSON will represent this as a Base64-encoded string,
	// e.g. LUt2MTZEOXc3d3I2dVV0RExFS2Q=.
	//
	// The current hash is provided in the game state. The correct Hash
	// value can be calculated by hashing (unencoded byte array)
	// len(Clicks) times.
	Hash []byte `json:"hash"`
}

type NewGameResponse

type NewGameResponse struct {
	// The full URL of the game state,
	// e.g. https://some-project-id.firebaseio.com/game/some-game-id.json
	Path string `json:"path"`
}

NewGameResponse encapsulates the game state resource path.

Jump to

Keyboard shortcuts

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