From d496d2d04be963d55b25b95be439c6c89c02c11d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 16 Jun 2026 10:01:02 +0100 Subject: [PATCH] Require typed faction keys in runtime state --- .voidbot/state/aetheria.cc | Bin 154437 -> 157756 bytes Aetheria.State.Verify/Program.cs | 40 ++++++++++++++++++ Aetheria.State/README.md | 7 ++- Assets/Scripts/Gameplay/ActionGameManager.cs | 30 ++----------- .../EntityConstructionBlueprintProjector.cs | 11 +---- docs/aetheria-perfect-machine-map.md | 10 +++-- 6 files changed, 55 insertions(+), 43 deletions(-) diff --git a/.voidbot/state/aetheria.cc b/.voidbot/state/aetheria.cc index 0992fc63ee2a983916ed39be382767019a10992e..6a64baad98ccdddd62d6e4d99e2975af6bdf5a5f 100644 GIT binary patch delta 3019 zcma);TWl0n7{{3@&=xHz38g3n4hBS|d#k;pfl@9K!mSjDKuFHcoZTHeJ7+y}X4@q( zg$Pd?kc{DIqVX;SFF=|AMiYXG(P%>8!I%;hF{WSImm@Dj3I}Ov6d9IJBZKA(m|JPfmM*~0TpX>pJyKwn!@*L4dyF8LQw9d3H@A`!qK;i^ zMQ~Bxk>AuV60z(DZADXf%cj_*9#4e9CB(&kttkQ4@)mbd!Askgn?q#8a=GPXC!Soy zVBT#-*fIShg9}Dc*2Bz%XtUUITn@I<92XKi{_AFJ z~) zhi_M9vK6@$WxODHkbW2CJ#gI&qxEFyQRy}e?m%vifMbm0Da0Pefo(>xS&A8SQNCak zPE5q^(+vde-+5@s=x-Y+XhY@&{ASej41&_-3aS(Z#m->cPGe&Tf#>~|z@eT`M8QGg zR+TM<)j}qSs2Ic;N88B=uPAnyvY}CMpL({5IA&SGQJCzNkl!eQB~=t8V~x@;(+y6j zn9|fNp}@rgW-gSrH3*64peLky16`iOj*+8mfMnd;Gm0<0&q(IHLC1!U*3|fSKApRL z+W>jNvltna4HR`*6c$7XqGO~8Y6Q=q7btjKos&R6jAR)d1_$C}ZyhT(FWjrTbt*Zp zx?j$rq$)O{;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A0(U@KZz|J;r4?+EWz)+862PK0wS zbM?b#(2wru{aw@^?Vd)v+It6by#qac+5Wy<;jt!V5I0#bPNQEdX0K0=-CF(JgPbMs zSZLZ(zj+Nk`m*{3<5o~4M&j-0)7eBOoJ($Ay4DAmZ~xl{(zy98(ecrQXrS@+kLE@b WSC^2!9`iw{PhL*EYi&RW3x5EMnvSjj diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index e82c3793e..37d578a4b 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -10,6 +10,7 @@ var statePath = args.Length > 1 RequireGameplaySourcePurity(root); RequirePackageSerializerBoundary(root); RequireTypedPendingCommitKeys(root); +RequireTypedRuntimeFactionKeys(root); RequireEveRuntimeBootstrap(root); RequireNoRendererLocalConsole(root); RequireNoRendererLocalDebugPanels(root); @@ -622,6 +623,45 @@ static void RequireTypedPendingCommitKeys(string root) } } +static void RequireTypedRuntimeFactionKeys(string root) +{ + var checkedFiles = new[] + { + Path.Combine(root, "Assets", "Scripts", "ServerShared", "EntityConstructionBlueprintProjector.cs"), + Path.Combine(root, "Assets", "Scripts", "Gameplay", "ActionGameManager.cs") + }; + + var forbiddenSymbols = new[] + { + "public Guid Faction", + "blueprint.Faction =", + "blueprint.Faction)", + "blueprint.Faction,", + "blueprint.Faction;", + "ResolveFaction(blueprint.Faction", + "LegacyId(blueprint.Faction", + "ReferenceKey(blueprint.FactionKey", + "CorporationKey(entity.Faction?.ID", + "CorporationKey(pair.Key.ID", + "private static string CorporationKey" + }; + + var hits = checkedFiles + .Where(File.Exists) + .SelectMany(path => File.ReadLines(path) + .Select((line, index) => new { Path = path, LineNumber = index + 1, Line = line })) + .Where(line => forbiddenSymbols.Any(symbol => line.Line.Contains(symbol, StringComparison.Ordinal))) + .Select(line => $"{Path.GetRelativePath(root, line.Path)}:{line.LineNumber}: {line.Line.Trim()}") + .ToArray(); + + if (hits.Length > 0) + { + throw new InvalidOperationException( + "Runtime faction commits must use typed FactionKey authority, not legacy GUID fallback: " + + string.Join("; ", hits)); + } +} + static void RequireEveRuntimeBootstrap(string root) { var bootstrapPath = Path.Combine( diff --git a/Aetheria.State/README.md b/Aetheria.State/README.md index 790563a77..93f2d7028 100644 --- a/Aetheria.State/README.md +++ b/Aetheria.State/README.md @@ -105,10 +105,9 @@ item GUID fields. Unity runtime commit DTOs now carry typed `FactionKey` only for loadout entities, run entity snapshots, and faction relationship state. The old pending-command `CorporationLegacyId` fallback fields are deleted. -`EntityConstructionBlueprint` also carries `FactionKey` now. Loadout restore and -entity construction resolve factions by typed key first, with the old GUID -field kept as compatibility for construction callers that have not yet been -lowered. +`EntityConstructionBlueprint` also carries `FactionKey` only. Loadout restore, +entity construction, run entity snapshots, and faction relationship commits no +longer rebuild corporation references from legacy `Faction.ID` GUIDs. Run checkpoint commit DTOs carry typed `OrbitKey`, `ParentOrbitKey`, and `BodyKey` only for zone orbit/body snapshots. The old pending-command `OrbitLegacyId`, `ParentLegacyId`, and `BodyLegacyId` fallback fields are diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index bc4c15120..63ea74426 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -235,7 +235,6 @@ public class ActionGameManager : MonoBehaviour blueprint.Name = entity.Name; blueprint.FactionKey = entity.FactionKey ?? ""; - blueprint.Faction = ParseLegacyGuidFromReferenceKey(blueprint.FactionKey, "aetheria.corporation"); blueprint.Hull = hull; blueprint.Equipment = CreateEquippableSlots(entity.Equipment); blueprint.CargoBays = CreateEquippableSlots(entity.CargoBays); @@ -277,7 +276,6 @@ public class ActionGameManager : MonoBehaviour blueprint.Name = entity.Name ?? ""; blueprint.FactionKey = entity.FactionKey ?? ""; - blueprint.Faction = ParseLegacyGuidFromReferenceKey(blueprint.FactionKey, "aetheria.corporation"); blueprint.Hull = hull; blueprint.Equipment = CreateEquippableSlots(entity.Equipment); blueprint.CargoBays = CreateEquippableSlots(entity.CargoBays); @@ -559,7 +557,7 @@ public class ActionGameManager : MonoBehaviour { Name = blueprint.Name ?? "", Kind = blueprint is ShipConstructionBlueprint ? "ship" : blueprint is OrbitalEntityConstructionBlueprint ? "orbital" : "entity", - FactionKey = ReferenceKey(blueprint.FactionKey ?? "", "aetheria.corporation", LegacyId(blueprint.Faction)), + FactionKey = blueprint.FactionKey ?? "", Hull = ProjectLoadoutItem(blueprint.Hull), Equipment = ProjectSlots(blueprint.Equipment), CargoBays = ProjectSlots(blueprint.CargoBays), @@ -687,7 +685,7 @@ public class ActionGameManager : MonoBehaviour .OrderBy(pair => pair.Key.ID) .Select(pair => new AetheriaRuntimeFactionRelationshipCommit { - FactionKey = CorporationKey(pair.Key.ID), + FactionKey = pair.Key.FactionKey ?? "", Relationship = pair.Value.ToString(), Standing = (int)pair.Value }) @@ -958,7 +956,7 @@ public class ActionGameManager : MonoBehaviour TractorPower = entity.TractorPower, Heatstroke = entity.Heatstroke, Hypothermia = entity.Hypothermia, - FactionKey = CorporationKey(entity.Faction?.ID ?? Guid.Empty), + FactionKey = entity.Faction?.FactionKey ?? "", HullItemKey = entity.Hull?.ItemKey ?? "", Equipment = ProjectEquippedSlots(entity.Equipment), CargoBays = ProjectEquippedSlots(entity.CargoBays), @@ -1396,16 +1394,6 @@ public class ActionGameManager : MonoBehaviour .ToArray() ?? Array.Empty(); } - private static string LegacyId(Guid id) - { - return id == Guid.Empty ? "" : id.ToString("D"); - } - - private static string CorporationKey(Guid id) - { - return id == Guid.Empty ? "" : $"aetheria.corporation:legacy:{id:D}"; - } - private static string OrbitKey(Guid id) { return id == Guid.Empty ? "" : $"aetheria.orbit:legacy:{id:D}"; @@ -1559,18 +1547,6 @@ public class ActionGameManager : MonoBehaviour .ToArray(); } - private static string ReferenceKey(string prefix, string legacyId) - { - return string.IsNullOrWhiteSpace(legacyId) ? "" : $"{prefix}:legacy:{legacyId}"; - } - - private static string ReferenceKey(string typedKey, string prefix, string legacyId) - { - return !string.IsNullOrWhiteSpace(typedKey) - ? typedKey - : ReferenceKey(prefix, legacyId); - } - private void OnApplicationQuit() => QueueRunCheckpoint("application-quit"); private void QueueRunCheckpoint(string reason) diff --git a/Assets/Scripts/ServerShared/EntityConstructionBlueprintProjector.cs b/Assets/Scripts/ServerShared/EntityConstructionBlueprintProjector.cs index edb11cd6b..98f6838fc 100644 --- a/Assets/Scripts/ServerShared/EntityConstructionBlueprintProjector.cs +++ b/Assets/Scripts/ServerShared/EntityConstructionBlueprintProjector.cs @@ -29,8 +29,7 @@ public static class EntityConstructionBlueprintProjector blueprint.Hull = entity.Hull; blueprint.Name = entity.Name; - blueprint.Faction = entity.Faction?.ID ?? Guid.Empty; - blueprint.FactionKey = entity.Faction?.FactionKey ?? CorporationKey(blueprint.Faction); + blueprint.FactionKey = entity.Faction?.FactionKey ?? ""; blueprint.Equipment = entity.Equipment.Select(e => (e.Position, e.EquippableItem)).ToArray(); blueprint.CargoBays = entity.CargoBays.Select(e => (e.Position, e.EquippableItem)).ToArray(); blueprint.DockingBays = entity.DockingBays.Select(e => (e.Position, e.EquippableItem)).ToArray(); @@ -116,12 +115,7 @@ public static class EntityConstructionBlueprintProjector { return galaxy == null ? null - : galaxy.ResolveFactionByKey(blueprint.FactionKey) ?? galaxy.ResolveFaction(blueprint.Faction); - } - - private static string CorporationKey(Guid id) - { - return id == Guid.Empty ? "" : $"aetheria.corporation:legacy:{id:D}"; + : galaxy.ResolveFactionByKey(blueprint.FactionKey); } } @@ -152,7 +146,6 @@ public abstract class EntityConstructionBlueprint public (int2 position, ItemInstance item)[][] DockingBayContents; public EntityConstructionBlueprint[] Children; public EntitySettings Settings; - public Guid Faction; public string FactionKey; public int[][] WeaponGroups; diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index 531af90f3..ed26b833b 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -1007,9 +1007,10 @@ First Aetheria surfaces to publish: decide generated sector factions or zone names. - Done: move entity faction restore to `Galaxy.ResolveFactionByKey` through `EntityConstructionBlueprint.FactionKey`, so typed loadout readback and - entity construction resolve corporation identity by typed key first. The - old blueprint `Faction` GUID remains compatibility/fallback for callers - that have not yet been lowered. + entity construction resolve corporation identity by typed key only. The + old blueprint `Faction` GUID compatibility field is deleted, and runtime + entity/faction-relationship commits no longer rebuild faction keys from + legacy `Faction.ID` GUIDs. - Done: move package and canonical manufacturer/corporation/name-file lookup to typed keys (`ManufacturerKey`, `CorporationKey`, `GeonameFileKey`, and `NameFileKey`), and move loadout manufacturer-distance weighting to @@ -1731,6 +1732,9 @@ First Aetheria surfaces to publish: `AetheriaRuntimePendingCultCacheStore`, `AetheriaRuntimeStateCommitDocument`, and `AetheriaRuntimeEveCommandDocument` until CultLib generated serializers become the Unity runtime owner. +- `Aetheria.State.Verify` also guards runtime faction identity ownership: + construction blueprints cannot carry a legacy faction GUID, and runtime + entity/faction commits cannot rebuild `FactionKey` from `Faction.ID`. - Unity batchmode compile returned cleanly after the runtime blueprint rename; live Unity source has no `EntityPack`, `ShipPack`, `OrbitalEntityPack`, `ZonePack`, `PackedContents`, `PackZone`, `EntitySerializer.Pack`, or