Beispiel #1
0
        /// <summary>
        /// Handles operation <see cref="Chat"/>: Chat from one item and send the chat message to another clients using event <see cref="ItemChat"/>
        /// </summary>
        /// <param name="peer">The client peer</param>
        /// <param name="request">The request</param>
        /// <returns>Null or an <see cref="OperationResponse"/>with error code <see cref="ErrorCode.ItemNotFound"/></returns>
        public OperationResponse OperationChat(PeerBase peer, OperationRequest request, SendParameters sendParameters)
        {
            var operation = new Chat(peer.Protocol, request);
            if (!operation.IsValid)
            {
                return new OperationResponse(request.OperationCode) { ReturnCode = (int)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() };
            }

            Item item;
            if (false == operation.ItemType.HasValue || string.IsNullOrEmpty(operation.ItemId))
            {
                item = this.Avatar;

                operation.ItemId = item.Id;
                operation.ItemType = item.Type;
            }
            else if (this.TryGetItem(operation.ItemType.Value, operation.ItemId, out item) == false)
            {
                return operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound");
            }

            return this.ItemOperationChat((MmoItem)item, operation, sendParameters);
        }
Beispiel #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);
        }