4765bbce28
ci / verify (push) Successful in 47s
Identity is shaped like Steamworks so swapping to it is one subclass and no schema change: the client presents an opaque ticket, the server validates it into a stable 64-bit account id, and nothing downstream sees anything else. LocalAuthProvider takes any ticket at face value -- insecure on purpose, and labelled as such everywhere, because the point is the shape rather than the security. Do not ship it. Characters persist as JSON keyed by account. Account ids are written as decimal strings because they are 64-bit and JSON numbers are doubles, which would silently round them. A corrupt store aborts the server rather than starting empty: starting empty looks like it worked and then saves over every character on the first level-up. Levels 1-15, +10 max health each, level DERIVED from lifetime experience rather than stored beside it, so a hand-edited save cannot produce a level 12 character with a level 3's experience. Experience is shared undivided across everyone alive in the instance -- splitting it would make bringing a friend cost you progress. A level-up heals by what it added, so gaining one mid-fight is relief rather than a bar that moved further from full. Death is permanent and unbinds the character entirely: no "return to the hub as the character who just died", because the run is over. The record is retired, never deleted. The five-character cap counts LIVING characters only -- counting the dead would lock a player out of their own account after five deaths. Verified by tools/diag_progression.tscn, which drives the real server through kill -> xp -> level -> health and death -> retire -> roster. The bot smoke test cannot cover that: bots are poor shots and rarely kill anything. Writing it caught two real ordering bugs -- the death event was dispatched before the payload that tells the player they died, and the dead character stayed bound to the peer. Also added --account and --store so several clients and test runs can coexist on one machine. The smoke test now uses a scratch store; without it a rerun resumed the previous run's characters and "a character was created" quietly stopped being true. 193 tests. check.sh, test.sh, smoke.sh, diag_progression and diag_prediction all pass.
64 lines
2.2 KiB
GDScript
64 lines
2.2 KiB
GDScript
class_name LocalAuthProvider
|
|
extends AuthProvider
|
|
## Development identity: no accounts, no passwords, no Steam.
|
|
##
|
|
## The client generates a 64-bit id once, stores it in user://, and presents it
|
|
## as its own ticket. The server takes it at face value.
|
|
##
|
|
## This is NOT secure and is not meant to be. Anyone can present any id, so
|
|
## anyone can claim any account's characters. It is deliberately the same shape
|
|
## as the real thing -- opaque ticket in, 64-bit account id out -- so the Steam
|
|
## provider replaces it without touching the character store, the protocol, or
|
|
## anything that consumes an account id.
|
|
##
|
|
## Before this game is reachable from the internet, this must be swapped for a
|
|
## provider that actually verifies. See docs/ROADMAP.md.
|
|
|
|
const ID_PATH := "user://account_id"
|
|
|
|
var _cached: int = AuthProvider.NO_ACCOUNT
|
|
|
|
|
|
func provider_name() -> String:
|
|
return "local-dev (insecure)"
|
|
|
|
|
|
## Read this machine's id, generating and saving one on first run.
|
|
func account_id() -> int:
|
|
if _cached != AuthProvider.NO_ACCOUNT:
|
|
return _cached
|
|
if GameOpts.account_override != AuthProvider.NO_ACCOUNT:
|
|
_cached = GameOpts.account_override
|
|
return _cached
|
|
if FileAccess.file_exists(ID_PATH):
|
|
var f := FileAccess.open(ID_PATH, FileAccess.READ)
|
|
if f != null:
|
|
var parsed := int(f.get_as_text().strip_edges())
|
|
f.close()
|
|
if parsed != AuthProvider.NO_ACCOUNT:
|
|
_cached = parsed
|
|
return _cached
|
|
var rng := RandomNumberGenerator.new()
|
|
rng.randomize()
|
|
# Positive and comfortably inside 64 bits, so it round-trips through the
|
|
# store's decimal-string keys without surprises.
|
|
_cached = absi(rng.randi()) << 20 | (absi(rng.randi()) & 0xFFFFF)
|
|
var out := FileAccess.open(ID_PATH, FileAccess.WRITE)
|
|
if out != null:
|
|
out.store_string(str(_cached))
|
|
out.close()
|
|
GameLog.info("auth", "generated local account id %d" % _cached)
|
|
return _cached
|
|
|
|
|
|
func get_ticket() -> PackedByteArray:
|
|
return str(account_id()).to_utf8_buffer()
|
|
|
|
|
|
## Accepts whatever it is given, which is the entire security model here.
|
|
func validate(ticket: PackedByteArray) -> int:
|
|
if ticket.is_empty() or ticket.size() > 64:
|
|
return AuthProvider.NO_ACCOUNT
|
|
var id := int(ticket.get_string_from_utf8().strip_edges())
|
|
return id if id > 0 else AuthProvider.NO_ACCOUNT
|