chore: added logging

This commit is contained in:
2023-11-05 22:19:55 +03:00
parent 33f8bba2ed
commit 2dcb047014
10 changed files with 86 additions and 39 deletions
@@ -51,6 +51,8 @@ internal class EntityCreateHandler : IHandler
if (player == null)
{
RagonLog.Warn($"Owner {ownerId}|{player.Name} not found in players");
_playerCache.Dump();
return;
}
@@ -42,7 +42,9 @@ internal class EntityEventHandler : IHandler
var player = _playerCache.GetPlayerByPeer(peerId);
if (player == null)
{
RagonLog.Warn($"Player not found for event {eventCode}");
RagonLog.Error($"Player with peerId:{peerId} not found as owner of event with code:{eventCode}");
_playerCache.Dump();
return;
}
@@ -41,6 +41,14 @@ internal class EntityOwnershipHandler: IHandler
var entities = reader.ReadUShort();
var player = _playerCache.GetPlayerByPeer(newOwnerId);
if (player == null)
{
RagonLog.Error($"Player with Id:{newOwnerId} not found in cache");
_playerCache.Dump();
return;
}
for (var i = 0; i < entities; i++)
{
var entityId = reader.ReadUShort();
@@ -19,7 +19,7 @@ using Ragon.Protocol;
namespace Ragon.Client;
internal class OwnershipRoomHandler: IHandler
internal class OwnershipRoomHandler : IHandler
{
private readonly RagonListenerList _listenerList;
private readonly RagonPlayerCache _playerCache;
@@ -39,6 +39,13 @@ internal class OwnershipRoomHandler: IHandler
{
var newOwnerId = reader.ReadUShort();
var player = _playerCache.GetPlayerByPeer(newOwnerId);
if (player == null)
{
RagonLog.Warn($"Player with peerId:{newOwnerId} not found in cache");
_playerCache.Dump();
return;
}
_playerCache.OnOwnershipChanged(newOwnerId);
_listenerList.OnOwnershipChanged(player);
@@ -45,6 +45,6 @@ internal class PlayerJoinHandler : IHandler
if (player != null)
_listenerList.OnPlayerJoined(player);
else
RagonLog.Trace($"[Joined] {playerId}");
RagonLog.Warn($"Player with Id:{playerId} not found in cache");
}
}
@@ -57,5 +57,9 @@ internal class PlayerLeftHandler : IHandler
foreach (var id in toDeleteIds)
_entityCache.OnDestroy(id, emptyPayload);
}
else
{
RagonLog.Warn($"Player with Id:{playerId} not found in cache");
}
}
}
@@ -37,6 +37,15 @@ internal class RoomDataHandler: IHandler
var rawData = reader.RawData;
var peerId = (ushort)(rawData[1] + (rawData[2] << 8));
var player = _playerCache.GetPlayerByPeer(peerId);
if (player == null)
{
RagonLog.Error($"Player with peerId:{peerId} not found");
_playerCache.Dump();
return;
}
var headerSize = 3;
var payload = new byte[rawData.Length - headerSize];
@@ -18,7 +18,7 @@ using Ragon.Protocol;
namespace Ragon.Client;
public class RoomEventHandler: IHandler
public class RoomEventHandler : IHandler
{
private readonly RagonClient _client;
private readonly RagonPlayerCache _playerCache;
@@ -41,7 +41,9 @@ public class RoomEventHandler: IHandler
var player = _playerCache.GetPlayerByPeer(peerId);
if (player == null)
{
RagonLog.Warn($"Player not found for event {eventCode}");
RagonLog.Error($"Player with peerId:{peerId} not found as owner of event with code:{eventCode}");
_playerCache.Dump();
return;
}
@@ -71,6 +71,8 @@ internal class SnapshotHandler : IHandler
if (player == null)
{
RagonLog.Error($"Player not found with peerId: ${ownerPeerId}");
_playerCache.Dump();
return;
}
@@ -105,6 +107,8 @@ internal class SnapshotHandler : IHandler
if (player == null)
{
RagonLog.Error($"Player not found with peerId: ${ownerPeerId}");
_playerCache.Dump();
return;
}
@@ -112,7 +116,6 @@ internal class SnapshotHandler : IHandler
var entity = _entityCache.TryGetEntity(0, entityType, staticId, entityId, hasAuthority, out _);
entity.Prepare(_client, entityId, entityType, hasAuthority, player, RagonPayload.Empty);
entity.Read(buffer);
entity.Attach();
}
+10
View File
@@ -104,4 +104,14 @@ public sealed class RagonPlayerCache
_playersByConnection.Clear();
_playersById.Clear();
}
public void Dump()
{
RagonLog.Trace("Players: ");
RagonLog.Trace("[Connection] [ID] [Name]");
foreach (var player in _players)
{
RagonLog.Trace($"[{player.PeerId}] {player.Id} {player.Name}");
}
}
}