Skip to content

Commit

Permalink
Convert values to milliseconds, tweak logging
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-r-elp committed Dec 20, 2023
1 parent 1a032a1 commit 1392f19
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
14 changes: 10 additions & 4 deletions BeatTogether.DedicatedServer.Kernel/Managers/LobbyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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));
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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
{
Expand All @@ -375,15 +381,15 @@ 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;
case CountdownState.WaitingForEntitlement:
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions BeatTogether.DedicatedServer.Node/InstanceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IDedicatedInstance>();
if (!_instanceRegistry.AddInstance(instance))
return null;
Expand Down
4 changes: 2 additions & 2 deletions BeatTogether.DedicatedServer.Node/NodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public async Task<CreateMatchmakingServerResponse> 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,
Expand Down

0 comments on commit 1392f19

Please sign in to comment.