diff --git a/Ragon.Client/Sources/Entity/RagonEntity.cs b/Ragon.Client/Sources/Entity/RagonEntity.cs index 7e828b5..5268eb8 100644 --- a/Ragon.Client/Sources/Entity/RagonEntity.cs +++ b/Ragon.Client/Sources/Entity/RagonEntity.cs @@ -77,9 +77,9 @@ namespace Ragon.Client Attached?.Invoke(this); } - internal void PrepareDetach() + internal void SetReplication(bool enabled) { - IsAttached = false; + Replication = enabled; } internal void Detach(RagonPayload payload) diff --git a/Ragon.Client/Sources/RagonEntityCache.cs b/Ragon.Client/Sources/RagonEntityCache.cs index 1628883..ea27049 100644 --- a/Ragon.Client/Sources/RagonEntityCache.cs +++ b/Ragon.Client/Sources/RagonEntityCache.cs @@ -83,13 +83,13 @@ public sealed class RagonEntityCache public void Destroy(RagonEntity entity, RagonPayload destroyPayload) { - if (!entity.IsAttached) + if (!entity.IsAttached && !entity.HasAuthority) { - RagonLog.Warn("Can't destroy object, he is not created"); + RagonLog.Warn("Can't destroy object"); return; } - entity.PrepareDetach(); + entity.SetReplication(false); var buffer = _client.Buffer; diff --git a/Ragon.Server/Sources/Handler/EntityRemoveOperation.cs b/Ragon.Server/Sources/Handler/EntityRemoveOperation.cs index 13de6f7..cf858de 100644 --- a/Ragon.Server/Sources/Handler/EntityRemoveOperation.cs +++ b/Ragon.Server/Sources/Handler/EntityRemoveOperation.cs @@ -35,7 +35,7 @@ public sealed class EntityDestroyOperation: BaseOperation var room = context.Room; var entityId = Reader.ReadUShort(); - if (room.Entities.TryGetValue(entityId, out var entity)) + if (room.Entities.TryGetValue(entityId, out var entity) && entity.Owner.Connection.Id == player.Connection.Id) { var payload = new RagonPayload(); payload.Read(Reader); @@ -47,5 +47,9 @@ public sealed class EntityDestroyOperation: BaseOperation _logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} destoyed entity {entity.Id}"); } + else + { + _logger.Trace($"Entity ${entity.Id} not found or Player {context.Connection.Id}|{context.LobbyPlayer.Name} have not authority"); + } } } \ No newline at end of file