feat(headless): hydrate isolated collision worlds
This commit is contained in:
parent
9569dadb57
commit
b6547ff38c
20 changed files with 1960 additions and 101 deletions
|
|
@ -1,4 +1,6 @@
|
|||
using System.Reflection;
|
||||
using System.Collections.Immutable;
|
||||
using System.Runtime.InteropServices;
|
||||
using AcDream.Content;
|
||||
using AcDream.Headless.Configuration;
|
||||
using AcDream.Headless.Hosting;
|
||||
|
|
@ -114,6 +116,9 @@ public sealed class HeadlessProcessContentOwnerTests
|
|||
IPreparedCollisionSource sharedCollision =
|
||||
Assert.IsAssignableFrom<IPreparedCollisionSource>(
|
||||
host.Sessions[0].Content?.PreparedCollision);
|
||||
float[] sharedHeightTable = Assert.IsType<float[]>(
|
||||
ImmutableCollectionsMarshal.AsArray(
|
||||
host.Sessions[0].Content!.HeightTable));
|
||||
Assert.All(
|
||||
host.Sessions,
|
||||
session =>
|
||||
|
|
@ -130,6 +135,10 @@ public sealed class HeadlessProcessContentOwnerTests
|
|||
Assert.Same(
|
||||
sharedCollision,
|
||||
session.Content?.PreparedCollision);
|
||||
Assert.Same(
|
||||
sharedHeightTable,
|
||||
ImmutableCollectionsMarshal.AsArray(
|
||||
session.Content!.HeightTable));
|
||||
});
|
||||
Assert.Equal(
|
||||
sessionCount,
|
||||
|
|
@ -151,6 +160,13 @@ public sealed class HeadlessProcessContentOwnerTests
|
|||
session.Runtime.EntityObjects.Physics.DataCache)
|
||||
.Distinct(ReferenceEqualityComparer.Instance)
|
||||
.Count());
|
||||
Assert.Equal(
|
||||
sessionCount,
|
||||
host.Sessions
|
||||
.Select(static session =>
|
||||
session.Runtime.MovementOwner)
|
||||
.Distinct(ReferenceEqualityComparer.Instance)
|
||||
.Count());
|
||||
|
||||
HeadlessSessionHost[] sessions = host.Sessions.ToArray();
|
||||
host.Dispose();
|
||||
|
|
@ -223,7 +239,8 @@ public sealed class HeadlessProcessContentOwnerTests
|
|||
return new HeadlessOpenedProcessContent(
|
||||
DatsResource,
|
||||
PreparedResource,
|
||||
MagicCatalog.Empty);
|
||||
MagicCatalog.Empty,
|
||||
ImmutableArray.CreateRange(new float[256]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using AcDream.Headless.Credentials;
|
|||
using AcDream.Headless.Diagnostics;
|
||||
using AcDream.Headless.Hosting;
|
||||
using AcDream.Headless.Platform;
|
||||
using AcDream.Headless.Policies;
|
||||
using AcDream.Runtime;
|
||||
using AcDream.Runtime.Session;
|
||||
|
||||
|
|
@ -186,11 +187,60 @@ public sealed class HeadlessProcessSchedulerTests
|
|||
StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ThrowingPolicyQuarantinesOnlyItsOwnSession()
|
||||
{
|
||||
var time = new ManualTimeProvider();
|
||||
var operations = new FixtureSessionOperations();
|
||||
var throwing = new ThrowingPolicy();
|
||||
var healthy = new CountingPolicy();
|
||||
using HeadlessSessionHost first =
|
||||
CreateSession(
|
||||
"fault",
|
||||
time,
|
||||
operations,
|
||||
policyOverride: throwing);
|
||||
using HeadlessSessionHost second =
|
||||
CreateSession(
|
||||
"healthy",
|
||||
time,
|
||||
operations,
|
||||
policyOverride: healthy);
|
||||
Assert.Equal(
|
||||
RuntimeSessionStartStatus.Connected,
|
||||
first.Start().Status);
|
||||
Assert.Equal(
|
||||
RuntimeSessionStartStatus.Connected,
|
||||
second.Start().Status);
|
||||
var scheduler = new HeadlessProcessScheduler(
|
||||
[first, second],
|
||||
time);
|
||||
|
||||
time.Advance(TimeSpan.FromMilliseconds(15));
|
||||
Assert.True(scheduler.DispatchDue(time.GetTimestamp()));
|
||||
|
||||
Assert.True(first.IsFaulted);
|
||||
Assert.IsType<InvalidOperationException>(first.Fault);
|
||||
Assert.False(second.IsFaulted);
|
||||
Assert.Equal(1, healthy.TickCount);
|
||||
HeadlessSchedulerSnapshot snapshot =
|
||||
scheduler.CaptureSnapshot();
|
||||
Assert.Equal(1, snapshot.FaultedSessionCount);
|
||||
Assert.Equal(1, snapshot.ActiveSessionCount);
|
||||
|
||||
time.Advance(TimeSpan.FromMilliseconds(15));
|
||||
Assert.True(scheduler.DispatchDue(time.GetTimestamp()));
|
||||
Assert.Equal(2, healthy.TickCount);
|
||||
Assert.Equal(1UL, first.Runtime.Clock.FrameNumber);
|
||||
Assert.Equal(2UL, second.Runtime.Clock.FrameNumber);
|
||||
}
|
||||
|
||||
private static HeadlessSessionHost CreateSession(
|
||||
string id,
|
||||
TimeProvider time,
|
||||
ILiveSessionOperations operations,
|
||||
TimeSpan? reconnectQuiescence = null)
|
||||
TimeSpan? reconnectQuiescence = null,
|
||||
IHeadlessBotPolicy? policyOverride = null)
|
||||
{
|
||||
var credential = new HeadlessCredentialSecret(
|
||||
$"{id}-credential",
|
||||
|
|
@ -203,7 +253,8 @@ public sealed class HeadlessProcessSchedulerTests
|
|||
new HeadlessDiagnosticWriter(TextWriter.Null),
|
||||
operations,
|
||||
time,
|
||||
reconnectQuiescence);
|
||||
reconnectQuiescence,
|
||||
policyOverride: policyOverride);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -304,4 +355,67 @@ public sealed class HeadlessProcessSchedulerTests
|
|||
session.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private abstract class FixturePolicy : IHeadlessBotPolicy
|
||||
{
|
||||
public virtual bool IsComplete => false;
|
||||
|
||||
public abstract void Tick(
|
||||
IGameRuntimeView view,
|
||||
IGameRuntimeCommands commands);
|
||||
|
||||
public void OnLifecycle(in RuntimeLifecycleDelta delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnCommand(in RuntimeCommandDelta delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnEntity(in RuntimeEntityDelta delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnInventory(in RuntimeInventoryDelta delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnChat(in RuntimeChatDelta delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnMovement(in RuntimeMovementDelta delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnPortal(in RuntimePortalDelta delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnCombat(in RuntimeCombatDelta delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class ThrowingPolicy : FixturePolicy
|
||||
{
|
||||
public override void Tick(
|
||||
IGameRuntimeView view,
|
||||
IGameRuntimeCommands commands) =>
|
||||
throw new InvalidOperationException("injected policy fault");
|
||||
}
|
||||
|
||||
private sealed class CountingPolicy : FixturePolicy
|
||||
{
|
||||
public int TickCount { get; private set; }
|
||||
|
||||
public override void Tick(
|
||||
IGameRuntimeView view,
|
||||
IGameRuntimeCommands commands) =>
|
||||
TickCount++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ using AcDream.Runtime;
|
|||
using AcDream.Runtime.Entities;
|
||||
using AcDream.Runtime.Gameplay;
|
||||
using AcDream.Runtime.Session;
|
||||
using AcDream.Runtime.World;
|
||||
|
||||
namespace AcDream.Headless.Tests;
|
||||
|
||||
|
|
@ -186,6 +187,71 @@ public sealed class HeadlessSessionHostTests
|
|||
Assert.True(host.Runtime.CaptureOwnership().IsConverged);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WorldProjectionHydratesCanonicalMovementAndTeleportState()
|
||||
{
|
||||
var operations = new FixtureSessionOperations();
|
||||
using var credential = new HeadlessCredentialSecret(
|
||||
"fixture",
|
||||
"password");
|
||||
using var host = new HeadlessSessionHost(
|
||||
Descriptor(),
|
||||
credential,
|
||||
new HeadlessDiagnosticWriter(TextWriter.Null),
|
||||
operations);
|
||||
GameRuntime runtime = host.Runtime;
|
||||
const uint player = 0x50000002u;
|
||||
runtime.PlayerIdentity.ServerGuid = player;
|
||||
AddFlatLandblock(runtime.EntityObjects.Physics.Engine);
|
||||
RuntimeEntityRecord record = runtime.EntityObjects
|
||||
.RegisterEntity(Spawn(player))
|
||||
.Canonical!;
|
||||
Assert.True(runtime.EntityObjects.ApplyAcceptedSpawn(
|
||||
record,
|
||||
record.CreateIntegrationVersion,
|
||||
record.Snapshot,
|
||||
replaceGeneration: false));
|
||||
var collision = new FixtureCollisionNeighborhood();
|
||||
var projection = new HeadlessSessionWorldProjection(
|
||||
runtime,
|
||||
collision);
|
||||
|
||||
projection.ProjectSpawn(record, isLocalPlayer: true);
|
||||
PlayerMovementController controller =
|
||||
Assert.IsType<PlayerMovementController>(
|
||||
runtime.MovementOwner.Controller);
|
||||
projection.ProjectPosition(record, isLocalPlayer: true);
|
||||
|
||||
Assert.Same(controller, runtime.MovementOwner.Controller);
|
||||
Assert.Equal(record.LocalEntityId, controller.LocalEntityId);
|
||||
Assert.Equal(
|
||||
0xA9B40000u,
|
||||
controller.CellId & 0xFFFF0000u);
|
||||
Assert.True((controller.CellId & 0xFFFFu) < 0x0100u);
|
||||
projection.BeginTeleport();
|
||||
Assert.Equal(PlayerState.PortalSpace, controller.State);
|
||||
|
||||
RuntimeDestinationReadiness readiness =
|
||||
projection.PrepareDestination(
|
||||
revealGeneration: 7,
|
||||
new RuntimeTeleportDestination(
|
||||
player,
|
||||
InstanceSequence: 1,
|
||||
PositionSequence: 2,
|
||||
TeleportSequence: 1,
|
||||
ForcePositionSequence: 0,
|
||||
new Position(
|
||||
0xA9B40001u,
|
||||
new Vector3(96f, 97f, 50f),
|
||||
Quaternion.Identity)));
|
||||
|
||||
Assert.True(readiness.IsCollisionReady);
|
||||
Assert.False(readiness.IsUnhydratable);
|
||||
Assert.Equal(PlayerState.InWorld, controller.State);
|
||||
Assert.Equal(4, collision.CenterCount);
|
||||
Assert.Equal(0xA9B40001u, collision.LastCell);
|
||||
}
|
||||
|
||||
private static HeadlessSessionDescriptor Descriptor(
|
||||
HeadlessCredentialProviderKind provider =
|
||||
HeadlessCredentialProviderKind.Environment,
|
||||
|
|
@ -217,18 +283,7 @@ public sealed class HeadlessSessionHostTests
|
|||
{
|
||||
const uint player = 0x50000002u;
|
||||
PhysicsEngine engine = runtime.EntityObjects.Physics.Engine;
|
||||
var heights = new byte[81];
|
||||
Array.Fill(heights, (byte)50);
|
||||
var heightTable = new float[256];
|
||||
for (int index = 0; index < heightTable.Length; index++)
|
||||
heightTable[index] = index;
|
||||
engine.AddLandblock(
|
||||
0xA9B4FFFFu,
|
||||
new TerrainSurface(heights, heightTable),
|
||||
[],
|
||||
[],
|
||||
worldOffsetX: 0f,
|
||||
worldOffsetY: 0f);
|
||||
AddFlatLandblock(engine);
|
||||
|
||||
RuntimeEntityRecord record = runtime.EntityObjects
|
||||
.RegisterEntity(Spawn(player))
|
||||
|
|
@ -246,6 +301,22 @@ public sealed class HeadlessSessionHostTests
|
|||
runtime.MovementOwner.Controller = controller;
|
||||
}
|
||||
|
||||
private static void AddFlatLandblock(PhysicsEngine engine)
|
||||
{
|
||||
var heights = new byte[81];
|
||||
Array.Fill(heights, (byte)50);
|
||||
var heightTable = new float[256];
|
||||
for (int index = 0; index < heightTable.Length; index++)
|
||||
heightTable[index] = index;
|
||||
engine.AddLandblock(
|
||||
0xA9B4FFFFu,
|
||||
new TerrainSurface(heights, heightTable),
|
||||
[],
|
||||
[],
|
||||
worldOffsetX: 0f,
|
||||
worldOffsetY: 0f);
|
||||
}
|
||||
|
||||
private static WorldSession.EntitySpawn Spawn(uint guid)
|
||||
{
|
||||
var position = new CreateObject.ServerPosition(
|
||||
|
|
@ -389,4 +460,20 @@ public sealed class HeadlessSessionHostTests
|
|||
}
|
||||
}
|
||||
|
||||
private sealed class FixtureCollisionNeighborhood
|
||||
: IHeadlessCollisionNeighborhood
|
||||
{
|
||||
public int CenterCount { get; private set; }
|
||||
public uint LastCell { get; private set; }
|
||||
|
||||
public void CenterOn(uint fullCellId)
|
||||
{
|
||||
CenterCount++;
|
||||
LastCell = fullCellId;
|
||||
}
|
||||
|
||||
public bool IsReady(uint fullCellId) =>
|
||||
fullCellId == LastCell;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
376
tests/AcDream.Headless.Tests/HeadlessSessionIsolationTests.cs
Normal file
376
tests/AcDream.Headless.Tests/HeadlessSessionIsolationTests.cs
Normal file
|
|
@ -0,0 +1,376 @@
|
|||
using System.Net;
|
||||
using System.Reflection;
|
||||
using AcDream.Core.Net;
|
||||
using AcDream.Core.Net.Messages;
|
||||
using AcDream.Core.Physics;
|
||||
using AcDream.Headless.Configuration;
|
||||
using AcDream.Headless.Credentials;
|
||||
using AcDream.Headless.Diagnostics;
|
||||
using AcDream.Headless.Hosting;
|
||||
using AcDream.Runtime;
|
||||
using AcDream.Runtime.Entities;
|
||||
using AcDream.Runtime.Session;
|
||||
|
||||
namespace AcDream.Headless.Tests;
|
||||
|
||||
public sealed class HeadlessSessionIsolationTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(1)]
|
||||
[InlineData(5)]
|
||||
[InlineData(10)]
|
||||
public void SameServerIdentityStaysIsolatedAcrossActivityPortalAndReconnect(
|
||||
int sessionCount)
|
||||
{
|
||||
const uint sharedPlayerGuid = 0x50000001u;
|
||||
var operations = new FixtureOperations(sharedPlayerGuid);
|
||||
HeadlessSessionHost[] hosts = Enumerable.Range(0, sessionCount)
|
||||
.Select(index => CreateHost(index, operations))
|
||||
.ToArray();
|
||||
try
|
||||
{
|
||||
foreach (HeadlessSessionHost host in hosts)
|
||||
{
|
||||
Assert.Equal(
|
||||
RuntimeSessionStartStatus.Connected,
|
||||
host.Start().Status);
|
||||
}
|
||||
|
||||
var firstRecords = new RuntimeEntityRecord[sessionCount];
|
||||
for (int index = 0; index < hosts.Length; index++)
|
||||
{
|
||||
HeadlessSessionHost host = hosts[index];
|
||||
WorldSession session =
|
||||
operations.ActiveSession(host.SessionId);
|
||||
session.GameActionCapture = _ => { };
|
||||
SpawnInto(session, sharedPlayerGuid, index + 1f);
|
||||
RuntimeCommandResult selected =
|
||||
host.Commands.Selection.SelectObject(
|
||||
host.Runtime.Generation,
|
||||
sharedPlayerGuid);
|
||||
Assert.True(selected.Accepted);
|
||||
Assert.True(
|
||||
host.Runtime.EntityObjects.Entities.TryGetActive(
|
||||
sharedPlayerGuid,
|
||||
out RuntimeEntityRecord record));
|
||||
firstRecords[index] = record;
|
||||
Assert.Equal(
|
||||
index + 1f,
|
||||
record.Snapshot.Position!.Value.PositionX);
|
||||
|
||||
Portal(
|
||||
session,
|
||||
sharedPlayerGuid,
|
||||
index + 20f);
|
||||
Assert.True(host.Runtime.Portal.Snapshot.Completed);
|
||||
Assert.True(
|
||||
host.Runtime.TransitOwner
|
||||
.CaptureOwnership()
|
||||
.IsSessionIdle);
|
||||
}
|
||||
|
||||
Assert.Equal(
|
||||
sessionCount,
|
||||
firstRecords
|
||||
.Distinct(ReferenceEqualityComparer.Instance)
|
||||
.Count());
|
||||
Assert.Equal(
|
||||
sessionCount,
|
||||
hosts
|
||||
.Select(static host => host.Runtime.Entities)
|
||||
.Distinct(ReferenceEqualityComparer.Instance)
|
||||
.Count());
|
||||
|
||||
for (int index = 0; index < hosts.Length; index++)
|
||||
{
|
||||
HeadlessSessionHost host = hosts[index];
|
||||
ulong priorGeneration = host.Runtime.Generation.Value;
|
||||
Assert.Equal(
|
||||
RuntimeSessionStartStatus.Connected,
|
||||
host.Reconnect().Status);
|
||||
Assert.True(
|
||||
host.Runtime.Generation.Value > priorGeneration);
|
||||
Assert.Equal(0, host.Runtime.Entities.Count);
|
||||
|
||||
WorldSession replacement =
|
||||
operations.ActiveSession(host.SessionId);
|
||||
replacement.GameActionCapture = _ => { };
|
||||
SpawnInto(
|
||||
replacement,
|
||||
sharedPlayerGuid,
|
||||
index + 101f);
|
||||
Assert.True(
|
||||
host.Runtime.EntityObjects.Entities.TryGetActive(
|
||||
sharedPlayerGuid,
|
||||
out RuntimeEntityRecord replacementRecord));
|
||||
Assert.NotSame(firstRecords[index], replacementRecord);
|
||||
Assert.Equal(
|
||||
index + 101f,
|
||||
replacementRecord.Snapshot.Position!.Value.PositionX);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
for (int index = hosts.Length - 1; index >= 0; index--)
|
||||
hosts[index].Dispose();
|
||||
}
|
||||
|
||||
Assert.Equal(sessionCount * 2, operations.CreatedSessionCount);
|
||||
Assert.Equal(sessionCount * 2, operations.DisposedSessionCount);
|
||||
Assert.All(
|
||||
hosts,
|
||||
static host =>
|
||||
Assert.True(host.Runtime.CaptureOwnership().IsConverged));
|
||||
}
|
||||
|
||||
private static HeadlessSessionHost CreateHost(
|
||||
int index,
|
||||
FixtureOperations operations)
|
||||
{
|
||||
string id = $"bot-{index}";
|
||||
var credential = new HeadlessCredentialSecret(
|
||||
$"{id}-credential",
|
||||
"fixture-password");
|
||||
try
|
||||
{
|
||||
return new HeadlessSessionHost(
|
||||
new HeadlessSessionDescriptor
|
||||
{
|
||||
Id = id,
|
||||
Endpoint = new HeadlessEndpointDescriptor
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
Port = 9000,
|
||||
},
|
||||
Account = id,
|
||||
Character = new HeadlessCharacterSelector
|
||||
{
|
||||
Index = 0,
|
||||
},
|
||||
Policy = new HeadlessBotPolicyDescriptor
|
||||
{
|
||||
Id = "idle",
|
||||
},
|
||||
Credential = new HeadlessCredentialReference
|
||||
{
|
||||
Provider =
|
||||
HeadlessCredentialProviderKind.StandardInput,
|
||||
Reference = $"{id}-credential",
|
||||
},
|
||||
},
|
||||
credential,
|
||||
new HeadlessDiagnosticWriter(TextWriter.Null),
|
||||
operations);
|
||||
}
|
||||
catch
|
||||
{
|
||||
credential.Dispose();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SpawnInto(
|
||||
WorldSession session,
|
||||
uint guid,
|
||||
float positionX) =>
|
||||
EventDelegate<Action<WorldSession.EntitySpawn>>(
|
||||
session,
|
||||
nameof(session.EntitySpawned))(
|
||||
Spawn(guid, positionX));
|
||||
|
||||
private static void Portal(
|
||||
WorldSession session,
|
||||
uint guid,
|
||||
float positionX)
|
||||
{
|
||||
EventDelegate<Action<uint>>(
|
||||
session,
|
||||
nameof(session.TeleportStarted))(1u);
|
||||
EventDelegate<Action<WorldSession.EntityPositionUpdate>>(
|
||||
session,
|
||||
nameof(session.PositionUpdated))(
|
||||
new WorldSession.EntityPositionUpdate(
|
||||
guid,
|
||||
Position(positionX) with
|
||||
{
|
||||
LandblockId = 0x01020001u,
|
||||
},
|
||||
Velocity: null,
|
||||
PlacementId: null,
|
||||
IsGrounded: true,
|
||||
InstanceSequence: 1,
|
||||
PositionSequence: 2,
|
||||
TeleportSequence: 1,
|
||||
ForcePositionSequence: 0));
|
||||
}
|
||||
|
||||
private static WorldSession.EntitySpawn Spawn(
|
||||
uint guid,
|
||||
float positionX)
|
||||
{
|
||||
CreateObject.ServerPosition position = Position(positionX);
|
||||
var timestamps = new PhysicsTimestamps(
|
||||
Position: 1,
|
||||
Movement: 1,
|
||||
State: 1,
|
||||
Vector: 1,
|
||||
Teleport: 0,
|
||||
ServerControlledMove: 1,
|
||||
ForcePosition: 0,
|
||||
ObjDesc: 1,
|
||||
Instance: 1);
|
||||
var physics = new PhysicsSpawnData(
|
||||
RawState: (uint)PhysicsStateFlags.ReportCollisions,
|
||||
Position: position,
|
||||
Movement: null,
|
||||
AnimationFrame: null,
|
||||
SetupTableId: 0x02000001u,
|
||||
MotionTableId: null,
|
||||
SoundTableId: null,
|
||||
PhysicsScriptTableId: null,
|
||||
Parent: null,
|
||||
Children: null,
|
||||
Scale: null,
|
||||
Friction: null,
|
||||
Elasticity: null,
|
||||
Translucency: null,
|
||||
Velocity: null,
|
||||
Acceleration: null,
|
||||
AngularVelocity: null,
|
||||
DefaultScriptType: null,
|
||||
DefaultScriptIntensity: null,
|
||||
Timestamps: timestamps);
|
||||
return new WorldSession.EntitySpawn(
|
||||
guid,
|
||||
position,
|
||||
0x02000001u,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
null,
|
||||
null,
|
||||
"Headless",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
PhysicsState: physics.RawState,
|
||||
InstanceSequence: 1,
|
||||
MovementSequence: 1,
|
||||
ServerControlSequence: 1,
|
||||
PositionSequence: 1,
|
||||
Physics: physics);
|
||||
}
|
||||
|
||||
private static CreateObject.ServerPosition Position(float positionX) =>
|
||||
new(
|
||||
0x01010001u,
|
||||
positionX,
|
||||
10f,
|
||||
5f,
|
||||
1f,
|
||||
0f,
|
||||
0f,
|
||||
0f);
|
||||
|
||||
private static TDelegate EventDelegate<TDelegate>(
|
||||
WorldSession session,
|
||||
string eventName)
|
||||
where TDelegate : Delegate =>
|
||||
Assert.IsType<TDelegate>(
|
||||
typeof(WorldSession).GetField(
|
||||
eventName,
|
||||
BindingFlags.Instance | BindingFlags.NonPublic)
|
||||
?.GetValue(session));
|
||||
|
||||
private sealed class FixtureOperations(uint sharedPlayerGuid)
|
||||
: ILiveSessionOperations
|
||||
{
|
||||
private readonly Dictionary<string, WorldSession> _active =
|
||||
new(StringComparer.Ordinal);
|
||||
|
||||
public int CreatedSessionCount { get; private set; }
|
||||
public int DisposedSessionCount { get; private set; }
|
||||
|
||||
public WorldSession ActiveSession(string account) =>
|
||||
_active[account];
|
||||
|
||||
public IPEndPoint ResolveEndpoint(string host, int port) =>
|
||||
new(IPAddress.Loopback, port);
|
||||
|
||||
public WorldSession CreateSession(IPEndPoint endpoint)
|
||||
{
|
||||
CreatedSessionCount++;
|
||||
return new WorldSession(endpoint, new FixtureTransport());
|
||||
}
|
||||
|
||||
public void Connect(
|
||||
WorldSession session,
|
||||
string user,
|
||||
string password) =>
|
||||
_active[user] = session;
|
||||
|
||||
public CharacterList.Parsed GetCharacters(
|
||||
WorldSession session) =>
|
||||
new(
|
||||
0u,
|
||||
[
|
||||
new CharacterList.Character(
|
||||
sharedPlayerGuid,
|
||||
"Headless",
|
||||
0u),
|
||||
],
|
||||
[],
|
||||
11,
|
||||
"account",
|
||||
true,
|
||||
true);
|
||||
|
||||
public void EnterWorld(
|
||||
WorldSession session,
|
||||
int activeCharacterIndex)
|
||||
{
|
||||
}
|
||||
|
||||
public void Tick(WorldSession session)
|
||||
{
|
||||
}
|
||||
|
||||
public void DisposeSession(WorldSession session)
|
||||
{
|
||||
DisposedSessionCount++;
|
||||
session.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class FixtureTransport : IWorldSessionTransport
|
||||
{
|
||||
public void Send(ReadOnlySpan<byte> datagram)
|
||||
{
|
||||
}
|
||||
|
||||
public void Send(
|
||||
IPEndPoint remote,
|
||||
ReadOnlySpan<byte> datagram)
|
||||
{
|
||||
}
|
||||
|
||||
public int Receive(
|
||||
Span<byte> destination,
|
||||
TimeSpan timeout,
|
||||
out IPEndPoint? from)
|
||||
{
|
||||
from = null;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public ValueTask<NetReceiveResult> ReceiveAsync(
|
||||
Memory<byte> destination,
|
||||
CancellationToken cancellationToken) =>
|
||||
ValueTask.FromException<NetReceiveResult>(
|
||||
new OperationCanceledException(cancellationToken));
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ using AcDream.Core.Spells;
|
|||
using AcDream.Runtime.Entities;
|
||||
using AcDream.Runtime.Gameplay;
|
||||
using AcDream.Runtime.Session;
|
||||
using AcDream.Runtime.World;
|
||||
|
||||
namespace AcDream.Runtime.Tests.Session;
|
||||
|
||||
|
|
@ -102,6 +103,54 @@ public sealed class RuntimeLiveEntitySessionControllerTests
|
|||
Assert.Equal(0x01020001u, runtime.Portal.Snapshot.DestinationCell);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DirectSinkProjectsAcceptedLocalWorldStateThroughOneHostSeam()
|
||||
{
|
||||
using GameRuntime runtime = CreateRuntime();
|
||||
const uint playerGuid = 0x50000002u;
|
||||
runtime.PlayerIdentity.ServerGuid = playerGuid;
|
||||
using var session = new WorldSession(
|
||||
new IPEndPoint(IPAddress.Loopback, 9000),
|
||||
new FixtureTransport());
|
||||
session.GameActionCapture = _ => { };
|
||||
var projection = new FixtureWorldProjection();
|
||||
var controller = new RuntimeLiveEntitySessionController(
|
||||
runtime,
|
||||
session,
|
||||
worldProjection: projection);
|
||||
LiveEntitySessionSink sink = controller.CreateSink();
|
||||
WorldSession.EntitySpawn spawn =
|
||||
Spawn(playerGuid, incarnation: 1);
|
||||
|
||||
sink.Spawned(spawn);
|
||||
sink.TeleportStarted(1u);
|
||||
sink.PositionUpdated(new WorldSession.EntityPositionUpdate(
|
||||
playerGuid,
|
||||
spawn.Position!.Value with
|
||||
{
|
||||
LandblockId = 0x01020001u,
|
||||
PositionX = 30f,
|
||||
},
|
||||
Velocity: null,
|
||||
PlacementId: null,
|
||||
IsGrounded: true,
|
||||
InstanceSequence: 1,
|
||||
PositionSequence: 2,
|
||||
TeleportSequence: 1,
|
||||
ForcePositionSequence: 0));
|
||||
|
||||
Assert.Equal(1, projection.SpawnCount);
|
||||
Assert.Equal(1, projection.PositionCount);
|
||||
Assert.Equal(1, projection.TeleportStartCount);
|
||||
Assert.Equal(1, projection.PrepareCount);
|
||||
Assert.True(projection.LastSpawnWasLocal);
|
||||
Assert.True(projection.LastPositionWasLocal);
|
||||
Assert.Equal(playerGuid, projection.LastRecord?.ServerGuid);
|
||||
Assert.Equal(0x01020001u, projection.LastDestination.CellId);
|
||||
Assert.True(runtime.TransitOwner.CaptureOwnership().IsSessionIdle);
|
||||
Assert.True(runtime.Portal.Snapshot.Completed);
|
||||
}
|
||||
|
||||
private static GameRuntime CreateRuntime()
|
||||
{
|
||||
var operations = new FixtureGameplayOperations();
|
||||
|
|
@ -211,6 +260,57 @@ public sealed class RuntimeLiveEntitySessionControllerTests
|
|||
}
|
||||
}
|
||||
|
||||
private sealed class FixtureWorldProjection
|
||||
: IRuntimeDirectWorldProjection
|
||||
{
|
||||
public int SpawnCount { get; private set; }
|
||||
public int PositionCount { get; private set; }
|
||||
public int TeleportStartCount { get; private set; }
|
||||
public int PrepareCount { get; private set; }
|
||||
public bool LastSpawnWasLocal { get; private set; }
|
||||
public bool LastPositionWasLocal { get; private set; }
|
||||
public RuntimeEntityRecord? LastRecord { get; private set; }
|
||||
public RuntimeTeleportDestination LastDestination { get; private set; }
|
||||
|
||||
public void ProjectSpawn(
|
||||
RuntimeEntityRecord record,
|
||||
bool isLocalPlayer)
|
||||
{
|
||||
SpawnCount++;
|
||||
LastRecord = record;
|
||||
LastSpawnWasLocal = isLocalPlayer;
|
||||
}
|
||||
|
||||
public void ProjectPosition(
|
||||
RuntimeEntityRecord record,
|
||||
bool isLocalPlayer)
|
||||
{
|
||||
PositionCount++;
|
||||
LastRecord = record;
|
||||
LastPositionWasLocal = isLocalPlayer;
|
||||
}
|
||||
|
||||
public void BeginTeleport() => TeleportStartCount++;
|
||||
|
||||
public RuntimeDestinationReadiness PrepareDestination(
|
||||
long revealGeneration,
|
||||
RuntimeTeleportDestination destination)
|
||||
{
|
||||
PrepareCount++;
|
||||
LastDestination = destination;
|
||||
bool indoor = (destination.CellId & 0xFFFFu) >= 0x0100u;
|
||||
return new RuntimeDestinationReadiness(
|
||||
revealGeneration,
|
||||
destination.CellId,
|
||||
indoor,
|
||||
IsUnhydratable: false,
|
||||
RequiredRenderRadius: indoor ? 0 : 1,
|
||||
IsRenderNeighborhoodReady: true,
|
||||
AreCompositeTexturesReady: true,
|
||||
IsCollisionReady: true);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class FixtureGameplayOperations
|
||||
: IRuntimeCombatAttackOperations,
|
||||
IRuntimeCombatTargetOperations,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue