From ca4ac436aa668051e97a36b40c2f275ee9730bab Mon Sep 17 00:00:00 2001 From: cubic Date: Sat, 6 Apr 2024 15:07:17 +0100 Subject: [PATCH] Fix dependency loop, Fix dedi-master message serialisation --- .../Responses/CreateMatchmakingServerResponse.cs | 6 +++--- .../BeatTogether.DedicatedServer.Kernel.csproj | 1 - .../DedicatedInstance.cs | 13 +++++-------- .../ENet/ENetServer.cs | 2 +- .../Extensions/HostBuilderExtensions.cs | 2 +- .../BeatTogether.DedicatedServer.Messaging.csproj | 4 ++++ .../InstanceFactory.cs | 1 - BeatTogether.DedicatedServer.Node/NodeService.cs | 4 +++- 8 files changed, 17 insertions(+), 16 deletions(-) diff --git a/BeatTogether.DedicatedServer.Interface/Responses/CreateMatchmakingServerResponse.cs b/BeatTogether.DedicatedServer.Interface/Responses/CreateMatchmakingServerResponse.cs index 3a122e1f..84c7e0cc 100644 --- a/BeatTogether.DedicatedServer.Interface/Responses/CreateMatchmakingServerResponse.cs +++ b/BeatTogether.DedicatedServer.Interface/Responses/CreateMatchmakingServerResponse.cs @@ -9,9 +9,9 @@ public enum CreateMatchmakingServerError public record CreateMatchmakingServerResponse( CreateMatchmakingServerError Error, - string? RemoteEndPoint = null, - byte[]? Random = null, - byte[]? PublicKey = null) + string RemoteEndPoint, + byte[] Random, + byte[] PublicKey) { public bool Success => Error == default; } diff --git a/BeatTogether.DedicatedServer.Kernel/BeatTogether.DedicatedServer.Kernel.csproj b/BeatTogether.DedicatedServer.Kernel/BeatTogether.DedicatedServer.Kernel.csproj index b5a15957..a7f9ea63 100644 --- a/BeatTogether.DedicatedServer.Kernel/BeatTogether.DedicatedServer.Kernel.csproj +++ b/BeatTogether.DedicatedServer.Kernel/BeatTogether.DedicatedServer.Kernel.csproj @@ -21,7 +21,6 @@ - diff --git a/BeatTogether.DedicatedServer.Kernel/DedicatedInstance.cs b/BeatTogether.DedicatedServer.Kernel/DedicatedInstance.cs index 7d30761a..529d9400 100644 --- a/BeatTogether.DedicatedServer.Kernel/DedicatedInstance.cs +++ b/BeatTogether.DedicatedServer.Kernel/DedicatedInstance.cs @@ -19,6 +19,7 @@ using BeatTogether.DedicatedServer.Messaging.Util; using Serilog; using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore; +using Microsoft.Extensions.DependencyInjection; namespace BeatTogether.DedicatedServer.Kernel { @@ -46,8 +47,8 @@ public sealed class DedicatedInstance : ENetServer, IDedicatedInstance private readonly IPlayerRegistry _playerRegistry; private readonly IServiceProvider _serviceProvider; - private readonly IPacketDispatcher PacketDispatcher; - private readonly PacketSource ConnectedMessageSource; + private IPacketDispatcher PacketDispatcher; + private PacketSource ConnectedMessageSource; private byte _connectionIdCount = 0; @@ -64,16 +65,12 @@ public sealed class DedicatedInstance : ENetServer, IDedicatedInstance public DedicatedInstance( InstanceConfiguration configuration, IPlayerRegistry playerRegistry, - IPacketDispatcher packetDispatcher, - PacketSource connectedMessageSource, IServiceProvider serviceProvider) : base (configuration.Port) { _configuration = configuration; _playerRegistry = playerRegistry; _serviceProvider = serviceProvider; - PacketDispatcher = packetDispatcher; - ConnectedMessageSource = connectedMessageSource; } #region Public Methods @@ -93,8 +90,8 @@ public async Task Start(CancellationToken cancellationToken = default) if (IsRunning) return; - //PacketDispatcher = _serviceProvider.GetRequiredService(); - //ConnectedMessageSource = _serviceProvider.GetRequiredService(); + PacketDispatcher = _serviceProvider.GetRequiredService(); + ConnectedMessageSource = _serviceProvider.GetRequiredService(); _startTime = DateTime.UtcNow.Ticks; diff --git a/BeatTogether.DedicatedServer.Kernel/ENet/ENetServer.cs b/BeatTogether.DedicatedServer.Kernel/ENet/ENetServer.cs index 91eecfd5..4d7762f9 100644 --- a/BeatTogether.DedicatedServer.Kernel/ENet/ENetServer.cs +++ b/BeatTogether.DedicatedServer.Kernel/ENet/ENetServer.cs @@ -16,7 +16,7 @@ namespace BeatTogether.DedicatedServer.Kernel.ENet { /// - /// Temporary secondary server/socket for ENet (1.31+) connectivity. + /// Server/socket for ENet (1.31+) connectivity. /// public class ENetServer : IDisposable { diff --git a/BeatTogether.DedicatedServer.Kernel/Extensions/HostBuilderExtensions.cs b/BeatTogether.DedicatedServer.Kernel/Extensions/HostBuilderExtensions.cs index bd28ed0c..b81bee35 100644 --- a/BeatTogether.DedicatedServer.Kernel/Extensions/HostBuilderExtensions.cs +++ b/BeatTogether.DedicatedServer.Kernel/Extensions/HostBuilderExtensions.cs @@ -35,7 +35,7 @@ public static IHostBuilder UseDedicatedInstances(this IHostBuilder hostBuilder) .AddDedicatedServerMessaging() .AddScoped() .AddExisting() - .AddExisting() + .AddExisting() //Used to be like this for lnl //.AddScoped() .AddScoped() //.AddScoped() diff --git a/BeatTogether.DedicatedServer.Messaging/BeatTogether.DedicatedServer.Messaging.csproj b/BeatTogether.DedicatedServer.Messaging/BeatTogether.DedicatedServer.Messaging.csproj index 05ac0b57..29409fe6 100644 --- a/BeatTogether.DedicatedServer.Messaging/BeatTogether.DedicatedServer.Messaging.csproj +++ b/BeatTogether.DedicatedServer.Messaging/BeatTogether.DedicatedServer.Messaging.csproj @@ -12,4 +12,8 @@ + + + + diff --git a/BeatTogether.DedicatedServer.Node/InstanceFactory.cs b/BeatTogether.DedicatedServer.Node/InstanceFactory.cs index 97dea86a..53d86abc 100644 --- a/BeatTogether.DedicatedServer.Node/InstanceFactory.cs +++ b/BeatTogether.DedicatedServer.Node/InstanceFactory.cs @@ -49,7 +49,6 @@ bool AllowNE var scope = _serviceProvider.CreateScope(); var instanceConfig = scope.ServiceProvider.GetRequiredService(); - //instanceConfig.LiteNetPort = (int)liteNetPort!; instanceConfig.Port = (int)Port!; instanceConfig.Secret = secret; instanceConfig.ServerOwnerId = managerId; diff --git a/BeatTogether.DedicatedServer.Node/NodeService.cs b/BeatTogether.DedicatedServer.Node/NodeService.cs index 7c3cefe7..4f9c3b27 100644 --- a/BeatTogether.DedicatedServer.Node/NodeService.cs +++ b/BeatTogether.DedicatedServer.Node/NodeService.cs @@ -72,7 +72,9 @@ public async Task CreateMatchmakingServer(Creat await matchmakingServer.Start(); return new CreateMatchmakingServerResponse( CreateMatchmakingServerError.None, - $"{_configuration.HostName}:{matchmakingServer.Port}" + $"{_configuration.HostName}:{matchmakingServer.Port}", + Array.Empty(), + Array.Empty() ); }