Skip to content

Commit

Permalink
Add pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaioru committed Apr 15, 2024
1 parent 472e833 commit e7e13a5
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/app/Edelstein.Application.Server/ProgramHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,7 +46,10 @@ public async static Task ExecuteRoot(FileInfo file)
builder.Services.AddSingleton<IHostedService>(p =>
{
var loginConfig = new StageConfigLogin();
var loginSystem = new LoginStageSystem(loginConfig);
var loginSystem = new LoginStageSystem(
loginConfig,
p.GetRequiredService<ILoginContextPipelines>()
);

config.Bind(loginConfig);

Expand Down
Original file line number Diff line number Diff line change
@@ -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<UserOnPacket<ILoginStageUser, ILoginStageSystem>> userOnPacketPipeline,
IPipeline<UserOnException<ILoginStageUser, ILoginStageSystem>> userOnExceptionPipeline,
IPipeline<UserOnDisconnect<ILoginStageUser, ILoginStageSystem>> userOnDisconnectPipeline
) : ILoginContextPipelines
{
public IPipeline<UserOnPacket<ILoginStageUser, ILoginStageSystem>> UserOnPacketPipeline { get; } = userOnPacketPipeline;
public IPipeline<UserOnException<ILoginStageUser, ILoginStageSystem>> UserOnExceptionPipeline { get; } = userOnExceptionPipeline;
public IPipeline<UserOnDisconnect<ILoginStageUser, ILoginStageSystem>> UserOnDisconnectPipeline { get; } = userOnDisconnectPipeline;
}
14 changes: 12 additions & 2 deletions src/common/Edelstein.Common.Gameplay.Login/LoginStageSystem.cs
Original file line number Diff line number Diff line change
@@ -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<ILoginStageUser, ILoginStageSystem>, ILoginStageSystem
{
public override string ID => options.ID;

protected override IPipeline<UserOnPacket<ILoginStageUser, ILoginStageSystem>> UserOnPacketPipeline => pipelines.UserOnPacketPipeline;
protected override IPipeline<UserOnException<ILoginStageUser, ILoginStageSystem>> UserOnExceptionPipeline => pipelines.UserOnExceptionPipeline;
protected override IPipeline<UserOnDisconnect<ILoginStageUser, ILoginStageSystem>> UserOnDisconnectPipeline => pipelines.UserOnDisconnectPipeline;

public ILoginStageSystemOptions Options => options;
public ILoginContextPipelines Pipelines => pipelines;

public override ILoginStageUser CreateUser(ISocket socket)
=> new LoginStageUser(this, socket);
Expand Down
17 changes: 14 additions & 3 deletions src/common/Edelstein.Common.Gameplay/AbstractStageSystem.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -13,9 +15,18 @@ public abstract class AbstractStageSystem<TStageUser, TStageSystem> :
{
public abstract string ID { get; }

protected abstract IPipeline<UserOnPacket<TStageUser, TStageSystem>> UserOnPacketPipeline { get; }
protected abstract IPipeline<UserOnException<TStageUser, TStageSystem>> UserOnExceptionPipeline { get; }
protected abstract IPipeline<UserOnDisconnect<TStageUser, TStageSystem>> 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<TStageUser, TStageSystem>(user, packet));

public Task OnException(TStageUser user, Exception exception)
=> UserOnExceptionPipeline.Process(new UserOnException<TStageUser, TStageSystem>(user, exception));

public Task OnDisconnect(TStageUser user)
=> UserOnDisconnectPipeline.Process(new UserOnDisconnect<TStageUser, TStageSystem>(user));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Edelstein.Protocol.Gameplay.Contexts;

namespace Edelstein.Protocol.Gameplay.Login.Contexts;

public interface ILoginContextPipelines : IStageContextPipelines<ILoginStageUser, ILoginStageSystem>
{
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
namespace Edelstein.Protocol.Gameplay.Login;
using Edelstein.Protocol.Gameplay.Login.Contexts;

namespace Edelstein.Protocol.Gameplay.Login;

public interface ILoginStageSystem : IStageSystem<ILoginStageUser, ILoginStageSystem>
{
ILoginStageSystemOptions Options { get; }
ILoginContextPipelines Pipelines { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Edelstein.Protocol.Gameplay.Contracts;
using Edelstein.Protocol.Utilities.Pipelines;

namespace Edelstein.Protocol.Gameplay.Contexts;

public interface IStageContextPipelines<TStageUser, TStageSystem>
where TStageUser : IStageUser<TStageUser, TStageSystem>
where TStageSystem : IStageSystem<TStageUser, TStageSystem>
{
IPipeline<UserOnPacket<TStageUser, TStageSystem>> UserOnPacketPipeline { get; }
IPipeline<UserOnException<TStageUser, TStageSystem>> UserOnExceptionPipeline { get; }
IPipeline<UserOnDisconnect<TStageUser, TStageSystem>> UserOnDisconnectPipeline { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Edelstein.Protocol.Gameplay.Contracts;

public record UserOnDisconnect<TStageUser, TStageSystem>(
TStageUser User
)
where TStageUser : IStageUser<TStageUser, TStageSystem>
where TStageSystem : IStageSystem<TStageUser, TStageSystem>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace Edelstein.Protocol.Gameplay.Contracts;

public record UserOnException<TStageUser, TStageSystem>(
TStageUser User,
Exception Exception
)
where TStageUser : IStageUser<TStageUser, TStageSystem>
where TStageSystem : IStageSystem<TStageUser, TStageSystem>;
10 changes: 10 additions & 0 deletions src/protocol/Edelstein.Protocol.Gameplay/Contracts/UserOnPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Edelstein.Protocol.Utilities.Buffers;

namespace Edelstein.Protocol.Gameplay.Contracts;

public record UserOnPacket<TStageUser, TStageSystem>(
TStageUser User,
IPacket Packet
)
where TStageUser : IStageUser<TStageUser, TStageSystem>
where TStageSystem : IStageSystem<TStageUser, TStageSystem>;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<ProjectReference Include="..\Edelstein.Protocol.Services.Server\Edelstein.Protocol.Services.Server.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Contracts\" />
<Folder Include="Entities\" />
</ItemGroup>
</Project>

0 comments on commit e7e13a5

Please sign in to comment.