Skip to content

Commit

Permalink
Fix dependency loop, Fix dedi-master message serialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
cubicgraphics committed Apr 6, 2024
1 parent 17c3760 commit ca4ac43
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BeatTogether.DedicatedServer.Ignorance\BeatTogether.DedicatedServer.Ignorance.csproj" />
<ProjectReference Include="..\BeatTogether.DedicatedServer.Messaging\BeatTogether.DedicatedServer.Messaging.csproj" />
</ItemGroup>

Expand Down
13 changes: 5 additions & 8 deletions BeatTogether.DedicatedServer.Kernel/DedicatedInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using BeatTogether.DedicatedServer.Messaging.Util;
using Serilog;
using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
using Microsoft.Extensions.DependencyInjection;

namespace BeatTogether.DedicatedServer.Kernel
{
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -93,8 +90,8 @@ public async Task Start(CancellationToken cancellationToken = default)
if (IsRunning)
return;

//PacketDispatcher = _serviceProvider.GetRequiredService<IPacketDispatcher>();
//ConnectedMessageSource = _serviceProvider.GetRequiredService<PacketSource>();
PacketDispatcher = _serviceProvider.GetRequiredService<IPacketDispatcher>();
ConnectedMessageSource = _serviceProvider.GetRequiredService<PacketSource>();

_startTime = DateTime.UtcNow.Ticks;

Expand Down
2 changes: 1 addition & 1 deletion BeatTogether.DedicatedServer.Kernel/ENet/ENetServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace BeatTogether.DedicatedServer.Kernel.ENet
{
/// <summary>
/// Temporary secondary server/socket for ENet (1.31+) connectivity.
/// Server/socket for ENet (1.31+) connectivity.
/// </summary>
public class ENetServer : IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static IHostBuilder UseDedicatedInstances(this IHostBuilder hostBuilder)
.AddDedicatedServerMessaging()
.AddScoped<DedicatedInstance>()
.AddExisting<IDedicatedInstance, DedicatedInstance>()
.AddExisting<ENetServer, DedicatedInstance>()
.AddExisting<ENetServer, DedicatedInstance>() //Used to be like this for lnl
//.AddScoped<IHandshakeSessionRegistry, HandshakeSessionRegistry>()
.AddScoped<IPlayerRegistry, PlayerRegistry>()
//.AddScoped<UnconnectedMessageSource, UnconnectedSource>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BeatTogether.DedicatedServer.Ignorance\BeatTogether.DedicatedServer.Ignorance.csproj" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion BeatTogether.DedicatedServer.Node/InstanceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ bool AllowNE
var scope = _serviceProvider.CreateScope();

var instanceConfig = scope.ServiceProvider.GetRequiredService<InstanceConfiguration>();
//instanceConfig.LiteNetPort = (int)liteNetPort!;
instanceConfig.Port = (int)Port!;
instanceConfig.Secret = secret;
instanceConfig.ServerOwnerId = managerId;
Expand Down
4 changes: 3 additions & 1 deletion BeatTogether.DedicatedServer.Node/NodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public async Task<CreateMatchmakingServerResponse> CreateMatchmakingServer(Creat
await matchmakingServer.Start();
return new CreateMatchmakingServerResponse(
CreateMatchmakingServerError.None,
$"{_configuration.HostName}:{matchmakingServer.Port}"
$"{_configuration.HostName}:{matchmakingServer.Port}",
Array.Empty<byte>(),
Array.Empty<byte>()
);
}

Expand Down

0 comments on commit ca4ac43

Please sign in to comment.