diff --git a/BeatTogether.DedicatedServer.Instancing/Abstractions/IInstanceFactory.cs b/BeatTogether.DedicatedServer.Instancing/Abstractions/IInstanceFactory.cs
new file mode 100644
index 00000000..cf67c6f3
--- /dev/null
+++ b/BeatTogether.DedicatedServer.Instancing/Abstractions/IInstanceFactory.cs
@@ -0,0 +1,11 @@
+using BeatTogether.DedicatedServer.Kernel.Abstractions;
+using BeatTogether.Core.Abstractions;
+
+namespace BeatTogether.DedicatedServer.Instancing.Abstractions
+{
+ public interface IInstanceFactory
+ {
+ public IDedicatedInstance? CreateInstance(
+ IServerInstance serverInstance);
+ }
+}
diff --git a/BeatTogether.DedicatedServer.Instancing/Abstractions/IInstanceRegistry.cs b/BeatTogether.DedicatedServer.Instancing/Abstractions/IInstanceRegistry.cs
new file mode 100644
index 00000000..05114182
--- /dev/null
+++ b/BeatTogether.DedicatedServer.Instancing/Abstractions/IInstanceRegistry.cs
@@ -0,0 +1,15 @@
+using BeatTogether.Core.Enums;
+using BeatTogether.DedicatedServer.Kernel.Abstractions;
+using System.Diagnostics.CodeAnalysis;
+
+namespace BeatTogether.DedicatedServer.Instancing.Abstractions
+{
+ public interface IInstanceRegistry
+ {
+ public bool AddInstance(IDedicatedInstance instance);
+ public bool RemoveInstance(IDedicatedInstance instance);
+ public bool TryGetInstance(string secret, [MaybeNullWhen(false)] out IDedicatedInstance instance);
+ public bool TryGetInstanceByCode(string code, [MaybeNullWhen(false)] out IDedicatedInstance instance);
+ public bool TryGetAvailablePublicServer(InvitePolicy invitePolicy, GameplayServerMode serverMode, SongSelectionMode songMode, GameplayServerControlSettings serverControlSettings, BeatmapDifficultyMask difficultyMask, GameplayModifiersMask modifiersMask, string songPackMasks, [MaybeNullWhen(false)] out IDedicatedInstance instance);
+ }
+}
diff --git a/BeatTogether.DedicatedServer.Node/Abstractions/IPortAllocator.cs b/BeatTogether.DedicatedServer.Instancing/Abstractions/IPortAllocator.cs
similarity index 63%
rename from BeatTogether.DedicatedServer.Node/Abstractions/IPortAllocator.cs
rename to BeatTogether.DedicatedServer.Instancing/Abstractions/IPortAllocator.cs
index ef13698e..39ac81e3 100644
--- a/BeatTogether.DedicatedServer.Node/Abstractions/IPortAllocator.cs
+++ b/BeatTogether.DedicatedServer.Instancing/Abstractions/IPortAllocator.cs
@@ -1,4 +1,4 @@
-namespace BeatTogether.DedicatedServer.Node.Abstractions
+namespace BeatTogether.DedicatedServer.Instancing.Abstractions
{
public interface IPortAllocator
{
diff --git a/BeatTogether.DedicatedServer.Instancing/BeatTogether.DedicatedServer.Instancing.csproj b/BeatTogether.DedicatedServer.Instancing/BeatTogether.DedicatedServer.Instancing.csproj
new file mode 100644
index 00000000..ebcdd38d
--- /dev/null
+++ b/BeatTogether.DedicatedServer.Instancing/BeatTogether.DedicatedServer.Instancing.csproj
@@ -0,0 +1,22 @@
+
+
+
+ net6.0
+ 9
+ icon.png
+ BeatTogether Team
+ BeatTogether
+ https://github.com/beattogether/BeatTogether.DedicatedServer
+ 1.0.0
+ enable
+
+
+
+
+
+
+
+
+
+
+
diff --git a/BeatTogether.DedicatedServer.Instancing/Configuration/InstancingConfiguration.cs b/BeatTogether.DedicatedServer.Instancing/Configuration/InstancingConfiguration.cs
new file mode 100644
index 00000000..8be3b3b2
--- /dev/null
+++ b/BeatTogether.DedicatedServer.Instancing/Configuration/InstancingConfiguration.cs
@@ -0,0 +1,11 @@
+using System;
+
+namespace BeatTogether.DedicatedServer.Instancing.Configuration
+{
+ public sealed class InstancingConfiguration
+ {
+ public string HostName { get; set; } = "192.168.0.21";
+ public int BasePort { get; set; } = 30000;
+ public int MaximumSlots { get; set; } = 10000;
+ }
+}
diff --git a/BeatTogether.DedicatedServer.Instancing/Extensions/HostBuilderExtensions.cs b/BeatTogether.DedicatedServer.Instancing/Extensions/HostBuilderExtensions.cs
new file mode 100644
index 00000000..b918e4fe
--- /dev/null
+++ b/BeatTogether.DedicatedServer.Instancing/Extensions/HostBuilderExtensions.cs
@@ -0,0 +1,27 @@
+using BeatTogether.DedicatedServer.Instancing.Configuration;
+using BeatTogether.DedicatedServer.Instancing.Abstractions;
+using BeatTogether.Extensions;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using BeatTogether.DedicatedServer.Kernel.Extensions;
+using BeatTogether.Core.Abstractions;
+
+namespace BeatTogether.DedicatedServer.Instancing.Extensions
+{
+ public static class HostBuilderExtensions
+ {
+ public static IHostBuilder UseDedicatedServerInstancing(this IHostBuilder hostBuilder) =>
+ hostBuilder
+ .ConfigureAppConfiguration()
+ .UseSerilog()
+ .UseDedicatedInstances()
+ .ConfigureServices((hostBuilderContext, services) =>
+ services
+ .AddConfiguration("Instancing")
+ .AddSingleton()
+ .AddSingleton()
+ .AddSingleton()
+ .AddSingleton()
+ );
+ }
+}
\ No newline at end of file
diff --git a/BeatTogether.DedicatedServer.Instancing/Implimentations/ServerInstance.cs b/BeatTogether.DedicatedServer.Instancing/Implimentations/ServerInstance.cs
new file mode 100644
index 00000000..77e1e24b
--- /dev/null
+++ b/BeatTogether.DedicatedServer.Instancing/Implimentations/ServerInstance.cs
@@ -0,0 +1,46 @@
+using BeatTogether.Core.Abstractions;
+using BeatTogether.Core.Enums;
+using BeatTogether.Core.Models;
+using BeatTogether.DedicatedServer.Kernel.Abstractions;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+
+namespace BeatTogether.DedicatedServer.Instancing.Implimentations
+{
+ public class ServerInstance : IServerInstance
+ {
+ private readonly IDedicatedInstance _ServerInstance;
+
+ public ServerInstance(IDedicatedInstance serverInstance, IPEndPoint instanceEndPoint)
+ {
+ _ServerInstance = serverInstance;
+ InstanceEndPoint = instanceEndPoint;
+ }
+
+ public string ServerName { get => _ServerInstance._configuration.ServerName; set => throw new NotImplementedException(); }
+ public IPEndPoint InstanceEndPoint { get; set; }
+ public string Secret { get => _ServerInstance._configuration.Secret; set => throw new NotImplementedException(); }
+ public string Code { get => _ServerInstance._configuration.Code; set => throw new NotImplementedException(); }
+ public MultiplayerGameState GameState { get => (MultiplayerGameState)_ServerInstance.State; set => throw new NotImplementedException(); }
+ public BeatmapDifficultyMask BeatmapDifficultyMask { get => _ServerInstance._configuration.BeatmapDifficultyMask; set => throw new NotImplementedException(); }
+ public GameplayModifiersMask GameplayModifiersMask { get => _ServerInstance._configuration.GameplayModifiersMask; set => throw new NotImplementedException(); }
+ public string SongPackMasks { get => _ServerInstance._configuration.SongPacksMask; set => throw new NotImplementedException(); }
+ public GameplayServerConfiguration GameplayServerConfiguration { get => _ServerInstance._configuration.GameplayServerConfiguration; set => throw new NotImplementedException(); }
+ public HashSet PlayerHashes { get => _ServerInstance.GetPlayerRegistry().Players.Select(p => p.HashedUserId).ToHashSet(); set => throw new NotImplementedException(); }
+ public string InstanceId { get => _ServerInstance._configuration.ServerId; set => throw new NotImplementedException(); }
+ public string ManagerId { get => _ServerInstance._configuration.ServerOwnerId; set => throw new NotImplementedException(); }
+ public bool PermanentManager { get => !string.IsNullOrEmpty(_ServerInstance._configuration.SetConstantManagerFromUserId); set => throw new NotImplementedException(); }
+ public long ServerStartJoinTimeout { get => _ServerInstance._configuration.DestroyInstanceTimeout; set => throw new NotImplementedException(); }
+ public bool NeverCloseServer { get => _ServerInstance._configuration.DestroyInstanceTimeout == -1; set => throw new NotImplementedException(); }
+ public long ResultScreenTime { get => _ServerInstance._configuration.CountdownConfig.ResultsScreenTime; set => throw new NotImplementedException(); }
+ public long BeatmapStartTime { get => _ServerInstance._configuration.CountdownConfig.BeatMapStartCountdownTime; set => throw new NotImplementedException(); }
+ public long PlayersReadyCountdownTime { get => _ServerInstance._configuration.CountdownConfig.CountdownTimePlayersReady; set => throw new NotImplementedException(); }
+ public bool AllowPerPlayerModifiers { get => _ServerInstance._configuration.AllowPerPlayerModifiers; set => throw new NotImplementedException(); }
+ public bool AllowPerPlayerDifficulties { get => _ServerInstance._configuration.AllowPerPlayerDifficulties; set => throw new NotImplementedException(); }
+ public bool AllowChroma { get => _ServerInstance._configuration.AllowChroma; set => throw new NotImplementedException(); }
+ public bool AllowME { get => _ServerInstance._configuration.AllowMappingExtensions; set => throw new NotImplementedException(); }
+ public bool AllowNE { get => _ServerInstance._configuration.AllowNoodleExtensions; set => throw new NotImplementedException(); }
+ }
+}
diff --git a/BeatTogether.DedicatedServer.Instancing/InstanceFactory.cs b/BeatTogether.DedicatedServer.Instancing/InstanceFactory.cs
new file mode 100644
index 00000000..4d8ece01
--- /dev/null
+++ b/BeatTogether.DedicatedServer.Instancing/InstanceFactory.cs
@@ -0,0 +1,104 @@
+using System;
+using BeatTogether.DedicatedServer.Kernel.Abstractions;
+using BeatTogether.DedicatedServer.Kernel.Configuration;
+using BeatTogether.Core.Enums;
+using BeatTogether.DedicatedServer.Instancing.Abstractions;
+using Microsoft.Extensions.DependencyInjection;
+using BeatTogether.Core.Abstractions;
+using System.Net;
+using BeatTogether.DedicatedServer.Instancing.Configuration;
+using BeatTogether.Core.ServerMessaging;
+using BeatTogether.DedicatedServer.Instancing.Implimentations;
+using Serilog;
+
+namespace BeatTogether.DedicatedServer.Instancing
+{
+ public sealed class InstanceFactory : IInstanceFactory
+ {
+ private readonly IInstanceRegistry _instanceRegistry;
+ private readonly IServiceProvider _serviceProvider;
+ private readonly IPortAllocator _portAllocator;
+ private readonly InstancingConfiguration _config;
+ private readonly ILayer1? _SendEventsLayer;
+ private readonly ILogger _logger = Log.ForContext();
+
+ public InstanceFactory(
+ IInstanceRegistry instanceRegistry,
+ IServiceProvider serviceProvider,
+ IPortAllocator portAllocator,
+ InstancingConfiguration instancingConfiguration)
+ {
+ _instanceRegistry = instanceRegistry;
+ _serviceProvider = serviceProvider;
+ _portAllocator = portAllocator;
+ _config = instancingConfiguration;
+
+ _SendEventsLayer = _serviceProvider.GetService();
+ }
+
+ public IDedicatedInstance? CreateInstance(IServerInstance serverInstance)
+ {
+ var Port = _portAllocator.AcquirePort();
+
+ if (!Port.HasValue)
+ return null;
+
+ var scope = _serviceProvider.CreateScope();
+
+ var instanceConfig = scope.ServiceProvider.GetRequiredService();
+ instanceConfig.Port = (int)Port!;
+ instanceConfig.Secret = serverInstance.Secret;
+ instanceConfig.Code = serverInstance.Code;
+ instanceConfig.ServerId = serverInstance.InstanceId;
+ _logger.Information("Server ID: " + instanceConfig.ServerId);
+ instanceConfig.ServerOwnerId = serverInstance.ManagerId;
+ _logger.Information("Server owner ID: " + instanceConfig.ServerOwnerId);
+ instanceConfig.GameplayServerConfiguration = serverInstance.GameplayServerConfiguration;
+ instanceConfig.GameplayModifiersMask = serverInstance.GameplayModifiersMask;
+ instanceConfig.BeatmapDifficultyMask = serverInstance.BeatmapDifficultyMask;
+ instanceConfig.SongPacksMask = serverInstance.SongPackMasks;
+ instanceConfig.DestroyInstanceTimeout = serverInstance.ServerStartJoinTimeout;
+ instanceConfig.ServerName = serverInstance.ServerName;
+ instanceConfig.CountdownConfig.BeatMapStartCountdownTime = Math.Max(serverInstance.BeatmapStartTime, 0L);
+ instanceConfig.CountdownConfig.ResultsScreenTime = Math.Max(serverInstance.ResultScreenTime, 0L); //TODO convert the dedi logic to use long instead of float
+ instanceConfig.AllowChroma = serverInstance.AllowChroma;
+ instanceConfig.AllowMappingExtensions = serverInstance.AllowME;
+ instanceConfig.AllowNoodleExtensions = serverInstance.AllowNE;
+ instanceConfig.AllowPerPlayerDifficulties = serverInstance.AllowPerPlayerDifficulties;
+ instanceConfig.AllowPerPlayerModifiers = serverInstance.AllowPerPlayerModifiers;
+ if (serverInstance.PermanentManager)
+ instanceConfig.SetConstantManagerFromUserId = serverInstance.ManagerId;
+ instanceConfig.CountdownConfig.CountdownTimePlayersReady = Math.Max(serverInstance.PlayersReadyCountdownTime, 0L);
+ if (instanceConfig.CountdownConfig.CountdownTimePlayersReady == 0L)
+ instanceConfig.CountdownConfig.CountdownTimePlayersReady = instanceConfig.GameplayServerConfiguration.GameplayServerMode == GameplayServerMode.Managed ? 15000L : 30000L;
+ var instance = scope.ServiceProvider.GetRequiredService();
+ if (!_instanceRegistry.AddInstance(instance))
+ {
+ return null;
+
+ }
+ instance.StopEvent += HandleStopEvent;
+
+ serverInstance.InstanceEndPoint = IPEndPoint.Parse($"{_config.HostName}:{instanceConfig.Port}");
+
+ //Subscribe to server events if the layer above allows this.
+ if(_SendEventsLayer != null)
+ {
+ instance.StopEvent += (dedi) => _SendEventsLayer.InstanceClosed(new ServerInstance(instance, serverInstance.InstanceEndPoint));
+ instance.PlayerConnectedEvent += (player) => _SendEventsLayer.PlayerJoined(new ServerInstance(instance, serverInstance.InstanceEndPoint), player);
+ instance.PlayerDisconnectedEvent += (player) => _SendEventsLayer.PlayerLeft(new ServerInstance(instance, serverInstance.InstanceEndPoint), player);
+ instance.PlayerDisconnectBeforeJoining += (a, b, c) => _SendEventsLayer.InstancePlayersChanged(new ServerInstance(instance, serverInstance.InstanceEndPoint));
+ instance.GameIsInLobby += (a, b) => _SendEventsLayer.InstanceStateChanged(new ServerInstance(instance, serverInstance.InstanceEndPoint));
+ instance.UpdateInstanceEvent += (dedi) => _SendEventsLayer.InstanceConfigChanged(new ServerInstance(instance, serverInstance.InstanceEndPoint));
+ }
+
+ return instance;
+ }
+
+ private void HandleStopEvent(IDedicatedInstance Instance)
+ {
+ _instanceRegistry.RemoveInstance(Instance);
+ _portAllocator.ReleasePort(Instance.Port);
+ }
+ }
+}
diff --git a/BeatTogether.DedicatedServer.Instancing/InstanceRegistry.cs b/BeatTogether.DedicatedServer.Instancing/InstanceRegistry.cs
new file mode 100644
index 00000000..edf8f689
--- /dev/null
+++ b/BeatTogether.DedicatedServer.Instancing/InstanceRegistry.cs
@@ -0,0 +1,60 @@
+using BeatTogether.DedicatedServer.Kernel.Abstractions;
+using BeatTogether.DedicatedServer.Instancing.Abstractions;
+using System.Collections.Concurrent;
+using System.Diagnostics.CodeAnalysis;
+using BeatTogether.Core.Enums;
+using System.Linq;
+
+namespace BeatTogether.DedicatedServer.Instancing
+{
+ public sealed class InstanceRegistry : IInstanceRegistry
+ {
+ private readonly ConcurrentDictionary _instances = new();
+ private readonly ConcurrentDictionary _instancesByCode = new();
+
+ public bool AddInstance(IDedicatedInstance instance){
+ if (_instances.TryAdd(instance._configuration.Secret, instance)) {
+ if(_instancesByCode.TryAdd(instance._configuration.Code, instance))
+ return true;
+ _instances.TryRemove(instance._configuration.Secret, out _);
+ }
+ return false;
+ }
+
+ public bool RemoveInstance(IDedicatedInstance instance) => _instances.TryRemove(instance._configuration.Secret, out _) && _instancesByCode.TryRemove(instance._configuration.Code, out _);
+
+ public bool TryGetAvailablePublicServer(InvitePolicy invitePolicy, GameplayServerMode serverMode, SongSelectionMode songMode, GameplayServerControlSettings serverControlSettings, BeatmapDifficultyMask difficultyMask, GameplayModifiersMask modifiersMask, string songPackMasks, [MaybeNullWhen(false)] out IDedicatedInstance instance)
+ {
+ instance = null;
+ var AvaliableServers = _instances.Values.Where(s =>
+ s._configuration.GameplayServerConfiguration.InvitePolicy == invitePolicy &&
+ s._configuration.GameplayServerConfiguration.GameplayServerMode == serverMode &&
+ s._configuration.GameplayServerConfiguration.SongSelectionMode == songMode &&
+ s._configuration.GameplayServerConfiguration.GameplayServerControlSettings == serverControlSettings &&
+ s._configuration.BeatmapDifficultyMask == difficultyMask &&
+ s._configuration.GameplayModifiersMask == modifiersMask &&
+ s._configuration.SongPacksMask == songPackMasks
+ );
+ if (!AvaliableServers.Any())
+ return false;
+ var server = AvaliableServers.First();
+ foreach (var publicServer in AvaliableServers)
+ {
+ if ((publicServer.GetPlayerRegistry().GetPlayerCount() < publicServer._configuration.GameplayServerConfiguration.MaxPlayerCount && publicServer.GetPlayerRegistry().GetPlayerCount() > server.GetPlayerRegistry().GetPlayerCount()))
+ {
+ server = publicServer;
+ }
+ }
+ if (server.GetPlayerRegistry().GetPlayerCount() >= server._configuration.GameplayServerConfiguration.MaxPlayerCount)
+ return false;
+ instance = server;
+ return true;
+ }
+
+ public bool TryGetInstance(string secret, [MaybeNullWhen(false)] out IDedicatedInstance instance) =>
+ _instances.TryGetValue(secret, out instance);
+
+ public bool TryGetInstanceByCode(string code, [MaybeNullWhen(false)] out IDedicatedInstance instance) =>
+ _instancesByCode.TryGetValue(code, out instance);
+ }
+}
diff --git a/BeatTogether.DedicatedServer.Instancing/LayerService.cs b/BeatTogether.DedicatedServer.Instancing/LayerService.cs
new file mode 100644
index 00000000..b8b323b0
--- /dev/null
+++ b/BeatTogether.DedicatedServer.Instancing/LayerService.cs
@@ -0,0 +1,93 @@
+using BeatTogether.Core.Abstractions;
+using BeatTogether.Core.Enums;
+using BeatTogether.DedicatedServer.Instancing.Abstractions;
+using BeatTogether.DedicatedServer.Instancing.Configuration;
+using BeatTogether.DedicatedServer.Instancing.Implimentations;
+using Serilog;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace BeatTogether.DedicatedServer.Instancing
+{
+ public class LayerService : ILayer2
+ {
+ private readonly IInstanceRegistry _instanceRegistry;
+ private readonly IInstanceFactory _instanceFactory;
+ private readonly InstancingConfiguration _instancingConfiguration;
+ private readonly ILogger _logger = Log.ForContext();
+
+
+ public LayerService(IInstanceRegistry instanceRegistry, IInstanceFactory instanceFactory, InstancingConfiguration instancingConfiguration)
+ {
+ _instanceRegistry = instanceRegistry;
+ _instancingConfiguration = instancingConfiguration;
+ _instanceFactory = instanceFactory;
+ }
+
+ public Task CloseInstance(string InstanceSecret)
+ {
+ if(_instanceRegistry.TryGetInstance(InstanceSecret, out var Instance)){
+ Instance.Stop();
+ }
+ return Task.CompletedTask;
+ }
+
+ public async Task CreateInstance(IServerInstance serverInstance)
+ {
+ var inst = _instanceFactory.CreateInstance(serverInstance);
+ if(inst != null)
+ await inst.Start();
+ return inst != null;
+ }
+
+ public Task DisconnectPlayer(string InstanceSecret, string PlayerUserId)
+ {
+ if (!_instanceRegistry.TryGetInstance(InstanceSecret, out var instance))
+ return Task.CompletedTask;
+ if (instance.GetPlayerRegistry().TryGetPlayer(PlayerUserId, out var player))
+ instance.DisconnectPlayer(player);
+
+ return Task.CompletedTask;
+ }
+
+ public Task GetAvailablePublicServer(InvitePolicy invitePolicy, GameplayServerMode serverMode, SongSelectionMode songMode, GameplayServerControlSettings serverControlSettings, BeatmapDifficultyMask difficultyMask, GameplayModifiersMask modifiersMask, string songPackMasks)
+ {
+ IServerInstance? serverInstance = null;
+ if (_instanceRegistry.TryGetAvailablePublicServer(invitePolicy, serverMode, songMode, serverControlSettings, difficultyMask, modifiersMask, songPackMasks, out var instance))
+ {
+ serverInstance = new ServerInstance(instance, IPEndPoint.Parse($"{_instancingConfiguration.HostName}:{instance._configuration.Port}"));
+ }
+ return Task.FromResult(serverInstance);
+ }
+
+ public Task GetServer(string secret)
+ {
+ IServerInstance? serverInstance = null;
+ if (_instanceRegistry.TryGetInstance(secret, out var instance))
+ {
+ serverInstance = new ServerInstance(instance, IPEndPoint.Parse($"{_instancingConfiguration.HostName}:{instance._configuration.Port}"));
+ }
+ return Task.FromResult(serverInstance);
+ }
+
+ public Task GetServerByCode(string code)
+ {
+ IServerInstance? serverInstance = null;
+ if (_instanceRegistry.TryGetInstanceByCode(code, out var instance))
+ {
+ serverInstance = new ServerInstance(instance, IPEndPoint.Parse($"{_instancingConfiguration.HostName}:{instance._configuration.Port}"));
+ }
+ return Task.FromResult(serverInstance);
+ }
+
+ public Task SetPlayerSessionData(string serverSecret, IPlayer playerSessionData)
+ {
+ _logger.Information("Setting playerSessionData: " + playerSessionData.PlayerSessionId + " In instance: " + serverSecret);
+ if (!_instanceRegistry.TryGetInstance(serverSecret, out var instance))
+ return Task.FromResult(false);
+ _logger.Information("Found instance, setting session data");
+ instance.GetPlayerRegistry().AddExtraPlayerSessionData(playerSessionData);
+ return Task.FromResult(true);
+ }
+ }
+}
diff --git a/BeatTogether.DedicatedServer.Node/PortAllocator.cs b/BeatTogether.DedicatedServer.Instancing/PortAllocator.cs
similarity index 81%
rename from BeatTogether.DedicatedServer.Node/PortAllocator.cs
rename to BeatTogether.DedicatedServer.Instancing/PortAllocator.cs
index 169577a7..06a88a3d 100644
--- a/BeatTogether.DedicatedServer.Node/PortAllocator.cs
+++ b/BeatTogether.DedicatedServer.Instancing/PortAllocator.cs
@@ -1,13 +1,13 @@
-using BeatTogether.DedicatedServer.Node.Abstractions;
-using BeatTogether.DedicatedServer.Node.Configuration;
+using BeatTogether.DedicatedServer.Instancing.Abstractions;
+using BeatTogether.DedicatedServer.Instancing.Configuration;
using System.Collections.Generic;
using System.Linq;
-namespace BeatTogether.DedicatedServer.Node
+namespace BeatTogether.DedicatedServer.Instancing
{
public sealed class PortAllocator : IPortAllocator
{
- private readonly NodeConfiguration _configuration;
+ private readonly InstancingConfiguration _configuration;
private readonly object _lock = new();
@@ -17,7 +17,7 @@ public sealed class PortAllocator : IPortAllocator
private int _lastPort;
public PortAllocator(
- NodeConfiguration configuration)
+ InstancingConfiguration configuration)
{
_configuration = configuration;
diff --git a/BeatTogether.DedicatedServer.Interface/BeatTogether.DedicatedServer.Interface.csproj b/BeatTogether.DedicatedServer.Interface/BeatTogether.DedicatedServer.Interface.csproj
index d4e8eb39..991752d4 100644
--- a/BeatTogether.DedicatedServer.Interface/BeatTogether.DedicatedServer.Interface.csproj
+++ b/BeatTogether.DedicatedServer.Interface/BeatTogether.DedicatedServer.Interface.csproj
@@ -7,7 +7,7 @@
BeatTogether Team
BeatTogether
https://github.com/beattogether/BeatTogether.DedicatedServer
- 1.7.3
+ 2.0.2
enable
@@ -17,6 +17,7 @@
+
diff --git a/BeatTogether.DedicatedServer.Interface/Enums/CountdownState.cs b/BeatTogether.DedicatedServer.Interface/Enums/CountdownState.cs
deleted file mode 100644
index 652daf71..00000000
--- a/BeatTogether.DedicatedServer.Interface/Enums/CountdownState.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace BeatTogether.DedicatedServer.Interface.Enums
-{
- public enum CountdownState : byte
- {
- NotCountingDown = 0,
- CountingDown = 1,
- StartBeatmapCountdown = 2,
- WaitingForEntitlement = 3
- }
-}
diff --git a/BeatTogether.DedicatedServer.Interface/Enums/DiscoveryPolicy.cs b/BeatTogether.DedicatedServer.Interface/Enums/DiscoveryPolicy.cs
deleted file mode 100644
index 06a31e51..00000000
--- a/BeatTogether.DedicatedServer.Interface/Enums/DiscoveryPolicy.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace BeatTogether.DedicatedServer.Interface.Enums
-{
- public enum DiscoveryPolicy : byte
- {
- Hidden = 0,
- WithCode = 1,
- Public = 2
- }
-}
diff --git a/BeatTogether.DedicatedServer.Interface/Enums/GameplayServerControlSettings.cs b/BeatTogether.DedicatedServer.Interface/Enums/GameplayServerControlSettings.cs
deleted file mode 100644
index c4eb0165..00000000
--- a/BeatTogether.DedicatedServer.Interface/Enums/GameplayServerControlSettings.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using System;
-
-namespace BeatTogether.DedicatedServer.Interface.Enums
-{
- [Flags]
- public enum GameplayServerControlSettings
- {
- None = 0,
- AllowModifierSelection = 1,
- AllowSpectate = 2,
- All = 3
- }
-}
diff --git a/BeatTogether.DedicatedServer.Interface/Enums/GameplayServerMode.cs b/BeatTogether.DedicatedServer.Interface/Enums/GameplayServerMode.cs
deleted file mode 100644
index 1ad500fc..00000000
--- a/BeatTogether.DedicatedServer.Interface/Enums/GameplayServerMode.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace BeatTogether.DedicatedServer.Interface.Enums
-{
- public enum GameplayServerMode
- {
- Countdown = 0,
- Managed = 1,
- QuickStartOneSong = 2,
- Tournament = 3
- }
-}
diff --git a/BeatTogether.DedicatedServer.Interface/Enums/GameplayState.cs b/BeatTogether.DedicatedServer.Interface/Enums/GameplayState.cs
deleted file mode 100644
index 275d7ff3..00000000
--- a/BeatTogether.DedicatedServer.Interface/Enums/GameplayState.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-namespace BeatTogether.DedicatedServer.Interface.Enums
-{
- public enum GameplayState : byte
- {
- None = 0,
- SceneLoad = 1,
- SongLoad = 2,
- Gameplay = 3,
- Results = 4
- }
-}
diff --git a/BeatTogether.DedicatedServer.Interface/Enums/InvitePolicy.cs b/BeatTogether.DedicatedServer.Interface/Enums/InvitePolicy.cs
deleted file mode 100644
index 429dc2c3..00000000
--- a/BeatTogether.DedicatedServer.Interface/Enums/InvitePolicy.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace BeatTogether.DedicatedServer.Interface.Enums
-{
- public enum InvitePolicy : byte
- {
- OnlyConnectionOwnerCanInvite = 0,
- AnyoneCanInvite = 1
- }
-}
diff --git a/BeatTogether.DedicatedServer.Interface/Enums/MultiplayerGameState.cs b/BeatTogether.DedicatedServer.Interface/Enums/MultiplayerGameState.cs
deleted file mode 100644
index 792b010b..00000000
--- a/BeatTogether.DedicatedServer.Interface/Enums/MultiplayerGameState.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace BeatTogether.DedicatedServer.Interface.Enums
-{
- public enum MultiplayerGameState : byte
- {
- None = 0,
- Lobby = 1,
- Game = 2
- }
-}
diff --git a/BeatTogether.DedicatedServer.Interface/Enums/SongSelectionMode.cs b/BeatTogether.DedicatedServer.Interface/Enums/SongSelectionMode.cs
deleted file mode 100644
index 532dc61b..00000000
--- a/BeatTogether.DedicatedServer.Interface/Enums/SongSelectionMode.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-namespace BeatTogether.DedicatedServer.Interface.Enums
-{
- public enum SongSelectionMode
- {
- Vote = 0,
- Random = 1,
- ManagerPicks = 2,
- RandomPlayerPicks = 3,
- ServerPicks = 4
- }
-}
diff --git a/BeatTogether.DedicatedServer.Interface/Events/MatchmakingServerStoppedEvent.cs b/BeatTogether.DedicatedServer.Interface/Events/MatchmakingServerStoppedEvent.cs
index a0b984f2..f0889094 100644
--- a/BeatTogether.DedicatedServer.Interface/Events/MatchmakingServerStoppedEvent.cs
+++ b/BeatTogether.DedicatedServer.Interface/Events/MatchmakingServerStoppedEvent.cs
@@ -1,4 +1,5 @@
namespace BeatTogether.DedicatedServer.Interface.Events
{
- public sealed record MatchmakingServerStoppedEvent(string Secret);
+ public sealed record MatchmakingServerStoppedEvent(
+ string Secret);
}
diff --git a/BeatTogether.DedicatedServer.Interface/Events/NodeOnlineEvent.cs b/BeatTogether.DedicatedServer.Interface/Events/NodeOnlineEvent.cs
index d65d06a1..6c8a4b10 100644
--- a/BeatTogether.DedicatedServer.Interface/Events/NodeOnlineEvent.cs
+++ b/BeatTogether.DedicatedServer.Interface/Events/NodeOnlineEvent.cs
@@ -1,6 +1,7 @@
-using System;
-
+
namespace BeatTogether.DedicatedServer.Interface.Events
{
- public sealed record NodeOnlineEvent(string EndPoint, string NodeVersion);
+ public sealed record NodeOnlineEvent(
+ string EndPoint,
+ string NodeVersion);
}
\ No newline at end of file
diff --git a/BeatTogether.DedicatedServer.Interface/Events/NodeReceivedPlayerEncryptionEvent.cs b/BeatTogether.DedicatedServer.Interface/Events/NodeReceivedPlayerEncryptionEvent.cs
deleted file mode 100644
index 09f2b5e8..00000000
--- a/BeatTogether.DedicatedServer.Interface/Events/NodeReceivedPlayerEncryptionEvent.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace BeatTogether.DedicatedServer.Interface.Events
-{
- public sealed record NodeReceivedPlayerEncryptionEvent(string EndPoint, string PlayerEndPoint);
-}
\ No newline at end of file
diff --git a/BeatTogether.DedicatedServer.Interface/Events/NodeReceivedPlayerSessionDataEvent.cs b/BeatTogether.DedicatedServer.Interface/Events/NodeReceivedPlayerSessionDataEvent.cs
new file mode 100644
index 00000000..92696207
--- /dev/null
+++ b/BeatTogether.DedicatedServer.Interface/Events/NodeReceivedPlayerSessionDataEvent.cs
@@ -0,0 +1,6 @@
+namespace BeatTogether.DedicatedServer.Interface.Events
+{
+ public sealed record NodeReceivedPlayerSessionDataEvent(
+ string EndPoint,
+ string PlayerSessionId);
+}
\ No newline at end of file
diff --git a/BeatTogether.DedicatedServer.Interface/Events/NodeStartedEvent.cs b/BeatTogether.DedicatedServer.Interface/Events/NodeStartedEvent.cs
index 58a41439..06f5501f 100644
--- a/BeatTogether.DedicatedServer.Interface/Events/NodeStartedEvent.cs
+++ b/BeatTogether.DedicatedServer.Interface/Events/NodeStartedEvent.cs
@@ -1,6 +1,7 @@
-using System;
-
+
namespace BeatTogether.DedicatedServer.Interface.Events
{
- public sealed record NodeStartedEvent(string EndPoint, string NodeVersion);
+ public sealed record NodeStartedEvent(
+ string EndPoint,
+ string NodeVersion);
}
\ No newline at end of file
diff --git a/BeatTogether.DedicatedServer.Interface/Events/PlayerJoinEvent.cs b/BeatTogether.DedicatedServer.Interface/Events/PlayerJoinEvent.cs
index 9d687e13..4b406be6 100644
--- a/BeatTogether.DedicatedServer.Interface/Events/PlayerJoinEvent.cs
+++ b/BeatTogether.DedicatedServer.Interface/Events/PlayerJoinEvent.cs
@@ -1,4 +1,7 @@
-namespace BeatTogether.DedicatedServer.Interface.Events
+
+namespace BeatTogether.DedicatedServer.Interface.Events
{
- public sealed record PlayerJoinEvent(string Secret, string EndPoint, string UserId);
+ public sealed record PlayerJoinEvent(
+ string Secret,
+ string HashedUserId);
}
diff --git a/BeatTogether.DedicatedServer.Interface/Events/PlayerLeaveServerEvent.cs b/BeatTogether.DedicatedServer.Interface/Events/PlayerLeaveServerEvent.cs
index b6d98e21..3baf7829 100644
--- a/BeatTogether.DedicatedServer.Interface/Events/PlayerLeaveServerEvent.cs
+++ b/BeatTogether.DedicatedServer.Interface/Events/PlayerLeaveServerEvent.cs
@@ -1,6 +1,7 @@
-using System.Net;
-
+
namespace BeatTogether.DedicatedServer.Interface.Events
{
- public sealed record PlayerLeaveServerEvent(string Secret, string UserId, string EndPoint);
+ public sealed record PlayerLeaveServerEvent(
+ string Secret,
+ string HashedUserId);
}
diff --git a/BeatTogether.DedicatedServer.Interface/Events/ServerInGameplayEvent.cs b/BeatTogether.DedicatedServer.Interface/Events/ServerInGameplayEvent.cs
index e314e29c..a644b50c 100644
--- a/BeatTogether.DedicatedServer.Interface/Events/ServerInGameplayEvent.cs
+++ b/BeatTogether.DedicatedServer.Interface/Events/ServerInGameplayEvent.cs
@@ -1,9 +1,9 @@
-
+using BeatTogether.Core.Enums;
+
namespace BeatTogether.DedicatedServer.Interface.Events
{
public sealed record ServerInGameplayEvent(
string Secret,
- bool InGame,
- string LevelID
+ MultiplayerGameState MultiplayerGameState
);
}
diff --git a/BeatTogether.DedicatedServer.Interface/Events/UpdateInstanceConfigEvent.cs b/BeatTogether.DedicatedServer.Interface/Events/UpdateInstanceConfigEvent.cs
index a30a95e2..e470e960 100644
--- a/BeatTogether.DedicatedServer.Interface/Events/UpdateInstanceConfigEvent.cs
+++ b/BeatTogether.DedicatedServer.Interface/Events/UpdateInstanceConfigEvent.cs
@@ -1,9 +1,7 @@
-using BeatTogether.DedicatedServer.Interface.Models;
+using BeatTogether.Core.ServerMessaging.Models;
namespace BeatTogether.DedicatedServer.Interface.Events
{
public sealed record UpdateInstanceConfigEvent(
- string Secret, //Cannot change the secret
- string ServerName,
- GameplayServerConfiguration Configuration);
+ Server ServerInsance);
}
diff --git a/BeatTogether.DedicatedServer.Interface/Events/UpdatePlayersEvent.cs b/BeatTogether.DedicatedServer.Interface/Events/UpdatePlayersEvent.cs
index a84d13aa..08d45ded 100644
--- a/BeatTogether.DedicatedServer.Interface/Events/UpdatePlayersEvent.cs
+++ b/BeatTogether.DedicatedServer.Interface/Events/UpdatePlayersEvent.cs
@@ -1,4 +1,6 @@
namespace BeatTogether.DedicatedServer.Interface.Events
{
- public sealed record UpdatePlayersEvent(string Secret, string[] Users);
+ public sealed record UpdatePlayersEvent(
+ string Secret,
+ string[] HashedUserIds);
}
diff --git a/BeatTogether.DedicatedServer.Interface/IMatchmakingService.cs b/BeatTogether.DedicatedServer.Interface/IMatchmakingService.cs
index d5950f39..fa061a80 100644
--- a/BeatTogether.DedicatedServer.Interface/IMatchmakingService.cs
+++ b/BeatTogether.DedicatedServer.Interface/IMatchmakingService.cs
@@ -21,7 +21,7 @@ public override void Build(IServiceContractBuilder builder) =>
.AddEvent()
.AddEvent()
.AddEvent()
- .AddEvent()
+ .AddEvent()
.AddEvent()
.AddEvent()
.AddEvent();
diff --git a/BeatTogether.DedicatedServer.Interface/Models/GameplayServerConfiguration.cs b/BeatTogether.DedicatedServer.Interface/Models/GameplayServerConfiguration.cs
deleted file mode 100644
index 6250cbc0..00000000
--- a/BeatTogether.DedicatedServer.Interface/Models/GameplayServerConfiguration.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using BeatTogether.DedicatedServer.Interface.Enums;
-
-namespace BeatTogether.DedicatedServer.Interface.Models
-{
- public record GameplayServerConfiguration(
- int MaxPlayerCount,
- DiscoveryPolicy DiscoveryPolicy,
- InvitePolicy InvitePolicy,
- GameplayServerMode GameplayServerMode,
- SongSelectionMode SongSelectionMode,
- GameplayServerControlSettings GameplayServerControlSettings);
-}
diff --git a/BeatTogether.DedicatedServer.Interface/Requests/CreateMatchmakingServerRequest.cs b/BeatTogether.DedicatedServer.Interface/Requests/CreateMatchmakingServerRequest.cs
index 95cd444e..57dd35b9 100644
--- a/BeatTogether.DedicatedServer.Interface/Requests/CreateMatchmakingServerRequest.cs
+++ b/BeatTogether.DedicatedServer.Interface/Requests/CreateMatchmakingServerRequest.cs
@@ -1,21 +1,7 @@
-using BeatTogether.DedicatedServer.Interface.Models;
+using BeatTogether.Core.ServerMessaging.Models;
namespace BeatTogether.DedicatedServer.Interface.Requests
{
public record CreateMatchmakingServerRequest(
- string Secret,
- string ManagerId,
- GameplayServerConfiguration Configuration,
- bool PermanentManager = true,
- float Timeout = 10f,
- string ServerName = "",
- float ResultScreenTime = 20.0f,
- float BeatmapStartTime = 5.0f,
- float PlayersReadyCountdownTime = 0f,
- bool AllowPerPlayerModifiers = false,
- bool AllowPerPlayerDifficulties = false,
- bool AllowChroma = true,
- bool AllowME = true,
- bool AllowNE = true
- );
+ Server Server);
}
diff --git a/BeatTogether.DedicatedServer.Interface/Responses/CreateMatchmakingServerResponse.cs b/BeatTogether.DedicatedServer.Interface/Responses/CreateMatchmakingServerResponse.cs
index 84c7e0cc..20d2bc16 100644
--- a/BeatTogether.DedicatedServer.Interface/Responses/CreateMatchmakingServerResponse.cs
+++ b/BeatTogether.DedicatedServer.Interface/Responses/CreateMatchmakingServerResponse.cs
@@ -9,9 +9,7 @@ public enum CreateMatchmakingServerError
public record CreateMatchmakingServerResponse(
CreateMatchmakingServerError Error,
- string RemoteEndPoint,
- byte[] Random,
- byte[] PublicKey)
+ string RemoteEndPoint)
{
public bool Success => Error == default;
}
diff --git a/BeatTogether.DedicatedServer.Kernel/Abstractions/IDedicatedInstance.cs b/BeatTogether.DedicatedServer.Kernel/Abstractions/IDedicatedInstance.cs
index bf18e1de..957529a7 100644
--- a/BeatTogether.DedicatedServer.Kernel/Abstractions/IDedicatedInstance.cs
+++ b/BeatTogether.DedicatedServer.Kernel/Abstractions/IDedicatedInstance.cs
@@ -2,8 +2,8 @@
using System.Net;
using System.Threading;
using System.Threading.Tasks;
+using BeatTogether.Core.Enums;
using BeatTogether.DedicatedServer.Kernel.Configuration;
-using BeatTogether.DedicatedServer.Messaging.Enums;
namespace BeatTogether.DedicatedServer.Kernel.Abstractions
{
@@ -24,7 +24,7 @@ public interface IDedicatedInstance
public int Port { get; }
MultiplayerGameState State { get; }
- float NoPlayersTime { get; }
+ long NoPlayersTime { get; }
IPlayerRegistry GetPlayerRegistry();
IServiceProvider GetServiceProvider();
diff --git a/BeatTogether.DedicatedServer.Kernel/Abstractions/IPlayer.cs b/BeatTogether.DedicatedServer.Kernel/Abstractions/IPlayer.cs
index 6e09c0c9..6a88398e 100644
--- a/BeatTogether.DedicatedServer.Kernel/Abstractions/IPlayer.cs
+++ b/BeatTogether.DedicatedServer.Kernel/Abstractions/IPlayer.cs
@@ -7,21 +7,21 @@
namespace BeatTogether.DedicatedServer.Kernel.Abstractions
{
- public interface IPlayer
+ public interface IPlayer : Core.Abstractions.IPlayer
{
EndPoint Endpoint { get; }
IDedicatedInstance Instance { get; }
byte ConnectionId { get; }
byte RemoteConnectionId { get; }
- string UserId { get; }
+ //string UserId { get; }
string UserName { get; }
- string PlayerSessionId { get; }
+ //string PlayerSessionId { get; }
byte[]? Random { get; set; }
byte[]? PublicEncryptionKey { get; set; }
- string ClientVersion { get; set; }
- Platform Platform { get; set; }
- string PlatformUserId { get; set; }
+ //string ClientVersion { get; set; }
+ //Platform Platform { get; set; }
+ //string PlatformUserId { get; set; }
uint ENetPeerId { get; set; }
@@ -62,7 +62,7 @@ public interface IPlayer
bool UpdateEntitlement { get; set; }
public string MapHash { get; set; }
- public Dictionary BeatmapDifficultiesRequirements{ get; set; }
+ public Dictionary BeatmapDifficultiesRequirements { get; set; }
long TicksAtLastSyncStateDelta { get; set; }
long TicksAtLastSyncState { get; set; }
}
diff --git a/BeatTogether.DedicatedServer.Kernel/Abstractions/IPlayerRegistry.cs b/BeatTogether.DedicatedServer.Kernel/Abstractions/IPlayerRegistry.cs
index 0b7a93b6..c69827b7 100644
--- a/BeatTogether.DedicatedServer.Kernel/Abstractions/IPlayerRegistry.cs
+++ b/BeatTogether.DedicatedServer.Kernel/Abstractions/IPlayerRegistry.cs
@@ -14,7 +14,8 @@ public interface IPlayerRegistry
bool TryGetPlayer(string userId, [MaybeNullWhen(false)] out IPlayer player);
int GetMillisBetweenSyncStatePackets();
- public void AddExtraPlayerSessionData(string playerSessionId, string ClientVersion, byte PlatformId, string PlayerPlatformUserId);
- public bool RemoveExtraPlayerSessionData(string playerSessionId, out string ClientVersion, out byte Platform, out string PlayerPlatformUserId);
+ public void AddExtraPlayerSessionData(Core.Abstractions.IPlayer playerSessionData);
+ public bool RemoveExtraPlayerSessionDataAndApply(Core.Abstractions.IPlayer playerSessionData/*out string ClientVersion, out byte Platform, out string PlayerPlatformUserId*/);
+ public bool RemoveExtraPlayerSessionData(string playerSessionId/*out string ClientVersion, out byte Platform, out string PlayerPlatformUserId*/);
}
}
diff --git a/BeatTogether.DedicatedServer.Kernel/BeatTogether.DedicatedServer.Kernel.csproj b/BeatTogether.DedicatedServer.Kernel/BeatTogether.DedicatedServer.Kernel.csproj
index a7f9ea63..8f78936c 100644
--- a/BeatTogether.DedicatedServer.Kernel/BeatTogether.DedicatedServer.Kernel.csproj
+++ b/BeatTogether.DedicatedServer.Kernel/BeatTogether.DedicatedServer.Kernel.csproj
@@ -7,6 +7,7 @@
+
diff --git a/BeatTogether.DedicatedServer.Kernel/CommandHandlers/SetCountdownTimeHandler.cs b/BeatTogether.DedicatedServer.Kernel/CommandHandlers/SetCountdownTimeHandler.cs
index 34c473f1..521f4d42 100644
--- a/BeatTogether.DedicatedServer.Kernel/CommandHandlers/SetCountdownTimeHandler.cs
+++ b/BeatTogether.DedicatedServer.Kernel/CommandHandlers/SetCountdownTimeHandler.cs
@@ -19,7 +19,7 @@ public SetCountdownTimeHandler(IPacketDispatcher packetDisapatcher, InstanceConf
public override void Handle(IPlayer player, SetCountdown command)
{
- _Configuration.CountdownConfig.CountdownTimePlayersReady = command.Countdown;
+ _Configuration.CountdownConfig.CountdownTimePlayersReady = command.Countdown * 1000;
_packetDisapatcher.SendToNearbyPlayers(new MpcTextChatPacket
{
Text = "Countdown time is now: " + command.Countdown
diff --git a/BeatTogether.DedicatedServer.Kernel/CommandHandlers/SetResultsTimeHandler.cs b/BeatTogether.DedicatedServer.Kernel/CommandHandlers/SetResultsTimeHandler.cs
index 0fb524db..0063f325 100644
--- a/BeatTogether.DedicatedServer.Kernel/CommandHandlers/SetResultsTimeHandler.cs
+++ b/BeatTogether.DedicatedServer.Kernel/CommandHandlers/SetResultsTimeHandler.cs
@@ -19,7 +19,7 @@ public SetResultsTimeHandler(IPacketDispatcher packetDisapatcher, InstanceConfig
public override void Handle(IPlayer player, SetResultsTime command)
{
- _Configuration.CountdownConfig.ResultsScreenTime = command.Countdown;
+ _Configuration.CountdownConfig.ResultsScreenTime = command.Countdown*1000;
_packetDisapatcher.SendToNearbyPlayers(new MpcTextChatPacket
{
Text = "Results screen time is now: " + command.Countdown
diff --git a/BeatTogether.DedicatedServer.Kernel/CommandHandlers/StartBeatmapTimeHandler.cs b/BeatTogether.DedicatedServer.Kernel/CommandHandlers/StartBeatmapTimeHandler.cs
index 38d69d9e..d857b6dc 100644
--- a/BeatTogether.DedicatedServer.Kernel/CommandHandlers/StartBeatmapTimeHandler.cs
+++ b/BeatTogether.DedicatedServer.Kernel/CommandHandlers/StartBeatmapTimeHandler.cs
@@ -19,7 +19,7 @@ public StartBeatmapTimeHandler(IPacketDispatcher packetDisapatcher, InstanceConf
public override void Handle(IPlayer player, SetBeatmapStartTime command)
{
- _Configuration.CountdownConfig.BeatMapStartCountdownTime = command.Countdown;
+ _Configuration.CountdownConfig.BeatMapStartCountdownTime = command.Countdown*1000;
_packetDisapatcher.SendToNearbyPlayers(new MpcTextChatPacket
{
Text = "Beatmap start time is now: " + command.Countdown
diff --git a/BeatTogether.DedicatedServer.Kernel/Configuration/InstanceConfiguration.cs b/BeatTogether.DedicatedServer.Kernel/Configuration/InstanceConfiguration.cs
index 2ba9300f..60aa612b 100644
--- a/BeatTogether.DedicatedServer.Kernel/Configuration/InstanceConfiguration.cs
+++ b/BeatTogether.DedicatedServer.Kernel/Configuration/InstanceConfiguration.cs
@@ -1,27 +1,29 @@
-using BeatTogether.DedicatedServer.Kernel.Enums;
+using BeatTogether.Core.Enums;
+using BeatTogether.Core.Models;
namespace BeatTogether.DedicatedServer.Kernel.Configuration
{
public sealed class InstanceConfiguration
{
- //public int LiteNetPort { get; set; }
public int Port { get; set; }
public string Secret { get; set; } = string.Empty;
+ public string Code { get; set; } = string.Empty;
public string ServerOwnerId { get; set; } = string.Empty;
public string ServerId { get; set; } = "ziuMSceapEuNN7wRGQXrZg";
public string WelcomeMessage { get; set; } = string.Empty;
public string ServerName { get; set; } = string.Empty;
- public float DestroyInstanceTimeout { get; set; } = 10f; //set to -1 for no timeout(must close using api), 0 would be for instant close, 10 seconds is default. Less than 6 seconds can cause cfr-3 issues
+ public long DestroyInstanceTimeout { get; set; } = 10000L; //set to -1 for no timeout(must close using api), 0 would be for instant close, 10 seconds is default. Less than 6 seconds can cause cfr-3 issues
public string SetConstantManagerFromUserId { get; set; } = string.Empty; //If a user creates a server using the api and enteres there userId (eg uses discord bot with linked account))
public bool AllowPerPlayerDifficulties { get; set; } = false;
public bool AllowPerPlayerModifiers { get; set; } = false;
public CountdownConfig CountdownConfig { get; set; } = new();
- public int MaxPlayerCount { get; set; }
- public DiscoveryPolicy DiscoveryPolicy { get; set; }
- public InvitePolicy InvitePolicy { get; set; }
- public GameplayServerMode GameplayServerMode { get; set; }
- public SongSelectionMode SongSelectionMode { get; set; }
- public GameplayServerControlSettings GameplayServerControlSettings { get; set; }
+
+ public GameplayServerConfiguration GameplayServerConfiguration { get; set; } = new();
+
+ public BeatmapDifficultyMask BeatmapDifficultyMask { get; set; }
+ public GameplayModifiersMask GameplayModifiersMask { get; set; }
+ public string SongPacksMask { get; set; } = string.Empty;
+
public bool AllowChroma { get; set; }
public bool AllowMappingExtensions { get; set; }
public bool AllowNoodleExtensions { get; set; }
@@ -38,6 +40,6 @@ public sealed class CountdownConfig
{
public long CountdownTimePlayersReady { get; set; } = 30000L;
public long BeatMapStartCountdownTime { get; set; } = 5000L;
- public float ResultsScreenTime { get; set; } = 20.0f;
+ public long ResultsScreenTime { get; set; } = 20000L;
}
}
diff --git a/BeatTogether.DedicatedServer.Kernel/DedicatedInstance.cs b/BeatTogether.DedicatedServer.Kernel/DedicatedInstance.cs
index 34de97c3..df450ed9 100644
--- a/BeatTogether.DedicatedServer.Kernel/DedicatedInstance.cs
+++ b/BeatTogether.DedicatedServer.Kernel/DedicatedInstance.cs
@@ -7,7 +7,6 @@
using BeatTogether.DedicatedServer.Kernel.Abstractions;
using BeatTogether.DedicatedServer.Kernel.Configuration;
using BeatTogether.DedicatedServer.Kernel.ENet;
-using BeatTogether.DedicatedServer.Kernel.Enums;
using BeatTogether.DedicatedServer.Kernel.Extensions;
using BeatTogether.DedicatedServer.Messaging.Enums;
using BeatTogether.DedicatedServer.Messaging.Models;
@@ -20,6 +19,7 @@
using Serilog;
using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
using Microsoft.Extensions.DependencyInjection;
+using BeatTogether.Core.Enums;
namespace BeatTogether.DedicatedServer.Kernel
{
@@ -35,7 +35,7 @@ public sealed class DedicatedInstance : ENetServer, IDedicatedInstance
public int Port => _configuration.Port;
public bool IsRunning => IsAlive;
public long RunTime => (DateTime.UtcNow.Ticks - _startTime) / 10000L;
- public float NoPlayersTime { get; private set; } = -1; //tracks the instance time once there are 0 players in the lobby
+ public long NoPlayersTime { get; private set; } = -1; //tracks the instance time once there are 0 players in the lobby
public MultiplayerGameState State { get; private set; } = MultiplayerGameState.Lobby;
public event Action StopEvent = null!;
@@ -62,7 +62,6 @@ public sealed class DedicatedInstance : ENetServer, IDedicatedInstance
private CancellationTokenSource? _waitForPlayerCts = null;
private CancellationTokenSource? _stopServerCts;
-
public DedicatedInstance(
InstanceConfiguration configuration,
IPlayerRegistry playerRegistry,
@@ -105,13 +104,14 @@ public async Task Start(CancellationToken cancellationToken = default)
$"Endpoint={EndPoint}," +
$"ServerName='{_configuration.ServerName}', " +
$"Secret='{_configuration.Secret}', " +
+ $"Code='{_configuration.Code}', " +
$"ManagerId='{_configuration.ServerOwnerId}', " +
- $"MaxPlayerCount={_configuration.MaxPlayerCount}, " +
- $"DiscoveryPolicy={_configuration.DiscoveryPolicy}, " +
- $"InvitePolicy={_configuration.InvitePolicy}, " +
- $"GameplayServerMode={_configuration.GameplayServerMode}, " +
- $"SongSelectionMode={_configuration.SongSelectionMode}, " +
- $"GameplayServerControlSettings={_configuration.GameplayServerControlSettings})"
+ $"MaxPlayerCount={_configuration.GameplayServerConfiguration.MaxPlayerCount}, " +
+ $"DiscoveryPolicy={_configuration.GameplayServerConfiguration.DiscoveryPolicy}, " +
+ $"InvitePolicy={_configuration.GameplayServerConfiguration.InvitePolicy}, " +
+ $"GameplayServerMode={_configuration.GameplayServerConfiguration.GameplayServerMode}, " +
+ $"SongSelectionMode={_configuration.GameplayServerConfiguration.SongSelectionMode}, " +
+ $"GameplayServerControlSettings={_configuration.GameplayServerConfiguration.GameplayServerControlSettings})"
);
_stopServerCts = new CancellationTokenSource();
@@ -119,7 +119,7 @@ public async Task Start(CancellationToken cancellationToken = default)
{
_waitForPlayerCts = new CancellationTokenSource();
- var waitTimeLimit = (WaitForPlayerTimeLimit + (int)(_configuration.DestroyInstanceTimeout * 1000));
+ var waitTimeLimit = (int)(WaitForPlayerTimeLimit + _configuration.DestroyInstanceTimeout);
_ = Task.Delay(waitTimeLimit, _waitForPlayerCts.Token)
.ContinueWith(t =>
@@ -149,16 +149,17 @@ public async Task Stop(CancellationToken cancellationToken = default)
_logger.Information(
"Stopping dedicated server " +
- $"(Port={Port}," +
+ $"(Port={Port}, " +
$"ServerName='{_configuration.ServerName}', " +
$"Secret='{_configuration.Secret}', " +
+ $"Code='{_configuration.Code}', " +
$"ManagerId='{_configuration.ServerOwnerId}', " +
- $"MaxPlayerCount={_configuration.MaxPlayerCount}, " +
- $"DiscoveryPolicy={_configuration.DiscoveryPolicy}, " +
- $"InvitePolicy={_configuration.InvitePolicy}, " +
- $"GameplayServerMode={_configuration.GameplayServerMode}, " +
- $"SongSelectionMode={_configuration.SongSelectionMode}, " +
- $"GameplayServerControlSettings={_configuration.GameplayServerControlSettings})."
+ $"MaxPlayerCount={_configuration.GameplayServerConfiguration.MaxPlayerCount}, " +
+ $"DiscoveryPolicy={_configuration.GameplayServerConfiguration.DiscoveryPolicy}, " +
+ $"InvitePolicy={_configuration.GameplayServerConfiguration.InvitePolicy}, " +
+ $"GameplayServerMode={_configuration.GameplayServerConfiguration.GameplayServerMode}, " +
+ $"SongSelectionMode={_configuration.GameplayServerConfiguration.SongSelectionMode}, " +
+ $"GameplayServerControlSettings={_configuration.GameplayServerConfiguration.GameplayServerControlSettings})."
);
ServerStateHash.WriteToBitMask("terminating");
PacketDispatcher.SendToNearbyPlayers(new INetSerializable[]{
@@ -188,7 +189,7 @@ public int GetNextSortIndex()
return sortIndex;
_lastSortIndex++;
- if (_lastSortIndex > _configuration.MaxPlayerCount)
+ if (_lastSortIndex > _configuration.GameplayServerConfiguration.MaxPlayerCount)
{
return 0;
}
@@ -248,7 +249,7 @@ public void SetState(MultiplayerGameState state)
goto EndOfTryAccept;
}
- _logger.Debug(
+ _logger.Information(
"Handling connection request though Enet" +
$"(RemoteEndPoint='{endPoint}', " +
$"PlayerSessionId='{connectionRequestData.PlayerSessionId}', " +
@@ -269,7 +270,7 @@ public void SetState(MultiplayerGameState state)
PlayerNoJoin = true;
goto EndOfTryAccept;
}
- if (_playerRegistry.GetPlayerCount() >= _configuration.MaxPlayerCount)
+ if (_playerRegistry.GetPlayerCount() >= _configuration.GameplayServerConfiguration.MaxPlayerCount)
{
_logger.Warning("Master server sent a player to a full server");
PlayerNoJoin = true;
@@ -305,7 +306,7 @@ public void SetState(MultiplayerGameState state)
if (_configuration.ServerName == string.Empty)
{
- _logger.Information("About to update servers name" + _configuration.ServerName);
+ //_logger.Information("About to update servers name" + _configuration.ServerName);
_configuration.ServerName = player.UserName + "'s server";
InstanceConfigUpdated();
_logger.Information("Updated servers name to: " + _configuration.ServerName);
@@ -315,7 +316,7 @@ public void SetState(MultiplayerGameState state)
$"(RemoteEndPoint='{player.Endpoint}', " +
$"ConnectionId={player.ConnectionId}, " +
$"PlayerSessionId='{player.PlayerSessionId}', " +
- $"UserId='{player.UserId}', " +
+ $"UserId='{player.HashedUserId}', " +
$"UserName='{player.UserName}', " +
$"SortIndex={player.SortIndex})."
);
@@ -323,20 +324,23 @@ public void SetState(MultiplayerGameState state)
if (_waitForPlayerCts != null)
_waitForPlayerCts.Cancel();
- if (GetPlayerRegistry().RemoveExtraPlayerSessionData(connectionRequestData.PlayerSessionId, out var ClientVer, out var Platform, out var PlayerPlatformUserId))
+ //UserID, UserName, and session
+ _logger.Information("Applying session data recv from master");
+ if (GetPlayerRegistry().RemoveExtraPlayerSessionDataAndApply(player))
{
- player.ClientVersion = ClientVer;
- player.Platform = (Enums.Platform)Platform;
- player.PlatformUserId = PlayerPlatformUserId;
+ _logger.Information("Successfull session data extraction");
}
+ _logger.Information("Client ver: " + player.PlayerClientVersion.ToString());
+ _logger.Information("Client platform: " + player.PlayerPlatform.ToString());
+ _logger.Information("Client PlatformUserId: " + player.PlatformUserId);
return player;
EndOfTryAccept:
if (PlayerNoJoin)
{
- GetPlayerRegistry().RemoveExtraPlayerSessionData(connectionRequestData.PlayerSessionId, out _, out _, out _);
- string[] Players = _playerRegistry.Players.Select(p => p.UserId).ToArray();
+ GetPlayerRegistry().RemoveExtraPlayerSessionData(connectionRequestData.PlayerSessionId);
+ string[] Players = _playerRegistry.Players.Select(p => p.HashedUserId).ToArray();
PlayerDisconnectBeforeJoining?.Invoke(_configuration.Secret, endPoint, Players);
return null;
}
@@ -367,13 +371,13 @@ public override void OnConnect(EndPoint endPoint)
new PlayerConnectedPacket
{
RemoteConnectionId = player.ConnectionId,
- UserId = player.UserId,
+ UserId = player.HashedUserId,
UserName = player.UserName,
IsConnectionOwner = false
},
new PlayerSortOrderPacket
{
- UserId = player.UserId,
+ UserId = player.HashedUserId,
SortIndex = player.SortIndex
},
new MpNodePoseSyncStatePacket
@@ -392,7 +396,7 @@ public override void OnConnect(EndPoint endPoint)
},
new PlayerSortOrderPacket
{
- UserId = player.UserId,
+ UserId = player.HashedUserId,
SortIndex = player.SortIndex
},
new PlayerConnectedPacket
@@ -403,12 +407,12 @@ public override void OnConnect(EndPoint endPoint)
IsConnectionOwner = true
},
new PlayerStatePacket
- {
- PlayerState = ServerStateHash
- },
+ {
+ PlayerState = ServerStateHash
+ },
new SetIsStartButtonEnabledPacket// Disables start button if they are server owner without selected song
{
- Reason = player.UserId == _configuration.ServerOwnerId ? CannotStartGameReason.NoSongSelected : CannotStartGameReason.None
+ Reason = player.HashedUserId == _configuration.ServerOwnerId ? CannotStartGameReason.NoSongSelected : CannotStartGameReason.None
},
new MpNodePoseSyncStatePacket
{
@@ -428,13 +432,13 @@ public override void OnConnect(EndPoint endPoint)
MakeBigPacketToSendToPlayer.Add(new PlayerConnectedPacket
{
RemoteConnectionId = p.ConnectionId,
- UserId = p.UserId,
+ UserId = p.HashedUserId,
UserName = p.UserName,
IsConnectionOwner = false
});
MakeBigPacketToSendToPlayer.Add(new PlayerSortOrderPacket
{
- UserId = p.UserId,
+ UserId = p.HashedUserId,
SortIndex = p.SortIndex
});
}
@@ -448,6 +452,7 @@ public override void OnConnect(EndPoint endPoint)
INetSerializable[] SendToPlayerFromPlayers = new INetSerializable[2];
SendToPlayerFromPlayers[0] = new PlayerIdentityPacket();
SendToPlayerFromPlayers[1] = new MpPlayerData();
+ //TODO send selected modifiers if they have any, selected beatmap and custom bm packet.
foreach (IPlayer p in _playerRegistry.Players)
{
@@ -459,8 +464,8 @@ public override void OnConnect(EndPoint endPoint)
((PlayerIdentityPacket)SendToPlayerFromPlayers[0]).Random = new ByteArray { Data = p.Random };
((PlayerIdentityPacket)SendToPlayerFromPlayers[0]).PublicEncryptionKey = new ByteArray { Data = p.PublicEncryptionKey };
((MpPlayerData)SendToPlayerFromPlayers[1]).PlatformID = p.PlatformUserId;
- ((MpPlayerData)SendToPlayerFromPlayers[1]).Platform = p.Platform.Convert();
- ((MpPlayerData)SendToPlayerFromPlayers[1]).ClientVersion = p.ClientVersion;
+ ((MpPlayerData)SendToPlayerFromPlayers[1]).Platform = p.PlayerPlatform.Convert();
+ ((MpPlayerData)SendToPlayerFromPlayers[1]).ClientVersion = p.PlayerClientVersion.ToString();
// Send all player avatars and states to just joined player
PacketDispatcher.SendFromPlayerToPlayer(p, player, SendToPlayerFromPlayers, IgnoranceChannelTypes.Reliable);
@@ -468,16 +473,16 @@ public override void OnConnect(EndPoint endPoint)
}
// Update permissions
- if ((_configuration.SetConstantManagerFromUserId == player.UserId || _playerRegistry.GetPlayerCount() == 1) && _configuration.GameplayServerMode == GameplayServerMode.Managed)
+ if ((_configuration.SetConstantManagerFromUserId == player.HashedUserId || _playerRegistry.GetPlayerCount() == 1) && _configuration.GameplayServerConfiguration.GameplayServerMode == Core.Enums.GameplayServerMode.Managed)
SetNewServerOwner(player);
- if (player.Platform == Enums.Platform.Test) //If the player is a bot, send permissions. Normal players request this in a packet when they join
+ if (player.PlayerPlatform == Core.Enums.Platform.Test) //If the player is a bot, send permissions. Normal players request this in a packet when they join
{
bool HasManager = (_playerRegistry.TryGetPlayer(_configuration.ServerOwnerId, out var ServerOwner) && !player.IsServerOwner);
PlayerPermissionConfiguration[] playerPermissionConfigurations = new PlayerPermissionConfiguration[HasManager ? 2 : 1];
playerPermissionConfigurations[0] = new PlayerPermissionConfiguration
{
- UserId = player.UserId,
+ UserId = player.HashedUserId,
IsServerOwner = player.IsServerOwner,
HasRecommendBeatmapsPermission = player.CanRecommendBeatmaps,
HasRecommendGameplayModifiersPermission = player.CanRecommendModifiers,
@@ -487,7 +492,7 @@ public override void OnConnect(EndPoint endPoint)
if (HasManager)
playerPermissionConfigurations[1] = new PlayerPermissionConfiguration
{
- UserId = ServerOwner!.UserId,
+ UserId = ServerOwner!.HashedUserId,
IsServerOwner = ServerOwner!.IsServerOwner,
HasRecommendBeatmapsPermission = ServerOwner!.CanRecommendBeatmaps,
HasRecommendGameplayModifiersPermission = ServerOwner!.CanRecommendModifiers,
@@ -511,17 +516,18 @@ public override void OnConnect(EndPoint endPoint)
PacketDispatcher.SendFromPlayerToPlayer(player, p, new MpPlayerData
{
PlatformID = player.PlatformUserId!,
- Platform = player.Platform.Convert(),
- ClientVersion = player.ClientVersion!
+ Platform = player.PlayerPlatform.Convert(),
+ ClientVersion = player.PlayerClientVersion.ToString()!
}, IgnoranceChannelTypes.Reliable);
}
}
PacketDispatcher.SendToNearbyPlayers(new MpcTextChatPacket
{
- Text = player.UserName + " Joined, Platform: " + player.Platform.ToString() + " Version: " + player.ClientVersion
+ Text = player.UserName + " Joined, Platform: " + player.PlayerPlatform.ToString() + " Version: " + player.PlayerClientVersion.ToString()
}, IgnoranceChannelTypes.Reliable);
+ _logger.Information($"Sent connection data though for (RemoteEndPoint='{endPoint}')");
}
public void DisconnectPlayer(IPlayer player)
@@ -560,7 +566,7 @@ public override void OnDisconnect(EndPoint endPoint)
if(_playerRegistry.GetPlayerCount() != 0)
{
- if (player.IsServerOwner && _configuration.GameplayServerMode == GameplayServerMode.Managed)
+ if (player.IsServerOwner && _configuration.GameplayServerConfiguration.GameplayServerMode == Core.Enums.GameplayServerMode.Managed)
{
// Update permissions
SetNewServerOwner(_playerRegistry.Players[0]);
@@ -577,7 +583,7 @@ public override void OnDisconnect(EndPoint endPoint)
if (_configuration.DestroyInstanceTimeout != -1)
{
_waitForPlayerCts = new CancellationTokenSource();
- _ = Task.Delay((int)(_configuration.DestroyInstanceTimeout * 1000), _waitForPlayerCts.Token).ContinueWith(t =>
+ _ = Task.Delay((int)(_configuration.DestroyInstanceTimeout), _waitForPlayerCts.Token).ContinueWith(t =>
{
if (!t.IsCanceled && _playerRegistry.GetPlayerCount() == 0)
{
@@ -601,7 +607,7 @@ private void SetNewServerOwner(IPlayer NewOwner)
{
if (_playerRegistry.TryGetPlayer(_configuration.ServerOwnerId, out var OldOwner))
{
- _configuration.ServerOwnerId = NewOwner.UserId;
+ _configuration.ServerOwnerId = NewOwner.HashedUserId;
PacketDispatcher.SendToNearbyPlayers(new SetPlayersPermissionConfigurationPacket
{
PermissionConfiguration = new PlayersPermissionConfiguration
@@ -610,7 +616,7 @@ private void SetNewServerOwner(IPlayer NewOwner)
{
new PlayerPermissionConfiguration()
{
- UserId = OldOwner.UserId,
+ UserId = OldOwner.HashedUserId,
IsServerOwner = OldOwner.IsServerOwner,
HasRecommendBeatmapsPermission = OldOwner.CanRecommendBeatmaps,
HasRecommendGameplayModifiersPermission = OldOwner.CanRecommendModifiers,
@@ -619,7 +625,7 @@ private void SetNewServerOwner(IPlayer NewOwner)
},
new PlayerPermissionConfiguration()
{
- UserId = NewOwner.UserId,
+ UserId = NewOwner.HashedUserId,
IsServerOwner = NewOwner.IsServerOwner,
HasRecommendBeatmapsPermission = NewOwner.CanRecommendBeatmaps,
HasRecommendGameplayModifiersPermission = NewOwner.CanRecommendModifiers,
@@ -636,7 +642,7 @@ private void SetNewServerOwner(IPlayer NewOwner)
}
else
{
- _configuration.ServerOwnerId = NewOwner.UserId;
+ _configuration.ServerOwnerId = NewOwner.HashedUserId;
PacketDispatcher.SendToNearbyPlayers(new SetPlayersPermissionConfigurationPacket
{
PermissionConfiguration = new PlayersPermissionConfiguration
@@ -645,7 +651,7 @@ private void SetNewServerOwner(IPlayer NewOwner)
{
new PlayerPermissionConfiguration()
{
- UserId = NewOwner.UserId,
+ UserId = NewOwner.HashedUserId,
IsServerOwner = NewOwner.IsServerOwner,
HasRecommendBeatmapsPermission = NewOwner.CanRecommendBeatmaps,
HasRecommendGameplayModifiersPermission = NewOwner.CanRecommendModifiers,
diff --git a/BeatTogether.DedicatedServer.Kernel/Enums/CountdownState.cs b/BeatTogether.DedicatedServer.Kernel/Enums/CountdownState.cs
deleted file mode 100644
index 5ffa7571..00000000
--- a/BeatTogether.DedicatedServer.Kernel/Enums/CountdownState.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace BeatTogether.DedicatedServer.Kernel.Enums
-{
- public enum CountdownState : byte
- {
- NotCountingDown = 0,
- CountingDown = 1,
- StartBeatmapCountdown = 2,
- WaitingForEntitlement = 3
- }
-}
diff --git a/BeatTogether.DedicatedServer.Kernel/Enums/DiscoveryPolicy.cs b/BeatTogether.DedicatedServer.Kernel/Enums/DiscoveryPolicy.cs
deleted file mode 100644
index 59339aff..00000000
--- a/BeatTogether.DedicatedServer.Kernel/Enums/DiscoveryPolicy.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace BeatTogether.DedicatedServer.Kernel.Enums
-{
- public enum DiscoveryPolicy : byte
- {
- Hidden = 0,
- WithCode = 1,
- Public = 2
- }
-}
diff --git a/BeatTogether.DedicatedServer.Kernel/Enums/GameplayServerControlSettings.cs b/BeatTogether.DedicatedServer.Kernel/Enums/GameplayServerControlSettings.cs
deleted file mode 100644
index 797c68bf..00000000
--- a/BeatTogether.DedicatedServer.Kernel/Enums/GameplayServerControlSettings.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using System;
-
-namespace BeatTogether.DedicatedServer.Kernel.Enums
-{
- [Flags]
- public enum GameplayServerControlSettings
- {
- None = 0,
- AllowModifierSelection = 1,
- AllowSpectate = 2,
- All = 3
- }
-}
diff --git a/BeatTogether.DedicatedServer.Kernel/Enums/GameplayServerMode.cs b/BeatTogether.DedicatedServer.Kernel/Enums/GameplayServerMode.cs
deleted file mode 100644
index 74eaed61..00000000
--- a/BeatTogether.DedicatedServer.Kernel/Enums/GameplayServerMode.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace BeatTogether.DedicatedServer.Kernel.Enums
-{
- public enum GameplayServerMode
- {
- Countdown = 0,
- Managed = 1,
- QuickStartOneSong = 2,
- Tournament = 3
- }
-}
diff --git a/BeatTogether.DedicatedServer.Kernel/Enums/InvitePolicy.cs b/BeatTogether.DedicatedServer.Kernel/Enums/InvitePolicy.cs
deleted file mode 100644
index 2439c019..00000000
--- a/BeatTogether.DedicatedServer.Kernel/Enums/InvitePolicy.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace BeatTogether.DedicatedServer.Kernel.Enums
-{
- public enum InvitePolicy : byte
- {
- OnlyConnectionOwnerCanInvite = 0,
- AnyoneCanInvite = 1
- }
-}
diff --git a/BeatTogether.DedicatedServer.Kernel/Enums/Platform.cs b/BeatTogether.DedicatedServer.Kernel/Enums/Platform.cs
deleted file mode 100644
index f5fc4aa3..00000000
--- a/BeatTogether.DedicatedServer.Kernel/Enums/Platform.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-namespace BeatTogether.DedicatedServer.Kernel.Enums
-{
- public enum Platform : byte
- {
- Test,
- OculusRift,
- OculusQuest,
- Steam,
- PS4,
- PS4Dev,
- PS4Cert,
- Oculus = 1
- }
-}
diff --git a/BeatTogether.DedicatedServer.Kernel/Enums/SongSelectionMode.cs b/BeatTogether.DedicatedServer.Kernel/Enums/SongSelectionMode.cs
deleted file mode 100644
index 7781431e..00000000
--- a/BeatTogether.DedicatedServer.Kernel/Enums/SongSelectionMode.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-namespace BeatTogether.DedicatedServer.Kernel.Enums
-{
- public enum SongSelectionMode
- {
- Vote = 0,
- Random = 1,
- ServerOwnerPicks = 2,
- RandomPlayerPicks = 3,
- ServerPicks = 4
- }
-}
diff --git a/BeatTogether.DedicatedServer.Kernel/Extensions/GamePlatformToMpCorePlatform.cs b/BeatTogether.DedicatedServer.Kernel/Extensions/GamePlatformToMpCorePlatform.cs
index b1022423..4c9b870d 100644
--- a/BeatTogether.DedicatedServer.Kernel/Extensions/GamePlatformToMpCorePlatform.cs
+++ b/BeatTogether.DedicatedServer.Kernel/Extensions/GamePlatformToMpCorePlatform.cs
@@ -4,15 +4,15 @@ namespace BeatTogether.DedicatedServer.Kernel.Extensions
{
public static class GamePlatformToMpCorePlatform
{
- public static Platform Convert(this Enums.Platform gamePlatform)
+ public static Platform Convert(this Core.Enums.Platform gamePlatform)
{
return gamePlatform switch
{
- Enums.Platform.Test => Platform.Unknown,
- Enums.Platform.OculusRift => Platform.OculusPC,
- Enums.Platform.OculusQuest => Platform.OculusQuest,
- Enums.Platform.Steam => Platform.Steam,
- Enums.Platform.PS4 or Enums.Platform.PS4Dev or Enums.Platform.PS4Cert => Platform.PS4,
+ Core.Enums.Platform.Test => Platform.Unknown,
+ Core.Enums.Platform.OculusRift => Platform.OculusPC,
+ Core.Enums.Platform.OculusQuest => Platform.OculusQuest,
+ Core.Enums.Platform.Steam => Platform.Steam,
+ Core.Enums.Platform.PS4 or Core.Enums.Platform.PS4Dev or Core.Enums.Platform.PS4Cert => Platform.PS4,
_ => 0,
};
}
diff --git a/BeatTogether.DedicatedServer.Kernel/Managers/Abstractions/ILobbyManager.cs b/BeatTogether.DedicatedServer.Kernel/Managers/Abstractions/ILobbyManager.cs
index 14b9105e..4d60a0c2 100644
--- a/BeatTogether.DedicatedServer.Kernel/Managers/Abstractions/ILobbyManager.cs
+++ b/BeatTogether.DedicatedServer.Kernel/Managers/Abstractions/ILobbyManager.cs
@@ -1,5 +1,5 @@
-using BeatTogether.DedicatedServer.Kernel.Abstractions;
-using BeatTogether.DedicatedServer.Kernel.Enums;
+using BeatTogether.Core.Enums;
+using BeatTogether.DedicatedServer.Kernel.Abstractions;
using BeatTogether.DedicatedServer.Messaging.Enums;
using BeatTogether.DedicatedServer.Messaging.Models;
using System.Collections.Generic;
diff --git a/BeatTogether.DedicatedServer.Kernel/Managers/GameplayManager.cs b/BeatTogether.DedicatedServer.Kernel/Managers/GameplayManager.cs
index 028bde36..cbfdcea6 100644
--- a/BeatTogether.DedicatedServer.Kernel/Managers/GameplayManager.cs
+++ b/BeatTogether.DedicatedServer.Kernel/Managers/GameplayManager.cs
@@ -1,4 +1,5 @@
-using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
+using BeatTogether.Core.Enums;
+using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
using BeatTogether.DedicatedServer.Kernel.Abstractions;
using BeatTogether.DedicatedServer.Kernel.Enums;
using BeatTogether.DedicatedServer.Kernel.Managers.Abstractions;
@@ -103,7 +104,7 @@ public async void StartSong(CancellationToken cancellationToken)
{
if (player.WantsToPlayNextLevel && !player.IsSpectating && !player.IsBackgrounded && !player.ForceLateJoin)
{
- PlayersAtStart.Add(player.UserId);
+ PlayersAtStart.Add(player.HashedUserId);
}
//if (!player.IsSpectating && !player.ForceLateJoin && !player.IsBackgrounded)
// PlayersAtStart.Add(player.UserId);
@@ -198,8 +199,8 @@ public async void StartSong(CancellationToken cancellationToken)
State = GameplayManagerState.Results;
- if (_levelCompletionResults.Values.Any(result => result.LevelEndStateType == LevelEndStateType.Cleared) && _instance._configuration.CountdownConfig.ResultsScreenTime > 0)
- await Task.Delay((int)(_instance._configuration.CountdownConfig.ResultsScreenTime * 1000), cancellationToken);
+ if (_levelCompletionResults.Values.Any(result => result.LevelEndStateType == LevelEndStateType.Cleared) && _instance._configuration.CountdownConfig.ResultsScreenTime != 0)
+ await Task.Delay((int)_instance._configuration.CountdownConfig.ResultsScreenTime, cancellationToken);
// End gameplay and reset
SetBeatmap(null, new());
@@ -223,17 +224,17 @@ private void ResetValues()
public void HandleGameSceneLoaded(IPlayer player, SetGameplaySceneReadyPacket packet)
{
- if (State == GameplayManagerState.SceneLoad && _sceneReadyTcs.TryGetValue(player.UserId, out var tcs) && !tcs.Task.IsCompleted)
+ if (State == GameplayManagerState.SceneLoad && _sceneReadyTcs.TryGetValue(player.HashedUserId, out var tcs) && !tcs.Task.IsCompleted)
{
- _playerSpecificSettings[player.UserId] = packet.PlayerSpecificSettings;
- PlayerSceneReady(player.UserId);
+ _playerSpecificSettings[player.HashedUserId] = packet.PlayerSpecificSettings;
+ PlayerSceneReady(player.HashedUserId);
return;
}
if (_instance.State != MultiplayerGameState.Game || State == GameplayManagerState.Results || State == GameplayManagerState.None) //Returns player to lobby
{
_packetDispatcher.SendToPlayer(player, new ReturnToMenuPacket(), IgnoranceChannelTypes.Reliable);
- LeaveGameplay(player.UserId);
+ LeaveGameplay(player.HashedUserId);
return;
}
@@ -241,7 +242,7 @@ public void HandleGameSceneLoaded(IPlayer player, SetGameplaySceneReadyPacket pa
{
_packetDispatcher.SendToNearbyPlayers(new SetPlayerDidConnectLatePacket
{
- UserId = player.UserId,
+ UserId = player.HashedUserId,
PlayersAtStart = new PlayerSpecificSettingsAtStart
{
ActivePlayerSpecificSettingsAtStart = _playerSpecificSettings.Values.ToArray()
@@ -254,9 +255,9 @@ public void HandleGameSceneLoaded(IPlayer player, SetGameplaySceneReadyPacket pa
public void HandleGameSongLoaded(IPlayer player)
{
- if (State == GameplayManagerState.SongLoad && _songReadyTcs.TryGetValue(player.UserId, out var tcs) && !tcs.Task.IsCompleted)
+ if (State == GameplayManagerState.SongLoad && _songReadyTcs.TryGetValue(player.HashedUserId, out var tcs) && !tcs.Task.IsCompleted)
{
- PlayerSongReady(player.UserId);
+ PlayerSongReady(player.HashedUserId);
return;
}
if (_instance.State != MultiplayerGameState.Game || State == GameplayManagerState.Results || State == GameplayManagerState.None) //Player is sent back to lobby
@@ -275,10 +276,10 @@ public void HandleGameSongLoaded(IPlayer player)
public void HandleLevelFinished(IPlayer player, LevelFinishedPacket packet)
{
- if (_levelFinishedTcs.TryGetValue(player.UserId, out var tcs) && tcs.Task.IsCompleted)
+ if (_levelFinishedTcs.TryGetValue(player.HashedUserId, out var tcs) && tcs.Task.IsCompleted)
return;
- _levelCompletionResults[player.UserId] = packet.Results.LevelCompletionResults;
- PlayerFinishLevel(player.UserId);
+ _levelCompletionResults[player.HashedUserId] = packet.Results.LevelCompletionResults;
+ PlayerFinishLevel(player.HashedUserId);
}
public void SignalRequestReturnToMenu()
@@ -290,7 +291,7 @@ public void SignalRequestReturnToMenu()
//will set players tasks as done if they leave gameplay due to disconnect or returning to the menu
public void HandlePlayerLeaveGameplay(IPlayer player)
{
- LeaveGameplay(player.UserId);
+ LeaveGameplay(player.HashedUserId);
}
private void LeaveGameplay(string UserId)
diff --git a/BeatTogether.DedicatedServer.Kernel/Managers/LobbyManager.cs b/BeatTogether.DedicatedServer.Kernel/Managers/LobbyManager.cs
index 9d4e3d1f..c30e5b5d 100644
--- a/BeatTogether.DedicatedServer.Kernel/Managers/LobbyManager.cs
+++ b/BeatTogether.DedicatedServer.Kernel/Managers/LobbyManager.cs
@@ -3,10 +3,10 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using BeatTogether.Core.Enums;
using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
using BeatTogether.DedicatedServer.Kernel.Abstractions;
using BeatTogether.DedicatedServer.Kernel.Configuration;
-using BeatTogether.DedicatedServer.Kernel.Enums;
using BeatTogether.DedicatedServer.Kernel.Managers.Abstractions;
using BeatTogether.DedicatedServer.Messaging.Enums;
using BeatTogether.DedicatedServer.Messaging.Models;
@@ -43,7 +43,7 @@ public sealed class LobbyManager : ILobbyManager, IDisposable
private BeatmapIdentifier? _lastBeatmap = null;
private bool _lastSpectatorState;
private bool _LastCanEveryonePlayBeatmap;
- private string _lastManagerId = null!;
+ //private string _lastManagerId = null!;
private readonly CancellationTokenSource _stopCts = new();
private const int LoopTime = 100;
public GameplayModifiers EmptyModifiers { get; } = new();
@@ -151,14 +151,14 @@ public void Update()
if (_instance.State != MultiplayerGameState.Lobby)
return;
- if (!_playerRegistry.TryGetPlayer(_configuration.ServerOwnerId, out var serverOwner) && _configuration.SongSelectionMode == SongSelectionMode.ServerOwnerPicks)
+ if (!_playerRegistry.TryGetPlayer(_configuration.ServerOwnerId, out var serverOwner) && _configuration.GameplayServerConfiguration.SongSelectionMode == SongSelectionMode.ManagerPicks)
return;
UpdateBeatmap(GetSelectedBeatmap(), GetSelectedModifiers());
UpdatePlayersMissingEntitlementsMessages();
- if (_configuration.SongSelectionMode == SongSelectionMode.ServerOwnerPicks)
+ if (_configuration.GameplayServerConfiguration.SongSelectionMode == SongSelectionMode.ManagerPicks)
{
if (_lastBeatmap != SelectedBeatmap || _LastCanEveryonePlayBeatmap != CanEveryonePlayBeatmap || _lastSpectatorState != AllPlayersNotWantToPlayNextLevel)
{
@@ -169,9 +169,9 @@ public void Update()
}
}
- switch (_configuration.SongSelectionMode) //server modes
+ switch (_configuration.GameplayServerConfiguration.SongSelectionMode) //server modes
{
- case SongSelectionMode.ServerOwnerPicks:
+ case SongSelectionMode.ManagerPicks:
CountingDown(serverOwner!.IsReady, !serverOwner.IsReady || AllPlayersNotWantToPlayNextLevel || !CanEveryonePlayBeatmap);
break;
case SongSelectionMode.Vote:
@@ -186,7 +186,7 @@ public void Update()
}
_LastCanEveryonePlayBeatmap = CanEveryonePlayBeatmap;
- _lastManagerId = _configuration.ServerOwnerId;
+ //_lastManagerId = _configuration.ServerOwnerId;
_lastSpectatorState = AllPlayersNotWantToPlayNextLevel;
_lastBeatmap = SelectedBeatmap;
}
@@ -262,7 +262,7 @@ private void UpdateBeatmap(BeatmapIdentifier? beatmap, GameplayModifiers modifie
_packetDispatcher.SendToNearbyPlayers(new SetSelectedBeatmap()
{
Beatmap = SelectedBeatmap
- }, IgnoranceChannelTypes.Reliable);
+ }, IgnoranceChannelTypes.Reliable); //TODO send custom mp packet details
else
_packetDispatcher.SendToNearbyPlayers(new ClearSelectedBeatmap(), IgnoranceChannelTypes.Reliable);
}
@@ -292,7 +292,7 @@ private void UpdatePlayersMissingEntitlementsMessages()
{
PlayersWithoutEntitlements = _playerRegistry.Players
.Where(p => (p.GetEntitlement(player.BeatmapIdentifier.LevelId) is EntitlementStatus.NotOwned) && !p.IsSpectating && p.WantsToPlayNextLevel && !p.IsBackgrounded)
- .Select(p => p.UserId).ToArray()
+ .Select(p => p.HashedUserId).ToArray()
}, IgnoranceChannelTypes.Reliable);
//_logger.Debug("Sent missing entitlement packet");
}
@@ -413,6 +413,7 @@ private void CancelCountdown()
private bool PlayerMapCheck(IPlayer p)
{
+ if(p.BeatmapIdentifier == null) return false;
//If no map hash then treat as base game map for compat reasons and while waiting for a packet
var Passed = string.IsNullOrEmpty(p.MapHash);
//If not passed, then we have difficulties, and if we have the diff we are looking for, then we can check it for requirements.
@@ -423,9 +424,9 @@ private bool PlayerMapCheck(IPlayer p)
private BeatmapIdentifier? GetSelectedBeatmap()
{
- switch(_configuration.SongSelectionMode)
+ switch(_configuration.GameplayServerConfiguration.SongSelectionMode)
{
- case SongSelectionMode.ServerOwnerPicks:
+ case SongSelectionMode.ManagerPicks:
{
if (_playerRegistry.TryGetPlayer(_configuration.ServerOwnerId, out var p) && p.BeatmapIdentifier != null)
{
@@ -463,7 +464,7 @@ private bool PlayerMapCheck(IPlayer p)
{
Random rand = new();
int selectedPlayer = rand.Next(_playerRegistry.GetPlayerCount() - 1);
- RandomlyPickedPlayer = _playerRegistry.Players[selectedPlayer].UserId;
+ RandomlyPickedPlayer = _playerRegistry.Players[selectedPlayer].HashedUserId;
return PlayerMapCheck(_playerRegistry.Players[selectedPlayer]) ? _playerRegistry.Players[selectedPlayer].BeatmapIdentifier : null;
}
return SelectedBeatmap;
@@ -478,9 +479,9 @@ private bool PlayerMapCheck(IPlayer p)
private GameplayModifiers GetSelectedModifiers()
{
- switch(_configuration.SongSelectionMode)
+ switch(_configuration.GameplayServerConfiguration.SongSelectionMode)
{
- case SongSelectionMode.ServerOwnerPicks:
+ case SongSelectionMode.ManagerPicks:
if(_playerRegistry.TryGetPlayer(_configuration.ServerOwnerId, out var ServerOwner))
return ServerOwner.Modifiers;
return EmptyModifiers;
diff --git a/BeatTogether.DedicatedServer.Kernel/PacketDispatcher.cs b/BeatTogether.DedicatedServer.Kernel/PacketDispatcher.cs
index 3c69f147..5f2d3c30 100644
--- a/BeatTogether.DedicatedServer.Kernel/PacketDispatcher.cs
+++ b/BeatTogether.DedicatedServer.Kernel/PacketDispatcher.cs
@@ -31,7 +31,7 @@ public PacketDispatcher(
private void SendInternal(IPlayer player, ref SpanBuffer writer, IgnoranceChannelTypes deliveryMethod)
{
- _logger.Verbose($"Sending packet (SenderId={ServerId}) to player {player.ConnectionId} with UserId {player.UserId}");
+ _logger.Verbose($"Sending packet (SenderId={ServerId}) to player {player.ConnectionId} with UserId {player.HashedUserId}");
_serverInstance.Send(player, writer.Data, deliveryMethod);
}
diff --git a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetCountdownEndTimePacketHandler.cs b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetCountdownEndTimePacketHandler.cs
index 009f4872..b15f7e66 100644
--- a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetCountdownEndTimePacketHandler.cs
+++ b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetCountdownEndTimePacketHandler.cs
@@ -1,4 +1,5 @@
-using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
+using BeatTogether.Core.Enums;
+using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
using BeatTogether.DedicatedServer.Kernel.Abstractions;
using BeatTogether.DedicatedServer.Kernel.Managers.Abstractions;
using BeatTogether.DedicatedServer.Messaging.Packets.MultiplayerSession.MenuRpc;
@@ -26,7 +27,7 @@ public override void Handle(IPlayer sender, GetCountdownEndTimePacket packet)
$"Handling packet of type '{nameof(GetCountdownEndTimePacket)}' " +
$"(SenderId={sender.ConnectionId} CountdownTime={_lobbyManager.CountdownEndTime})."
);
- if(_lobbyManager.CountDownState == Enums.CountdownState.CountingDown)
+ if(_lobbyManager.CountDownState == CountdownState.CountingDown)
_packetDispatcher.SendToPlayer(sender, new SetCountdownEndTimePacket
{
CountdownTime = _lobbyManager.CountdownEndTime
diff --git a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetIsInLobbyPacketHandler.cs b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetIsInLobbyPacketHandler.cs
index 0412283d..0ce108bf 100644
--- a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetIsInLobbyPacketHandler.cs
+++ b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetIsInLobbyPacketHandler.cs
@@ -1,7 +1,7 @@
-using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
+using BeatTogether.Core.Enums;
+using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
using BeatTogether.DedicatedServer.Kernel.Abstractions;
using BeatTogether.DedicatedServer.Kernel.Managers.Abstractions;
-using BeatTogether.DedicatedServer.Messaging.Enums;
using BeatTogether.DedicatedServer.Messaging.Packets.MultiplayerSession.MenuRpc;
using Serilog;
diff --git a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetPlayersPermissionConfigurationPacketHandler.cs b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetPlayersPermissionConfigurationPacketHandler.cs
index bddaaaf6..2d8dd787 100644
--- a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetPlayersPermissionConfigurationPacketHandler.cs
+++ b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetPlayersPermissionConfigurationPacketHandler.cs
@@ -35,7 +35,7 @@ public override void Handle(IPlayer sender, GetPlayersPermissionConfigurationPac
PlayerPermissionConfiguration[] playerPermissionConfigurations = new PlayerPermissionConfiguration[HasManager ? 2 : 1];
playerPermissionConfigurations[0] = new PlayerPermissionConfiguration
{
- UserId = sender.UserId,
+ UserId = sender.HashedUserId,
IsServerOwner = sender.IsServerOwner,
HasRecommendBeatmapsPermission = sender.CanRecommendBeatmaps,
HasRecommendGameplayModifiersPermission = sender.CanRecommendModifiers,
@@ -45,7 +45,7 @@ public override void Handle(IPlayer sender, GetPlayersPermissionConfigurationPac
if (HasManager)
playerPermissionConfigurations[1] = new PlayerPermissionConfiguration
{
- UserId = ServerOwner!.UserId,
+ UserId = ServerOwner!.HashedUserId,
IsServerOwner = ServerOwner!.IsServerOwner,
HasRecommendBeatmapsPermission = ServerOwner!.CanRecommendBeatmaps,
HasRecommendGameplayModifiersPermission = ServerOwner!.CanRecommendModifiers,
diff --git a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetRecommendedBeatmapPacketHandler.cs b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetRecommendedBeatmapPacketHandler.cs
index 99deced7..e75fdfbf 100644
--- a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetRecommendedBeatmapPacketHandler.cs
+++ b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetRecommendedBeatmapPacketHandler.cs
@@ -22,8 +22,8 @@ public override void Handle(IPlayer sender, GetRecommendedBeatmapPacket packet)
$"Handling packet of type '{nameof(GetRecommendedBeatmapPacket)}' " +
$"(SenderId={sender.ConnectionId})."
);
-
- if(sender.BeatmapIdentifier != null)
+ //TODO send custom packet details
+ if (sender.BeatmapIdentifier != null)
_packetDispatcher.SendToPlayer(sender, new SetRecommendedBeatmapPacket
{
BeatmapIdentifier = sender.BeatmapIdentifier
diff --git a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetSelectedBeatmapHandler.cs b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetSelectedBeatmapHandler.cs
index b3f2a60e..33f6646f 100644
--- a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetSelectedBeatmapHandler.cs
+++ b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetSelectedBeatmapHandler.cs
@@ -1,4 +1,5 @@
-using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
+using BeatTogether.Core.Enums;
+using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
using BeatTogether.DedicatedServer.Kernel.Abstractions;
using BeatTogether.DedicatedServer.Kernel.Managers.Abstractions;
using BeatTogether.DedicatedServer.Messaging.Packets.MultiplayerSession.MenuRpc;
@@ -32,7 +33,8 @@ public override void Handle(IPlayer sender, GetSelectedBeatmap packet)
$"Handling packet of type '{nameof(GetSelectedBeatmap)}' " +
$"(SenderId={sender.ConnectionId})."
);
- if(_instance.State == Messaging.Enums.MultiplayerGameState.Lobby && _lobbyManager.SelectedBeatmap != null)
+ //TODO send custom packet details
+ if (_instance.State != MultiplayerGameState.Game && _lobbyManager.SelectedBeatmap != null)
{
_packetDispatcher.SendToPlayer(sender, new SetSelectedBeatmap
{
@@ -40,7 +42,7 @@ public override void Handle(IPlayer sender, GetSelectedBeatmap packet)
}, IgnoranceChannelTypes.Reliable);
return;
}
- if (_instance.State == Messaging.Enums.MultiplayerGameState.Game && _gameplayManager.CurrentBeatmap != null)
+ if (_instance.State == MultiplayerGameState.Game && _gameplayManager.CurrentBeatmap != null)
{
_packetDispatcher.SendToPlayer(sender, new SetSelectedBeatmap
{
diff --git a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetSelectedGameplayModifiersHandler.cs b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetSelectedGameplayModifiersHandler.cs
index 0c32148e..1979e4fe 100644
--- a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetSelectedGameplayModifiersHandler.cs
+++ b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetSelectedGameplayModifiersHandler.cs
@@ -1,4 +1,5 @@
-using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
+using BeatTogether.Core.Enums;
+using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
using BeatTogether.DedicatedServer.Kernel.Abstractions;
using BeatTogether.DedicatedServer.Kernel.Managers.Abstractions;
using BeatTogether.DedicatedServer.Messaging.Packets.MultiplayerSession.MenuRpc;
@@ -32,7 +33,7 @@ public override void Handle(IPlayer sender, GetSelectedGameplayModifiers packet)
$"Handling packet of type '{nameof(GetSelectedGameplayModifiers)}' " +
$"(SenderId={sender.ConnectionId})."
);
- if(_instance.State == Messaging.Enums.MultiplayerGameState.Lobby && _lobbyManager.SelectedModifiers != _lobbyManager.EmptyModifiers)
+ if(_instance.State != MultiplayerGameState.Game && _lobbyManager.SelectedModifiers != _lobbyManager.EmptyModifiers)
{
_packetDispatcher.SendToPlayer(sender, new SetSelectedGameplayModifiers
{
@@ -40,7 +41,7 @@ public override void Handle(IPlayer sender, GetSelectedGameplayModifiers packet)
}, IgnoranceChannelTypes.Reliable);
return;
}
- if (_instance.State == Messaging.Enums.MultiplayerGameState.Game)
+ if (_instance.State == MultiplayerGameState.Game)
{
_packetDispatcher.SendToPlayer(sender, new SetSelectedGameplayModifiers
{
diff --git a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetStartedLevelPacketHandler.cs b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetStartedLevelPacketHandler.cs
index d26f228d..10910223 100644
--- a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetStartedLevelPacketHandler.cs
+++ b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetStartedLevelPacketHandler.cs
@@ -1,4 +1,5 @@
-using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
+using BeatTogether.Core.Enums;
+using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
using BeatTogether.DedicatedServer.Kernel.Abstractions;
using BeatTogether.DedicatedServer.Kernel.Configuration;
using BeatTogether.DedicatedServer.Kernel.Enums;
@@ -7,7 +8,6 @@
using BeatTogether.DedicatedServer.Messaging.Models;
using BeatTogether.DedicatedServer.Messaging.Packets.MultiplayerSession.MenuRpc;
using Serilog;
-using System.Linq;
namespace BeatTogether.DedicatedServer.Kernel.PacketHandlers.MultiplayerSession.MenuRpc
{
diff --git a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/SetIsReadyPacketHandler.cs b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/SetIsReadyPacketHandler.cs
index aa06740a..db533291 100644
--- a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/SetIsReadyPacketHandler.cs
+++ b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/SetIsReadyPacketHandler.cs
@@ -1,8 +1,8 @@
-using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
+using BeatTogether.Core.Enums;
+using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
using BeatTogether.DedicatedServer.Kernel.Abstractions;
using BeatTogether.DedicatedServer.Kernel.Enums;
using BeatTogether.DedicatedServer.Kernel.Managers.Abstractions;
-using BeatTogether.DedicatedServer.Messaging.Enums;
using BeatTogether.DedicatedServer.Messaging.Packets.MultiplayerSession.MenuRpc;
using Serilog;
diff --git a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/SetRecommendedBeatmapPacketHandler.cs b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/SetRecommendedBeatmapPacketHandler.cs
index 7115e2a4..adf46185 100644
--- a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/SetRecommendedBeatmapPacketHandler.cs
+++ b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/SetRecommendedBeatmapPacketHandler.cs
@@ -40,6 +40,7 @@ public override void Handle(IPlayer sender, SetRecommendedBeatmapPacket packet)
}
sender.BeatmapIdentifier = packet.BeatmapIdentifier;
sender.UpdateEntitlement = true;
+ //Our custom mpbeatmap packet stuff gets sent anyway
//TODO apply this logic to all entitlement checks, and check it works well. Might need to send everyones entitlements to a player when they select a map
_packetDispatcher.SendToPlayers(_playerRegistry.Players.Where(p => p.GetEntitlement(sender.BeatmapIdentifier.LevelId) == Messaging.Enums.EntitlementStatus.Unknown).ToArray(), new GetIsEntitledToLevelPacket
{
diff --git a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MultiplayerCore/DediPacketSetNewManagerHandler.cs b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MultiplayerCore/DediPacketSetNewManagerHandler.cs
index 721568a2..9367b7f8 100644
--- a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MultiplayerCore/DediPacketSetNewManagerHandler.cs
+++ b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MultiplayerCore/DediPacketSetNewManagerHandler.cs
@@ -1,4 +1,5 @@
-using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
+using BeatTogether.Core.Enums;
+using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
using BeatTogether.DedicatedServer.Kernel.Abstractions;
using BeatTogether.DedicatedServer.Kernel.Configuration;
using BeatTogether.DedicatedServer.Messaging.Models;
@@ -33,7 +34,7 @@ public override void Handle(IPlayer sender, DediPacketSetNewManagerPacket packet
$"(SenderId={sender.ConnectionId})."
);
- if (sender.IsServerOwner && _configuration.GameplayServerMode == Enums.GameplayServerMode.Managed)
+ if (sender.IsServerOwner && _configuration.GameplayServerConfiguration.GameplayServerMode == GameplayServerMode.Managed)
{
_configuration.ServerOwnerId = packet.NewManagerID;
@@ -43,7 +44,7 @@ public override void Handle(IPlayer sender, DediPacketSetNewManagerPacket packet
{
PlayersPermission = _playerRegistry.Players.Select(x => new PlayerPermissionConfiguration
{
- UserId = x.UserId,
+ UserId = x.HashedUserId,
IsServerOwner = x.IsServerOwner,
HasRecommendBeatmapsPermission = x.CanRecommendBeatmaps,
HasRecommendGameplayModifiersPermission = x.CanRecommendModifiers,
diff --git a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MultiplayerCore/GetExtraPlayerDataPacketHandler.cs b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MultiplayerCore/GetExtraPlayerDataPacketHandler.cs
index 6f34093a..cb6d0746 100644
--- a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MultiplayerCore/GetExtraPlayerDataPacketHandler.cs
+++ b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MultiplayerCore/GetExtraPlayerDataPacketHandler.cs
@@ -26,8 +26,8 @@ public override void Handle(IPlayer sender, MpPlayerData packet)
_PacketDispatcher.SendFromPlayerToPlayer(Player, sender, new MpPlayerData()
{
PlatformID = Player.PlatformUserId,
- Platform = Player.Platform.Convert(),
- ClientVersion = Player.ClientVersion
+ Platform = Player.PlayerPlatform.Convert(),
+ ClientVersion = Player.PlayerClientVersion.ToString(),
}, IgnoranceChannelTypes.Reliable);
}
}
diff --git a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/PlayerSortOrderPacketHandler.cs b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/PlayerSortOrderPacketHandler.cs
index 049ebb16..9bf14e7d 100644
--- a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/PlayerSortOrderPacketHandler.cs
+++ b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/PlayerSortOrderPacketHandler.cs
@@ -21,7 +21,7 @@ public override void Handle(IPlayer sender, PlayerSortOrderPacket packet)
$"Handling packet of type '{nameof(PlayerSortOrderPacket)}' " +
$"(SenderId={sender.ConnectionId})."
);
- if (sender.UserId == packet.UserId && sender.SortIndex != packet.SortIndex) //If they send themselves as being in the wrong place, correct them. Although this probably shouldnt have a handler
+ if (sender.HashedUserId == packet.UserId && sender.SortIndex != packet.SortIndex) //If they send themselves as being in the wrong place, correct them. Although this probably shouldnt have a handler
{
packet.SortIndex = sender.SortIndex;
_packetDispatcher.SendToPlayer(sender, packet, IgnoranceChannelTypes.Reliable);
diff --git a/BeatTogether.DedicatedServer.Kernel/Player.cs b/BeatTogether.DedicatedServer.Kernel/Player.cs
index 8105162b..2cf4b44f 100644
--- a/BeatTogether.DedicatedServer.Kernel/Player.cs
+++ b/BeatTogether.DedicatedServer.Kernel/Player.cs
@@ -2,6 +2,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Net;
+using BeatTogether.Core.Enums;
using BeatTogether.DedicatedServer.Kernel.Abstractions;
using BeatTogether.DedicatedServer.Kernel.Enums;
using BeatTogether.DedicatedServer.Kernel.Types;
@@ -16,9 +17,9 @@ public sealed class Player : IPlayer
public IDedicatedInstance Instance { get; }
public byte ConnectionId { get; }
public byte RemoteConnectionId => 0;
- public string UserId { get; }
+ public string HashedUserId { get; set; }
public string UserName { get; }
- public string PlayerSessionId { get; }
+ public string PlayerSessionId { get; set; }
public uint ENetPeerId { get; set; }
@@ -29,8 +30,8 @@ public sealed class Player : IPlayer
public int SortIndex { get; set; }
public byte[]? Random { get; set; }
public byte[]? PublicEncryptionKey { get; set; }
- public string ClientVersion { get; set; } = "Unknown";
- public Platform Platform { get; set; } = Platform.Test; //Unknown
+ public Version PlayerClientVersion { get; set; } = new();
+ public Platform PlayerPlatform { get; set; } = Platform.Test; //Unknown
public string PlatformUserId { get; set; } = "";
public MultiplayerAvatarsData Avatar { get; set; } = new();
public bool IsReady { get; set; }
@@ -39,13 +40,13 @@ public sealed class Player : IPlayer
public BeatmapIdentifier? BeatmapIdentifier { get; set; } = null;
public GameplayModifiers Modifiers { get; set; } = new();
public PlayerStateHash State { get; set; } = new();
- public bool IsServerOwner => UserId == Instance._configuration.ServerOwnerId;
+ public bool IsServerOwner => HashedUserId == Instance._configuration.ServerOwnerId;
public bool CanRecommendBeatmaps => true;// This check is wrong as GameplayServerControlSettings is None in Quickplay to disable Modifier selection //Instance._configuration.GameplayServerControlSettings is not GameplayServerControlSettings.None;
public bool CanRecommendModifiers =>
- Instance._configuration.GameplayServerControlSettings is GameplayServerControlSettings.AllowModifierSelection or GameplayServerControlSettings.All;
- public bool CanKickVote => UserId == Instance._configuration.ServerOwnerId;
+ Instance._configuration.GameplayServerConfiguration.GameplayServerControlSettings is GameplayServerControlSettings.AllowModifierSelection or GameplayServerControlSettings.All;
+ public bool CanKickVote => HashedUserId == Instance._configuration.ServerOwnerId;
public bool CanInvite =>
- Instance._configuration.DiscoveryPolicy is DiscoveryPolicy.WithCode or DiscoveryPolicy.Public;
+ Instance._configuration.GameplayServerConfiguration.DiscoveryPolicy is DiscoveryPolicy.WithCode or DiscoveryPolicy.Public;
public bool ForceLateJoin { get; set; } = false; //Used to force trouble players to late join a mp game/tell them to spectate
public bool IsPlayer => State.Contains("player"); //If the user is a player
@@ -67,7 +68,7 @@ public Player(EndPoint endPoint, IDedicatedInstance instance,
Endpoint = endPoint;
Instance = instance;
ConnectionId = connectionId;
- UserId = userId;
+ HashedUserId = userId;
UserName = userName;
PlayerSessionId = playerSessionId;
_AccessLevel = accessLevel;
@@ -103,7 +104,7 @@ public void SetEntitlement(string levelId, EntitlementStatus entitlement)
public bool UpdateEntitlement { get; set; } = false;
public string MapHash { get; set; } = string.Empty;
- public Dictionary BeatmapDifficultiesRequirements { get; set; }
+ public Dictionary BeatmapDifficultiesRequirements { get; set; } = new();
public long TicksAtLastSyncStateDelta { get; set; } = 0; //33ms gaps for 30/sec, 66ms gap for 15/sec
public long TicksAtLastSyncState { get; set; } = 0;
diff --git a/BeatTogether.DedicatedServer.Kernel/PlayerRegistry.cs b/BeatTogether.DedicatedServer.Kernel/PlayerRegistry.cs
index 12acbe03..9d4f69b5 100644
--- a/BeatTogether.DedicatedServer.Kernel/PlayerRegistry.cs
+++ b/BeatTogether.DedicatedServer.Kernel/PlayerRegistry.cs
@@ -16,38 +16,36 @@ public sealed class PlayerRegistry : IPlayerRegistry
private readonly Dictionary _playersByConnectionId = new();
private readonly Dictionary _playersByUserId = new();
- private readonly object pendingPlayerSessionData_Lock = new();
- private readonly Dictionary _pendingPlayerSessionData = new();
+ private readonly Dictionary _pendingPlayerSessionData = new();
- public void AddExtraPlayerSessionData(string playerSessionId, string ClientVersion, byte PlatformId, string PlayerPlatformUserId)
+ public void AddExtraPlayerSessionData(Core.Abstractions.IPlayer playerSessionData)
{
- lock (pendingPlayerSessionData_Lock)
- {
- _pendingPlayerSessionData[playerSessionId] = (ClientVersion, PlatformId, PlayerPlatformUserId);
- }
+ _pendingPlayerSessionData[playerSessionData.PlayerSessionId] = playerSessionData;
}
- public bool RemoveExtraPlayerSessionData(string playerSessionId, out string ClientVersion, out byte Platform, out string PlayerPlatformUserId)
+ public bool RemoveExtraPlayerSessionDataAndApply(Core.Abstractions.IPlayer playerSessionData)
{
- lock (pendingPlayerSessionData_Lock)
+
+ if (_pendingPlayerSessionData.Remove(playerSessionData.PlayerSessionId, out var Value))
{
- if (_pendingPlayerSessionData.Remove(playerSessionId, out var Values))
- {
- ClientVersion = Values.Item1;
- Platform = Values.Item2;
- PlayerPlatformUserId = Values.Item3;
- return true;
- }
- ClientVersion = "ERROR";
- Platform = 0;
- PlayerPlatformUserId = "ERROR";
- return false;
+ playerSessionData.PlayerClientVersion = Value.PlayerClientVersion;
+ playerSessionData.PlayerPlatform = Value.PlayerPlatform;
+ playerSessionData.PlatformUserId = Value.PlatformUserId;
+ return true;
}
+ playerSessionData.PlayerClientVersion = new System.Version("1.0.0");
+ playerSessionData.PlayerPlatform = Core.Enums.Platform.Test;
+ playerSessionData.PlatformUserId = "ERROR";
+ return false;
}
+ public bool RemoveExtraPlayerSessionData(string playerSessionId)
+ {
+ return _pendingPlayerSessionData.Remove(playerSessionId, out _);
+ }
private int _PlayerCount = 0;
@@ -73,7 +71,7 @@ public bool AddPlayer(IPlayer player)
{
lock (PlayerDictionaries_Lock)
{
- if (_playersByUserId.TryAdd(player.UserId, player))
+ if (_playersByUserId.TryAdd(player.HashedUserId, player))
{
_playersByRemoteEndPoint.TryAdd(player.Endpoint, player);
_playersByConnectionId.TryAdd(player.ConnectionId, player);
@@ -89,7 +87,7 @@ public void RemovePlayer(IPlayer player)
{
lock (PlayerDictionaries_Lock)
{
- if (_playersByUserId.Remove(player.UserId, out _))
+ if (_playersByUserId.Remove(player.HashedUserId, out _))
{
_playersByRemoteEndPoint.Remove(player.Endpoint, out _);
_playersByConnectionId.Remove(player.ConnectionId, out _);
diff --git a/BeatTogether.DedicatedServer.Messaging/BeatTogether.DedicatedServer.Messaging.csproj b/BeatTogether.DedicatedServer.Messaging/BeatTogether.DedicatedServer.Messaging.csproj
index 29409fe6..9ed81f49 100644
--- a/BeatTogether.DedicatedServer.Messaging/BeatTogether.DedicatedServer.Messaging.csproj
+++ b/BeatTogether.DedicatedServer.Messaging/BeatTogether.DedicatedServer.Messaging.csproj
@@ -7,6 +7,7 @@
+
diff --git a/BeatTogether.DedicatedServer.Messaging/Enums/MultiplayerGameState.cs b/BeatTogether.DedicatedServer.Messaging/Enums/MultiplayerGameState.cs
deleted file mode 100644
index d2e4238d..00000000
--- a/BeatTogether.DedicatedServer.Messaging/Enums/MultiplayerGameState.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace BeatTogether.DedicatedServer.Messaging.Enums
-{
- public enum MultiplayerGameState
- {
- None = 0,
- Lobby = 1,
- Game = 2
- }
-}
diff --git a/BeatTogether.DedicatedServer.Messaging/Packets/MultiplayerSession/MenuRpc/SetMultiplayerGameStatePacket.cs b/BeatTogether.DedicatedServer.Messaging/Packets/MultiplayerSession/MenuRpc/SetMultiplayerGameStatePacket.cs
index d6d2b986..8727e360 100644
--- a/BeatTogether.DedicatedServer.Messaging/Packets/MultiplayerSession/MenuRpc/SetMultiplayerGameStatePacket.cs
+++ b/BeatTogether.DedicatedServer.Messaging/Packets/MultiplayerSession/MenuRpc/SetMultiplayerGameStatePacket.cs
@@ -1,7 +1,7 @@
using BeatTogether.DedicatedServer.Messaging.Abstractions;
-using BeatTogether.DedicatedServer.Messaging.Enums;
using BeatTogether.Extensions;
using BeatTogether.DedicatedServer.Messaging.Util;
+using BeatTogether.Core.Enums;
namespace BeatTogether.DedicatedServer.Messaging.Packets.MultiplayerSession.MenuRpc
{
diff --git a/BeatTogether.DedicatedServer.Node/Abstractions/IInstanceFactory.cs b/BeatTogether.DedicatedServer.Node/Abstractions/IInstanceFactory.cs
deleted file mode 100644
index 65845bcd..00000000
--- a/BeatTogether.DedicatedServer.Node/Abstractions/IInstanceFactory.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using BeatTogether.DedicatedServer.Interface.Models;
-using BeatTogether.DedicatedServer.Kernel.Abstractions;
-
-namespace BeatTogether.DedicatedServer.Node.Abstractions
-{
- public interface IInstanceFactory
- {
- public IDedicatedInstance? CreateInstance(
- string secret,
- string managerId,
- GameplayServerConfiguration config,
- bool permanentManager = false,//If a user links there account to discord and uses a bot to make a lobby, then can enter there userId
- float instanceTimeout = 0f,
- string ServerName = "",
- long resultScreenTime = 20,
- long BeatmapStartTime = 5,
- long PlayersReadyCountdownTime = 0,
- bool AllowPerPlayerModifiers = false,
- bool AllowPerPlayerDifficulties = false,
- bool AllowChroma = true,
- bool AllowME = true,
- bool AllowNE = true
- );
- }
-}
diff --git a/BeatTogether.DedicatedServer.Node/Abstractions/IInstanceRegistry.cs b/BeatTogether.DedicatedServer.Node/Abstractions/IInstanceRegistry.cs
deleted file mode 100644
index 99a5928c..00000000
--- a/BeatTogether.DedicatedServer.Node/Abstractions/IInstanceRegistry.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using BeatTogether.DedicatedServer.Kernel.Abstractions;
-using System.Diagnostics.CodeAnalysis;
-
-namespace BeatTogether.DedicatedServer.Node.Abstractions
-{
- public interface IInstanceRegistry
- {
- public bool AddInstance(IDedicatedInstance instance);
- public bool RemoveInstance(IDedicatedInstance instance);
- public bool TryGetInstance(string secret, [MaybeNullWhen(false)] out IDedicatedInstance instance);
- }
-}
diff --git a/BeatTogether.DedicatedServer.Node/Abstractions/INodeService.cs b/BeatTogether.DedicatedServer.Node/Abstractions/INodeService.cs
deleted file mode 100644
index 33e39416..00000000
--- a/BeatTogether.DedicatedServer.Node/Abstractions/INodeService.cs
+++ /dev/null
@@ -1,6 +0,0 @@
-namespace BeatTogether.DedicatedServer.Node.Abstractions
-{
- public interface INodeService
- {
- }
-}
diff --git a/BeatTogether.DedicatedServer.Node/BeatTogether.DedicatedServer.Node.csproj b/BeatTogether.DedicatedServer.Node/BeatTogether.DedicatedServer.Node.csproj
index 7da5c8c4..06d26b42 100644
--- a/BeatTogether.DedicatedServer.Node/BeatTogether.DedicatedServer.Node.csproj
+++ b/BeatTogether.DedicatedServer.Node/BeatTogether.DedicatedServer.Node.csproj
@@ -12,13 +12,13 @@
-
-
+
+
-
+
diff --git a/BeatTogether.DedicatedServer.Node/Configuration/NodeConfiguration.cs b/BeatTogether.DedicatedServer.Node/Configuration/NodeConfiguration.cs
index eafd2838..75b264b2 100644
--- a/BeatTogether.DedicatedServer.Node/Configuration/NodeConfiguration.cs
+++ b/BeatTogether.DedicatedServer.Node/Configuration/NodeConfiguration.cs
@@ -4,9 +4,7 @@ namespace BeatTogether.DedicatedServer.Node.Configuration
{
public sealed class NodeConfiguration
{
- public string HostName { get; set; } = "127.0.0.1";
- public Version NodeVersion { get; } = new Version(1,6,0);
- public int BasePort { get; set; } = 30000;
- public int MaximumSlots { get; set; } = 10000;
+ public string HostName { get; set; } = "192.168.0.21";
+ public Version NodeVersion { get; } = new Version(2,0,0);
}
}
diff --git a/BeatTogether.DedicatedServer.Node/Extensions/HostBuilderExtensions.cs b/BeatTogether.DedicatedServer.Node/Extensions/HostBuilderExtensions.cs
index 3c2137ee..1395bdfe 100644
--- a/BeatTogether.DedicatedServer.Node/Extensions/HostBuilderExtensions.cs
+++ b/BeatTogether.DedicatedServer.Node/Extensions/HostBuilderExtensions.cs
@@ -1,10 +1,6 @@
-using System.Security.Cryptography;
using Autobus;
+using BeatTogether.Core.ServerMessaging;
using BeatTogether.DedicatedServer.Interface;
-using BeatTogether.DedicatedServer.Kernel.Abstractions;
-using BeatTogether.DedicatedServer.Kernel.Extensions;
-using BeatTogether.DedicatedServer.Kernel.Providers;
-using BeatTogether.DedicatedServer.Node.Abstractions;
using BeatTogether.DedicatedServer.Node.Configuration;
using BeatTogether.Extensions;
using Microsoft.Extensions.DependencyInjection;
@@ -19,19 +15,12 @@ public static IHostBuilder UseDedicatedServerNode(this IHostBuilder hostBuilder)
.ConfigureAppConfiguration()
.UseSerilog()
.UseAutobus()
- .UseDedicatedInstances()
.ConfigureServices((hostBuilderContext, services) =>
services
- .AddCoreSecurity()
.AddConfiguration("Node")
- .AddSingleton(RandomNumberGenerator.Create())
- .AddSingleton()
- .AddSingleton()
- .AddSingleton()
- .AddSingleton()
- .AddSingleton()
- .AddServiceKernel()
- .AddHostedService()
+ .AddServiceKernel()
+ .AddSingleton()
+ .AddHostedService()
);
}
}
\ No newline at end of file
diff --git a/BeatTogether.DedicatedServer.Node/ForwardServerEventsLayer.cs b/BeatTogether.DedicatedServer.Node/ForwardServerEventsLayer.cs
new file mode 100644
index 00000000..f455cae4
--- /dev/null
+++ b/BeatTogether.DedicatedServer.Node/ForwardServerEventsLayer.cs
@@ -0,0 +1,57 @@
+using Autobus;
+using BeatTogether.Core.Abstractions;
+using BeatTogether.Core.ServerMessaging;
+using BeatTogether.DedicatedServer.Interface.Events;
+using System;
+using System.Linq;
+
+namespace BeatTogether.DedicatedServer.Node
+{
+ public class ForwardServerEventsLayer : ILayer1
+ {
+
+ private readonly IAutobus _autobus;
+ //private readonly ILogger _logger = Log.ForContext();
+
+ public ForwardServerEventsLayer(
+ IAutobus autobus)
+ {
+ _autobus = autobus;
+ }
+
+ public void InstanceClosed(IServerInstance instance)
+ {
+ _autobus.Publish(new MatchmakingServerStoppedEvent(instance.Secret));
+ }
+
+ public void InstanceConfigChanged(IServerInstance instance)
+ {
+ _autobus.Publish(new UpdateInstanceConfigEvent(new Core.ServerMessaging.Models.Server(instance)));
+ }
+
+ public void InstanceCreated(IServerInstance instance)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void InstancePlayersChanged(IServerInstance instance)
+ {
+ _autobus.Publish(new UpdatePlayersEvent(instance.Secret, instance.PlayerHashes.ToArray()));
+ }
+
+ public void InstanceStateChanged(IServerInstance instance)
+ {
+ _autobus.Publish(new ServerInGameplayEvent(instance.Secret, instance.GameState));
+ }
+
+ public void PlayerJoined(IServerInstance instance, IPlayer player)
+ {
+ _autobus.Publish(new PlayerJoinEvent(instance.Secret, player.HashedUserId));
+ }
+
+ public void PlayerLeft(IServerInstance instance, IPlayer player)
+ {
+ _autobus.Publish(new PlayerLeaveServerEvent(instance.Secret, player.HashedUserId));
+ }
+ }
+}
diff --git a/BeatTogether.DedicatedServer.Node/InstanceFactory.cs b/BeatTogether.DedicatedServer.Node/InstanceFactory.cs
deleted file mode 100644
index a7bb7f78..00000000
--- a/BeatTogether.DedicatedServer.Node/InstanceFactory.cs
+++ /dev/null
@@ -1,88 +0,0 @@
-using System;
-using BeatTogether.DedicatedServer.Interface.Models;
-using BeatTogether.DedicatedServer.Kernel.Abstractions;
-using BeatTogether.DedicatedServer.Kernel.Configuration;
-using BeatTogether.DedicatedServer.Kernel.Enums;
-using BeatTogether.DedicatedServer.Node.Abstractions;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace BeatTogether.DedicatedServer.Node
-{
- public sealed class InstanceFactory : IInstanceFactory
- {
- private readonly IInstanceRegistry _instanceRegistry;
- private readonly IServiceProvider _serviceProvider;
- private readonly IPortAllocator _portAllocator;
-
- public InstanceFactory(
- IInstanceRegistry instanceRegistry,
- IServiceProvider serviceProvider,
- IPortAllocator portAllocator)
- {
- _instanceRegistry = instanceRegistry;
- _serviceProvider = serviceProvider;
- _portAllocator = portAllocator;
- }
-
- public IDedicatedInstance? CreateInstance(
- string secret,
- string managerId,
- GameplayServerConfiguration config,
- bool permanentManager,
- float instanceTimeout,
- string ServerName,
- long resultScreenTime,
- long BeatmapStartTime,
- long PlayersReadyCountdownTime,
- bool AllowPerPlayerModifiers,
- bool AllowPerPlayerDifficulties,
- bool AllowChroma,
- bool AllowME,
- bool AllowNE
- )
- {
- var Port = _portAllocator.AcquirePort();
-
- if (!Port.HasValue)
- return null;
-
- var scope = _serviceProvider.CreateScope();
-
- var instanceConfig = scope.ServiceProvider.GetRequiredService();
- instanceConfig.Port = (int)Port!;
- instanceConfig.Secret = secret;
- instanceConfig.ServerOwnerId = managerId;
- instanceConfig.MaxPlayerCount = Math.Min(config.MaxPlayerCount,250); //max size of 254, id 127 routes packets to all, max is 250, last 4 ID's will be reserved for future features
- instanceConfig.DiscoveryPolicy = (DiscoveryPolicy)config.DiscoveryPolicy;
- instanceConfig.InvitePolicy = (InvitePolicy)config.InvitePolicy;
- instanceConfig.GameplayServerMode = (GameplayServerMode)config.GameplayServerMode;
- instanceConfig.SongSelectionMode = (SongSelectionMode)config.SongSelectionMode;
- instanceConfig.GameplayServerControlSettings = (GameplayServerControlSettings)config.GameplayServerControlSettings;
- instanceConfig.DestroyInstanceTimeout = instanceTimeout;
- instanceConfig.ServerName = ServerName;
- instanceConfig.CountdownConfig.BeatMapStartCountdownTime = Math.Max(BeatmapStartTime,0);
- instanceConfig.CountdownConfig.ResultsScreenTime = Math.Max(resultScreenTime,0);
- instanceConfig.AllowChroma = AllowChroma;
- instanceConfig.AllowMappingExtensions = AllowME;
- instanceConfig.AllowNoodleExtensions = AllowNE;
- instanceConfig.AllowPerPlayerDifficulties = AllowPerPlayerDifficulties;
- instanceConfig.AllowPerPlayerModifiers = AllowPerPlayerModifiers;
- if (permanentManager)
- instanceConfig.SetConstantManagerFromUserId = managerId;
- instanceConfig.CountdownConfig.CountdownTimePlayersReady = Math.Max(PlayersReadyCountdownTime,0L);
- if (instanceConfig.CountdownConfig.CountdownTimePlayersReady == 0L)
- instanceConfig.CountdownConfig.CountdownTimePlayersReady = instanceConfig.GameplayServerMode == GameplayServerMode.Managed ? 15000L : 30000L;
- var instance = scope.ServiceProvider.GetRequiredService();
- if (!_instanceRegistry.AddInstance(instance))
- return null;
- instance.StopEvent += HandleStopEvent;
- return instance;
- }
-
- private void HandleStopEvent(IDedicatedInstance Instance)
- {
- _instanceRegistry.RemoveInstance(Instance);
- _portAllocator.ReleasePort(Instance.Port);
- }
- }
-}
diff --git a/BeatTogether.DedicatedServer.Node/InstanceRegistry.cs b/BeatTogether.DedicatedServer.Node/InstanceRegistry.cs
deleted file mode 100644
index 5929bfa9..00000000
--- a/BeatTogether.DedicatedServer.Node/InstanceRegistry.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using BeatTogether.DedicatedServer.Kernel.Abstractions;
-using BeatTogether.DedicatedServer.Node.Abstractions;
-using System.Collections.Concurrent;
-using System.Diagnostics.CodeAnalysis;
-
-namespace BeatTogether.DedicatedServer.Node
-{
- public sealed class InstanceRegistry : IInstanceRegistry
- {
- private readonly ConcurrentDictionary _instances = new();
-
- public bool AddInstance(IDedicatedInstance instance) =>
- _instances.TryAdd(instance._configuration.Secret, instance);
-
- public bool RemoveInstance(IDedicatedInstance instance) =>
- _instances.TryRemove(instance._configuration.Secret, out _);
-
- public bool TryGetInstance(string secret, [MaybeNullWhen(false)] out IDedicatedInstance instance) =>
- _instances.TryGetValue(secret, out instance);
- }
-}
diff --git a/BeatTogether.DedicatedServer.Node/MasterServerEventHandler.cs b/BeatTogether.DedicatedServer.Node/MasterServerEventHandler.cs
deleted file mode 100644
index cfd91018..00000000
--- a/BeatTogether.DedicatedServer.Node/MasterServerEventHandler.cs
+++ /dev/null
@@ -1,110 +0,0 @@
-using System;
-using System.Net;
-using System.Threading;
-using System.Threading.Tasks;
-using Autobus;
-using BeatTogether.DedicatedServer.Interface.Events;
-using BeatTogether.DedicatedServer.Kernel.Abstractions;
-using BeatTogether.DedicatedServer.Node.Abstractions;
-using BeatTogether.DedicatedServer.Node.Configuration;
-using BeatTogether.MasterServer.Interface.Events;
-using Microsoft.Extensions.Hosting;
-using Serilog;
-
-namespace BeatTogether.DedicatedServer.Node
-{
- public sealed class MasterServerEventHandler : IHostedService
- {
- private readonly IAutobus _autobus;
- private readonly ILogger _logger = Log.ForContext();
- private readonly NodeConfiguration _configuration;
- private readonly IInstanceRegistry _instanceRegistry;
-
- public MasterServerEventHandler(
- IAutobus autobus,
- NodeConfiguration nodeConfiguration,
- IInstanceRegistry instanceRegistry)
- {
- _autobus = autobus;
- _configuration = nodeConfiguration;
- _instanceRegistry = instanceRegistry;
- }
-
- #region Start/Stop
-
- public Task StartAsync(CancellationToken cancellationToken)
- {
- _autobus.Subscribe(HandlePlayerConnectedToMatchmaking);
- _autobus.Subscribe(HandleCheckNode);
- _autobus.Subscribe(HandleDisconnectPlayer);
- _autobus.Subscribe(HandleCloseServer);
- _autobus.Publish(new NodeStartedEvent(_configuration.HostName, _configuration.NodeVersion.ToString()));
- _logger.Information("Dedicated node version: " + _configuration.NodeVersion.ToString() + " starting: " + _configuration.HostName);
- return Task.CompletedTask;
- }
-
- public Task StopAsync(CancellationToken cancellationToken)
- {
- _autobus.Unsubscribe(HandlePlayerConnectedToMatchmaking);
- _autobus.Unsubscribe(HandleCheckNode);
- _autobus.Unsubscribe(HandleDisconnectPlayer);
- _autobus.Unsubscribe(HandleCloseServer);
- return Task.CompletedTask;
- }
-
- #endregion
-
- #region Handlers
-
- private Task HandlePlayerConnectedToMatchmaking(PlayerConnectedToMatchmakingServerEvent @event)
- {
- if (@event.NodeEndpoint != _configuration.HostName)
- return Task.CompletedTask;
-
- //var remoteEndPoint = IPEndPoint.Parse(@event.RemoteEndPoint);
- var playerSessionId = @event.PlayerSessionId;
- var serverSecret = @event.Secret;
- var PlayerClientVersion = @event.ClientVersion;
- var PlayerPlatform = @event.Platform;
- var PlayerPlatformUserId = @event.PlatformUserId;
-
-
- TryGetDedicatedInstance(serverSecret)?.GetPlayerRegistry().AddExtraPlayerSessionData(playerSessionId, PlayerClientVersion, PlayerPlatform, PlayerPlatformUserId);
-
- _autobus.Publish(new NodeReceivedPlayerEncryptionEvent(_configuration.HostName, @event.RemoteEndPoint));
- return Task.CompletedTask;
- }
-
- private Task HandleCheckNode(CheckNodesEvent checkNodesEvent)
- {
- _autobus.Publish(new NodeOnlineEvent(_configuration.HostName, _configuration.NodeVersion.ToString()));
- return Task.CompletedTask;
- }
-
- private Task HandleDisconnectPlayer(DisconnectPlayerFromMatchmakingServerEvent disconnectEvent)
- {
- var instance = TryGetDedicatedInstance(disconnectEvent.Secret);
- if (instance != null && instance.GetPlayerRegistry().TryGetPlayer(disconnectEvent.UserId, out var player))
- {
- instance.DisconnectPlayer(player);
- }
-
- return Task.CompletedTask;
- }
-
- private Task HandleCloseServer(CloseServerInstanceEvent closeEvent)
- {
- TryGetDedicatedInstance(closeEvent.Secret)?.Stop();
- return Task.CompletedTask;
- }
-
- #endregion
-
- #region Util
-
- private IDedicatedInstance? TryGetDedicatedInstance(string secret) =>
- _instanceRegistry.TryGetInstance(secret, out var instance) ? instance : null;
-
- #endregion
- }
-}
diff --git a/BeatTogether.DedicatedServer.Node/Models/PlayerFromMessage.cs b/BeatTogether.DedicatedServer.Node/Models/PlayerFromMessage.cs
new file mode 100644
index 00000000..c6b39aef
--- /dev/null
+++ b/BeatTogether.DedicatedServer.Node/Models/PlayerFromMessage.cs
@@ -0,0 +1,24 @@
+using BeatTogether.Core.Abstractions;
+using BeatTogether.Core.Enums;
+using System;
+
+namespace BeatTogether.DedicatedServer.Node.Models
+{
+ public class PlayerFromMessage : IPlayer
+ {
+ public string HashedUserId { get; set; }
+ public string PlatformUserId { get; set; }
+ public string PlayerSessionId { get; set; }
+ public Platform PlayerPlatform { get; set; }
+ public Version PlayerClientVersion { get; set; }
+
+ public PlayerFromMessage(Core.ServerMessaging.Models.Player player)
+ {
+ HashedUserId = player.HashedUserId;
+ PlatformUserId = player.PlatformUserId;
+ PlayerSessionId = player.PlayerSessionId;
+ PlayerPlatform = player.PlayerPlatform;
+ PlayerClientVersion = new Version(player.PlayerClientVersion);
+ }
+ }
+}
diff --git a/BeatTogether.DedicatedServer.Node/Models/ServerFromMessage.cs b/BeatTogether.DedicatedServer.Node/Models/ServerFromMessage.cs
new file mode 100644
index 00000000..45c6907e
--- /dev/null
+++ b/BeatTogether.DedicatedServer.Node/Models/ServerFromMessage.cs
@@ -0,0 +1,81 @@
+using BeatTogether.Core.Abstractions;
+using BeatTogether.Core.Enums;
+using BeatTogether.Core.Models;
+using System.Collections.Generic;
+using System.Net;
+
+namespace BeatTogether.DedicatedServer.Node.Models
+{
+ public class ServerFromMessage : IServerInstance
+ {
+ public string ServerName { get; set; }
+
+ public string Secret { get; set; }
+
+ public string Code { get; set; }
+
+ public string InstanceId { get; set; }
+
+ public MultiplayerGameState GameState { get; set; }
+
+ public BeatmapDifficultyMask BeatmapDifficultyMask { get; set; }
+
+ public GameplayModifiersMask GameplayModifiersMask { get; set; }
+
+ public GameplayServerConfiguration GameplayServerConfiguration { get; set; }
+
+ public string SongPackMasks { get; set; }
+
+ public string ManagerId { get; set; }
+
+ public bool PermanentManager { get; set; }
+
+ public long ServerStartJoinTimeout { get; set; }
+
+ public bool NeverCloseServer { get; set; }
+
+ public long ResultScreenTime { get; set; }
+
+ public long BeatmapStartTime { get; set; }
+
+ public long PlayersReadyCountdownTime { get; set; }
+
+ public bool AllowPerPlayerModifiers { get; set; }
+
+ public bool AllowPerPlayerDifficulties { get; set; }
+
+ public bool AllowChroma { get; set; }
+
+ public bool AllowME { get; set; }
+
+ public bool AllowNE { get; set; }
+
+ public IPEndPoint InstanceEndPoint { get; set; } = null!;
+ public HashSet PlayerHashes { get; set; } = null!;
+
+ public ServerFromMessage(Core.ServerMessaging.Models.Server instance)
+ {
+ ServerName = instance.ServerName;
+ Secret = instance.Secret;
+ Code = instance.Code;
+ InstanceId = instance.InstanceId;
+ GameState = instance.GameState;
+ BeatmapDifficultyMask = instance.BeatmapDifficultyMask;
+ GameplayModifiersMask = instance.GameplayModifiersMask;
+ GameplayServerConfiguration = instance.GameplayServerConfiguration;
+ SongPackMasks = instance.SongPackMasks;
+ ManagerId = instance.ManagerId;
+ PermanentManager = instance.PermanentManager;
+ ServerStartJoinTimeout = instance.ServerStartJoinTimeout;
+ NeverCloseServer = instance.NeverCloseServer;
+ ResultScreenTime = instance.ResultScreenTime;
+ BeatmapStartTime = instance.BeatmapStartTime;
+ PlayersReadyCountdownTime = instance.PlayersReadyCountdownTime;
+ AllowPerPlayerDifficulties = instance.AllowPerPlayerDifficulties;
+ AllowPerPlayerModifiers = instance.AllowPerPlayerModifiers;
+ AllowChroma = instance.AllowChroma;
+ AllowME = instance.AllowME;
+ AllowNE = instance.AllowNE;
+ }
+ }
+}
diff --git a/BeatTogether.DedicatedServer.Node/NodeMessageEventHandler.cs b/BeatTogether.DedicatedServer.Node/NodeMessageEventHandler.cs
new file mode 100644
index 00000000..3bdb89b3
--- /dev/null
+++ b/BeatTogether.DedicatedServer.Node/NodeMessageEventHandler.cs
@@ -0,0 +1,100 @@
+using System.Threading;
+using System.Threading.Tasks;
+using Autobus;
+using BeatTogether.Core.Abstractions;
+using BeatTogether.Core.Extensions;
+using BeatTogether.Core.ServerMessaging.Models;
+using BeatTogether.DedicatedServer.Interface.Events;
+using BeatTogether.DedicatedServer.Node.Configuration;
+using BeatTogether.DedicatedServer.Node.Models;
+using BeatTogether.MasterServer.Interface.Events;
+using BinaryRecords;
+using Microsoft.Extensions.Hosting;
+using Serilog;
+
+namespace BeatTogether.DedicatedServer.Node
+{
+ public sealed class NodeMessageEventHandler : IHostedService
+ {
+ private readonly IAutobus _autobus;
+ private readonly ILogger _logger = Log.ForContext();
+ private readonly NodeConfiguration _configuration;
+ private readonly ILayer2 _Layer2;
+
+ public NodeMessageEventHandler(
+ IAutobus autobus,
+ NodeConfiguration nodeConfiguration,
+ ILayer2 layer2)
+ {
+ _autobus = autobus;
+ _configuration = nodeConfiguration;
+ _Layer2 = layer2;
+
+ BinarySerializer.AddGeneratorProvider(
+ (Player value, ref BinaryBufferWriter buffer) => BinaryBufferWriterExtensions.WritePlayer(ref buffer, value),
+ (ref BinaryBufferReader bufferReader) => BinaryBufferReaderExtensions.ReadPlayer(ref bufferReader)
+ );
+ BinarySerializer.AddGeneratorProvider(
+ (Server value, ref BinaryBufferWriter buffer) => BinaryBufferWriterExtensions.WriteServer(ref buffer, value),
+ (ref BinaryBufferReader bufferReader) => BinaryBufferReaderExtensions.ReadServer(ref bufferReader)
+ );
+ }
+
+ #region Start/Stop
+
+ public Task StartAsync(CancellationToken cancellationToken)
+ {
+ _autobus.Subscribe(HandlePlayerConnectedToMatchmaking);
+ _autobus.Subscribe(HandleCheckNode);
+ _autobus.Subscribe(HandleDisconnectPlayer);
+ _autobus.Subscribe(HandleCloseServer);
+ _autobus.Publish(new NodeStartedEvent(_configuration.HostName, _configuration.NodeVersion.ToString()));
+ _logger.Information("Dedicated node version: " + _configuration.NodeVersion.ToString() + " starting: " + _configuration.HostName);
+ return Task.CompletedTask;
+ }
+
+ public Task StopAsync(CancellationToken cancellationToken)
+ {
+ _autobus.Unsubscribe(HandlePlayerConnectedToMatchmaking);
+ _autobus.Unsubscribe(HandleCheckNode);
+ _autobus.Unsubscribe(HandleDisconnectPlayer);
+ _autobus.Unsubscribe(HandleCloseServer);
+ return Task.CompletedTask;
+ }
+
+ #endregion
+
+ #region Handlers
+
+ private async Task HandlePlayerConnectedToMatchmaking(PlayerSessionDataSendToDediEvent SessionDataEvent)
+ {
+ if (SessionDataEvent.NodeEndpoint != _configuration.HostName)
+ return;
+
+ Core.Abstractions.IPlayer player = new PlayerFromMessage(SessionDataEvent.Player);
+ if (!await _Layer2.SetPlayerSessionData(SessionDataEvent.serverInstanceSecret, player))
+ return;
+
+ _autobus.Publish(new NodeReceivedPlayerSessionDataEvent(_configuration.HostName, SessionDataEvent.Player.PlayerSessionId));
+ return;
+ }
+
+ private Task HandleCheckNode(CheckNodesEvent checkNodesEvent)
+ {
+ _autobus.Publish(new NodeOnlineEvent(_configuration.HostName, _configuration.NodeVersion.ToString()));
+ return Task.CompletedTask;
+ }
+
+ private async Task HandleDisconnectPlayer(DisconnectPlayerFromMatchmakingServerEvent disconnectEvent)
+ {
+ await _Layer2.DisconnectPlayer(disconnectEvent.Secret, disconnectEvent.HashedUserId);
+ }
+
+ private async Task HandleCloseServer(CloseServerInstanceEvent closeEvent)
+ {
+ await _Layer2.CloseInstance(closeEvent.Secret);
+ }
+
+ #endregion
+ }
+}
diff --git a/BeatTogether.DedicatedServer.Node/NodeService.cs b/BeatTogether.DedicatedServer.Node/NodeService.cs
index 90f5f161..b97098f5 100644
--- a/BeatTogether.DedicatedServer.Node/NodeService.cs
+++ b/BeatTogether.DedicatedServer.Node/NodeService.cs
@@ -1,123 +1,49 @@
-using System;
-using System.Net;
-using System.Threading.Tasks;
-using Autobus;
+using System.Threading.Tasks;
+using BeatTogether.Core.Abstractions;
using BeatTogether.DedicatedServer.Interface;
-using BeatTogether.DedicatedServer.Interface.Events;
using BeatTogether.DedicatedServer.Interface.Requests;
using BeatTogether.DedicatedServer.Interface.Responses;
-using BeatTogether.DedicatedServer.Kernel.Abstractions;
-using BeatTogether.DedicatedServer.Messaging.Models;
-using BeatTogether.DedicatedServer.Node.Abstractions;
-using BeatTogether.DedicatedServer.Node.Configuration;
+using BeatTogether.DedicatedServer.Node.Models;
using Serilog;
namespace BeatTogether.DedicatedServer.Node
{
- public sealed class NodeService : IMatchmakingService
+ public sealed class NodeMatchmakingService : IMatchmakingService
{
- private readonly NodeConfiguration _configuration;
- private readonly IInstanceFactory _instanceFactory;
- private readonly IAutobus _autobus;
- private readonly ILogger _logger = Log.ForContext();
+ private readonly ILayer2 _Layer2;
+ private readonly ILogger _logger = Log.ForContext();
- public NodeService(
- NodeConfiguration configuration,
- IInstanceFactory instanceFactory,
- IAutobus autobus)
+ public NodeMatchmakingService(
+ ILayer2 layer2)
{
- _configuration = configuration;
- _instanceFactory = instanceFactory;
- _autobus = autobus;
+ _Layer2 = layer2;
}
public async Task CreateMatchmakingServer(CreateMatchmakingServerRequest request)
{
- _logger.Debug($"Received request to create matchmaking server. " +
- $"(Secret={request.Secret}, " +
- $"ManagerId={request.ManagerId}, " +
- $"MaxPlayerCount={request.Configuration.MaxPlayerCount}, " +
- $"DiscoveryPolicy={request.Configuration.DiscoveryPolicy}, " +
- $"InvitePolicy={request.Configuration.InvitePolicy}, " +
- $"GameplayServerMode={request.Configuration.GameplayServerMode}, " +
- $"SongSelectionMode={request.Configuration.SongSelectionMode}, " +
- $"GameplayServerControlSettings={request.Configuration.GameplayServerControlSettings})");
+ _logger.Debug($"Received request to create matchmaking server from node messaging. " +
+ $"(Secret={request.Server.Secret}, " +
+ $"Code={request.Server.Code}, " +
+ $"ManagerId={request.Server.ManagerId}, " +
+ $"MaxPlayerCount={request.Server.GameplayServerConfiguration.MaxPlayerCount}, " +
+ $"DiscoveryPolicy={request.Server.GameplayServerConfiguration.DiscoveryPolicy}, " +
+ $"InvitePolicy={request.Server.GameplayServerConfiguration.InvitePolicy}, " +
+ $"GameplayServerMode={request.Server.GameplayServerConfiguration.GameplayServerMode}, " +
+ $"SongSelectionMode={request.Server.GameplayServerConfiguration.SongSelectionMode}, " +
+ $"GameplayServerControlSettings={request.Server.GameplayServerConfiguration.GameplayServerControlSettings})");
- var matchmakingServer = _instanceFactory.CreateInstance(
- request.Secret,
- request.ManagerId,
- request.Configuration,
- request.PermanentManager,
- request.Timeout,
- request.ServerName,
- (long)request.ResultScreenTime,
- ((long)request.BeatmapStartTime) * 1000,
- ((long)request.PlayersReadyCountdownTime) * 1000,
- request.AllowPerPlayerModifiers,
- request.AllowPerPlayerDifficulties,
- request.AllowChroma,
- request.AllowME,
- request.AllowNE
- );
- if (matchmakingServer is null)
- return new CreateMatchmakingServerResponse(CreateMatchmakingServerError.NoAvailableSlots, string.Empty, Array.Empty(), Array.Empty());
+ IServerInstance serverInstance = new ServerFromMessage(request.Server);
- matchmakingServer.PlayerConnectedEvent += HandleUpdatePlayerEvent;
- matchmakingServer.PlayerDisconnectedEvent += HandlePlayerDisconnectEvent;
- matchmakingServer.PlayerDisconnectBeforeJoining += HandlePlayerLeaveBeforeJoining;
- matchmakingServer.StopEvent += HandleStopEvent;
- matchmakingServer.GameIsInLobby += HandleGameInLobbyEvent;
- matchmakingServer.UpdateInstanceEvent += HandleConfigChangeEvent;
- await matchmakingServer.Start();
+ var result = await _Layer2.CreateInstance(serverInstance);
+
+ if(!result)
+ return new CreateMatchmakingServerResponse(CreateMatchmakingServerError.NoAvailableSlots, string.Empty);
+
return new CreateMatchmakingServerResponse(
CreateMatchmakingServerError.None,
- $"{_configuration.HostName}:{matchmakingServer.Port}",
- Array.Empty(),
- Array.Empty()
+ $"{serverInstance.InstanceEndPoint}"
);
}
-
-
- #region EventHandlers
-
- private void HandleGameInLobbyEvent(string secret, bool state)
- {
- _autobus.Publish(new ServerInGameplayEvent(secret, !state, string.Empty));
- }
-
- private void HandleConfigChangeEvent(IDedicatedInstance inst)
- {
- _autobus.Publish(new UpdateInstanceConfigEvent(
- inst._configuration.Secret,
- inst._configuration.ServerName,
- new Interface.Models.GameplayServerConfiguration(
- inst._configuration.MaxPlayerCount,
- (Interface.Enums.DiscoveryPolicy)inst._configuration.DiscoveryPolicy,
- (Interface.Enums.InvitePolicy)inst._configuration.InvitePolicy,
- (Interface.Enums.GameplayServerMode)inst._configuration.GameplayServerMode,
- (Interface.Enums.SongSelectionMode)inst._configuration.SongSelectionMode,
- (Interface.Enums.GameplayServerControlSettings)inst._configuration.GameplayServerControlSettings
- )
- ));
- }
-
- private void HandleStopEvent(IDedicatedInstance inst)
- {
- _autobus.Publish(new MatchmakingServerStoppedEvent(inst._configuration.Secret));
- }
- private void HandleUpdatePlayerEvent(IPlayer player)
- {
- _autobus.Publish(new PlayerJoinEvent(player.Instance._configuration.Secret, ((IPEndPoint)player.Endpoint).ToString(), player.UserId));
- }
- private void HandlePlayerDisconnectEvent(IPlayer player)
- {
- _autobus.Publish(new PlayerLeaveServerEvent(player.Instance._configuration.Secret, player.UserId, ((IPEndPoint)player.Endpoint).ToString()));
- }
- private void HandlePlayerLeaveBeforeJoining(string Secret, EndPoint endPoint, string[] Players)
- {
- _autobus.Publish(new UpdatePlayersEvent(Secret, Players));
- }
- #endregion
}
}
\ No newline at end of file
diff --git a/BeatTogether.DedicatedServer.sln b/BeatTogether.DedicatedServer.sln
index ed19c0a4..ef5f959d 100644
--- a/BeatTogether.DedicatedServer.sln
+++ b/BeatTogether.DedicatedServer.sln
@@ -13,7 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeatTogether.DedicatedServe
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeatTogether.DedicatedServer.Node", "BeatTogether.DedicatedServer.Node\BeatTogether.DedicatedServer.Node.csproj", "{D2B3DC3B-FECD-4E06-8B20-7A60A0BE3C2E}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeatTogether.DedicatedServer.Ignorance", "BeatTogether.DedicatedServer.Ignorance\BeatTogether.DedicatedServer.Ignorance.csproj", "{775C10CC-FE88-41DD-A9E3-7F66CBA87470}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeatTogether.DedicatedServer.Ignorance", "BeatTogether.DedicatedServer.Ignorance\BeatTogether.DedicatedServer.Ignorance.csproj", "{775C10CC-FE88-41DD-A9E3-7F66CBA87470}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeatTogether.DedicatedServer.Instancing", "BeatTogether.DedicatedServer.Instancing\BeatTogether.DedicatedServer.Instancing.csproj", "{2C9A5AAD-D817-4410-BBF2-2EA765C31C1B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -45,6 +47,10 @@ Global
{775C10CC-FE88-41DD-A9E3-7F66CBA87470}.Debug|Any CPU.Build.0 = Debug|Any CPU
{775C10CC-FE88-41DD-A9E3-7F66CBA87470}.Release|Any CPU.ActiveCfg = Release|Any CPU
{775C10CC-FE88-41DD-A9E3-7F66CBA87470}.Release|Any CPU.Build.0 = Release|Any CPU
+ {2C9A5AAD-D817-4410-BBF2-2EA765C31C1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2C9A5AAD-D817-4410-BBF2-2EA765C31C1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2C9A5AAD-D817-4410-BBF2-2EA765C31C1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2C9A5AAD-D817-4410-BBF2-2EA765C31C1B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/BeatTogether.DedicatedServer/BeatTogether.DedicatedServer.csproj b/BeatTogether.DedicatedServer/BeatTogether.DedicatedServer.csproj
index f9defa64..d2e91a76 100644
--- a/BeatTogether.DedicatedServer/BeatTogether.DedicatedServer.csproj
+++ b/BeatTogether.DedicatedServer/BeatTogether.DedicatedServer.csproj
@@ -29,6 +29,7 @@
+
diff --git a/BeatTogether.DedicatedServer/Program.cs b/BeatTogether.DedicatedServer/Program.cs
index aacc2d0b..f6a45f76 100644
--- a/BeatTogether.DedicatedServer/Program.cs
+++ b/BeatTogether.DedicatedServer/Program.cs
@@ -1,4 +1,5 @@
-using BeatTogether.DedicatedServer.Node.Extensions;
+using BeatTogether.DedicatedServer.Instancing.Extensions;
+using BeatTogether.DedicatedServer.Node.Extensions;
using Microsoft.Extensions.Hosting;
namespace BeatTogether.DedicatedServer
@@ -9,6 +10,6 @@ public static void Main(string[] args) =>
CreateHostBuilder(args).Build().Run();
public static IHostBuilder CreateHostBuilder(string[] args) =>
- Host.CreateDefaultBuilder(args).UseDedicatedServerNode();
+ Host.CreateDefaultBuilder(args).UseDedicatedServerNode().UseDedicatedServerInstancing();
}
}