Add Starbridge player seat state document
This commit is contained in:
parent
20a1d11163
commit
426cd8f656
7 changed files with 302 additions and 1 deletions
87
Assets/Scripts/Tests/StarbridgePlayerSeatDocumentTests.cs
Normal file
87
Assets/Scripts/Tests/StarbridgePlayerSeatDocumentTests.cs
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
using GameCult.Aetheria.State.Verse;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
public class StarbridgePlayerSeatDocumentTests
|
||||
{
|
||||
[Test]
|
||||
public void StarbridgePlayerSeatRoundTripsCrashReconnectState()
|
||||
{
|
||||
var createdAt = DateTimeOffset.Parse("2026-06-27T10:00:00Z");
|
||||
var disconnectedAt = createdAt.AddMinutes(3);
|
||||
var reconnectedAt = disconnectedAt.AddMinutes(1);
|
||||
|
||||
var seat = AetheriaRuntimeStarbridgePlayerSeatDocument.Create(
|
||||
"seat-alpha",
|
||||
"player-7",
|
||||
"session-1",
|
||||
"scenario-1",
|
||||
"run-1",
|
||||
AetheriaRuntimeStarbridgePlayerSeatRoles.Support,
|
||||
"unity-runtime-old",
|
||||
createdAt);
|
||||
seat.PlayerDisplayName = "Vega";
|
||||
seat.ControlledEntityKey = "entity:ship:7";
|
||||
seat.ShipEntityKey = "entity:ship:7";
|
||||
seat.CockpitItemKey = "item:cockpit:7";
|
||||
seat.EscapePodEntityKey = "entity:pod:7";
|
||||
seat.LoadoutDocumentKey = "loadout:ship:7";
|
||||
seat.AuthorityLeaseId = "lease:seat-alpha";
|
||||
seat.ClaimKinds = new[] { AetheriaRuntimeClaimKinds.Movement, AetheriaRuntimeClaimKinds.Combat };
|
||||
|
||||
seat.MarkDisconnected(disconnectedAt);
|
||||
|
||||
Assert.AreEqual(AetheriaRuntimeStarbridgePlayerSeatConnectionStates.Grace, seat.ConnectionState);
|
||||
Assert.IsTrue(seat.IsResumeGraceActive(disconnectedAt.AddSeconds(30), TimeSpan.FromMinutes(2)));
|
||||
Assert.IsFalse(seat.IsResumeGraceActive(disconnectedAt.AddMinutes(3), TimeSpan.FromMinutes(2)));
|
||||
|
||||
seat.AttachRuntime("unity-runtime-new", reconnectedAt);
|
||||
|
||||
Assert.AreEqual(AetheriaRuntimeStarbridgePlayerSeatConnectionStates.Connected, seat.ConnectionState);
|
||||
Assert.AreEqual("unity-runtime-new", seat.RuntimeId);
|
||||
Assert.Contains("unity-runtime-old", seat.PreviousRuntimeIds);
|
||||
Assert.AreEqual("entity:ship:7", seat.ControlledEntityKey);
|
||||
Assert.AreEqual("item:cockpit:7", seat.CockpitItemKey);
|
||||
Assert.AreEqual("entity:pod:7", seat.EscapePodEntityKey);
|
||||
Assert.AreEqual("loadout:ship:7", seat.LoadoutDocumentKey);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StarbridgePlayerSeatCanBeReadAsManagedCultMeshDocument()
|
||||
{
|
||||
var statePath = Path.Combine(
|
||||
Path.GetTempPath(),
|
||||
"aetheria-starbridge-seat-reactive-tests",
|
||||
Path.GetRandomFileName(),
|
||||
"state.cc");
|
||||
var seat = AetheriaRuntimeStarbridgePlayerSeatDocument.Create(
|
||||
"seat-support",
|
||||
"player-support",
|
||||
"session-1",
|
||||
"scenario-1",
|
||||
"run-1",
|
||||
AetheriaRuntimeStarbridgePlayerSeatRoles.Support,
|
||||
"unity-support",
|
||||
DateTimeOffset.Parse("2026-06-27T11:00:00Z"));
|
||||
seat.CockpitItemKey = "item:cockpit:support";
|
||||
seat.EscapePodEntityKey = "entity:pod:support";
|
||||
|
||||
using var client = AetheriaRuntimeVerseClient
|
||||
.OpenAsync(statePath, "unity-support", startServer: false, pullOnOpen: true)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
|
||||
client.PutStarbridgePlayerSeatAsync(seat)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
var handle = client.Document<AetheriaRuntimeStarbridgePlayerSeatDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.StarbridgePlayerSeat(seat.SeatId));
|
||||
using var reactive = handle.Reactive();
|
||||
|
||||
Assert.AreEqual("seat-support", handle.Latest().SeatId);
|
||||
Assert.AreEqual("item:cockpit:support", reactive.Current.CockpitItemKey);
|
||||
Assert.AreEqual("entity:pod:support", reactive.Current.EscapePodEntityKey);
|
||||
Assert.AreEqual("unity-support", reactive.Document.Context.RuntimeId);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8ea79e799fe047618b652b9d835a4425
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -105,6 +105,7 @@
|
|||
<Compile Include="Packages\org.gamecult.aetheria.state\Runtime\AetheriaRuntimeRtsSimulation.cs" />
|
||||
<Compile Include="Packages\org.gamecult.aetheria.state\Runtime\AetheriaRuntimeRtsViewportDocuments.cs" />
|
||||
<Compile Include="Packages\org.gamecult.aetheria.state\Runtime\AetheriaRuntimeStarbridgeDocuments.cs" />
|
||||
<Compile Include="Packages\org.gamecult.aetheria.state\Runtime\AetheriaRuntimeStarbridgePlayerSeatDocuments.cs" />
|
||||
<Compile Include="Packages\org.gamecult.aetheria.state\Runtime\AetheriaRuntimeStateReader.cs" />
|
||||
<Compile Include="Packages\org.gamecult.aetheria.state\Runtime\AetheriaRuntimeDaemonObservationCursor.cs" />
|
||||
<Compile Include="Packages\org.gamecult.aetheria.state\Runtime\AetheriaRuntimeVerseDiscovery.cs" />
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
public const string StarbridgeScenario = "gamecult.aetheria.starbridge_scenario.v1";
|
||||
public const string StarbridgeSession = "gamecult.aetheria.starbridge_session.v1";
|
||||
public const string StarbridgeSessionSummary = "gamecult.aetheria.starbridge_session_summary.v1";
|
||||
public const string StarbridgePlayerSeat = "gamecult.aetheria.starbridge_player_seat.v1";
|
||||
public const string VerseAuthorityPolicy = AetheriaRuntimeVerseAuthoritySchemas.Policy;
|
||||
public const string AuthorityLease = AetheriaRuntimeVerseAuthoritySchemas.Lease;
|
||||
public const string SoaView = "gamecult.aetheria.daemon_soa_view.v1";
|
||||
|
|
@ -308,6 +309,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
AetheriaRuntimeDaemonSchemas.StarbridgeScenario,
|
||||
AetheriaRuntimeDaemonSchemas.StarbridgeSession,
|
||||
AetheriaRuntimeDaemonSchemas.StarbridgeSessionSummary,
|
||||
AetheriaRuntimeDaemonSchemas.StarbridgePlayerSeat,
|
||||
AetheriaRuntimeDaemonSchemas.VerseAuthorityPolicy,
|
||||
AetheriaRuntimeDaemonSchemas.AuthorityLease
|
||||
},
|
||||
|
|
|
|||
|
|
@ -0,0 +1,156 @@
|
|||
using System;
|
||||
using GameCult.Caching;
|
||||
using MessagePack;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Verse
|
||||
{
|
||||
public static class AetheriaRuntimeStarbridgePlayerSeatConnectionStates
|
||||
{
|
||||
public const string Connected = "connected";
|
||||
public const string Grace = "grace";
|
||||
public const string Disconnected = "disconnected";
|
||||
public const string Abandoned = "abandoned";
|
||||
public const string Replaced = "replaced";
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeStarbridgePlayerSeatRoles
|
||||
{
|
||||
public const string Commander = "commander";
|
||||
public const string Pilot = "pilot";
|
||||
public const string Support = "support";
|
||||
public const string Observer = "observer";
|
||||
}
|
||||
|
||||
[CultDocument("gamecult.aetheria.starbridge_player_seat", "gamecult.aetheria.starbridge_player_seat.v1")]
|
||||
[MessagePackObject]
|
||||
public sealed class AetheriaRuntimeStarbridgePlayerSeatDocument
|
||||
{
|
||||
[Key(0)] public string Schema { get; set; } = AetheriaRuntimeDaemonSchemas.StarbridgePlayerSeat;
|
||||
[Key(1)] public string SeatId { get; set; } = "";
|
||||
[Key(2)] public string PlayerId { get; set; } = "";
|
||||
[Key(3)] public string PlayerDisplayName { get; set; } = "";
|
||||
[Key(4)] public string SessionId { get; set; } = "";
|
||||
[Key(5)] public string ScenarioId { get; set; } = "";
|
||||
[Key(6)] public string RunId { get; set; } = "";
|
||||
[Key(7)] public string Role { get; set; } = AetheriaRuntimeStarbridgePlayerSeatRoles.Pilot;
|
||||
[Key(8)] public string RuntimeId { get; set; } = "";
|
||||
[Key(9)] public string[] PreviousRuntimeIds { get; set; } = Array.Empty<string>();
|
||||
[Key(10)] public string ControlledEntityKey { get; set; } = "";
|
||||
[Key(11)] public string ShipEntityKey { get; set; } = "";
|
||||
[Key(12)] public string CockpitItemKey { get; set; } = "";
|
||||
[Key(13)] public string EscapePodEntityKey { get; set; } = "";
|
||||
[Key(14)] public string LoadoutDocumentKey { get; set; } = "";
|
||||
[Key(15)] public string AuthorityLeaseId { get; set; } = "";
|
||||
[Key(16)] public string[] ClaimKinds { get; set; } = Array.Empty<string>();
|
||||
[Key(17)] public string ConnectionState { get; set; } =
|
||||
AetheriaRuntimeStarbridgePlayerSeatConnectionStates.Disconnected;
|
||||
[Key(18)] public string ConnectedAtUtc { get; set; } = "";
|
||||
[Key(19)] public string LastSeenAtUtc { get; set; } = "";
|
||||
[Key(20)] public string DisconnectedAtUtc { get; set; } = "";
|
||||
[Key(21)] public string ResumeTokenHash { get; set; } = "";
|
||||
[Key(22)] public string UpdatedAtUtc { get; set; } = "";
|
||||
|
||||
public static string RecordKey(string seatId)
|
||||
{
|
||||
return $"starbridge:player-seats:{AetheriaRuntimeVerseRecordKeys.StableToken(seatId)}:v1";
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeStarbridgePlayerSeatDocument Create(
|
||||
string seatId,
|
||||
string playerId,
|
||||
string sessionId,
|
||||
string scenarioId,
|
||||
string runId,
|
||||
string role,
|
||||
string runtimeId,
|
||||
DateTimeOffset now)
|
||||
{
|
||||
var stamp = now.ToString("O");
|
||||
return new AetheriaRuntimeStarbridgePlayerSeatDocument
|
||||
{
|
||||
SeatId = seatId ?? "",
|
||||
PlayerId = playerId ?? "",
|
||||
SessionId = sessionId ?? "",
|
||||
ScenarioId = scenarioId ?? "",
|
||||
RunId = runId ?? "",
|
||||
Role = string.IsNullOrWhiteSpace(role)
|
||||
? AetheriaRuntimeStarbridgePlayerSeatRoles.Pilot
|
||||
: role,
|
||||
RuntimeId = runtimeId ?? "",
|
||||
ConnectionState = AetheriaRuntimeStarbridgePlayerSeatConnectionStates.Connected,
|
||||
ConnectedAtUtc = stamp,
|
||||
LastSeenAtUtc = stamp,
|
||||
UpdatedAtUtc = stamp
|
||||
};
|
||||
}
|
||||
|
||||
public AetheriaRuntimeStarbridgePlayerSeatDocument AttachRuntime(
|
||||
string runtimeId,
|
||||
DateTimeOffset now)
|
||||
{
|
||||
var previousRuntimeId = RuntimeId ?? "";
|
||||
if (!string.IsNullOrWhiteSpace(previousRuntimeId) &&
|
||||
!string.Equals(previousRuntimeId, runtimeId, StringComparison.Ordinal))
|
||||
{
|
||||
PreviousRuntimeIds = AppendDistinct(PreviousRuntimeIds, previousRuntimeId);
|
||||
}
|
||||
|
||||
RuntimeId = runtimeId ?? "";
|
||||
ConnectionState = AetheriaRuntimeStarbridgePlayerSeatConnectionStates.Connected;
|
||||
ConnectedAtUtc = now.ToString("O");
|
||||
LastSeenAtUtc = ConnectedAtUtc;
|
||||
DisconnectedAtUtc = "";
|
||||
UpdatedAtUtc = ConnectedAtUtc;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AetheriaRuntimeStarbridgePlayerSeatDocument MarkSeen(DateTimeOffset now)
|
||||
{
|
||||
LastSeenAtUtc = now.ToString("O");
|
||||
UpdatedAtUtc = LastSeenAtUtc;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AetheriaRuntimeStarbridgePlayerSeatDocument MarkDisconnected(DateTimeOffset now)
|
||||
{
|
||||
DisconnectedAtUtc = now.ToString("O");
|
||||
LastSeenAtUtc = DisconnectedAtUtc;
|
||||
UpdatedAtUtc = DisconnectedAtUtc;
|
||||
ConnectionState = AetheriaRuntimeStarbridgePlayerSeatConnectionStates.Grace;
|
||||
return this;
|
||||
}
|
||||
|
||||
public bool IsResumeGraceActive(DateTimeOffset now, TimeSpan gracePeriod)
|
||||
{
|
||||
if (!string.Equals(
|
||||
ConnectionState,
|
||||
AetheriaRuntimeStarbridgePlayerSeatConnectionStates.Grace,
|
||||
StringComparison.Ordinal))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!DateTimeOffset.TryParse(DisconnectedAtUtc, out var disconnectedAt))
|
||||
return false;
|
||||
|
||||
return now - disconnectedAt <= gracePeriod;
|
||||
}
|
||||
|
||||
private static string[] AppendDistinct(string[]? values, string value)
|
||||
{
|
||||
values ??= Array.Empty<string>();
|
||||
foreach (var candidate in values)
|
||||
{
|
||||
if (string.Equals(candidate, value, StringComparison.Ordinal))
|
||||
return values;
|
||||
}
|
||||
|
||||
var next = new string[values.Length + 1];
|
||||
Array.Copy(values, next, values.Length);
|
||||
next[next.Length - 1] = value;
|
||||
return next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9b2ced5ab34e4c829b6b9d1c1a616008
|
||||
|
|
@ -38,6 +38,11 @@ namespace GameCult.Aetheria.State.Verse
|
|||
public static CultRecordKey StarbridgeSessionLatest { get; } =
|
||||
new CultRecordKey("starbridge:aetheria.session.latest.v1");
|
||||
|
||||
public static CultRecordKey StarbridgePlayerSeat(string seatId)
|
||||
{
|
||||
return new CultRecordKey(AetheriaRuntimeStarbridgePlayerSeatDocument.RecordKey(seatId));
|
||||
}
|
||||
|
||||
public static CultRecordKey DaemonGameSurface { get; } =
|
||||
new CultRecordKey("eve:surface:aetheria.daemon.game");
|
||||
|
||||
|
|
@ -84,7 +89,6 @@ namespace GameCult.Aetheria.State.Verse
|
|||
typeof(AetheriaRuntimeDaemonCommandBoundaryDocument),
|
||||
typeof(AetheriaRuntimeDaemonFrameDocument),
|
||||
typeof(AetheriaRuntimeDaemonSoaViewDocument),
|
||||
typeof(AetheriaRuntimeAssetManifestDocument),
|
||||
typeof(AetheriaRuntimeObjectsViewportDocument),
|
||||
typeof(AetheriaRuntimeGravityViewportDocument),
|
||||
typeof(AetheriaRuntimeCurrentZoneDocument),
|
||||
|
|
@ -100,6 +104,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
typeof(AetheriaRuntimeStarbridgeScenarioDocument),
|
||||
typeof(AetheriaRuntimeStarbridgeSessionDocument),
|
||||
typeof(AetheriaRuntimeStarbridgeSessionSummaryDocument),
|
||||
typeof(AetheriaRuntimeStarbridgePlayerSeatDocument),
|
||||
typeof(AetheriaRuntimeDaemonCommandDocument),
|
||||
typeof(AetheriaRuntimeEveCommandDocument),
|
||||
typeof(EveSurfaceState)
|
||||
|
|
@ -242,6 +247,13 @@ namespace GameCult.Aetheria.State.Verse
|
|||
AetheriaRuntimeVerseRecordKeys.StarbridgeSessionLatest);
|
||||
}
|
||||
|
||||
public Task<AetheriaRuntimeStarbridgePlayerSeatDocument?> GetStarbridgePlayerSeatAsync(string seatId)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return Database.GetAsync<AetheriaRuntimeStarbridgePlayerSeatDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.StarbridgePlayerSeat(seatId));
|
||||
}
|
||||
|
||||
public AetheriaRuntimeCatalogSnapshot OpenRuntimeCatalog()
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
|
@ -411,6 +423,14 @@ namespace GameCult.Aetheria.State.Verse
|
|||
AetheriaRuntimeVerseRecordKeys.StarbridgeSessionLatest);
|
||||
}
|
||||
|
||||
public CultMeshMutableStatePointer<AetheriaRuntimeStarbridgePlayerSeatDocument> StarbridgePlayerSeat(
|
||||
string seatId)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return MutableDocumentPointer<AetheriaRuntimeStarbridgePlayerSeatDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.StarbridgePlayerSeat(seatId));
|
||||
}
|
||||
|
||||
public CultMeshMutableStatePointer<EveSurfaceState> DaemonGameSurface()
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
|
@ -516,6 +536,14 @@ namespace GameCult.Aetheria.State.Verse
|
|||
AetheriaRuntimeVerseRecordKeys.StarbridgeSessionLatest);
|
||||
}
|
||||
|
||||
public Observable<CultNetDatabaseChange<AetheriaRuntimeStarbridgePlayerSeatDocument>>
|
||||
WatchStarbridgePlayerSeat(string seatId)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return Database.WatchRecord<AetheriaRuntimeStarbridgePlayerSeatDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.StarbridgePlayerSeat(seatId));
|
||||
}
|
||||
|
||||
public Observable<CultNetDatabaseChange<EveSurfaceState>> WatchDaemonGameSurfaces()
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
|
@ -613,6 +641,20 @@ namespace GameCult.Aetheria.State.Verse
|
|||
await FlushAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task PutStarbridgePlayerSeatAsync(
|
||||
AetheriaRuntimeStarbridgePlayerSeatDocument seat,
|
||||
bool flush = true)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
if (seat == null) throw new ArgumentNullException(nameof(seat));
|
||||
|
||||
seat.Schema = AetheriaRuntimeDaemonSchemas.StarbridgePlayerSeat;
|
||||
await Database.PutAsync(AetheriaRuntimeVerseRecordKeys.StarbridgePlayerSeat(seat.SeatId), seat)
|
||||
.ConfigureAwait(false);
|
||||
if (flush)
|
||||
await FlushAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal Task<AetheriaRuntimeEveCommandEnvelope> SubmitInputSettingsCommandAsync(
|
||||
AetheriaRuntimeEveCommandKind command,
|
||||
AetheriaRuntimeInputSettingsCommandBody body,
|
||||
|
|
|
|||
Loading…
Reference in a new issue