コード例 #1
0
ファイル: MmoActor.cs プロジェクト: azanium/PopBloop-Unity
        /// <summary>
        ///   Subscribes an item.
        /// </summary>
        /// <param name = "item">
        ///   The mmo item.
        /// </param>
        /// <param name = "operation">
        ///   The operation.
        /// </param>
        /// <param name = "interestArea">
        ///   The interestArea.
        /// </param>
        /// <returns>
        ///   Ok or ItemNotFound
        /// </returns>
        private OperationResponse ItemOperationSubscribeItem(Item item, SubscribeItem operation, InterestArea interestArea)
        {
            if (item.Disposed)
            {
                return operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound");
            }

            lock (interestArea.SyncRoot)
            {
                interestArea.SubscribeItem(item);
            }

            if (operation.PropertiesRevision.HasValue == false || operation.PropertiesRevision.Value != item.PropertiesRevision)
            {
                var properties = new ItemPropertiesSet
                    {
                       ItemId = item.Id, ItemType = item.Type, PropertiesRevision = item.PropertiesRevision, PropertiesSet = new Hashtable(item.Properties)
                    };
                var eventData = new EventData((byte)EventCode.ItemPropertiesSet, properties);
                this.Peer.SendEvent(eventData, new SendParameters { ChannelId = Settings.ItemEventChannel });
            }

            // don't send response
            operation.OnComplete();
            return null;
        }
コード例 #2
0
ファイル: MmoActor.cs プロジェクト: azanium/PopBloop-Unity
        /// <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);
        }