using EvilEngine.Host.Sessions; namespace EvilEngine.Shared.Sessions; public interface ILocalServer { ServerSession Session { get; } void Stop(string reason); } public static class LocalServer { public static Func? Starter { get; set; } public static ILocalServer Start(ServerSession session) { return (Starter ?? throw new InvalidOperationException("No server realm is registered. The game's boot registers it.")) .Invoke(session); } public static (ILocalServer Server, ClientSession Client) Play(SessionStart start, string name, PlayerChoices? choices = null) { var server = Start(new ServerSession(start)); var (serverEnd, clientEnd) = Loopback.Pair(); server.Session.Connect(serverEnd); return (server, new ClientSession(clientEnd, name, choices)); } }