Skip to content

Commit

Permalink
Cleanup code and bump interface version
Browse files Browse the repository at this point in the history
  • Loading branch information
cubicgraphics committed Apr 5, 2024
1 parent 6e2d6c7 commit 450fc98
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Authors>BeatTogether Team</Authors>
<Company>BeatTogether</Company>
<RepositoryUrl>https://github.com/beattogether/BeatTogether.DedicatedServer</RepositoryUrl>
<Version>1.7.2</Version>
<Version>1.7.3</Version>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
6 changes: 3 additions & 3 deletions BeatTogether.DedicatedServer.Interface/Enums/GameplayState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ public enum GameplayState : byte
{
None = 0,
SceneLoad = 1,
SongLoad = 1,
Gameplay = 2,
Results = 3
SongLoad = 2,
Gameplay = 3,
Results = 4
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

namespace BeatTogether.DedicatedServer.Interface.Events
{
public sealed record NodeOnlineEvent(string endPoint, string NodeVersion);
public sealed record NodeOnlineEvent(string EndPoint, string NodeVersion);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BeatTogether.DedicatedServer.Interface.Events
{
public sealed record NodeReceivedPlayerEncryptionEvent(string endPoint, string PlayerEndPoint);
public sealed record NodeReceivedPlayerEncryptionEvent(string EndPoint, string PlayerEndPoint);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

namespace BeatTogether.DedicatedServer.Interface.Events
{
public sealed record NodeStartedEvent(string endPoint, string NodeVersion);
public sealed record NodeStartedEvent(string EndPoint, string NodeVersion);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

namespace BeatTogether.DedicatedServer.Interface.Events
{
public sealed record PlayerLeaveServerEvent(string Secret, string UserId, string endPoint);
public sealed record PlayerLeaveServerEvent(string Secret, string UserId, string EndPoint);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public record CreateMatchmakingServerRequest(
bool PermanentManager = true,
float Timeout = 10f,
string ServerName = "",
float resultScreenTime = 20.0f,
float ResultScreenTime = 20.0f,
float BeatmapStartTime = 5.0f,
float PlayersReadyCountdownTime = 0f,
bool AllowPerPlayerModifiers = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ class SetWelcomeMessageHandler : BaseCommandHandler<SetWelcomeMessage>
{
private readonly IPacketDispatcher _packetDisapatcher;
private readonly InstanceConfiguration _Configuration;
private readonly IDedicatedInstance _instance;

public SetWelcomeMessageHandler(IPacketDispatcher packetDisapatcher, InstanceConfiguration instanceConfiguration, IDedicatedInstance instance)
public SetWelcomeMessageHandler(IPacketDispatcher packetDisapatcher, InstanceConfiguration instanceConfiguration)
{
_packetDisapatcher = packetDisapatcher;
_Configuration = instanceConfiguration;
_instance = instance;
}

public override void Handle(IPlayer player, SetWelcomeMessage command)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,15 @@ public static class GamePlatformToMpCorePlatform
{
public static Platform Convert(this Enums.Platform gamePlatform)
{
switch (gamePlatform)
return gamePlatform switch
{
case Enums.Platform.Test:
return Platform.Unknown;
case Enums.Platform.OculusRift:
return Platform.OculusPC;
case Enums.Platform.OculusQuest:
return Platform.OculusQuest;
case Enums.Platform.Steam:
return Platform.Steam;
case Enums.Platform.PS4:
case Enums.Platform.PS4Dev:
case Enums.Platform.PS4Cert:
return Platform.PS4;
default:
return 0;
}
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,
_ => 0,
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public interface IGameplayManager
GameplayManagerState State { get; }
BeatmapIdentifier? CurrentBeatmap { get; }
GameplayModifiers CurrentModifiers { get; }
public long _songStartTime { get; }

void HandlePlayerLeaveGameplay(IPlayer player);
void HandleGameSceneLoaded(IPlayer player, SetGameplaySceneReadyPacket packet);
Expand Down
27 changes: 12 additions & 15 deletions BeatTogether.DedicatedServer.Kernel/Managers/GameplayManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public sealed class GameplayManager : IGameplayManager, IDisposable
private const float SceneLoadTimeLimit = 15.0f;
private const float SongLoadTimeLimit = 15.0f;

public long _songStartTime { get; private set; }
List<string> PlayersAtStart = new();
private long SongStartTime { get; set; }

private readonly List<string> PlayersAtStart = new();

private CancellationTokenSource? _requestReturnToMenuCts;

Expand Down Expand Up @@ -166,14 +167,14 @@ public async void StartSong(CancellationToken cancellationToken)
}

// Start song and wait for finish
_songStartTime = (_instance.RunTime + SongStartDelay + (StartDelay * 2));
_logger.Verbose($"SongStartTime: {_songStartTime} RunTime: {_instance.RunTime}");
SongStartTime = (_instance.RunTime + SongStartDelay + (StartDelay * 2));
_logger.Verbose($"SongStartTime: {SongStartTime} RunTime: {_instance.RunTime}");

State = GameplayManagerState.Gameplay;

_packetDispatcher.SendToNearbyPlayers(new SetSongStartTimePacket
{
StartTime = _songStartTime
StartTime = SongStartTime
}, IgnoranceChannelTypes.Reliable);

//Initiates the song start process for forced late joiners
Expand All @@ -185,7 +186,7 @@ public async void StartSong(CancellationToken cancellationToken)
{
Beatmap = CurrentBeatmap,
Modifiers = CurrentModifiers,
StartTime = _songStartTime
StartTime = SongStartTime
}, IgnoranceChannelTypes.Reliable);
}
}
Expand All @@ -210,7 +211,7 @@ private void ResetValues()
_levelFinishedTcs.Clear();
_sceneReadyTcs.Clear();
_songReadyTcs.Clear();
_songStartTime = 0;
SongStartTime = 0;
_playerSpecificSettings.Clear();
_levelCompletionResults.Clear();
PlayersAtStart.Clear();
Expand Down Expand Up @@ -262,10 +263,10 @@ public void HandleGameSongLoaded(IPlayer player)
return;
}
if (State != GameplayManagerState.SceneLoad) //Late joiners get sent start time
if(_songStartTime != 0)
if(SongStartTime != 0)
_packetDispatcher.SendToPlayer(player, new SetSongStartTimePacket
{
StartTime = _songStartTime
StartTime = SongStartTime
}, IgnoranceChannelTypes.Reliable);
}

Expand All @@ -277,14 +278,10 @@ public void HandleLevelFinished(IPlayer player, LevelFinishedPacket packet)
PlayerFinishLevel(player.UserId);
}

object RequestReturnLock = new();
public void SignalRequestReturnToMenu()
{
lock (RequestReturnLock)
{
if (_requestReturnToMenuCts != null && !_requestReturnToMenuCts.IsCancellationRequested)
_requestReturnToMenuCts.Cancel();
}
if (_requestReturnToMenuCts != null && !_requestReturnToMenuCts.IsCancellationRequested)
_requestReturnToMenuCts.Cancel();
}

//will set players tasks as done if they leave gameplay due to disconnect or returning to the menu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace BeatTogether.DedicatedServer.Kernel.PacketHandlers.MultiplayerSession.
{
public sealed class LevelFinishedPacketHandler : BasePacketHandler<LevelFinishedPacket>
{
private IGameplayManager _gameplayManager;
private ILogger _logger = Log.ForContext<LevelFinishedPacketHandler>();
private readonly IGameplayManager _gameplayManager;
private readonly ILogger _logger = Log.ForContext<LevelFinishedPacketHandler>();

public LevelFinishedPacketHandler(
IGameplayManager gameplayManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class MpcCapabilitiesPacketHandler : BasePacketHandler<MpcCapabilitiesPac
{
private readonly IPacketDispatcher _packetDispatcher;
private readonly InstanceConfiguration _instanceConfiguration;
private readonly ILogger _logger = Log.ForContext<MpcCapabilitiesPacketHandler>();
//private readonly ILogger _logger = Log.ForContext<MpcCapabilitiesPacketHandler>();
public MpcCapabilitiesPacketHandler(IPacketDispatcher packetDispatcher,
InstanceConfiguration instanceConfiguration)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class MpcTextChatPacketHandler : BasePacketHandler<MpcTextChatPacket>
private readonly InstanceConfiguration _instanceConfiguration;
private readonly ITextCommandRepository _CommandRepository;
private readonly IServiceProvider _serviceProvider;
private readonly ILogger _logger = Log.ForContext<MpcTextChatPacketHandler>();
//private readonly ILogger _logger = Log.ForContext<MpcTextChatPacketHandler>();


public MpcTextChatPacketHandler(IPacketDispatcher packetDispatcher,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace BeatTogether.DedicatedServer.Kernel.PacketHandlers.MultiplayerSession.
{
class DediPacketSetNewManagerPacketHandler : BasePacketHandler<DediPacketSetNewManagerPacket>
{
private InstanceConfiguration _configuration;
private readonly InstanceConfiguration _configuration;
private readonly IPacketDispatcher _packetDispatcher;
private readonly IPlayerRegistry _playerRegistry;
private readonly ILogger _logger = Log.ForContext<DediPacketSetNewManagerPacketHandler>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace BeatTogether.DedicatedServer.Kernel.PacketHandlers.MultiplayerSession.
{
class GetPerPlayerHandler : BasePacketHandler<GetPerPlayer>
{
private InstanceConfiguration _configuration;
private readonly InstanceConfiguration _configuration;
private readonly IPacketDispatcher _PacketDispatcher;
private readonly ILogger _logger = Log.ForContext<GetPerPlayerHandler>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace BeatTogether.DedicatedServer.Kernel.PacketHandlers.MultiplayerSession.
{
class PerPlayerHandler : BasePacketHandler<PerPlayer>
{
private InstanceConfiguration _configuration;
private readonly InstanceConfiguration _configuration;
private readonly IPacketDispatcher _PacketDispatcher;
private readonly ILogger _logger = Log.ForContext<GetPerPlayerHandler>();

Expand Down
3 changes: 1 addition & 2 deletions BeatTogether.DedicatedServer.Kernel/TextCommandRepository.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using BeatTogether.DedicatedServer.Kernel.Abstractions;
using BeatTogether.DedicatedServer.Kernel.Commands;
using BeatTogether.DedicatedServer.Kernel.Enums;
using BeatTogether.DedicatedServer.Kernel.Managers;
using Serilog;
using System;
using System.Collections.Concurrent;
Expand All @@ -15,7 +14,7 @@ public class TextCommandRepository : ITextCommandRepository

private readonly ConcurrentDictionary<AccessLevel, ConcurrentDictionary<string, CommandFactory>> _Commands = new();
private readonly ConcurrentDictionary<AccessLevel, ConcurrentDictionary<string, CommandFactory>> _SHCommands = new();
private readonly ILogger _logger = Log.ForContext<LobbyManager>();
//private readonly ILogger _logger = Log.ForContext<LobbyManager>();
public TextCommandRepository()
{
RegisterCommands();
Expand Down
2 changes: 1 addition & 1 deletion BeatTogether.DedicatedServer.Node/NodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task<CreateMatchmakingServerResponse> CreateMatchmakingServer(Creat
request.PermanentManager,
request.Timeout,
request.ServerName,
(long)request.resultScreenTime,
(long)request.ResultScreenTime,
((long)request.BeatmapStartTime) * 1000,
((long)request.PlayersReadyCountdownTime) * 1000,
request.AllowPerPlayerModifiers,
Expand Down
2 changes: 1 addition & 1 deletion BeatTogether.DedicatedServer.Node/PortAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed class PortAllocator : IPortAllocator
{
private readonly NodeConfiguration _configuration;

private readonly object _lock = new object();
private readonly object _lock = new();

private readonly HashSet<int> _acquiredPorts = new();
private readonly HashSet<int> _releasedPorts = new();
Expand Down

0 comments on commit 450fc98

Please sign in to comment.