Stage 2: accounts, characters, permadeath, levels and experience
ci / verify (push) Successful in 47s
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.
This commit is contained in:
1 parent
ff5e527ad4
commit
4765bbce28
36 files changed
+1613
-34
No files matched your search
+62
-4
@@ -22,6 +22,10 @@ var server: ServerRuntime = null
|
||||
var client: ClientRuntime = null
|
||||
var last_error: String = ""
|
||||
|
||||
## How this build establishes identity. One line to swap for a Steam provider:
|
||||
## everything downstream deals only in the 64-bit account id it produces.
|
||||
var auth: AuthProvider = LocalAuthProvider.new()
|
||||
|
||||
|
||||
func _set_state(s: State) -> void:
|
||||
state = s
|
||||
@@ -116,7 +120,7 @@ func _on_peer_disconnected(peer_id: int) -> void:
|
||||
|
||||
func _on_connected() -> void:
|
||||
_set_state(State.ONLINE)
|
||||
c_hello.rpc_id(1, Protocol.VERSION, GameOpts.player_name)
|
||||
c_hello.rpc_id(1, Protocol.VERSION, auth.get_ticket())
|
||||
|
||||
|
||||
func _on_connect_failed() -> void:
|
||||
@@ -142,7 +146,7 @@ func start_local_client() -> void:
|
||||
client = ClientRuntime.new()
|
||||
client.name = "Client"
|
||||
add_child(client)
|
||||
server.on_hello(LOCAL_PEER, Protocol.VERSION, GameOpts.player_name)
|
||||
server.on_hello(LOCAL_PEER, Protocol.VERSION, auth.get_ticket())
|
||||
|
||||
|
||||
func _is_local(peer_id: int) -> bool:
|
||||
@@ -194,6 +198,20 @@ func send_events(peer_id: int, data: PackedByteArray) -> void:
|
||||
s_events.rpc_id(peer_id, data)
|
||||
|
||||
|
||||
func send_characters(peer_id: int, data: PackedByteArray) -> void:
|
||||
if _is_local(peer_id):
|
||||
client.on_characters(data)
|
||||
else:
|
||||
s_characters.rpc_id(peer_id, data)
|
||||
|
||||
|
||||
func send_select_result(peer_id: int, result: int, reason: String) -> void:
|
||||
if _is_local(peer_id):
|
||||
client.on_select_result(result, reason)
|
||||
else:
|
||||
s_select_result.rpc_id(peer_id, result, reason)
|
||||
|
||||
|
||||
func send_roster(peer_id: int, data: PackedByteArray) -> void:
|
||||
if _is_local(peer_id):
|
||||
client.on_roster(data)
|
||||
@@ -208,6 +226,20 @@ func send_reject(peer_id: int, reason: String) -> void:
|
||||
s_reject.rpc_id(peer_id, reason)
|
||||
|
||||
|
||||
func select_character(character_id: String) -> void:
|
||||
if server != null:
|
||||
server.on_select_character(LOCAL_PEER, character_id)
|
||||
elif state == State.ONLINE:
|
||||
c_select_character.rpc_id(1, character_id)
|
||||
|
||||
|
||||
func create_character(character_name: String) -> void:
|
||||
if server != null:
|
||||
server.on_create_character(LOCAL_PEER, character_name)
|
||||
elif state == State.ONLINE:
|
||||
c_create_character.rpc_id(1, character_name)
|
||||
|
||||
|
||||
func send_input(data: PackedByteArray) -> void:
|
||||
if server != null:
|
||||
server.on_input(LOCAL_PEER, data) # listen server: no transport at all
|
||||
@@ -218,10 +250,24 @@ func send_input(data: PackedByteArray) -> void:
|
||||
# --- Client -> server -------------------------------------------------------
|
||||
|
||||
@rpc("any_peer", "call_remote", "reliable", 1)
|
||||
func c_hello(version: int, display_name: String) -> void:
|
||||
func c_hello(version: int, ticket: PackedByteArray) -> void:
|
||||
if server == null:
|
||||
return
|
||||
server.on_hello(multiplayer.get_remote_sender_id(), version, display_name)
|
||||
server.on_hello(multiplayer.get_remote_sender_id(), version, ticket)
|
||||
|
||||
|
||||
@rpc("any_peer", "call_remote", "reliable", 1)
|
||||
func c_select_character(character_id: String) -> void:
|
||||
if server == null:
|
||||
return
|
||||
server.on_select_character(multiplayer.get_remote_sender_id(), character_id)
|
||||
|
||||
|
||||
@rpc("any_peer", "call_remote", "reliable", 1)
|
||||
func c_create_character(character_name: String) -> void:
|
||||
if server == null:
|
||||
return
|
||||
server.on_create_character(multiplayer.get_remote_sender_id(), character_name)
|
||||
|
||||
|
||||
@rpc("any_peer", "call_remote", "unreliable_ordered", 4)
|
||||
@@ -262,6 +308,18 @@ func s_reject(reason: String) -> void:
|
||||
_set_state(State.FAILED)
|
||||
|
||||
|
||||
@rpc("authority", "call_remote", "reliable", 1)
|
||||
func s_characters(data: PackedByteArray) -> void:
|
||||
if client != null:
|
||||
client.on_characters(data)
|
||||
|
||||
|
||||
@rpc("authority", "call_remote", "reliable", 1)
|
||||
func s_select_result(result: int, reason: String) -> void:
|
||||
if client != null:
|
||||
client.on_select_result(result, reason)
|
||||
|
||||
|
||||
@rpc("authority", "call_remote", "reliable", 1)
|
||||
func s_roster(data: PackedByteArray) -> void:
|
||||
if client != null:
|
||||
|
||||
Reference in new issue
Block a user