コード例 #1
0
        Tell(IEntityMessage message, Type messageType)
        {
            var invoker =
#if ECS_SERVER
                (Func <IComponentIntern, IEntityMessage, Task>
#else
                (Action <IComponentIntern, IEntityMessage>
#endif
                )GetOrAddMessageCaller(messageType);

            if (_messageHandlers.TryGetValue(messageType, out var handlers))
            {
                foreach (var handler in from h in handlers
                         orderby h.GetMessageOrder(message), _indexes[h]
                         select h)
                {
#if ECS_SERVER
                    await
#endif
                    invoker(handler, message);
                }
            }

#if ECS_SERVER
            await ClearOperationQueue();
#endif
        }
コード例 #2
0
        TryAsk <TResponse>(IEntityMessage <TResponse> message)
        {
            var messageType = message.GetType();
            var invoker     =
#if ECS_SERVER
                (Func <IComponentIntern, IEntityMessage <TResponse>, Task <TResponse> >
#else
                (Func <IComponentIntern, IEntityMessage <TResponse>, TResponse>
#endif
                )GetOrAddMessageCaller(messageType);

            if (_messageHandlers.TryGetValue(messageType, out var handlers))
            {
                foreach (var handler in from h in handlers
                         orderby h.GetMessageOrder(message), _indexes[h]
                         select h)
                {
                    var response =
#if ECS_SERVER
                        await
#endif
                        invoker(handler, message);
#if ECS_SERVER
                    await ClearOperationQueue();
#endif
                    return(new AskResult <TResponse> {
                        Succeeded = true, Response = response
                    });
                }
            }

            return(AskResult <TResponse> .Failed);
        }
コード例 #3
0
        Tell(IEntityMessage message)
        {
#if ECS_SERVER
            return
                (#endif
            Tell(message, message.GetType()));
        }
コード例 #4
0
 public static string GetEntityText(this IEntityMessage msg)
 {
     Sandbox.Game.Entities.MyEntity entity;
     if (Sandbox.Game.Entities.MyEntities.TryGetEntityById(msg.GetEntityId(), out entity))
     {
         return(entity.ToString());
     }
     return("null");
 }
コード例 #5
0
        public async Task <TResponse> Ask <TResponse>(IEntityMessage <TResponse> message)
        {
            var response = await TryAsk(message);

            if (!response.Succeeded)
            {
                throw new ReceiverNotFoundException();
            }
            return(response.Response);
        }
コード例 #6
0
ファイル: Network.cs プロジェクト: AutoMcDonough/Smart_Rotors
        /// <summary>
        ///     Send an entity message to other network handler.
        /// </summary>
        /// <param name="message">The message sent to others.</param>
        public void Sync(IEntityMessage message)
        {
            if (!Active)
            {
                return;
            }

            var bytes = WrapAndSerialize(message);

            MyAPIGateway.Multiplayer.SendMessageToOthers(_id, bytes);
        }
コード例 #7
0
ファイル: Network.cs プロジェクト: AutoMcDonough/Smart_Rotors
        /// <summary>
        ///     Sends an entity message to given recipient.
        /// </summary>
        /// <param name="message">The entity message send to recipient.</param>
        /// <param name="recipient">The recipient who should receive this message.</param>
        public void Send(IEntityMessage message, ulong recipient)
        {
            if (!Active)
            {
                return;
            }

            var bytes = WrapAndSerialize(message);

            MyAPIGateway.Multiplayer.SendMessageTo(_id, bytes, recipient);
        }
コード例 #8
0
ファイル: Network.cs プロジェクト: AutoMcDonough/Smart_Rotors
        /// <summary>
        ///     Wrap a message and serialize the wrapped message.
        /// </summary>
        /// <param name="message">The message that get wrapped.</param>
        /// <returns>Returns the serialized wrapper as a byte[].</returns>
        private byte[] WrapAndSerialize(IEntityMessage message)
        {
            var wrapper = new EntityMessageWrapper {
                EntityId = message.EntityId,
                Sender   = MyId,
                Content  = message.Serialze()
            };

            return(WrapAndSerialize(new EntityMessage {
                Wrapper = wrapper
            }));
        }
コード例 #9
0
        Ask <TResponse>(IEntityMessage <TResponse> message)
        {
            var response =
#if ECS_SERVER
                await
#endif
                TryAsk(message);

            if (!response.Succeeded)
            {
                throw new ReceiverNotFoundException();
            }
            return(response.Response);
        }
コード例 #10
0
        public async Task Tell(IEntityMessage message)
        {
            var messageType = message.GetType();
            var invoker     = (Func <IComponentIntern, IEntityMessage, Task>)GetOrAddMessageCaller(messageType);

            if (_messageHandlers.TryGetValue(messageType, out var handlers))
            {
                foreach (var handler in from h in handlers
                         orderby h.GetMessageOrder(message), _indexes[h]
                         select h)
                {
                    await invoker(handler, message);
                }
            }
        }
コード例 #11
0
        public async Task <AskResult <TResponse> > TryAsk <TResponse>(IEntityMessage <TResponse> message)
        {
            var messageType = message.GetType();
            var invoker     = (Func <IComponentIntern, IEntityMessage <TResponse>, Task <TResponse> >)GetOrAddMessageCaller(messageType);

            if (_messageHandlers.TryGetValue(messageType, out var handlers))
            {
                foreach (var handler in from h in handlers
                         orderby h.GetMessageOrder(message), _indexes[h]
                         select h)
                {
                    return new AskResult <TResponse> {
                               Succeeded = true, Response = await invoker(handler, message)
                    }
                }
                ;
            }

            return(AskResult <TResponse> .Failed);
        }