From c64cc61c786d01260ec65100274e05a0ae3d0221 Mon Sep 17 00:00:00 2001 From: edmand46 Date: Thu, 4 Jan 2024 23:29:35 +0300 Subject: [PATCH] :bug: prediction spawning for wrong connection, payload capacity --- .../Sources/Handler/SnapshotHandler.cs | 4 ++-- Ragon.Client/Sources/RagonEntityCache.cs | 24 ++++++++----------- Ragon.Client/Sources/RagonSession.cs | 4 ++-- Ragon.Protocol/Sources/RagonBuffer.cs | 2 +- Ragon.Server/Sources/Entity/RagonPayload.cs | 2 +- Ragon.Server/Sources/Event/RagonEvent.cs | 2 +- Ragon.Server/Sources/Logging/IRagonLogger.cs | 9 +++++++ 7 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 Ragon.Server/Sources/Logging/IRagonLogger.cs diff --git a/Ragon.Client/Sources/Handler/SnapshotHandler.cs b/Ragon.Client/Sources/Handler/SnapshotHandler.cs index 3e04264..efbebc9 100644 --- a/Ragon.Client/Sources/Handler/SnapshotHandler.cs +++ b/Ragon.Client/Sources/Handler/SnapshotHandler.cs @@ -70,7 +70,7 @@ internal class SnapshotHandler : IHandler var player = _playerCache.GetPlayerByPeer(ownerPeerId); if (player == null) { - RagonLog.Error($"Player not found with peerId: ${ownerPeerId}"); + RagonLog.Error($"Player not found with peerId: {ownerPeerId}"); _playerCache.Dump(); return; @@ -106,7 +106,7 @@ internal class SnapshotHandler : IHandler var player = _playerCache.GetPlayerByPeer(ownerPeerId); if (player == null) { - RagonLog.Error($"Player not found with peerId: ${ownerPeerId}"); + RagonLog.Error($"Player not found with peerId: {ownerPeerId}"); _playerCache.Dump(); return; diff --git a/Ragon.Client/Sources/RagonEntityCache.cs b/Ragon.Client/Sources/RagonEntityCache.cs index 3ca406d..b09cfa7 100644 --- a/Ragon.Client/Sources/RagonEntityCache.cs +++ b/Ragon.Client/Sources/RagonEntityCache.cs @@ -88,9 +88,9 @@ public sealed class RagonEntityCache RagonLog.Warn("Can't destroy object"); return; } - + entity.SetReplication(false); - + var buffer = _client.Buffer; buffer.Clear(); @@ -168,7 +168,7 @@ public sealed class RagonEntityCache _entityMap.Clear(); _entityList.Clear(); } - + internal RagonEntity TryGetEntity(ushort attachId, ushort entityType, ushort sceneId, ushort entityId, bool hasAuthority, out bool hasCreated) { if (sceneId > 0) @@ -179,36 +179,33 @@ public sealed class RagonEntityCache if (hasAuthority) _entityList.Add(sceneEntity); - + hasCreated = false; - + return sceneEntity; } } - if (_pendingEntities.TryGetValue(attachId, out var pendingEntity)) + if (_pendingEntities.TryGetValue(attachId, out var pendingEntity) && hasAuthority) { _pendingEntities.Remove(attachId); _entityMap.Add(entityId, pendingEntity); - - if (hasAuthority) - _entityList.Add(pendingEntity); + _entityList.Add(pendingEntity); hasCreated = false; return pendingEntity; } - var entity = new RagonEntity(entityType, sceneId); - + _entityMap.Add(entityId, entity); - + if (hasAuthority) _entityList.Add(entity); hasCreated = true; - + return entity; } @@ -217,7 +214,6 @@ public sealed class RagonEntityCache { if (_entityMap.TryGetValue(entityId, out var entity)) { - _entityMap.Remove(entityId); _entityList.Remove(entity); diff --git a/Ragon.Client/Sources/RagonSession.cs b/Ragon.Client/Sources/RagonSession.cs index 44e13a7..972d767 100644 --- a/Ragon.Client/Sources/RagonSession.cs +++ b/Ragon.Client/Sources/RagonSession.cs @@ -51,9 +51,9 @@ namespace Ragon.Client Create(null, new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers}); } - public void Create(string roomId, string sceneNa, int minPlayers, int maxPlayers) + public void Create(string roomId, string sceneName, int minPlayers, int maxPlayers) { - Create(roomId, new RagonRoomParameters() {Scene = sceneNa, Min = minPlayers, Max = maxPlayers}); + Create(roomId, new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers}); } public void Create(string roomId, RagonRoomParameters parameters) diff --git a/Ragon.Protocol/Sources/RagonBuffer.cs b/Ragon.Protocol/Sources/RagonBuffer.cs index b23a0f1..c4be53f 100644 --- a/Ragon.Protocol/Sources/RagonBuffer.cs +++ b/Ragon.Protocol/Sources/RagonBuffer.cs @@ -75,7 +75,7 @@ namespace Ragon.Protocol public int ReadOffset => _read; public int WriteOffset => _write; public int Length => ((_write - 1) >> 3) + 1; - public int Capacity => _write - _read; + public int Capacity => _write - _read - 1; public RagonBuffer(int capacity = 128) { diff --git a/Ragon.Server/Sources/Entity/RagonPayload.cs b/Ragon.Server/Sources/Entity/RagonPayload.cs index ee7232e..d073273 100644 --- a/Ragon.Server/Sources/Entity/RagonPayload.cs +++ b/Ragon.Server/Sources/Entity/RagonPayload.cs @@ -28,7 +28,7 @@ public class RagonPayload public void Read(RagonBuffer buffer) { - _size = buffer.Capacity - 1; + _size = buffer.Capacity; buffer.ReadArray(_data, _size); } diff --git a/Ragon.Server/Sources/Event/RagonEvent.cs b/Ragon.Server/Sources/Event/RagonEvent.cs index 0e22444..d49d886 100644 --- a/Ragon.Server/Sources/Event/RagonEvent.cs +++ b/Ragon.Server/Sources/Event/RagonEvent.cs @@ -39,7 +39,7 @@ public class RagonEvent public void Read(RagonBuffer buffer) { - _size = buffer.Capacity - 1; + _size = buffer.Capacity; buffer.ReadArray(_data, _size); } diff --git a/Ragon.Server/Sources/Logging/IRagonLogger.cs b/Ragon.Server/Sources/Logging/IRagonLogger.cs new file mode 100644 index 0000000..bbad315 --- /dev/null +++ b/Ragon.Server/Sources/Logging/IRagonLogger.cs @@ -0,0 +1,9 @@ +namespace Ragon.Server.Logging; + +public interface IRagonLogger +{ + public void Warning(string tag, string message); + public void Info(string tag, string message); + public void Error(string tag, string message); + public void Trace(string tag, string message); +} \ No newline at end of file