From a86675b0c92b6e219213959303895e23cd072ebc Mon Sep 17 00:00:00 2001 From: dingo Date: Sun, 15 Mar 2026 20:42:09 -0400 Subject: [PATCH] Fix: CORS header before upstream await + movement debug prints CORS: Access-Control-Allow-Origin must be set before the CDN GetAsync call so it is present even if the upstream throws (ASP.NET Core exception handling resets responses, dropping headers set after an exception). Added try/catch to return 502 cleanly on upstream failures. Debug: [Move] prints in _play_move_animations and _schedule_rebuild to diagnose why movement animation appears instant. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../origin-client/scenes/game/game_screen.gd | 12 ++++++++++- Server/src/SOR.Host/Program.cs | 20 ++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index 3d50781..4dda23e 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -886,6 +886,8 @@ func _animate_unit_move(iid: String, from_coord: Vector2i, to_coord: Vector2i, ## Detect position changes vs _prev_unit_pos and start move animations. ## Returns the maximum movement duration across all movers (seconds). func _play_move_animations(state: Dictionary) -> float: + print("[Move] _play_move_animations called. _prev_unit_pos.size=%d _unit_bodies.size=%d" \ + % [_prev_unit_pos.size(), _unit_bodies.size()]) if _prev_unit_pos.is_empty(): return 0.0 # Build the set of blocked tiles from old unit positions. @@ -902,19 +904,27 @@ func _play_move_animations(state: Dictionary) -> float: if not (pd is Dictionary) or (pd as Dictionary).is_empty(): continue var new_coord := Vector2i((pd as Dictionary).get("x", 0), (pd as Dictionary).get("y", 0)) - if not _prev_unit_pos.has(iid): continue + if not _prev_unit_pos.has(iid): + print("[Move] iid=%s not in _prev_unit_pos — skipping" % iid) + continue var old_coord : Vector2i = _prev_unit_pos[iid] if old_coord == new_coord: continue + print("[Move] iid=%s moved %s→%s body_valid=%s" % [ + iid, str(old_coord), str(new_coord), + str(is_instance_valid(_unit_bodies.get(iid) as StaticBody3D))]) # Mover has left its old tile — unblock it for BFS. blocked.erase(old_coord) var dur := _animate_unit_move(iid, old_coord, new_coord, blocked) + print("[Move] _animate_unit_move returned dur=%.2f" % dur) max_dur = maxf(max_dur, dur) + print("[Move] max_dur=%.2f" % max_dur) return max_dur ## Schedule a delayed call to _rebuild_units. ## Cancels any previous pending rebuild. If delay <= 0 rebuilds synchronously. func _schedule_rebuild(state: Dictionary, delay: float) -> void: + print("[Rebuild] _schedule_rebuild delay=%.2f" % delay) _pending_rebuild = state if _rebuild_tween != null: _rebuild_tween.kill() diff --git a/Server/src/SOR.Host/Program.cs b/Server/src/SOR.Host/Program.cs index 5a2296c..c605e94 100644 --- a/Server/src/SOR.Host/Program.cs +++ b/Server/src/SOR.Host/Program.cs @@ -210,14 +210,24 @@ if (IsEnabled("auth")) app.MapHealthChecks("/health"); // CDN asset proxy: adds CORS so browser web clients can fetch models/assets. +// Access-Control-Allow-Origin is set before the upstream await so it is +// present on error responses too (browsers suppress CORS errors otherwise). app.MapGet("/cdn/{**path}", async (string path, HttpContext httpCtx, IHttpClientFactory factory) => { - using var up = await factory.CreateClient("cdn").GetAsync($"{cdnProxyBase}/{path}"); httpCtx.Response.Headers["Access-Control-Allow-Origin"] = "*"; - httpCtx.Response.StatusCode = (int)up.StatusCode; - httpCtx.Response.ContentType = - up.Content.Headers.ContentType?.MediaType ?? "application/octet-stream"; - await up.Content.CopyToAsync(httpCtx.Response.Body); + try + { + using var up = await factory.CreateClient("cdn").GetAsync($"{cdnProxyBase}/{path}"); + httpCtx.Response.StatusCode = (int)up.StatusCode; + httpCtx.Response.ContentType = + up.Content.Headers.ContentType?.MediaType ?? "application/octet-stream"; + await up.Content.CopyToAsync(httpCtx.Response.Body); + } + catch + { + if (!httpCtx.Response.HasStarted) + httpCtx.Response.StatusCode = 502; + } }); // ── RUN ───────────────────────────────────────────────────────────────────────