The roster sent to clients now contains living characters only. Retirement stays server-side bookkeeping for archival; from the player's side a dead character is simply gone, and listing it offers a choice that cannot be taken. The XP bar only moved on a level-up or a character swap because it read the character roster, which is re-sent only when the SET of characters changes. Experience now rides the snapshot -- four bytes on a message already going out at 20Hz -- and the server mirrors each grant into the world immediately rather than only when a level is crossed. The create field starts with a suggested name instead of blank, and offers another after each creation. Two bugs found while testing, both mine: The first was a bad patch of my own: a change meant for the snapshot decoder also matched inside decode_characters, which then read a four-byte field its encoder never wrote and ran off the end of every packet. This is precisely the "encodes but decodes wrong" failure the codec tests exist to catch, and it was caught within a minute of the test being written. Chasing that exposed a real robustness gap: StreamPeerBuffer.get_utf8_string() pushes an engine error and returns garbage when the buffer is short, so a truncated or hostile character/roster packet produced error spam instead of degrading. Both decoders now bounds-check every field, with tests that slice each packet at many lengths and assert it degrades rather than inventing entries -- the same guarantee the input decoder already had. 206 tests. check.sh, test.sh, smoke.sh and both diagnostics pass.
This commit is contained in:
1 parent
7ef972e3b3
commit
d8197885ca
12 files changed
+214
-33
No files matched your search
@@ -222,8 +222,11 @@ func _send_characters(peer_id: int) -> void:
|
||||
var account: int = peer_accounts.get(peer_id, AuthProvider.NO_ACCOUNT)
|
||||
if account == AuthProvider.NO_ACCOUNT:
|
||||
return
|
||||
# Living characters only. Retirement is bookkeeping for the server's own
|
||||
# archive -- from the player's side a dead character is simply gone, and
|
||||
# listing it would offer a choice that cannot be taken.
|
||||
Net.send_characters(peer_id, NetCodec.encode_characters(
|
||||
store.characters_for(account), peer_characters.get(peer_id, "")))
|
||||
store.active_characters(account), peer_characters.get(peer_id, "")))
|
||||
|
||||
|
||||
func on_select_character(peer_id: int, character_id: String) -> void:
|
||||
@@ -439,6 +442,16 @@ func _grant_xp(peer_id: int, amount: int) -> void:
|
||||
if account == AuthProvider.NO_ACCOUNT or character_id.is_empty():
|
||||
return
|
||||
var levels := store.grant_xp(account, character_id, amount)
|
||||
var earned := store.get_character(account, character_id)
|
||||
if earned == null:
|
||||
return
|
||||
# Mirrored into the world every grant, not only on a level-up, so the bar
|
||||
# tracks each kill.
|
||||
var here := instance_of(peer_id)
|
||||
if here != null:
|
||||
var mine: SimPlayer = here.world.players.get(peer_id)
|
||||
if mine != null:
|
||||
mine.total_xp = earned.total_xp
|
||||
if levels <= 0:
|
||||
return
|
||||
# A level raises max health immediately, and heals by the amount gained --
|
||||
|
||||
Reference in new issue
Block a user