internal Option <uint> CreateEntityInternal(Worker.Entity template,
                                                    CommandCallback <CreateEntityResult> callback, TimeSpan?timeout = null)
        {
            Func <uint, uint> sendRequestWithTimeoutMs =
                timeoutMs => communicator.SendCreateEntityRequest(template, null, timeoutMs).Id;

            return(SendGenericCommand(callback, sendRequestWithTimeoutMs, timeout));
        }
        /// <summary>
        ///     Adds an ACL component to an entity or overwrites an existing one.
        /// </summary>
        public static void SetAcl(this Worker.Entity entity, Acl acl)
        {
            if (entity.Get <EntityAcl>().HasValue)
            {
                entity.Update(acl.ToUpdate());
                return;
            }

            entity.Add(acl.ToData());
        }
        /// <summary>
        ///     Merges an <see cref="Acl" /> into the entity's existing set of ACLs.
        /// </summary>
        public static void MergeAcl(this Worker.Entity entity, Acl newAcl)
        {
            if (entity.Get <EntityAcl>().HasValue)
            {
                entity.Update(Acl.MergeIntoAcl(entity.Get <EntityAcl>().Value.Get().Value, newAcl).ToUpdate());
                return;
            }

            entity.Add(newAcl.ToData());
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Creates an ACL with with read permissions set to client or server,
        ///     and write permissions to server, for all components that exist on the given entity.
        /// </summary>
        public static Acl GenerateServerAuthoritativeAcl(Worker.Entity entity)
        {
            var acl = Acl.Build().SetReadAccess(CommonRequirementSets.PhysicsOrVisual);

            foreach (var componentId in entity.GetComponentIds())
            {
                acl.SetWriteAccess(componentId, CommonRequirementSets.PhysicsOnly);
            }

            return(acl);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Creates an ACL with read permissions set to client or server,
        ///     and write permissions to a client worker with the given worker ID, for all
        ///     components that exist on the given entity.
        /// </summary>
        public static Acl GenerateClientAuthoritativeAcl(Worker.Entity entity, string workerId)
        {
            if (string.IsNullOrEmpty(workerId))
            {
                throw new ArgumentNullException("workerId");
            }

            var acl            = Acl.Build().SetReadAccess(CommonRequirementSets.PhysicsOrVisual);
            var specificClient = CommonRequirementSets.SpecificClientOnly(workerId);

            foreach (var componentId in entity.GetComponentIds())
            {
                acl.SetWriteAccess(componentId, specificClient);
            }

            return(acl);
        }
Exemplo n.º 6
0
 protected EntityBuilder()
 {
     entity    = new Worker.Entity();
     entityAcl = new Acl();
 }
 public ICommandResponseHandler <CreateEntityResult> CreateEntity(Worker.Entity template, TimeSpan?timeout = null)
 {
     return(CommandResponseHandler <CreateEntityResult> .Wrap(callback => CreateEntity(template, callback, timeout)));
 }
 /// <inheritdoc />
 public void CreateEntity(Worker.Entity template, CommandCallback <CreateEntityResult> callback, TimeSpan?timeout = null)
 {
     CreateEntityInternal(template, callback, timeout);
 }
Exemplo n.º 9
0
 public ICommandResponseHandler <CreateEntityResult> CreateEntity(IComponentWriter writer, EntityId reservedEntityId,
                                                                  Worker.Entity template, TimeSpan?timeout = null)
 {
     return(CommandResponseHandler <CreateEntityResult> .Wrap(callback => CreateEntity(writer, reservedEntityId, template, callback, timeout)));
 }
Exemplo n.º 10
0
        private void CreateEntityInternal(IComponentWriter writer, bool requireAuthority, Worker.Entity template,
                                          CommandCallback <CreateEntityResult> callback, TimeSpan?timeout = null)
        {
            Action sendAction = () =>
            {
                var requestId = componentCommander.CreateEntityInternal(template, callback, timeout);
                TrackRequest(writer, requestId);
            };

            SendGenericCommand(writer, requireAuthority, callback, sendAction);
        }
Exemplo n.º 11
0
 public void CreateEntity(IComponentWriter writer, Worker.Entity template,
                          CommandCallback <CreateEntityResult> callback, TimeSpan?timeout = null)
 {
     CreateEntityInternal(writer, PerformAuthorityCheck, template, callback, timeout);
 }
Exemplo n.º 12
0
 public void CreateEntity(EntityId reservedEntityId, Worker.Entity template,
                          CommandCallback <CreateEntityResult> callback, TimeSpan?timeout = null)
 {
     CreateEntityInternal(null, SkipAuthorityCheck, reservedEntityId, template, callback, timeout);
 }
Exemplo n.º 13
0
 /// <inheritdoc />
 public RequestId <CreateEntityRequest> SendCreateEntityRequest(Worker.Entity template, Option <EntityId> entityId, Option <uint> timeout)
 {
     return(connection.SendCreateEntityRequest(template, entityId, timeout));
 }