Ejemplo n.º 1
0
        /// <summary>
        ///   The set properties.
        /// </summary>
        /// <param name = "item">
        ///   The mmo item.
        /// </param>
        /// <param name = "operation">
        ///   The operation.
        /// </param>
        /// <param name = "sendParameters">
        ///   The send Parameters.
        /// </param>
        /// <returns>
        ///   error code ok
        /// </returns>
        private OperationResponse ItemOperationSetProperties(Item item, SetProperties operation, SendParameters sendParameters)
        {
            MethodReturnValue result = this.CheckAccess(item);
            if (result)
            {
                item.SetProperties(operation.PropertiesSet, operation.PropertiesUnset);
                var eventInstance = new ItemPropertiesSet
                    {
                        ItemId = item.Id,
                        ItemType = item.Type,
                        PropertiesRevision = item.PropertiesRevision,
                        PropertiesSet = operation.PropertiesSet,
                        PropertiesUnset = operation.PropertiesUnset
                    };

                var eventData = new EventData((byte)EventCode.ItemPropertiesSet, eventInstance);
                sendParameters.ChannelId = Settings.ItemEventChannel;
                var message = new ItemEventMessage(item, eventData, sendParameters);
                item.EventChannel.Publish(message);

                // no response sent
                operation.OnComplete();
                return null;
            }

            return operation.GetOperationResponse(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The Chat Operation
        /// </summary>
        /// <param name="item">The mmo item</param>
        /// <param name="operation">The operation</param>
        /// <returns>error code OK</returns>
        private OperationResponse ItemOperationChat(MmoItem item, Chat operation, SendParameters sendParameters)
        {
            MethodReturnValue result = this.CheckAccess(item);
            if (result)
            {
                var eventInstance = new ItemChat
                {
                    ItemId = item.Id,
                    ItemType = item.Type,
                    Group = operation.Group,
                    Message = operation.Message
                };

                EventData eventData = new EventData((byte)EventCode.ItemChat, eventInstance);
                sendParameters.ChannelId = Settings.ItemEventChannel;
                var message = new ItemEventMessage(item, eventData, sendParameters);
                item.EventChannel.Publish(message);

                operation.OnComplete();

                return null;
            }

            return operation.GetOperationResponse(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///   The move operation.
        /// </summary>
        /// <param name = "item">
        ///   The mmo item.
        /// </param>
        /// <param name = "operation">
        ///   The operation.
        /// </param>
        /// <param name = "sendParameters">
        ///   The send Parameters.
        /// </param>
        /// <returns>
        ///   error code ok
        /// </returns>
        private OperationResponse ItemOperationMove(MmoItem item, Move operation, SendParameters sendParameters)
        {
            // should always be OK
            MethodReturnValue result = this.CheckAccess(item);
            if (result)
            {
                // save previous for event
                float[] oldPosition = item.Coordinate;
                float[] oldRotation = item.Rotation;

                // move
                item.Rotation = operation.Rotation;
                item.Move(operation.Position);

                // send event
                var eventInstance = new ItemMoved
                    {
                        ItemId = item.Id,
                        ItemType = item.Type,
                        OldPosition = oldPosition,
                        Position = operation.Position,
                        Rotation = operation.Rotation,
                        OldRotation = oldRotation
                    };

                var eventData = new EventData((byte)EventCode.ItemMoved, eventInstance);
                sendParameters.ChannelId = Settings.ItemEventChannel;
                var message = new ItemEventMessage(item, eventData, sendParameters);
                item.EventChannel.Publish(message);

                // no response sent
                operation.OnComplete();
                return null;
            }

            return operation.GetOperationResponse(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///   The Game item move operation.
        /// </summary>
        /// <param name = "item">
        ///   The mmo item.
        /// </param>
        /// <param name = "operation">
        ///   The operation.
        /// </param>
        /// <param name = "sendParameters">
        ///   The send Parameters.
        /// </param>
        /// <returns>
        ///   error code ok
        /// </returns>
        private OperationResponse GameItemOperationMove(MmoItem item, GameItemMove operation, SendParameters sendParameters)
        {
            // should always be OK
            MethodReturnValue result = this.CheckAccess(item);
            if (result)
            {
                // send event
                var eventInstance = new GameItemMoved
                {
                    ItemId = operation.ItemId,
                    GameItemId = operation.GameItemId,
                    Position = operation.Position,
                    Rotation = operation.Rotation
                };

                var eventData = new EventData((byte)EventCode.GameItemMoved, eventInstance);
                sendParameters.ChannelId = Settings.ItemEventChannel;
                var message = new ItemEventMessage(item, eventData, sendParameters);
                item.EventChannel.Publish(message);

                // no response sent
                operation.OnComplete();
                return null;
            }

            return operation.GetOperationResponse(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// The Animate Operation
        /// </summary>
        /// <param name="item">The mmo item</param>
        /// <param name="operation">The operation</param>
        /// <returns>error code OK</returns>
        private OperationResponse ItemOperationAnimate(MmoItem item, Animate operation, string animation, byte action, byte animationWrap, float animationSpeed, int animationLayer, SendParameters sendParameters)
        {
            MethodReturnValue result = this.CheckAccess(item);
            if (result)
            {
                item.Animation = animation;
                item.AnimationWrap = animationWrap;
                item.AnimationSpeed = animationSpeed;

                var eventInstance = new ItemAnimate
                {
                    ItemId = item.Id,
                    ItemType = item.Type,
                    Animation = animation,
                    AnimationAction = action,
                    AnimationWrap = animationWrap,
                    AnimationSpeed = animationSpeed,
                    AnimationLayer = animationLayer
                };

                EventData eventData = new EventData((byte)EventCode.ItemAnimate, eventInstance);
                sendParameters.ChannelId = Settings.ItemEventChannel;
                var message = new ItemEventMessage(item, eventData, sendParameters);
                item.EventChannel.Publish(message);

                operation.OnComplete();

                return null;
            }

            return operation.GetOperationResponse(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///   The operation raise generic event.
        /// </summary>
        /// <param name = "item">
        ///   The mmo item.
        /// </param>
        /// <param name = "operation">
        ///   The operation.
        /// </param>
        /// <param name = "sendParameters">
        ///   The send Parameters.
        /// </param>
        /// <returns>
        ///   Ok or ItemNotFound
        /// </returns>
        private static OperationResponse ItemOperationRaiseGenericEvent(Item item, RaiseGenericEvent operation, SendParameters sendParameters)
        {
            if (item.Disposed)
            {
                return operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound");
            }

            var eventInstance = new ItemGeneric
                {
                   ItemId = item.Id, ItemType = item.Type, CustomEventCode = operation.CustomEventCode, EventData = operation.EventData
                };

            var eventData = new EventData((byte)EventCode.ItemGeneric, eventInstance);
            sendParameters.Unreliable = (Reliability)operation.EventReliability == Reliability.Unreliable;
            sendParameters.ChannelId = Settings.ItemEventChannel;
            switch (operation.EventReceiver)
            {
                case (byte)EventReceiver.ItemOwner:
                    {
                        if (((IMmoItem)item).ReceiveEvent(eventData, sendParameters) == false)
                        {
                            string debugMessage = string.Format("Target item {0}/{1} could not receive event", item.Type, item.Id);
                            return operation.GetOperationResponse((int)ReturnCode.InvalidOperation, debugMessage);
                        }

                        break;
                    }

                case (byte)EventReceiver.ItemSubscriber:
                    {
                        var message = new ItemEventMessage(item, eventData, sendParameters);
                        item.EventChannel.Publish(message);
                        break;
                    }

                default:
                    {
                        return operation.GetOperationResponse((int)ReturnCode.ParameterOutOfRange, "Invalid EventReceiver " + operation.EventReceiver);
                    }
            }

            // no response
            operation.OnComplete();
            return null;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// The publish update.
 /// </summary>
 /// <param name="item">
 /// The publisher.
 /// </param>
 /// <param name="position">
 /// The position.
 /// </param>
 /// <param name="unreliable">
 /// The unreliable.
 /// </param>
 private void PublishUpdate(Item item, float[] position, bool unreliable)
 {
     RadarUpdate updateEvent = GetUpdateEvent(item, position);
     IEventData eventData = new EventData((byte)EventCode.RadarUpdate, updateEvent);
     var message = new ItemEventMessage(item, eventData, new SendParameters { Unreliable = unreliable, ChannelId = Settings.RadarEventChannel });
     this.channel.Publish(message);
 }
 /// <summary>
 ///   The subscribed item event.
 /// </summary>
 /// <param name = "message">
 ///   The message.
 /// </param>
 private void SubscribedItem_OnItemEvent(ItemEventMessage message)
 {
     ItemEventMessage.CounterEventReceive.Increment();
     this.peer.SendEvent(message.EventData, message.SendParameters);
 }
Ejemplo n.º 9
0
 /// <summary>
 ///   Sends the event to the client.
 /// </summary>
 /// <param name = "peer">
 ///   The client peer.
 /// </param>
 /// <param name = "message">
 ///   The message.
 /// </param>
 private static void RadarChannel_OnItemEventMessage(PeerBase peer, ItemEventMessage message)
 {
     // already in right fiber, we would use peer.SendEvent otherwise
     peer.SendEvent(message.EventData, message.SendParameters);
 }
Ejemplo n.º 10
0
 /// <summary>
 ///   Publishes event <see cref = "ItemDestroyed" /> in the <see cref = "Item.EventChannel" />.
 /// </summary>
 protected override void OnDestroy()
 {
     var eventInstance = new ItemDestroyed { ItemId = this.Id, ItemType = this.Type };
     var eventData = new EventData((byte)EventCode.ItemDestroyed, eventInstance);
     var message = new ItemEventMessage(this, eventData, new SendParameters { ChannelId = Settings.ItemEventChannel });
     this.EventChannel.Publish(message);
 }