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:
@@ -148,3 +148,26 @@ func test_names_are_sanitised() -> void:
|
||||
var with_control := "ab" + String.chr(7) + String.chr(10) + "cd"
|
||||
assert_eq(Character.sanitize_name(with_control), "abcd",
|
||||
"control characters would let a name break the HUD's layout")
|
||||
|
||||
|
||||
## The suggested name exists so the create field is never blank. It only has to
|
||||
## be non-empty and survive sanitising -- it is a starting point, not an
|
||||
## identity.
|
||||
func test_suggested_names_are_usable() -> void:
|
||||
var rng := RandomNumberGenerator.new()
|
||||
rng.seed = 3
|
||||
for _i in 50:
|
||||
var n := Character.random_name(rng)
|
||||
assert_false(n.is_empty())
|
||||
assert_lte(n.length(), Character.MAX_NAME)
|
||||
assert_eq(Character.sanitize_name(n), n,
|
||||
"a suggestion must survive the sanitiser unchanged")
|
||||
|
||||
|
||||
func test_suggested_names_vary() -> void:
|
||||
var rng := RandomNumberGenerator.new()
|
||||
rng.seed = 9
|
||||
var seen := {}
|
||||
for _i in 40:
|
||||
seen[Character.random_name(rng)] = true
|
||||
assert_gt(seen.size(), 10, "a fixed suggestion would be worse than none")
|
||||
|
||||
Reference in New Issue
Block a user