Documentation ¶
Overview ¶
Package cc_rest_lib provides the handlers for managing and mutating CookieClicker games to the Firebase DB.
Index ¶
- Variables
- func BuildingHandler(resp http.ResponseWriter, req *http.Request)
- func ClickHandler(resp http.ResponseWriter, req *http.Request)
- func GameRouter(resp http.ResponseWriter, req *http.Request)
- func MineHandler(resp http.ResponseWriter, req *http.Request)
- func NewGameHandler(resp http.ResponseWriter, req *http.Request)
- func UpgradeHandler(resp http.ResponseWriter, req *http.Request)
- type ClickRequest
- type NewGameResponse
Constants ¶
This section is empty.
Variables ¶
var BuildingRegex *regexp.Regexp = regexp.MustCompile(`^/game/(?P<gameID>[\w-]*)/building/(?P<buildingType>[\w-]*)(/)?$`)
var ClickRegex *regexp.Regexp = regexp.MustCompile(`^/game/(?P<gameID>[\w-]*)/cookie/click(/)?$`)
var MineRegex *regexp.Regexp = regexp.MustCompile(`^/game/(?P<gameID>[\w-]*)/cookie/mine(/)?$`)
var NewGameRegex *regexp.Regexp = regexp.MustCompile(`^/game(/)?$`)
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.