feat(m5): client-server sync, offline queue and replay playback

This commit is contained in:
2026-10-24 23:37:13 +02:00
parent 4a9031b29c
commit 33bdc16fbd
22 changed files with 1419 additions and 184 deletions
+44
View File
@@ -64,6 +64,50 @@ mod tests {
assert_eq!(iron_arc_sim_version_code(), 100);
}
#[test]
fn replay_export_reproduces_state() {
unsafe {
let handle = match_api::iron_arc_new_match(77);
assert_eq!(match_api::iron_arc_fire(handle, 45_000, 65_536, 1), 0);
match_api::iron_arc_tick(handle, 400);
let hash = match_api::iron_arc_state_hash(handle);
let json_ptr = match_api::iron_arc_replay_json(handle);
assert!(!json_ptr.is_null(), "replay json must be produced");
let json = std::ffi::CStr::from_ptr(json_ptr)
.to_str()
.expect("utf8")
.to_string();
match_api::iron_arc_string_free(json_ptr);
assert!(json.contains(r#""commands""#));
let c_json = std::ffi::CString::new(json).expect("no nul bytes");
let playback = match_api::iron_arc_new_match_playback(c_json.as_ptr());
assert!(!playback.is_null(), "playback handle must be created");
assert_eq!(match_api::iron_arc_is_playback(playback), 1);
match_api::iron_arc_tick(playback, 400);
assert_eq!(
match_api::iron_arc_state_hash(playback),
hash,
"playback must reproduce the identical state"
);
match_api::iron_arc_free_match(playback);
match_api::iron_arc_free_match(handle);
}
}
#[test]
fn playback_rejects_foreign_content() {
unsafe {
let json = r#"{"v":1,"sim_version":"0.1.0","content_hash":"fnv1a:0000000000000000","seed":1,"mode":"hotseat","players":[{"tank":"a","loadout":[1,2,5]},{"tank":"b","loadout":[1,3,4]}],"commands":[],"final_hash":0,"duration_ticks":0}"#;
let c_json = std::ffi::CString::new(json).unwrap();
let handle = match_api::iron_arc_new_match_playback(c_json.as_ptr());
assert!(handle.is_null(), "content mismatch must be rejected");
}
}
#[test]
fn match_handle_roundtrip() {
unsafe {