refactor: shared data into library
This commit is contained in:
parent
76dc1ebf07
commit
b7d6865722
18 changed files with 60 additions and 28 deletions
|
@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csp
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmarks", "Benchmarks\Benchmarks.csproj", "{7D560FA1-A61C-4B67-8300-835CA5814621}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wonderking", "Wonderking\Wonderking.csproj", "{6B53A10B-C397-4347-BB00-A12272D0528E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -18,5 +20,9 @@ Global
|
|||
{7D560FA1-A61C-4B67-8300-835CA5814621}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7D560FA1-A61C-4B67-8300-835CA5814621}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7D560FA1-A61C-4B67-8300-835CA5814621}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6B53A10B-C397-4347-BB00-A12272D0528E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6B53A10B-C397-4347-BB00-A12272D0528E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6B53A10B-C397-4347-BB00-A12272D0528E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6B53A10B-C397-4347-BB00-A12272D0528E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using Wonderking.Packets;
|
||||
|
||||
namespace Server;
|
||||
|
||||
using System.Reflection;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
namespace Server;
|
||||
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Packets;
|
||||
using Wonderking.Packets;
|
||||
|
||||
namespace Server.LoggerMessages;
|
||||
|
||||
public static partial class PacketLoggerMessages
|
||||
{
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
using Wonderking.Packets.Incoming;
|
||||
|
||||
namespace Server.PacketHandlers;
|
||||
|
||||
using DB;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NetCoreServer;
|
||||
using Packets.Incoming;
|
||||
|
||||
public class ChannelSelectionHandler : IPacketHandler<ChannelSelectionPacket>
|
||||
{
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
using Wonderking.Packets;
|
||||
|
||||
namespace Server.PacketHandlers;
|
||||
|
||||
using JetBrains.Annotations;
|
||||
using NetCoreServer;
|
||||
using Packets;
|
||||
|
||||
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
|
||||
public interface IPacketHandler<in T> where T : IPacket
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
namespace Server.PacketHandlers;
|
||||
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Wonderking.Packets.Incoming;
|
||||
using Wonderking.Packets.Outgoing;
|
||||
|
||||
namespace Server.PacketHandlers;
|
||||
|
||||
using DB;
|
||||
using DB.Documents;
|
||||
using Konscious.Security.Cryptography;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NetCoreServer;
|
||||
using Packets.Incoming;
|
||||
using Packets.Outgoing;
|
||||
|
||||
public class LoginHandler : IPacketHandler<LoginInfoPacket>
|
||||
{
|
||||
|
@ -78,12 +79,9 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
|
|||
IsGameMaster = true
|
||||
};
|
||||
var sess = session as AuthSession;
|
||||
if (account != null)
|
||||
if (account != null && sess != null)
|
||||
{
|
||||
if (sess != null)
|
||||
{
|
||||
sess.AccountId = account.Id;
|
||||
}
|
||||
sess.AccountId = account.Id;
|
||||
}
|
||||
|
||||
sess?.Send(loginResponsePacket);
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using Wonderking.Packets;
|
||||
|
||||
namespace Server.Packets;
|
||||
|
||||
using MassTransit;
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2023.2.0"/>
|
||||
<PackageReference Include="JetBrains.ExternalAnnotations" Version="10.2.134" />
|
||||
<PackageReference Include="Konscious.Security.Cryptography.Argon2" Version="1.3.0"/>
|
||||
<PackageReference Include="MassTransit" Version="8.1.1"/>
|
||||
<PackageReference Include="MassTransit.Analyzers" Version="8.1.1">
|
||||
|
@ -68,4 +69,8 @@
|
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Wonderking\Wonderking.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
using Server.LoggerMessages;
|
||||
using Wonderking.Packets;
|
||||
|
||||
namespace Server.Services;
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
|
@ -86,7 +89,7 @@ public class PacketDistributorService : IHostedService
|
|||
return packetsWithId;
|
||||
}
|
||||
|
||||
this._logger.NoPacketsFound();
|
||||
LoggerMessages.PacketLoggerMessages.NoPacketsFound(this._logger);
|
||||
throw new IncompleteInitialization();
|
||||
}
|
||||
|
||||
|
@ -106,7 +109,7 @@ public class PacketDistributorService : IHostedService
|
|||
return packetHandlersWithId;
|
||||
}
|
||||
|
||||
this._logger.NoPacketHandlersFound();
|
||||
LoggerMessages.PacketLoggerMessages.NoPacketHandlersFound(this._logger);
|
||||
throw new IncompleteInitialization();
|
||||
}
|
||||
|
||||
|
@ -135,8 +138,9 @@ public class PacketDistributorService : IHostedService
|
|||
}
|
||||
|
||||
var packet = value(item.MessageBody);
|
||||
this._logger.PacketData(JsonConvert.SerializeObject(packet));
|
||||
this._packetHandlersInstantiation[item.OperationCode].GetType().GetMethod(nameof(IPacketHandler<IPacket>.HandleAsync))
|
||||
LoggerMessages.PacketLoggerMessages.PacketData(this._logger, JsonConvert.SerializeObject(packet));
|
||||
this._packetHandlersInstantiation[item.OperationCode].GetType()
|
||||
.GetMethod(nameof(IPacketHandler<IPacket>.HandleAsync))
|
||||
?.Invoke(this._packetHandlersInstantiation[item.OperationCode], new object[] { packet, item.Session });
|
||||
|
||||
this._logger.PacketFinished(item.Session.Id, item.OperationCode);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
namespace Server.Packets;
|
||||
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Wonderking.Packets;
|
||||
|
||||
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
|
||||
public interface IPacket
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Server.Packets.Incoming;
|
||||
namespace Wonderking.Packets.Incoming;
|
||||
|
||||
[PacketId(OperationCode.ChannelSelection)]
|
||||
public class ChannelSelectionPacket : IPacket
|
|
@ -1,7 +1,7 @@
|
|||
namespace Server.Packets.Incoming;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace Wonderking.Packets.Incoming;
|
||||
|
||||
[PacketId(OperationCode.LoginInfo)]
|
||||
public class LoginInfoPacket : IPacket
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Server.Packets;
|
||||
namespace Wonderking.Packets;
|
||||
|
||||
public enum OperationCode : ushort
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Server.Packets.Outgoing;
|
||||
namespace Wonderking.Packets.Outgoing;
|
||||
|
||||
[PacketId(OperationCode.LoginResponse)]
|
||||
public class LoginResponsePacket : IPacket
|
|
@ -1,4 +1,4 @@
|
|||
namespace Server.Packets.Outgoing;
|
||||
namespace Wonderking.Packets.Outgoing;
|
||||
|
||||
public enum LoginResponseReason : byte
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Server.Packets.Outgoing;
|
||||
namespace Wonderking.Packets.Outgoing;
|
||||
|
||||
public struct ServerChannelData
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Server.Packets;
|
||||
namespace Wonderking.Packets;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
public class PacketIdAttribute : Attribute
|
13
Wonderking/Wonderking.csproj
Normal file
13
Wonderking/Wonderking.csproj
Normal file
|
@ -0,0 +1,13 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<TargetFrameworks>net8.0;net7.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2023.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in a new issue