🐛 checking authority on destroy object

This commit is contained in:
2023-10-12 11:18:04 +03:00
parent 3da57e086e
commit b90ed974e5
3 changed files with 10 additions and 6 deletions
+2 -2
View File
@@ -77,9 +77,9 @@ namespace Ragon.Client
Attached?.Invoke(this); Attached?.Invoke(this);
} }
internal void PrepareDetach() internal void SetReplication(bool enabled)
{ {
IsAttached = false; Replication = enabled;
} }
internal void Detach(RagonPayload payload) internal void Detach(RagonPayload payload)
+3 -3
View File
@@ -83,13 +83,13 @@ public sealed class RagonEntityCache
public void Destroy(RagonEntity entity, RagonPayload destroyPayload) 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; return;
} }
entity.PrepareDetach(); entity.SetReplication(false);
var buffer = _client.Buffer; var buffer = _client.Buffer;
@@ -35,7 +35,7 @@ public sealed class EntityDestroyOperation: BaseOperation
var room = context.Room; var room = context.Room;
var entityId = Reader.ReadUShort(); 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(); var payload = new RagonPayload();
payload.Read(Reader); 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}"); _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");
}
} }
} }