hall.gno
1.93 Kb · 61 lines
1// Package hall is the scoreboard of Cellar, a capture-the-flag wargame
2// played on gno.land.
3//
4// Challenge realms enlist themselves here from their init. Players break a
5// challenge in its own realm, then Claim it here: the hall asks the
6// challenge whether the player captured it, records the solve, awards a
7// badge and updates the standings. Points follow the dynamic curve in
8// package flag, so a challenge is worth less as more players solve it.
9//
10// Everything a player sees is in Render, so gnoweb is a complete client.
11package hall
12
13import (
14 "strings"
15
16 "gno.land/p/nt/avl/v0"
17)
18
19// officialPrefix marks the realms of the Cellar team. Challenges enlisted
20// from below it are listed at once; everyone else waits for the curator.
21const officialPrefix = "gno.land/r/g15c02s5hhdny9uvr9za3xsyn9sw8p0klptrh6kf/cellar/"
22
23// feedSize is how many recent solves the hall remembers for its feed.
24const feedSize = 50
25
26var (
27 curator = address("g15c02s5hhdny9uvr9za3xsyn9sw8p0klptrh6kf")
28 selfPath string // web path of this realm, e.g. /r/<ns>/cellar/hall
29
30 entries = avl.NewTree() // slug -> *entry
31 paths = avl.NewTree() // challenge realm path -> slug
32 order []string // slugs in enlistment order
33 players = avl.NewTree() // address -> *profile
34 handles = avl.NewTree() // handle -> address
35 seasons []*season // the last one is open
36 feed []Solve // newest last, at most feedSize
37)
38
39func init(cur realm) {
40 selfPath = strings.TrimPrefix(cur.PkgPath(), "gno.land")
41 initBadges(cur)
42 seasons = append(seasons, newSeason(1, "First Pressing"))
43}
44
45// Curator returns the address allowed to curate the hall.
46func Curator() address { return curator }
47
48// TransferCuration hands the curator role to another address.
49func TransferCuration(cur realm, to address) {
50 assertCurator(cur)
51 if !to.IsValid() {
52 panic(ErrBadAddress)
53 }
54 curator = to
55}
56
57func assertCurator(cur realm) {
58 if cur.Previous().Address() != curator {
59 panic(ErrNotCurator)
60 }
61}