Add cache-only remote Verse replicas
This commit is contained in:
parent
c1267795bf
commit
9a52ac5767
11 changed files with 439 additions and 4 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -107,6 +107,8 @@ Aetheria.State.Unity/bin/
|
|||
Aetheria.State.Unity/obj/
|
||||
Aetheria.State.Unity.Smoke/bin/
|
||||
Aetheria.State.Unity.Smoke/obj/
|
||||
Aetheria.State.Replica/bin/
|
||||
Aetheria.State.Replica/obj/
|
||||
Aetheria.State.Verify/bin/
|
||||
Aetheria.State.Verify/obj/
|
||||
|
||||
|
|
|
|||
15
Aetheria.State.Replica/Aetheria.State.Replica.csproj
Normal file
15
Aetheria.State.Replica/Aetheria.State.Replica.csproj
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Description>Replica sync worker for pulling daemon-owned Aetheria Verse state into a local cache-only .cc witness.</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Aetheria.State\Aetheria.State.csproj" />
|
||||
<ProjectReference Include="..\Aetheria.State.Unity\Aetheria.State.Unity.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
120
Aetheria.State.Replica/Program.cs
Normal file
120
Aetheria.State.Replica/Program.cs
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
using Aetheria.State;
|
||||
using GameCult.Aetheria.State.Unity;
|
||||
|
||||
return await ProgramMainAsync(args).ConfigureAwait(false);
|
||||
|
||||
static async Task<int> ProgramMainAsync(string[] args)
|
||||
{
|
||||
if (args.Length == 0)
|
||||
{
|
||||
PrintUsage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
var mode = args[0].Trim();
|
||||
var options = ParseOptions(args.Skip(1));
|
||||
var endpoint = RequireOption(options, "endpoint");
|
||||
var runtimeId = ReadOption(options, "runtime-id", "aetheria-verse-replica");
|
||||
var replicaPath = ResolveReplicaPath(options);
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case "sync":
|
||||
{
|
||||
var appliedSequence = await AetheriaVerseReplica
|
||||
.SyncSnapshotAsync(replicaPath, endpoint, runtimeId)
|
||||
.ConfigureAwait(false);
|
||||
Console.WriteLine($"Synced Aetheria replica to {replicaPath} from {endpoint} at shard sequence {appliedSequence}.");
|
||||
return 0;
|
||||
}
|
||||
case "follow":
|
||||
{
|
||||
var pollSeconds = ReadDoubleOption(options, "poll-seconds", 1d);
|
||||
using var cancellation = new CancellationTokenSource();
|
||||
Console.CancelKeyPress += (_, eventArgs) =>
|
||||
{
|
||||
eventArgs.Cancel = true;
|
||||
cancellation.Cancel();
|
||||
};
|
||||
|
||||
Console.WriteLine(
|
||||
$"Following Aetheria replica at {replicaPath} from {endpoint} every {pollSeconds:0.###} seconds. Press Ctrl+C to stop.");
|
||||
await AetheriaVerseReplica
|
||||
.RunReplicaAsync(replicaPath, endpoint, TimeSpan.FromSeconds(pollSeconds), cancellation.Token, runtimeId)
|
||||
.ConfigureAwait(false);
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
Console.Error.WriteLine($"Unknown mode '{mode}'.");
|
||||
PrintUsage();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static string ResolveReplicaPath(IReadOnlyDictionary<string, string> options)
|
||||
{
|
||||
var explicitPath = ReadOption(options, "replica", "");
|
||||
if (!string.IsNullOrWhiteSpace(explicitPath))
|
||||
return Path.GetFullPath(explicitPath);
|
||||
|
||||
var gameDataRoot = RequireOption(options, "game-data-root");
|
||||
var verseId = RequireOption(options, "verse-id");
|
||||
return AetheriaRuntimeStateBoundary.GetReplicaStateFilePath(
|
||||
new DirectoryInfo(Path.GetFullPath(gameDataRoot)),
|
||||
verseId);
|
||||
}
|
||||
|
||||
static Dictionary<string, string> ParseOptions(IEnumerable<string> args)
|
||||
{
|
||||
var options = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
string? pendingKey = null;
|
||||
foreach (var arg in args)
|
||||
{
|
||||
if (arg.StartsWith("--", StringComparison.Ordinal))
|
||||
{
|
||||
pendingKey = arg[2..];
|
||||
options[pendingKey] = "true";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(pendingKey))
|
||||
{
|
||||
options[pendingKey] = arg;
|
||||
pendingKey = null;
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
static string RequireOption(IReadOnlyDictionary<string, string> options, string key)
|
||||
{
|
||||
var value = ReadOption(options, key, "");
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
return value;
|
||||
|
||||
throw new InvalidOperationException($"Missing required option --{key}.");
|
||||
}
|
||||
|
||||
static string ReadOption(IReadOnlyDictionary<string, string> options, string key, string fallback)
|
||||
{
|
||||
return options.TryGetValue(key, out var value) && !string.IsNullOrWhiteSpace(value)
|
||||
? value
|
||||
: fallback;
|
||||
}
|
||||
|
||||
static double ReadDoubleOption(IReadOnlyDictionary<string, string> options, string key, double fallback)
|
||||
{
|
||||
var value = ReadOption(options, key, "");
|
||||
return double.TryParse(value, out var parsed) && parsed > 0
|
||||
? parsed
|
||||
: fallback;
|
||||
}
|
||||
|
||||
static void PrintUsage()
|
||||
{
|
||||
Console.WriteLine("Usage:");
|
||||
Console.WriteLine(" sync --endpoint cultnet://host:3075 --replica path-to-replica.cc");
|
||||
Console.WriteLine(" sync --endpoint cultnet://host:3075 --game-data-root GameData --verse-id verse.id");
|
||||
Console.WriteLine(" follow --endpoint cultnet://host:3075 --replica path-to-replica.cc [--poll-seconds 1]");
|
||||
}
|
||||
|
|
@ -51,6 +51,7 @@ RequireNoDeadPopupShells(root);
|
|||
RequirePlayerSettingsEveSurface(root);
|
||||
RequireVerseHostSettingsAuthority(root);
|
||||
RequireClientTargetBootAuthority(root);
|
||||
RequireVerseReplicaTool(root);
|
||||
RequireVerseSettingsShellAndBridge(root);
|
||||
RequireMainMenuVerseHostProjection(root);
|
||||
RequireMainMenuContinueRunState(root);
|
||||
|
|
@ -539,6 +540,7 @@ Console.WriteLine("NameTools editor shell: the remaining name helper window lowe
|
|||
Console.WriteLine("Runtime state reader authority: Unity gameplay/UI read typed state through a shared runtime reader instead of direct store spelunking");
|
||||
Console.WriteLine("Verse host authority: daemon-owned typed verse host settings now drive provider advertisement, operations telemetry, and served Verse discovery");
|
||||
Console.WriteLine("Client target boot authority: Unity boot resolves the active Verse through a typed client target instead of local path folklore");
|
||||
Console.WriteLine("Verse replica authority: remote client targets resolve to cache-only replica .cc files fed from the daemon");
|
||||
Console.WriteLine("Verse settings shell: client target edits and Verse-host visibility commands lower through typed Eve surfaces");
|
||||
Console.WriteLine("Main-menu Verse projection: the Unity Eve shell lowers daemon-owned verse identity instead of ad-libbing local menu copy");
|
||||
Console.WriteLine("Runtime simulation tuning authority: UI writes flow through gameplay checkpoint commits");
|
||||
|
|
@ -3935,9 +3937,11 @@ static void RequireClientTargetBootAuthority(string root)
|
|||
var requiredBoundarySymbols = new[]
|
||||
{
|
||||
"RuntimeClientTargetFileName = \"aetheria-client.cc\"",
|
||||
"RuntimeReplicaDirectoryName = \"Verses\"",
|
||||
"RuntimeStatePathOverrideEnvironmentVariable = \"AETHERIA_STATE_PATH\"",
|
||||
"LegacyRuntimeStatePathOverrideEnvironmentVariable = \"AETHERIA_EVE_STATE_PATH\"",
|
||||
"GetClientTargetPath",
|
||||
"GetReplicaStateFilePath",
|
||||
"ResolveStatePathOverride"
|
||||
};
|
||||
var missingBoundarySymbols = requiredBoundarySymbols
|
||||
|
|
@ -3962,6 +3966,7 @@ static void RequireClientTargetBootAuthority(string root)
|
|||
"DiscoveredVerses",
|
||||
"LastDiscoveryAtUtc",
|
||||
"LastDiscoveryError",
|
||||
"ReplicaStateFilePath",
|
||||
"ReadOrInitialize",
|
||||
"CreateDefault",
|
||||
"Write(string clientTargetPath, AetheriaRuntimeClientTargetDocument document)",
|
||||
|
|
@ -3988,10 +3993,13 @@ static void RequireClientTargetBootAuthority(string root)
|
|||
"DiscoveredVerses",
|
||||
"LastDiscoveryAtUtc",
|
||||
"LastDiscoveryError",
|
||||
"ReplicaStateFilePath",
|
||||
"TargetLabel",
|
||||
"AetheriaRuntimeClientTargetStore.ReadOrInitialize",
|
||||
"AetheriaRuntimeStateBoundary.ResolveStatePathOverride()",
|
||||
"AetheriaRuntimeClientTargetKinds.CultMeshVerse",
|
||||
"GetReplicaStateFilePath",
|
||||
"Sync the local replica",
|
||||
"state-path-override",
|
||||
"client-target"
|
||||
};
|
||||
|
|
@ -4073,6 +4081,7 @@ static void RequireClientTargetBootAuthority(string root)
|
|||
"stateBoot.DiscoveredVerses",
|
||||
"stateBoot.LastDiscoveryAtUtc",
|
||||
"stateBoot.LastDiscoveryError",
|
||||
"stateBoot.ReplicaStateFilePath",
|
||||
"\"Client Target\"",
|
||||
"\"Transport\"",
|
||||
"\"Target Source\""
|
||||
|
|
@ -4121,6 +4130,99 @@ static void RequireClientTargetBootAuthority(string root)
|
|||
}
|
||||
}
|
||||
|
||||
static void RequireVerseReplicaTool(string root)
|
||||
{
|
||||
var replicaToolProjectPath = Path.Combine(root, "Aetheria.State.Replica", "Aetheria.State.Replica.csproj");
|
||||
var replicaToolProgramPath = Path.Combine(root, "Aetheria.State.Replica", "Program.cs");
|
||||
var replicaHostPath = Path.Combine(root, "Aetheria.State", "AetheriaVerseReplica.cs");
|
||||
var stateReadmePath = Path.Combine(root, "Aetheria.State", "README.md");
|
||||
|
||||
var requiredFiles = new[]
|
||||
{
|
||||
replicaToolProjectPath,
|
||||
replicaToolProgramPath,
|
||||
replicaHostPath,
|
||||
stateReadmePath
|
||||
};
|
||||
|
||||
var missingFiles = requiredFiles
|
||||
.Where(path => !File.Exists(path))
|
||||
.Select(path => Path.GetRelativePath(root, path))
|
||||
.ToArray();
|
||||
if (missingFiles.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Verse replica tool cannot be verified because required files are missing: " +
|
||||
string.Join(", ", missingFiles));
|
||||
}
|
||||
|
||||
var replicaToolProject = File.ReadAllText(replicaToolProjectPath);
|
||||
var replicaToolProgram = File.ReadAllText(replicaToolProgramPath);
|
||||
var replicaHost = File.ReadAllText(replicaHostPath);
|
||||
var stateReadme = File.ReadAllText(stateReadmePath);
|
||||
|
||||
var requiredProjectSymbols = new[]
|
||||
{
|
||||
"<ProjectReference Include=\"..\\Aetheria.State\\Aetheria.State.csproj\" />",
|
||||
"<ProjectReference Include=\"..\\Aetheria.State.Unity\\Aetheria.State.Unity.csproj\" />"
|
||||
};
|
||||
var missingProjectSymbols = requiredProjectSymbols
|
||||
.Where(symbol => !replicaToolProject.Contains(symbol, StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
if (missingProjectSymbols.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Verse replica tool project is incomplete: " +
|
||||
string.Join(", ", missingProjectSymbols));
|
||||
}
|
||||
|
||||
var requiredProgramSymbols = new[]
|
||||
{
|
||||
"sync",
|
||||
"follow",
|
||||
"AetheriaVerseReplica",
|
||||
"GetReplicaStateFilePath",
|
||||
"--endpoint",
|
||||
"--replica"
|
||||
};
|
||||
var missingProgramSymbols = requiredProgramSymbols
|
||||
.Where(symbol => !replicaToolProgram.Contains(symbol, StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
if (missingProgramSymbols.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Verse replica tool program is incomplete: " +
|
||||
string.Join(", ", missingProgramSymbols));
|
||||
}
|
||||
|
||||
var requiredReplicaHostSymbols = new[]
|
||||
{
|
||||
"public static class AetheriaVerseReplica",
|
||||
"SyncSnapshotAsync",
|
||||
"RunReplicaAsync",
|
||||
"CultNetSchemaShardSnapshotFetcher",
|
||||
"CultNetSchemaShardLogFetcher",
|
||||
"CultNetShardReplicator",
|
||||
"ApplyShardSnapshotResponseAsync"
|
||||
};
|
||||
var missingReplicaHostSymbols = requiredReplicaHostSymbols
|
||||
.Where(symbol => !replicaHost.Contains(symbol, StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
if (missingReplicaHostSymbols.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Verse replica host is incomplete: " +
|
||||
string.Join(", ", missingReplicaHostSymbols));
|
||||
}
|
||||
|
||||
if (!stateReadme.Contains("Aetheria.State.Replica", StringComparison.Ordinal) ||
|
||||
!stateReadme.Contains("GameData\\Verses\\<verse>.cc", StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Aetheria.State README does not describe the cache-only Verse replica workflow.");
|
||||
}
|
||||
}
|
||||
|
||||
static void RequireVerseSettingsShellAndBridge(string root)
|
||||
{
|
||||
var unityFacadeProjectPath = Path.Combine(root, "Aetheria.State.Unity", "Aetheria.State.Unity.csproj");
|
||||
|
|
@ -4248,6 +4350,7 @@ static void RequireVerseSettingsShellAndBridge(string root)
|
|||
"\"Target Fields\"",
|
||||
"\"Verse Discovery\"",
|
||||
"\"Daemon Verse Host\"",
|
||||
"\"Replica State File\"",
|
||||
"AetheriaRuntimeClientTargetCommands.SetStateFilePath",
|
||||
"AetheriaRuntimeClientTargetCommands.SetDiscoveryEndpoints",
|
||||
"AetheriaRuntimeClientTargetCommands.DiscoverVerses",
|
||||
|
|
|
|||
110
Aetheria.State/AetheriaVerseReplica.cs
Normal file
110
Aetheria.State/AetheriaVerseReplica.cs
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
using GameCult.Caching;
|
||||
using GameCult.Caching.MessagePack;
|
||||
using GameCult.Mesh;
|
||||
using GameCult.Networking;
|
||||
|
||||
namespace Aetheria.State;
|
||||
|
||||
public static class AetheriaVerseReplica
|
||||
{
|
||||
private const string ReplicaShardId = "primary";
|
||||
private const string ReplicaOwnerRuntimeId = "aetheria-remote";
|
||||
|
||||
public static async Task<long> SyncSnapshotAsync(
|
||||
string replicaStatePath,
|
||||
string endpoint,
|
||||
string runtimeId = "aetheria-verse-replica")
|
||||
{
|
||||
using var node = await OpenReplicaNodeAsync(replicaStatePath, endpoint, runtimeId).ConfigureAwait(false);
|
||||
var shard = BuildReplicaShard(endpoint);
|
||||
var fetcher = new CultNetSchemaShardSnapshotFetcher();
|
||||
var snapshot = await fetcher.FetchAsync(shard).ConfigureAwait(false);
|
||||
var appliedSequence = await node.Database.ApplyShardSnapshotResponseAsync(shard, snapshot).ConfigureAwait(false);
|
||||
await node.FlushAsync().ConfigureAwait(false);
|
||||
return appliedSequence;
|
||||
}
|
||||
|
||||
public static async Task RunReplicaAsync(
|
||||
string replicaStatePath,
|
||||
string endpoint,
|
||||
TimeSpan pollInterval,
|
||||
CancellationToken cancellationToken,
|
||||
string runtimeId = "aetheria-verse-replica")
|
||||
{
|
||||
using var node = await OpenReplicaNodeAsync(replicaStatePath, endpoint, runtimeId).ConfigureAwait(false);
|
||||
var shard = BuildReplicaShard(endpoint);
|
||||
var snapshotFetcher = new CultNetSchemaShardSnapshotFetcher();
|
||||
var logFetcher = new CultNetSchemaShardLogFetcher();
|
||||
|
||||
var snapshot = await snapshotFetcher.FetchAsync(shard).ConfigureAwait(false);
|
||||
await node.Database.ApplyShardSnapshotResponseAsync(shard, snapshot).ConfigureAwait(false);
|
||||
await node.FlushAsync().ConfigureAwait(false);
|
||||
|
||||
using var replicator = new CultNetShardReplicator(
|
||||
node.Database,
|
||||
new CultNetShardReplicatorOptions
|
||||
{
|
||||
PollInterval = pollInterval,
|
||||
Fetcher = logFetcher,
|
||||
SnapshotFetcher = snapshotFetcher
|
||||
});
|
||||
replicator.Start();
|
||||
|
||||
try
|
||||
{
|
||||
await Task.Delay(Timeout.Infinite, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
await node.FlushAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private static CultNetShardDescriptor BuildReplicaShard(string endpoint)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(endpoint))
|
||||
throw new ArgumentException("Replica endpoint must be non-empty.", nameof(endpoint));
|
||||
|
||||
return new CultNetShardDescriptor(
|
||||
ReplicaShardId,
|
||||
ReplicaOwnerRuntimeId,
|
||||
epoch: 1,
|
||||
isPrimary: false,
|
||||
primaryEndpoints: new[] { endpoint.Trim() });
|
||||
}
|
||||
|
||||
private static Task<CultMeshNode> OpenReplicaNodeAsync(
|
||||
string replicaStatePath,
|
||||
string endpoint,
|
||||
string runtimeId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(replicaStatePath))
|
||||
throw new ArgumentException("Replica state path must be non-empty.", nameof(replicaStatePath));
|
||||
|
||||
var shard = BuildReplicaShard(endpoint);
|
||||
var cacheRegistry = AetheriaDocumentRegistry.CreateCultCacheRegistry();
|
||||
return CultMesh.CreateNodeAsync(
|
||||
replicaStatePath,
|
||||
new CultMeshNodeOptions
|
||||
{
|
||||
StartServer = false,
|
||||
EnableDurableShardLogs = true,
|
||||
CacheOptions = new CultCacheOpenOptions
|
||||
{
|
||||
Registry = cacheRegistry,
|
||||
PullOnOpen = true,
|
||||
StoreFlushOnDispose = true,
|
||||
UseDirectoryStore = true
|
||||
},
|
||||
DatabaseOptions = new CultNetDatabaseOptions
|
||||
{
|
||||
RuntimeId = string.IsNullOrWhiteSpace(runtimeId) ? "aetheria-verse-replica" : runtimeId,
|
||||
Shards = new[] { shard },
|
||||
DocumentRegistry = AetheriaDocumentRegistry.CreateCultNetRegistry(cacheRegistry)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -411,6 +411,18 @@ advertisement still publishes `gamecult.eve.provider_advertisement.v1` for the
|
|||
`aetheria` provider, advertising the catalog, operations, and player-settings
|
||||
surfaces plus the typed schemas witnessed by the local `.cc` state file.
|
||||
|
||||
Remote Unity clients should not pretend a public Verse is local authority. Use
|
||||
`Aetheria.State.Replica` to pull a cache-only local witness from the daemon:
|
||||
|
||||
```powershell
|
||||
dotnet run --project .\Aetheria.State.Replica\Aetheria.State.Replica.csproj -- sync --endpoint cultnet://host:3075 --game-data-root .\GameData --verse-id aetheria.public
|
||||
```
|
||||
|
||||
That writes `GameData\Verses\<verse>.cc` as a replica projection of daemon
|
||||
truth. The selected remote client target resolves to that replica path. The
|
||||
daemon still owns accepted state; the replica is only the local read surface
|
||||
Unity lowers from.
|
||||
|
||||
`Aetheria.State.ApplyPending` is the smaller local operator applicator for
|
||||
queued Unity runtime commits and Eve commands when the server host is not being
|
||||
used. It also republishes the typed drain status, operations surface,
|
||||
|
|
|
|||
|
|
@ -453,6 +453,7 @@ public class MainMenu : MonoBehaviour
|
|||
stateBoot.VerseId,
|
||||
stateBoot.CultMeshAddress,
|
||||
stateBoot.StateFilePath,
|
||||
stateBoot.ReplicaStateFilePath,
|
||||
string.Join(", ", stateBoot.DiscoveryEndpoints ?? Array.Empty<string>()),
|
||||
stateBoot.DiscoveredVerses ?? Array.Empty<AetheriaRuntimeDiscoveredVerse>(),
|
||||
stateBoot.LastDiscoveryAtUtc,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
|
||||
#nullable enable
|
||||
|
|
@ -32,6 +33,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
[Key(8)] public AetheriaRuntimeDiscoveredVerse[] DiscoveredVerses { get; set; } = Array.Empty<AetheriaRuntimeDiscoveredVerse>();
|
||||
[Key(9)] public string LastDiscoveryAtUtc { get; set; } = "";
|
||||
[Key(10)] public string LastDiscoveryError { get; set; } = "";
|
||||
[Key(11)] public string ReplicaStateFilePath { get; set; } = "";
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
|
|
@ -70,6 +72,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
|
||||
public static AetheriaRuntimeClientTargetDocument CreateDefault(string defaultStateFilePath)
|
||||
{
|
||||
var gameDataDirectory = ResolveGameDataDirectory(defaultStateFilePath);
|
||||
return new AetheriaRuntimeClientTargetDocument
|
||||
{
|
||||
Schema = AetheriaRuntimeClientTargetDocument.SchemaId,
|
||||
|
|
@ -78,6 +81,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
VerseId = "aetheria.local",
|
||||
CultMeshAddress = "asgard.local.aetheria/eve",
|
||||
StateFilePath = defaultStateFilePath ?? "",
|
||||
ReplicaStateFilePath = AetheriaRuntimeStateBoundary.GetReplicaStateFilePath(gameDataDirectory, "aetheria.local"),
|
||||
UpdatedAtUtc = DateTime.UtcNow.ToString("O")
|
||||
};
|
||||
}
|
||||
|
|
@ -91,6 +95,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
document.DiscoveredVerses ??= Array.Empty<AetheriaRuntimeDiscoveredVerse>();
|
||||
document.LastDiscoveryAtUtc ??= "";
|
||||
document.LastDiscoveryError ??= "";
|
||||
document.ReplicaStateFilePath = NormalizeReplicaStateFilePath(document, clientTargetPath, document.ReplicaStateFilePath);
|
||||
foreach (var verse in document.DiscoveredVerses)
|
||||
{
|
||||
if (verse == null)
|
||||
|
|
@ -130,6 +135,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
|
||||
var document = ReadOrInitialize(clientTargetPath, defaultStateFilePath);
|
||||
mutate(document);
|
||||
document.ReplicaStateFilePath = NormalizeReplicaStateFilePath(document, clientTargetPath, document.ReplicaStateFilePath);
|
||||
Write(clientTargetPath, document);
|
||||
return document;
|
||||
}
|
||||
|
|
@ -313,5 +319,31 @@ namespace GameCult.Aetheria.State.Unity
|
|||
|
||||
File.Move(tempPath, path);
|
||||
}
|
||||
|
||||
private static string NormalizeReplicaStateFilePath(
|
||||
AetheriaRuntimeClientTargetDocument document,
|
||||
string clientTargetPath,
|
||||
string configuredPath)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(configuredPath))
|
||||
return Path.GetFullPath(configuredPath);
|
||||
|
||||
var gameDataDirectory = ResolveGameDataDirectoryFromClientTarget(clientTargetPath);
|
||||
return AetheriaRuntimeStateBoundary.GetReplicaStateFilePath(gameDataDirectory, document?.VerseId ?? "");
|
||||
}
|
||||
|
||||
private static DirectoryInfo ResolveGameDataDirectory(string defaultStateFilePath)
|
||||
{
|
||||
var fullPath = Path.GetFullPath(string.IsNullOrWhiteSpace(defaultStateFilePath) ? "." : defaultStateFilePath);
|
||||
var directory = Path.GetDirectoryName(fullPath);
|
||||
return new DirectoryInfo(string.IsNullOrWhiteSpace(directory) ? "." : directory);
|
||||
}
|
||||
|
||||
private static DirectoryInfo ResolveGameDataDirectoryFromClientTarget(string clientTargetPath)
|
||||
{
|
||||
var fullPath = Path.GetFullPath(string.IsNullOrWhiteSpace(clientTargetPath) ? "." : clientTargetPath);
|
||||
var directory = Path.GetDirectoryName(fullPath);
|
||||
return new DirectoryInfo(string.IsNullOrWhiteSpace(directory) ? "." : directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
string targetVerseId,
|
||||
string targetCultMeshAddress,
|
||||
string targetStateFilePath,
|
||||
string targetReplicaStateFilePath,
|
||||
string discoveryEndpointsText,
|
||||
IReadOnlyList<AetheriaRuntimeDiscoveredVerse> discoveredVerses,
|
||||
string lastDiscoveryAtUtc,
|
||||
|
|
@ -30,6 +31,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
TargetVerseId = targetVerseId ?? "";
|
||||
TargetCultMeshAddress = targetCultMeshAddress ?? "";
|
||||
TargetStateFilePath = targetStateFilePath ?? "";
|
||||
TargetReplicaStateFilePath = targetReplicaStateFilePath ?? "";
|
||||
DiscoveryEndpointsText = discoveryEndpointsText ?? "";
|
||||
DiscoveredVerses = discoveredVerses ?? Array.Empty<AetheriaRuntimeDiscoveredVerse>();
|
||||
LastDiscoveryAtUtc = lastDiscoveryAtUtc ?? "";
|
||||
|
|
@ -49,6 +51,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
public string TargetVerseId { get; }
|
||||
public string TargetCultMeshAddress { get; }
|
||||
public string TargetStateFilePath { get; }
|
||||
public string TargetReplicaStateFilePath { get; }
|
||||
public string DiscoveryEndpointsText { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeDiscoveredVerse> DiscoveredVerses { get; }
|
||||
public string LastDiscoveryAtUtc { get; }
|
||||
|
|
@ -90,6 +93,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
Array.Empty<AetheriaRuntimeDiscoveredVerse>(),
|
||||
"",
|
||||
"",
|
||||
|
|
@ -209,6 +213,10 @@ namespace GameCult.Aetheria.State.Unity
|
|||
"State File Path",
|
||||
state.TargetStateFilePath,
|
||||
AetheriaRuntimeClientTargetCommands.SetStateFilePath),
|
||||
Metric(
|
||||
"aetheria.clientTarget.target.replicaStateFilePath",
|
||||
"Replica State File",
|
||||
state.TargetReplicaStateFilePath),
|
||||
ButtonRow(
|
||||
"aetheria.clientTarget.target.actions",
|
||||
Button(
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
string verseId,
|
||||
string cultMeshAddress,
|
||||
string stateFilePath,
|
||||
string replicaStateFilePath,
|
||||
bool stateFileExists,
|
||||
bool supportsLocalStateFileRead,
|
||||
string failureMessage,
|
||||
|
|
@ -29,6 +30,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
VerseId = verseId;
|
||||
CultMeshAddress = cultMeshAddress;
|
||||
StateFilePath = stateFilePath;
|
||||
ReplicaStateFilePath = replicaStateFilePath;
|
||||
StateFileExists = stateFileExists;
|
||||
SupportsLocalStateFileRead = supportsLocalStateFileRead;
|
||||
FailureMessage = failureMessage;
|
||||
|
|
@ -45,6 +47,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
public string VerseId { get; }
|
||||
public string CultMeshAddress { get; }
|
||||
public string StateFilePath { get; }
|
||||
public string ReplicaStateFilePath { get; }
|
||||
public bool StateFileExists { get; }
|
||||
public bool SupportsLocalStateFileRead { get; }
|
||||
public string FailureMessage { get; }
|
||||
|
|
@ -87,17 +90,23 @@ namespace GameCult.Aetheria.State.Unity
|
|||
var supportsLocalStateFileRead = true;
|
||||
var failureMessage = "";
|
||||
string stateFilePath;
|
||||
string replicaStateFilePath;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(configuredOverride))
|
||||
{
|
||||
stateFilePath = Path.GetFullPath(configuredOverride);
|
||||
replicaStateFilePath = target.ReplicaStateFilePath ?? "";
|
||||
}
|
||||
else if (string.Equals(targetKind, AetheriaRuntimeClientTargetKinds.CultMeshVerse, StringComparison.Ordinal))
|
||||
{
|
||||
stateFilePath = "";
|
||||
supportsLocalStateFileRead = false;
|
||||
failureMessage =
|
||||
$"Selected client Verse target '{BuildTargetLabel(targetTitle, targetVerseId)}' points at CultMesh address '{targetCultMeshAddress}', but Unity still boots from local typed state until daemon transport lands.";
|
||||
replicaStateFilePath = string.IsNullOrWhiteSpace(target.ReplicaStateFilePath)
|
||||
? AetheriaRuntimeStateBoundary.GetReplicaStateFilePath(gameDataDirectory, targetVerseId)
|
||||
: Path.GetFullPath(target.ReplicaStateFilePath);
|
||||
stateFilePath = replicaStateFilePath;
|
||||
supportsLocalStateFileRead = File.Exists(replicaStateFilePath);
|
||||
failureMessage = supportsLocalStateFileRead
|
||||
? ""
|
||||
: $"Selected client Verse target '{BuildTargetLabel(targetTitle, targetVerseId)}' follows remote CultMesh endpoint '{targetCultMeshAddress}'. Sync the local replica at '{replicaStateFilePath}' before booting Unity from that Verse.";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -105,6 +114,9 @@ namespace GameCult.Aetheria.State.Unity
|
|||
? defaultStateFilePath
|
||||
: target.StateFilePath;
|
||||
stateFilePath = Path.GetFullPath(configuredStateFilePath);
|
||||
replicaStateFilePath = string.IsNullOrWhiteSpace(target.ReplicaStateFilePath)
|
||||
? AetheriaRuntimeStateBoundary.GetReplicaStateFilePath(gameDataDirectory, targetVerseId)
|
||||
: Path.GetFullPath(target.ReplicaStateFilePath);
|
||||
}
|
||||
|
||||
return new AetheriaRuntimeStateBootReport(
|
||||
|
|
@ -115,6 +127,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
targetVerseId,
|
||||
targetCultMeshAddress,
|
||||
stateFilePath,
|
||||
replicaStateFilePath,
|
||||
supportsLocalStateFileRead && File.Exists(stateFilePath),
|
||||
supportsLocalStateFileRead,
|
||||
failureMessage,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
|
|
@ -6,6 +7,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
{
|
||||
public const string RuntimeStateFileName = "aetheria-world.cc";
|
||||
public const string RuntimeClientTargetFileName = "aetheria-client.cc";
|
||||
public const string RuntimeReplicaDirectoryName = "Verses";
|
||||
public const string RuntimeStatePathOverrideEnvironmentVariable = "AETHERIA_STATE_PATH";
|
||||
public const string LegacyRuntimeStatePathOverrideEnvironmentVariable = "AETHERIA_EVE_STATE_PATH";
|
||||
|
||||
|
|
@ -19,6 +21,23 @@ namespace GameCult.Aetheria.State.Unity
|
|||
return Path.Combine(gameDataDirectory.FullName, RuntimeClientTargetFileName);
|
||||
}
|
||||
|
||||
public static string GetReplicaStateFilePath(DirectoryInfo gameDataDirectory, string verseId)
|
||||
{
|
||||
var safeVerseId = string.IsNullOrWhiteSpace(verseId)
|
||||
? "unknown-verse"
|
||||
: new string((verseId ?? "")
|
||||
.Select(ch => char.IsLetterOrDigit(ch) || ch == '-' || ch == '_' || ch == '.'
|
||||
? ch
|
||||
: '-')
|
||||
.ToArray())
|
||||
.Trim('-');
|
||||
|
||||
if (string.IsNullOrWhiteSpace(safeVerseId))
|
||||
safeVerseId = "unknown-verse";
|
||||
|
||||
return Path.Combine(gameDataDirectory.FullName, RuntimeReplicaDirectoryName, $"{safeVerseId}.cc");
|
||||
}
|
||||
|
||||
public static string ResolveStatePathOverride()
|
||||
{
|
||||
var configured = System.Environment.GetEnvironmentVariable(RuntimeStatePathOverrideEnvironmentVariable);
|
||||
|
|
|
|||
Loading…
Reference in a new issue