Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

v0 source realm

v0 - Unaudited: This is an initial version that has not yet been formally audited. Use in production at your own risk.

Overview

v0 - Unaudited: This is an initial version that has not yet been formally audited. Use in production at your own risk.

Package game is the on-chain part of gnofly, a multiplayer plane game. It is the source of truth for everything an admin can tune: the game parameters, the roles and the treasury. It also keeps what the referee attests and what has lasting value: the kills, on the kill leaderboard. Skins and planes are tokens of their own realms, gnofly/nfts/skins and gnofly/nfts/planes, which ask this one who the admins are and where the treasury is.

Three kinds of callers write to it:

  • the owner and the admins tune the game (SetParam, ...). Every such write bumps Version, which is how the game server knows it has to read StateJSON again;
  • referees, the game servers, record kills (SubmitKills).

Challenge runs never reach the chain: the game server defines the challenges, scores the runs and keeps the session boards.

Reads are plain functions meant for vm/qeval. The ones ending in JSON return a single string holding a JSON document. Render exposes the same data as markdown for gnoweb.

Functions 17

func AddAdmin

crossing Action
1func AddAdmin(cur realm, addr address)
source

AddAdmin adds addr to the admin list. Owner only.

func AddReferee

crossing Action
1func AddReferee(cur realm, addr address)
source

AddReferee allows addr to submit kills. Admin only.

func IsAdmin

Action
1func IsAdmin(addr address) bool
source

IsAdmin reports whether addr is an admin. The owner always is.

func KillLeaderboardJSON

Action
1func KillLeaderboardJSON() string
source

KillLeaderboardJSON returns the top players by kills recorded on-chain as a JSON array, best first, at most leaderboard_size entries:

Example
1[ { "address": "g1...", "kills": 17 } ]

The output has no whitespace. With equal kills, the player who got there first stays ahead.

func Param

Action
1func Param(key string) int64
source

Param returns the value of a game parameter. It panics on an unknown key.

func PlayerJSON

Action
1func PlayerJSON(addr address) string
source

PlayerJSON returns one player as a JSON object:

Example
1{ "address": "g1...", "kills": 17 }

The output has no whitespace. An unknown address has zero kills. The skins and planes a player owns are read from their realms (SkinsOf, PlanesOf).

func RemoveAdmin

crossing Action
1func RemoveAdmin(cur realm, addr address)
source

RemoveAdmin removes addr from the admin list. Owner only.

The owner is an admin by definition and cannot be demoted this way, use TransferOwnership.

func RemoveReferee

crossing Action
1func RemoveReferee(cur realm, addr address)
source

RemoveReferee stops addr from submitting kills. Admin only.

func Render

1func Render(path string) string
source

Render returns the state of the game as markdown, for gnoweb:

Example
1""               overview
2"leaderboard"    the top players by kills
3"params"         the game parameters and their bounds
4"player/<addr>"  one player

Everything printed here was validated against a narrow charset when it was written (see validate.gno), and the only caller-supplied value, the address of a player page, is printed only if it is a valid address. Nothing needs markdown escaping.

func SetParam

crossing Action
1func SetParam(cur realm, key string, value int64)
source

SetParam changes a game parameter. Admin only.

The key must exist and the value must be within the bounds of that key, see Render("params"). Lowering leaderboard_size truncates the kill leaderboard right away. Raising it does not bring back the lines that were dropped: the list fills up again as kills come in.

func SetParamBounds

crossing Action
1func SetParamBounds(cur realm, key string, min, max int64)
source

SetParamBounds changes the range SetParam accepts for a key. Owner only.

The bounds are the guard rail between the owner and the admins: admins tune values within them, the owner decides how far tuning may go. The current value has to fit the new bounds, so that the registry never holds a value SetParam would refuse.

func SetTreasury

crossing Action
1func SetTreasury(cur realm, addr address)
source

SetTreasury sets the address the sales of skins and planes are forwarded to. Owner only.

func StateJSON

Action
1func StateJSON() string
source

StateJSON returns everything the game needs from the chain, as one JSON object:

Example
1{
2  "version": 12,
3  "treasury": "g1...",
4  "params": { "plane_speed": 70, "boost_speed": 130 }
5}

The output has no whitespace. It only changes when Version does. The skins are in their own realm, gnofly/nfts/skins.

func SubmitKills

crossing Action
1func SubmitKills(cur realm, kills string)
source

SubmitKills adds kills to players' on-chain counts. Referee only.

kills is 1 to 32 entries "address:count" separated by ";", for example

Example
1g1abc...:3;g1def...:1

Each address must be valid and listed once, each count from 1 to 1000. Anything else aborts the transaction and nothing is recorded. The counts are added to what the players already have, and the kill leaderboard is updated. Kills are player actions: Version does not move.

func TransferOwnership

crossing Action
1func TransferOwnership(cur realm, newOwner address)
source

TransferOwnership hands the realm over to newOwner. Owner only.

The previous owner keeps no privilege, unless it was also added to the admin or referee lists.

func Version

Action
1func Version() int64
source

Version returns a counter that bumps on every admin write: params, treasury and roles. Referee actions (kills) do not bump it. A reader that cached StateJSON only has to read it again when Version changed.

Imports 6

Source Files 13