Documentation
¶
Overview ¶
Package boards holds the rules for the boards a mod declares in its manifest: which declarations a build may carry, and which partition values a score may name. A host that serves the scores service checks reports with the same rules.
Index ¶
- Constants
- func Answer(local *Local, manifest *wasm.Manifest, seats Seats, names func(uint64) string, ...) ([]byte, string, error)
- func Find(manifest *wasm.Manifest, name string) *scorespb.Board
- func Partitioned(board *scorespb.Board, values map[string]string) error
- func TeamEntrant(members []uint64) uint64
- func Teamed(board *scorespb.Board, player int32, teammates []int32) error
- func Validate(manifest *wasm.Manifest) error
- func Windows(board *scorespb.Board) []scorespb.Window
- type Binder
- type Entry
- type Local
- type Seat
- type Seats
- type Submission
Constants ¶
const ( // MaxScoreValue bounds a score's magnitude, and a KEEP_SUM standing // saturates at it, so a value read as a JSON number stays exact. MaxScoreValue = 1<<53 - 1 // MaxReportScores bounds the scores one submission ranks: the players of // the largest match a server reports. MaxReportScores = 64 // MaxKeyBytes bounds the key a mod names for a round or run. MaxKeyBytes = 128 // MaxEvidenceBytes bounds what a submission names as its evidence. MaxEvidenceBytes = 256 // EarnedGrace is how long before its report a score may have been // earned, so a late report cannot land in a window that already closed. EarnedGrace = time.Hour )
const MaxTeamSize = 4
MaxTeamSize is the most players a team board's team holds.
const Service = "scores"
Service names the service mods report scores to and read boards from.
Variables ¶
This section is empty.
Functions ¶
func Answer ¶
func Answer(local *Local, manifest *wasm.Manifest, seats Seats, names func(uint64) string, method string, payload []byte, now time.Time) ([]byte, string, error)
Answer answers one call to the scores service for the mod manifest describes, from local: Report and Match rank their scores, and Read returns a page. seats checks each connection the call names; nil trusts a host that checked them before passing the call on. names gives each player's name. Besides the reply it returns a line that says what a report ranked, or why the board held it back, for the session's log.
func Partitioned ¶
Partitioned checks that values names one accepted value for each of board's partitions and nothing else.
func TeamEntrant ¶
TeamEntrant is the entrant members rank under on a board that ranks teams: a hash of their sorted SteamID64s in the team range, so the same players in any order are one team.
func Teamed ¶
Teamed checks that a score or read on board names its teammates as the board's team takes them: the team size less one on a team board, each a different player and none the scoring player, and none on a board of single players. player is the scoring or reading player's slot, and teammates are the slots of the players the call names.
Types ¶
type Binder ¶
type Binder struct {
// Seat names each slot's live player.
Seat Seat
// contains filtered or unexported fields
}
Binder issues the proofs a host gives a mod for the connections it serves, and checks them when the mod reports. A proof stays valid after its player leaves, so a mod can report a departed player's score. It implements Seats. It is safe for concurrent use.
func (*Binder) Bind ¶
func (b *Binder) Bind(conn *scorespb.ScoreConnection) (*scorespb.ScoreConnection, error)
Bind returns conn with its proof when its player holds its slot on that generation, and an error otherwise. Binding a connection again returns the same proof.
type Entry ¶
type Entry struct {
// SteamID is the scoring player.
SteamID uint64
// Members are the team's players, the scoring one included, on a board
// that ranks teams, and none on a board of single players.
Members []uint64
// Value is the entry's score in the board's unit.
Value int64
// Tiebreak ranks equal values, lower first.
Tiebreak int64
}
Entry is one entrant's score in a submission.
type Local ¶
type Local struct {
// contains filtered or unexported fields
}
Local ranks one session's scores in memory, by the rules a published board ranks them by, for a host with no backend: a sandbox or a game on the author's computer. Its standings last as long as the Local.
It ranks scores from every server tier, where a published board holds back scores from a server below its declared tier; it keeps every other rule. It is safe for concurrent use.
func (*Local) Page ¶
func (l *Local) Page(board *scorespb.Board, query *scorespb.BoardQuery, viewer uint64, names func(uint64) string, now time.Time) *scorespb.BoardPage
Page reads the page of board that query selects at now, with viewer's own standing when viewer, a player or TeamEntrant, holds one. names gives each player's name. An omitted window reads all time, and an omitted partition value reads the partition's first declared value. A window or partition the board does not keep reads empty.
func (*Local) Record ¶
Record ranks the entries of sub at now. It refuses the whole submission or none of it; a resent submission changes nothing, and a different one with the same key is refused. It returns why the board holds back any entry of an accepted submission, a value outside its lowest and highest, or "" when every entry ranks.
type Seat ¶
Seat names the player who holds slot now, with the slot's generation, and ok false when no human holds it.
type Seats ¶
type Seats interface {
// Bound reports whether the host bound connection for the mod while it
// served the player in slot. Reports and matches carry bound connections,
// so a mod can report a player who has since left.
Bound(connection *scorespb.ScoreConnection, slot int32) bool
// Live reports whether connection still holds slot. A read names the
// viewer's live connection, with no proof.
Live(connection *scorespb.ScoreConnection, slot int32) bool
}
Seats checks the connections a scores call names. Answer refuses a call whose player, teammate or participant fails its check.
type Submission ¶
type Submission struct {
// Board is the declared board the entries rank on.
Board *scorespb.Board
// Key names the submission's receipt; the same key with the same
// contents is the same submission. The host frames it, so a mod's own
// key cannot name another player's implicit one.
Key string
// Partition names one value of each of the board's partitions.
Partition map[string]string
// Earned is when the scores were earned, in Unix milliseconds; zero
// means when they are recorded.
Earned int64
// Evidence is what the mod names as the scores' evidence.
Evidence string
// Entries are the scores, one per player.
Entries []Entry
}
Submission is one report or match: the entries it ranks together, all or none.