diff --git a/src/app/Edelstein.Application.Server/ProgramHandler.cs b/src/app/Edelstein.Application.Server/ProgramHandler.cs index 8078a9294..e607ca7db 100644 --- a/src/app/Edelstein.Application.Server/ProgramHandler.cs +++ b/src/app/Edelstein.Application.Server/ProgramHandler.cs @@ -5,6 +5,7 @@ using Edelstein.Application.Server.Bindings; using Edelstein.Common.Gameplay.Login; using Edelstein.Protocol.Gameplay.Login; +using Edelstein.Protocol.Gameplay.Login.Contexts; using Edelstein.Protocol.Network.Transports; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -45,7 +46,10 @@ public async static Task ExecuteRoot(FileInfo file) builder.Services.AddSingleton(p => { var loginConfig = new StageConfigLogin(); - var loginSystem = new LoginStageSystem(loginConfig); + var loginSystem = new LoginStageSystem( + loginConfig, + p.GetRequiredService() + ); config.Bind(loginConfig); diff --git a/src/common/Edelstein.Common.Gameplay.Login/Contexts/LoginContextPipelines.cs b/src/common/Edelstein.Common.Gameplay.Login/Contexts/LoginContextPipelines.cs new file mode 100644 index 000000000..d76d8e6a8 --- /dev/null +++ b/src/common/Edelstein.Common.Gameplay.Login/Contexts/LoginContextPipelines.cs @@ -0,0 +1,19 @@ +using Edelstein.Protocol.Gameplay.Contracts; +using Edelstein.Protocol.Gameplay.Login; +using Edelstein.Protocol.Gameplay.Login.Contexts; +using Edelstein.Protocol.Utilities.Pipelines; +using Injectio.Attributes; + +namespace Edelstein.Common.Gameplay.Login.Contexts; + +[RegisterScoped] +public class LoginContextPipelines( + IPipeline> userOnPacketPipeline, + IPipeline> userOnExceptionPipeline, + IPipeline> userOnDisconnectPipeline +) : ILoginContextPipelines +{ + public IPipeline> UserOnPacketPipeline { get; } = userOnPacketPipeline; + public IPipeline> UserOnExceptionPipeline { get; } = userOnExceptionPipeline; + public IPipeline> UserOnDisconnectPipeline { get; } = userOnDisconnectPipeline; +} diff --git a/src/common/Edelstein.Common.Gameplay.Login/LoginStageSystem.cs b/src/common/Edelstein.Common.Gameplay.Login/LoginStageSystem.cs index 513813e2f..fc4b90a0c 100644 --- a/src/common/Edelstein.Common.Gameplay.Login/LoginStageSystem.cs +++ b/src/common/Edelstein.Common.Gameplay.Login/LoginStageSystem.cs @@ -1,14 +1,24 @@ -using Edelstein.Protocol.Gameplay.Login; +using Edelstein.Protocol.Gameplay.Contracts; +using Edelstein.Protocol.Gameplay.Login; +using Edelstein.Protocol.Gameplay.Login.Contexts; using Edelstein.Protocol.Network; +using Edelstein.Protocol.Utilities.Pipelines; namespace Edelstein.Common.Gameplay.Login; public class LoginStageSystem( - ILoginStageSystemOptions options + ILoginStageSystemOptions options, + ILoginContextPipelines pipelines ) : AbstractStageSystem, ILoginStageSystem { public override string ID => options.ID; + + protected override IPipeline> UserOnPacketPipeline => pipelines.UserOnPacketPipeline; + protected override IPipeline> UserOnExceptionPipeline => pipelines.UserOnExceptionPipeline; + protected override IPipeline> UserOnDisconnectPipeline => pipelines.UserOnDisconnectPipeline; + public ILoginStageSystemOptions Options => options; + public ILoginContextPipelines Pipelines => pipelines; public override ILoginStageUser CreateUser(ISocket socket) => new LoginStageUser(this, socket); diff --git a/src/common/Edelstein.Common.Gameplay/AbstractStageSystem.cs b/src/common/Edelstein.Common.Gameplay/AbstractStageSystem.cs index 9f1dc0bd4..25771fe6f 100644 --- a/src/common/Edelstein.Common.Gameplay/AbstractStageSystem.cs +++ b/src/common/Edelstein.Common.Gameplay/AbstractStageSystem.cs @@ -1,8 +1,10 @@ using System; using System.Threading.Tasks; using Edelstein.Protocol.Gameplay; +using Edelstein.Protocol.Gameplay.Contracts; using Edelstein.Protocol.Network; using Edelstein.Protocol.Utilities.Buffers; +using Edelstein.Protocol.Utilities.Pipelines; namespace Edelstein.Common.Gameplay; @@ -13,9 +15,18 @@ public abstract class AbstractStageSystem : { public abstract string ID { get; } + protected abstract IPipeline> UserOnPacketPipeline { get; } + protected abstract IPipeline> UserOnExceptionPipeline { get; } + protected abstract IPipeline> UserOnDisconnectPipeline { get; } + public abstract TStageUser CreateUser(ISocket socket); - public Task OnPacket(TStageUser user, IPacket packet) => Task.CompletedTask; - public Task OnException(TStageUser user, Exception exception) => Task.CompletedTask; - public Task OnDisconnect(TStageUser user) => Task.CompletedTask; + public Task OnPacket(TStageUser user, IPacket packet) + => UserOnPacketPipeline.Process(new UserOnPacket(user, packet)); + + public Task OnException(TStageUser user, Exception exception) + => UserOnExceptionPipeline.Process(new UserOnException(user, exception)); + + public Task OnDisconnect(TStageUser user) + => UserOnDisconnectPipeline.Process(new UserOnDisconnect(user)); } diff --git a/src/protocol/Edelstein.Protocol.Gameplay.Login/Contexts/ILoginContextPipelines.cs b/src/protocol/Edelstein.Protocol.Gameplay.Login/Contexts/ILoginContextPipelines.cs new file mode 100644 index 000000000..3ec2f70cb --- /dev/null +++ b/src/protocol/Edelstein.Protocol.Gameplay.Login/Contexts/ILoginContextPipelines.cs @@ -0,0 +1,7 @@ +using Edelstein.Protocol.Gameplay.Contexts; + +namespace Edelstein.Protocol.Gameplay.Login.Contexts; + +public interface ILoginContextPipelines : IStageContextPipelines +{ +} diff --git a/src/protocol/Edelstein.Protocol.Gameplay.Login/ILoginStageSystem.cs b/src/protocol/Edelstein.Protocol.Gameplay.Login/ILoginStageSystem.cs index d0f2cca0c..47af41d5c 100644 --- a/src/protocol/Edelstein.Protocol.Gameplay.Login/ILoginStageSystem.cs +++ b/src/protocol/Edelstein.Protocol.Gameplay.Login/ILoginStageSystem.cs @@ -1,6 +1,9 @@ -namespace Edelstein.Protocol.Gameplay.Login; +using Edelstein.Protocol.Gameplay.Login.Contexts; + +namespace Edelstein.Protocol.Gameplay.Login; public interface ILoginStageSystem : IStageSystem { ILoginStageSystemOptions Options { get; } + ILoginContextPipelines Pipelines { get; } } diff --git a/src/protocol/Edelstein.Protocol.Gameplay/Contexts/IStageContextPipelines.cs b/src/protocol/Edelstein.Protocol.Gameplay/Contexts/IStageContextPipelines.cs new file mode 100644 index 000000000..a72e8dc55 --- /dev/null +++ b/src/protocol/Edelstein.Protocol.Gameplay/Contexts/IStageContextPipelines.cs @@ -0,0 +1,13 @@ +using Edelstein.Protocol.Gameplay.Contracts; +using Edelstein.Protocol.Utilities.Pipelines; + +namespace Edelstein.Protocol.Gameplay.Contexts; + +public interface IStageContextPipelines + where TStageUser : IStageUser + where TStageSystem : IStageSystem +{ + IPipeline> UserOnPacketPipeline { get; } + IPipeline> UserOnExceptionPipeline { get; } + IPipeline> UserOnDisconnectPipeline { get; } +} diff --git a/src/protocol/Edelstein.Protocol.Gameplay/Contracts/UserOnDisconnect.cs b/src/protocol/Edelstein.Protocol.Gameplay/Contracts/UserOnDisconnect.cs new file mode 100644 index 000000000..6cc208b65 --- /dev/null +++ b/src/protocol/Edelstein.Protocol.Gameplay/Contracts/UserOnDisconnect.cs @@ -0,0 +1,7 @@ +namespace Edelstein.Protocol.Gameplay.Contracts; + +public record UserOnDisconnect( + TStageUser User +) + where TStageUser : IStageUser + where TStageSystem : IStageSystem; diff --git a/src/protocol/Edelstein.Protocol.Gameplay/Contracts/UserOnException.cs b/src/protocol/Edelstein.Protocol.Gameplay/Contracts/UserOnException.cs new file mode 100644 index 000000000..6490ba9ad --- /dev/null +++ b/src/protocol/Edelstein.Protocol.Gameplay/Contracts/UserOnException.cs @@ -0,0 +1,10 @@ +using System; + +namespace Edelstein.Protocol.Gameplay.Contracts; + +public record UserOnException( + TStageUser User, + Exception Exception +) + where TStageUser : IStageUser + where TStageSystem : IStageSystem; diff --git a/src/protocol/Edelstein.Protocol.Gameplay/Contracts/UserOnPacket.cs b/src/protocol/Edelstein.Protocol.Gameplay/Contracts/UserOnPacket.cs new file mode 100644 index 000000000..a13e943da --- /dev/null +++ b/src/protocol/Edelstein.Protocol.Gameplay/Contracts/UserOnPacket.cs @@ -0,0 +1,10 @@ +using Edelstein.Protocol.Utilities.Buffers; + +namespace Edelstein.Protocol.Gameplay.Contracts; + +public record UserOnPacket( + TStageUser User, + IPacket Packet +) + where TStageUser : IStageUser + where TStageSystem : IStageSystem; diff --git a/src/protocol/Edelstein.Protocol.Gameplay/Edelstein.Protocol.Gameplay.csproj b/src/protocol/Edelstein.Protocol.Gameplay/Edelstein.Protocol.Gameplay.csproj index 6d8b4eb8d..56a6182fc 100644 --- a/src/protocol/Edelstein.Protocol.Gameplay/Edelstein.Protocol.Gameplay.csproj +++ b/src/protocol/Edelstein.Protocol.Gameplay/Edelstein.Protocol.Gameplay.csproj @@ -4,6 +4,6 @@ - +