Fix: ability WithinRange/IsAdjacentToSource filters + ModelCache web CORS

- AbilitySystem: implement WithinRangeFilter (Manhattan distance min/max) and
  IsAdjacentToSourceFilter in FilterMatches — both were falling through to
  _ => true, so range constraints on targeting were silently ignored
- Program.cs: add GET /cdn/{**path} proxy endpoint with
  Access-Control-Allow-Origin: * so browser web clients can fetch GLB models
  (Ceph RadosGW / cdn.aeternalisgames.com has no CORS headers)
- ModelCache.gd: on web export, rewrite cdn.aeternalisgames.com URLs to go
  through hub.aeternalisgames.com/cdn proxy; disk/memory cache still keyed
  on the original CDN URL for consistency across platforms

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-10 10:39:13 -04:00
co-authored by Claude Happy
parent da6899b2c7
commit 8e3f64d9d1
3 changed files with 47 additions and 4 deletions
+18 -4
View File
@@ -11,7 +11,12 @@ extends Node
## user://remote_model_cache/<sha256>.bin
## so subsequent app launches skip the download.
const _CACHE_DIR := "user://remote_model_cache"
const _CACHE_DIR := "user://remote_model_cache"
# On web exports, direct CDN fetches are blocked by CORS (Ceph RadosGW doesn't send
# Access-Control-Allow-Origin). Route through the game server proxy instead.
const _CDN_BASE := "https://cdn.aeternalisgames.com"
const _PROXY_BASE := "https://hub.aeternalisgames.com/cdn"
# url (String) → PackedScene or null (null means "tried and failed")
static var _mem: Dictionary = {}
@@ -59,8 +64,17 @@ func load_model(url: String, callback: Callable) -> void:
_download(url, disk)
## Returns the URL to actually fetch — on web, rewrites CDN URLs to go through
## the game server proxy so CORS headers are added.
func _fetch_url(url: String) -> String:
if OS.has_feature("web") and url.begins_with(_CDN_BASE + "/"):
return _PROXY_BASE + "/" + url.substr(_CDN_BASE.length() + 1)
return url
func _download(url: String, disk: String) -> void:
print("ModelCache: downloading — %s" % url)
var fetch := _fetch_url(url)
print("ModelCache: downloading — %s" % fetch)
var http := HTTPRequest.new()
http.body_size_limit = -1 # unlimited
add_child(http)
@@ -120,9 +134,9 @@ func _download(url: String, disk: String) -> void:
cb.call(packed.instantiate() if packed != null else null)
)
var err := http.request(url)
var err := http.request(fetch)
if err != OK:
push_warning("ModelCache: request() error %d — %s" % [err, url])
push_warning("ModelCache: request() error %d — %s" % [err, fetch])
var callbacks: Array = _pending.get(url, [])
_pending.erase(url)
for cb: Callable in callbacks:
@@ -1411,6 +1411,15 @@ public static class AbilitySystem
IsExactSelfFilter => ctx.Source is not null && card.InstanceId == ctx.Source.InstanceId,
HealthBelowFilter hbf => (card.CurrentHealth ?? 0) < hbf.N,
HealthAboveFilter haf => (card.CurrentHealth ?? 0) > haf.N,
IsAdjacentToSourceFilter =>
ctx.Source is FieldCard srcAdj && srcAdj.Position.HasValue &&
card is FieldCard adjTgt && adjTgt.Position.HasValue &&
srcAdj.Position.Value.IsOrthogonallyAdjacentTo(adjTgt.Position.Value),
WithinRangeFilter wrf =>
ctx.Source is FieldCard srcWr && srcWr.Position.HasValue &&
card is FieldCard wrTgt && wrTgt.Position.HasValue &&
srcWr.Position.Value.ManhattanDistance(wrTgt.Position.Value) >= wrf.Min &&
srcWr.Position.Value.ManhattanDistance(wrTgt.Position.Value) <= wrf.Max,
_ => true,
};
+20
View File
@@ -127,6 +127,15 @@ builder.Services.AddNats(configureOpts: opts =>
// TODO: add dependency health checks (Redis, NATS, Postgres) per service.
builder.Services.AddHealthChecks();
// ── CDN proxy ─────────────────────────────────────────────────────────────────
// Proxies CDN asset requests and adds CORS headers.
// Required for web (browser) clients: Ceph RadosGW (cdn.aeternalisgames.com) does not
// emit Access-Control-Allow-Origin, so browsers block direct CDN fetches.
// The web client routes model requests through https://hub.aeternalisgames.com/cdn/…
// instead of https://cdn.aeternalisgames.com/… to work around the restriction.
var cdnProxyBase = (builder.Configuration["Cdn:PublicBaseUrl"] ?? "https://cdn.aeternalisgames.com").TrimEnd('/');
builder.Services.AddHttpClient("cdn");
// ── Networking transports ─────────────────────────────────────────────────────
// These are the CONCRETE implementations of the networking abstractions.
// This section is the "wiring" point. To swap a transport, change only here.
@@ -200,6 +209,17 @@ if (IsEnabled("auth"))
// Health check endpoint: Kubernetes probes GET /health to check liveness.
app.MapHealthChecks("/health");
// CDN asset proxy: adds CORS so browser web clients can fetch models/assets.
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);
});
// ── RUN ───────────────────────────────────────────────────────────────────────
Log.Information("SOR Host starting. Services: {Services}", rawServices);