Repository navigation
Reject game mode JSON that lobby clients cannot read - #3074
moss-orbit-9f339e wants to merge 1 commit into
Conversation
The mod edit page stored GameModeJson unchecked, so a mode with a trailing comma was saved and sent to clients, where Chobby's decoder rejects it and the mode disappears from the list. Parse it with System.Text.Json (strict JSON, already referenced by ZkLobbyServer) on create and edit, require an object with a "name" text field, and show the line and position of the error. Fixes ZeroK-RTS#3073 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Test details. Corpus. 54 small files. Each one went through Chobby's
Every input that Chobby cannot load is rejected, except The issue case gives: Stored modes. I downloaded all 248 modes listed on https://zero-k.info/Mods (8 featured) and ran the same two checks.
The 47 modesTest, king_builder, flying_ships, infection, limited_tech, old_random_morphs, 1_unit, old_strider_goo, CAPTURE_SIDEARM, detriment_rush, ulti_spam, capture, zombie_building, chicken_farm_mex, half_price, Flip, i_love_geo, Geo_Flip, wallmap, rampmap, freakmap, sphere, MYAI, diceandsplice, ora, dasor, noregenhermit, randland, BossAI, fallback, ScaleAI, kingAI, chickmex, temple, moreme, terraforma, upgrader, ultimateAI, UltAIGreed, SliceTemple, UltimateAIGEOFlip, UltimateAIsplice, sg5050f, UltimateAIRelick, SKUAI, rampmapMEGA, FORT
Build. I could not build the web project here (no .NET Framework web build on this machine). The method was compiled alone with mcs, with the same System.Text.Json 5.0.0 DLL that the site already loads through ZkLobbyServer. |
The mod page saved the game mode JSON without a check. A mode with a trailing comma was saved and sent to clients, but Chobby cannot read it, so the mode disappears from the list.
This change parses the JSON with System.Text.Json (strict JSON; the site already gets this package through ZkLobbyServer) on create and edit. It also requires an object with a "name" field, which Chobby needs. The error message gives the line and position. 47 stored modes that Chobby loads are not strict JSON (mostly a missing comma): they keep working, but their next save needs a fix (list in the first comment).
Tested the method under Mono on 54 JSON files against Chobby's real json.lua under Lua 5.1: it rejects every file that Chobby cannot load, except valid JSON
1E5(Chobby's decoder does not read a capital E). Details are in the first comment.Fixes #3073
This PR was made with AI help (Claude Code); I checked the change and the test.
🤖 Generated with Claude Code