diff --git a/BeatTogether.DedicatedServer.Kernel/Configuration/InstanceConfiguration.cs b/BeatTogether.DedicatedServer.Kernel/Configuration/InstanceConfiguration.cs index 8dd9ed63..384652f0 100644 --- a/BeatTogether.DedicatedServer.Kernel/Configuration/InstanceConfiguration.cs +++ b/BeatTogether.DedicatedServer.Kernel/Configuration/InstanceConfiguration.cs @@ -28,15 +28,15 @@ public sealed class InstanceConfiguration public bool DisableNotes { get; set; } public bool ForceEnableNotes { get; set; } = false; public bool ForceStartMode { get; set; } = false; - public float SendPlayersWithoutEntitlementToSpectateTimeout { get; set; } = 30f; + public long SendPlayersWithoutEntitlementToSpectateTimeout { get; set; } = 30000L; public int MaxLengthCommand { get; set; } = 200; public bool ApplyNoFailModifier { get; set; } = true; } public sealed class CountdownConfig { - public long CountdownTimePlayersReady { get; set; } = 30; - public long BeatMapStartCountdownTime { get; set; } = 5; + public long CountdownTimePlayersReady { get; set; } = 30000L; + public long BeatMapStartCountdownTime { get; set; } = 5000L; public float ResultsScreenTime { get; set; } = 20.0f; } } diff --git a/BeatTogether.DedicatedServer.Kernel/Managers/GameplayManager.cs b/BeatTogether.DedicatedServer.Kernel/Managers/GameplayManager.cs index 3561048f..7d490ac9 100644 --- a/BeatTogether.DedicatedServer.Kernel/Managers/GameplayManager.cs +++ b/BeatTogether.DedicatedServer.Kernel/Managers/GameplayManager.cs @@ -29,7 +29,7 @@ public sealed class GameplayManager : IGameplayManager, IDisposable public BeatmapIdentifier? CurrentBeatmap { get; private set; } = null; public GameplayModifiers CurrentModifiers { get; private set; } = new(); - private const long SongStartDelay = 100; + private const long SongStartDelay = 500L; private const float SceneLoadTimeLimit = 15.0f; private const float SongLoadTimeLimit = 15.0f; @@ -165,8 +165,8 @@ public async void StartSong(CancellationToken cancellationToken) } // Start song and wait for finish - _songStartTime = (_instance.RunTime + SongStartDelay + (StartDelay * 2))*2; - _logger.Verbose($"Song start time: {_songStartTime}"); + _songStartTime = (_instance.RunTime + SongStartDelay + (StartDelay * 2)); + _logger.Verbose($"SongStartTime: {_songStartTime} RunTime: {_instance.RunTime}"); State = GameplayManagerState.Gameplay; diff --git a/BeatTogether.DedicatedServer.Kernel/Managers/LobbyManager.cs b/BeatTogether.DedicatedServer.Kernel/Managers/LobbyManager.cs index 2a3e0034..e3184677 100644 --- a/BeatTogether.DedicatedServer.Kernel/Managers/LobbyManager.cs +++ b/BeatTogether.DedicatedServer.Kernel/Managers/LobbyManager.cs @@ -248,6 +248,7 @@ public void Update() private void CountingDown(bool isReady, bool NotStartable) { + _logger.Debug($"CountdownEndTime '{CountdownEndTime}' RunTime '{_instance.RunTime}' BeatMapStartCountdownTime '{_configuration.CountdownConfig.BeatMapStartCountdownTime}' CountdownTimePlayersReady '{_configuration.CountdownConfig.CountdownTimePlayersReady}'"); // If not already counting down if (CountDownState == CountdownState.NotCountingDown) { @@ -261,8 +262,10 @@ private void CountingDown(bool isReady, bool NotStartable) // If counting down if (CountDownState != CountdownState.NotCountingDown) { + _logger.Debug($"CountdownEndTime '{CountdownEndTime}' RunTime '{_instance.RunTime}'"); if(CountdownEndTime <= _instance.RunTime) { + _logger.Debug($"Countdown finished, sending map"); // If countdown just finished, send map then pause lobby untill all players have map downloaded if (CountDownState != CountdownState.WaitingForEntitlement) { @@ -281,6 +284,7 @@ private void CountingDown(bool isReady, bool NotStartable) }, DeliveryMethod.ReliableOrdered); } } + _logger.Debug($"All players have entitlement, starting map"); //starts beatmap _gameplayManager.SetBeatmap(SelectedBeatmap!, SelectedModifiers); Task.Run(() => _gameplayManager.StartSong(CancellationToken.None)); @@ -290,6 +294,7 @@ private void CountingDown(bool isReady, bool NotStartable) } if (CountdownEndTime + _configuration.SendPlayersWithoutEntitlementToSpectateTimeout <= _instance.RunTime) //If takes too long to start then players are sent to spectate by telling them the beatmap already started { + _logger.Debug($"Took too long to start, sending players to spectate"); IPlayer[] MissingEntitlement = _playerRegistry.Players.Where(p => p.GetEntitlement(SelectedBeatmap!.LevelId) is not EntitlementStatus.Ok).ToArray(); foreach (IPlayer p in MissingEntitlement) { @@ -355,7 +360,8 @@ public BeatmapDifficulty[] GetSelectedBeatmapDifficulties() // If you want to cancel the countdown use CancelCountdown(), Not SetCountdown as CancelCountdown() ALSO informs the clients it has been canceled, whereas SetCountdown will not private void SetCountdown(CountdownState countdownState, long countdown = 0) { - _logger.Error($"CountdownEndTime currently is '{CountdownEndTime}' countdown is set to '{countdown}' state will be set to '{countdownState}'"); + _logger.Error($"CountdownEndTime currently is '{CountdownEndTime}' countdown is set to '{countdown}' state will be set to '{countdownState}' BeatmapStartTime is '{_configuration.CountdownConfig.BeatMapStartCountdownTime}'"); + _logger.Error($"Check should start Beatmap {(CountdownEndTime - _instance.RunTime) < _configuration.CountdownConfig.BeatMapStartCountdownTime} EndTime '{CountdownEndTime - _instance.RunTime}' RunTime '{_instance.RunTime}'"); CountDownState = countdownState; switch (CountDownState) { @@ -366,7 +372,7 @@ private void SetCountdown(CountdownState countdownState, long countdown = 0) break; case CountdownState.CountingDown: if (countdown == 0) - countdown = 30*2; + countdown = 30000L; CountdownEndTime = _instance.RunTime + countdown; _packetDispatcher.SendToNearbyPlayers(new SetCountdownEndTimePacket { @@ -375,7 +381,7 @@ private void SetCountdown(CountdownState countdownState, long countdown = 0) break; case CountdownState.StartBeatmapCountdown: if (countdown == 0) - countdown = 5*2; + countdown = 5000L; CountdownEndTime = _instance.RunTime + countdown; StartBeatmapPacket(); break; @@ -383,7 +389,7 @@ private void SetCountdown(CountdownState countdownState, long countdown = 0) StartBeatmapPacket(); break; } - _logger.Error($"CountdownEndTime final set to '{CountdownEndTime}' CountdownState '{CountDownState}' countdown is '{countdown}' RunTime is '{_instance.RunTime}'"); + _logger.Error($"CountdownEndTime final set to '{CountdownEndTime}' CountdownState '{CountDownState}' countdown is '{countdown}' RunTime is '{_instance.RunTime}' BeatmapStartTime is '{_configuration.CountdownConfig.BeatMapStartCountdownTime}'"); } //Checks the lobby settings and sends the player the correct beatmap diff --git a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetCountdownEndTimePacketHandler.cs b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetCountdownEndTimePacketHandler.cs index 7fda03f6..018efff0 100644 --- a/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetCountdownEndTimePacketHandler.cs +++ b/BeatTogether.DedicatedServer.Kernel/PacketHandlers/MultiplayerSession/MenuRpc/GetCountdownEndTimePacketHandler.cs @@ -25,7 +25,7 @@ public override Task Handle(IPlayer sender, GetCountdownEndTimePacket packet) { _logger.Debug( $"Handling packet of type '{nameof(GetCountdownEndTimePacket)}' " + - $"(SenderId={sender.ConnectionId})." + $"(SenderId={sender.ConnectionId} CountdownTime={_lobbyManager.CountdownEndTime})." ); if(_lobbyManager.CountDownState == Enums.CountdownState.CountingDown) _packetDispatcher.SendToPlayer(sender, new SetCountdownEndTimePacket diff --git a/BeatTogether.DedicatedServer.Node/InstanceFactory.cs b/BeatTogether.DedicatedServer.Node/InstanceFactory.cs index 321121b2..54755343 100644 --- a/BeatTogether.DedicatedServer.Node/InstanceFactory.cs +++ b/BeatTogether.DedicatedServer.Node/InstanceFactory.cs @@ -71,9 +71,9 @@ bool AllowNE instanceConfig.AllowPerPlayerModifiers = AllowPerPlayerModifiers; if (permanentManager) instanceConfig.SetConstantManagerFromUserId = managerId; - instanceConfig.CountdownConfig.CountdownTimePlayersReady = Math.Max(PlayersReadyCountdownTime,0); - if (instanceConfig.CountdownConfig.CountdownTimePlayersReady == 0f) - instanceConfig.CountdownConfig.CountdownTimePlayersReady = instanceConfig.GameplayServerMode == GameplayServerMode.Managed ? 15 : 30; + 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; diff --git a/BeatTogether.DedicatedServer.Node/NodeService.cs b/BeatTogether.DedicatedServer.Node/NodeService.cs index 3bd56917..064f7f7a 100644 --- a/BeatTogether.DedicatedServer.Node/NodeService.cs +++ b/BeatTogether.DedicatedServer.Node/NodeService.cs @@ -55,8 +55,8 @@ public async Task CreateMatchmakingServer(Creat request.Timeout, request.ServerName, (long)request.resultScreenTime, - (long)request.BeatmapStartTime, - (long)request.PlayersReadyCountdownTime , + ((long)request.BeatmapStartTime) * 1000, + ((long)request.PlayersReadyCountdownTime) * 1000, request.AllowPerPlayerModifiers, request.AllowPerPlayerDifficulties, request.AllowChroma,