feat(runtime): share chat commands and run login sequence

This commit is contained in:
Erik 2026-08-14 20:27:45 +02:00
parent 5535d0adac
commit 41b15efd4d
57 changed files with 1739 additions and 345 deletions

View file

@ -1,6 +1,7 @@
using System.Net;
using AcDream.Core.Net;
using AcDream.Core.Net.Messages;
using AcDream.Runtime.Chat;
using AcDream.Runtime.Session;
namespace AcDream.Runtime.Tests.Session;
@ -74,6 +75,37 @@ public sealed class LiveSessionHostTests
Assert.False(host.IsInWorld);
}
[Fact]
public void LoginSequenceStartsAfterTheEnteredWorldObservation()
{
var calls = new List<string>();
var operations = new TestOperations(calls);
var controller = new LiveSessionController(operations);
var bus = new LiveCommandBus();
bus.Register<SendChatCmd>(command => calls.Add($"login:{command.Text}"));
var loginCommands = new LoginCommandSequence(
["ready"],
TimeSpan.Zero,
new TestFeedback(),
bus);
LiveSessionHost host = CreateHost(
controller,
calls,
_ => new TestEventRouting(calls),
_ => new TestCommandRouting(calls),
loginCommands);
Assert.Equal(
LiveSessionStartStatus.Connected,
host.Start(LiveOptions()).Status);
int entered = calls.IndexOf("character-entered:1342177282");
int login = calls.IndexOf("login:ready");
Assert.True(entered >= 0);
Assert.Equal(entered + 1, login);
controller.Dispose();
}
[Fact]
public void CommandFactoryFailureRollsBackTheAlreadyAttachedEventRoute()
{
@ -219,7 +251,8 @@ public sealed class LiveSessionHostTests
LiveSessionController controller,
List<string> calls,
Func<WorldSession, ILiveSessionEventRouting> createEvents,
Func<WorldSession, ILiveSessionCommandRouting> createCommands) =>
Func<WorldSession, ILiveSessionCommandRouting> createCommands,
LoginCommandSequence? loginCommands = null) =>
new(controller, new LiveSessionHostBindings(
Routing: new(createEvents, createCommands),
Reset: _ => calls.Add("reset"),
@ -240,7 +273,8 @@ public sealed class LiveSessionHostTests
Connected: () => calls.Add("connected"),
Roster: roster => calls.Add($"roster:{roster.AccountName}"),
CharacterEntered: selection =>
calls.Add($"character-entered:{selection.CharacterId}")));
calls.Add($"character-entered:{selection.CharacterId}"),
LoginCommands: loginCommands));
private static LiveSessionConnectOptions LiveOptions(
bool live = true,
@ -291,6 +325,14 @@ public sealed class LiveSessionHostTests
public void Dispose() => calls.Add("dispose-commands");
}
private sealed class TestFeedback : IChatCommandFeedback
{
public string? LastIncomingTellSender => null;
public string? LastOutgoingTellTarget => null;
public void ShowInterfaceText(string text) { }
public void ShowSystemMessage(string text) { }
}
private sealed class TestOperations(List<string> calls) : ILiveSessionOperations
{
public List<WorldSession> Sessions { get; } = [];