Skip to content

Commit

Permalink
Added ping packet on join, Removed some logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cubicgraphics committed May 9, 2024
1 parent 44d928b commit bcf2125
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
17 changes: 9 additions & 8 deletions BeatTogether.DedicatedServer.Kernel/DedicatedInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,11 @@ public void SetState(MultiplayerGameState state)
_waitForPlayerCts.Cancel();

//UserID, UserName, and session
_logger.Information("Applying session data recv from master");
if (GetPlayerRegistry().RemoveExtraPlayerSessionDataAndApply(player))
if (!GetPlayerRegistry().RemoveExtraPlayerSessionDataAndApply(player))
{
_logger.Information("Successfull session data extraction");
goto EndOfTryAccept;
}
_logger.Information("Client ver: " + player.PlayerClientVersion.ToString());
_logger.Information("Client platform: " + player.PlayerPlatform.ToString());
_logger.Information("Client PlatformUserId: " + player.PlatformUserId);


return player;

Expand All @@ -354,7 +351,7 @@ public override void OnReceive(EndPoint remoteEndPoint, ref SpanBuffer reader, I

public override void OnConnect(EndPoint endPoint)
{
_logger.Information($"Endpoint connected (RemoteEndPoint='{endPoint}')");
//_logger.Information($"Endpoint connected (RemoteEndPoint='{endPoint}')");

if (!_playerRegistry.TryGetPlayer(endPoint, out var player))
{
Expand Down Expand Up @@ -390,6 +387,10 @@ public override void OnConnect(EndPoint endPoint)
//Send server infomation to player
var Player_ConnectPacket = new INetSerializable[]
{
new PingPacket
{
PingTime = RunTime
},
new SyncTimePacket
{
SyncTime = RunTime
Expand Down Expand Up @@ -527,7 +528,7 @@ public override void OnConnect(EndPoint endPoint)
Text = player.UserName + " Joined, Platform: " + player.PlayerPlatform.ToString() + " Version: " + player.PlayerClientVersion.ToString()
}, IgnoranceChannelTypes.Reliable);

_logger.Information($"Sent connection data though for (RemoteEndPoint='{endPoint}')");
//_logger.Information($"Sent connection data though for (RemoteEndPoint='{endPoint}')");
}

public void DisconnectPlayer(IPlayer player)
Expand Down
4 changes: 4 additions & 0 deletions BeatTogether.DedicatedServer.Kernel/Managers/LobbyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ private void CountingDown(bool isReady, bool NotStartable)
if (CountDownState != CountdownState.WaitingForEntitlement)
{
SetCountdown(CountdownState.WaitingForEntitlement);
_packetDispatcher.SendToPlayers(_playerRegistry.Players.Where(p => p.GetEntitlement(SelectedBeatmap!.LevelId) == Messaging.Enums.EntitlementStatus.Unknown).ToArray(), new GetIsEntitledToLevelPacket
{
LevelId = SelectedBeatmap!.LevelId
}, IgnoranceChannelTypes.Reliable);
}
if (_playerRegistry.Players.All(p => (p.GetEntitlement(SelectedBeatmap!.LevelId) is EntitlementStatus.Ok) || p.IsSpectating || !p.WantsToPlayNextLevel || p.IsBackgrounded || p.ForceLateJoin))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override void Handle(IPlayer sender, GetPlayersPermissionConfigurationPac
$"Handling packet of type '{nameof(GetPlayersPermissionConfigurationPacket)}' " +
$"(SenderId={sender.ConnectionId})."
);

//sends player there own permissions, and those of the player who is the current manager.
bool HasManager = (_playerRegistry.TryGetPlayer(_configuration.ServerOwnerId, out var ServerOwner) && !sender.IsServerOwner);
PlayerPermissionConfiguration[] playerPermissionConfigurations = new PlayerPermissionConfiguration[HasManager ? 2 : 1];
playerPermissionConfigurations[0] = new PlayerPermissionConfiguration
Expand Down
3 changes: 1 addition & 2 deletions BeatTogether.DedicatedServer.Kernel/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public sealed class Player : IPlayer

public RollingAverage Latency { get; } = new(30);
public long SyncTime =>
Math.Min(Instance.RunTime - Latency.CurrentAverage - _syncTimeOffset,
Math.Min(Instance.RunTime - Latency.CurrentAverage,
Instance.RunTime);
public int SortIndex { get; set; }
public byte[]? Random { get; set; }
Expand Down Expand Up @@ -59,7 +59,6 @@ public sealed class Player : IPlayer
public bool FinishedLevel => State.Contains("finished_level"); //If the player has finished the level
public bool InMenu => State.Contains("in_menu"); //Should be true while in lobby

private const long _syncTimeOffset = 6L;
private readonly ConcurrentDictionary<string, EntitlementStatus> _entitlements = new(); //Set a max amount of like 50 or something.

public Player(EndPoint endPoint, IDedicatedInstance instance,
Expand Down

0 comments on commit bcf2125

Please sign in to comment.