Esempio n. 1
0
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            var gameOperationRequest = new GameOperationRequest(operationRequest.Parameters);
            var parameters           = new MessageParameters {
                ChannelId = sendParameters.ChannelId, Encrypted = sendParameters.Encrypted
            };

            switch (operationRequest.OperationCode)
            {
            case (byte)ClientOperationCode.Login:
            {
                this.RequestFiber.Enqueue(() => this.loginOperationHandler.OnOperationRequest(gameOperationRequest, parameters));
            }
            break;

            case (byte)ClientOperationCode.Character:
            {
                this.RequestFiber.Enqueue(() => this.characterOperationHandler.OnOperationRequest(gameOperationRequest, parameters));
            }
            break;

            default:
            {
                this.SendOperationResponse(gameOperationRequest.ClientId,
                                           new GameErrorResponse(operationRequest.OperationCode)
                    {
                        ReturnCode = (short)ResultCode.OperationNotAvailable,
                    },
                                           new MessageParameters());
            }
            break;
            }
        }
        public void OnOperationRequest(GameOperationRequest operationRequest, MessageParameters parameters)
        {
            switch ((GameOperationCode)operationRequest.OperationCode)
            {
            case GameOperationCode.LoginUser:
            {
                this.ExecUserOperation(() => this.HandleOperationLogin(operationRequest, parameters), operationRequest.ClientId, parameters);
            }
            break;

            case GameOperationCode.CreateUser:
            {
                this.ExecUserOperation(() => this.HandleOperationCreateNewUser(operationRequest, parameters), operationRequest.ClientId, parameters);
            }
            break;

            default:
            {
                this.peer.SendOperationResponse(operationRequest.ClientId,
                                                new GameErrorResponse(operationRequest.OperationCode)
                    {
                        ReturnCode = (short)ResultCode.OperationNotAvailable,
                    },
                                                new MessageParameters());
            }
            break;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Called when an operation request has been received.
        /// </summary>
        /// <remarks>An operation request is sent when a client sends an operation request to the master. So all operation requests are from game clients</remarks>
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            var gameOperationRequest = new GameOperationRequest(operationRequest.Parameters);

            if (!gameOperationRequest.IsValid)
            {
#if MMO_DEBUG
                Logger.DebugFormat("[OnOperationRequest]: GameOperationRequest (OpCode={0}) is not valid", operationRequest.OperationCode);
#endif
                return;
            }

            ISession session;
            if (sessions.TryGetValue(gameOperationRequest.ClientId, out session))
            {
                var messageParameters = new MessageParameters {
                    ChannelId = sendParameters.ChannelId, Encrypted = sendParameters.Encrypted
                };
                session.ReceiveOperationRequest(gameOperationRequest, messageParameters);
            }
            else
            {
                Logger.ErrorFormat("[OnOperationRequest]: Session (Id={0}) cannot be found", gameOperationRequest.ClientId);
            }
        }
Esempio n. 4
0
        protected virtual GameOperationResponse HandleOperationLogoutUser(GameOperationRequest operationRequest, MessageParameters parameters)
        {
            this.peer.SendOperationRequest(new OperationRequest((byte)ServerOperationCode.KillClient,
                                                                new KillClient
            {
                ClientId = operationRequest.ClientId
            }),
                                           new SendParameters());

            return(null);
        }
Esempio n. 5
0
        protected virtual GameOperationResponse HandleOperationCreateCharacter(GameOperationRequest operationRequest, MessageParameters parameters)
        {
            var operation = new CreateCharacter(this.peer.Protocol, operationRequest);

            if (!operation.IsValid)
            {
                return(operation.GetErrorResponse((short)ResultCode.InvalidOperationParameter, operation.GetErrorMessage()));
            }

            ThreadPool.QueueUserWorkItem(
                o => this.ExecUserOperation(() => this.HandleCreateCharacter(operationRequest.ClientId, operation), operationRequest.ClientId, parameters));

            return(null);
        }
Esempio n. 6
0
 public AcceptQuest(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 7
0
 public SpHeal(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 8
0
 public LootAll(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 9
0
 public SelectDialogue(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 10
0
 public EnterWorld(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 11
0
 public CastSpell(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 12
0
 public LeaveGroup(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 13
0
 public MoveActionbarSlot(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 14
0
 /// <summary>
 /// Queues an <see cref="GameOperationRequest"/> to be processed
 /// </summary>
 public void ReceiveOperationRequest(GameOperationRequest operationRequest, MessageParameters messageParameters)
 {
     this.chat.SyncFiber.Enqueue(() => this.OnOperationRequest(operationRequest, messageParameters));
 }
Esempio n. 15
0
        private GameOperationResponse HandleOperationSendChat(GameOperationRequest operationRequest)
        {
            var operation = new SendChat(server.Protocol, operationRequest);

            if (!operation.IsValid)
            {
                return new GameErrorResponse(operationRequest.OperationCode)
                       {
                           ReturnCode = (short)ResultCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage()
                       }
            }
            ;

            switch ((MessageType)operation.MessageType)
            {
            case MessageType.Group:
            {
                lock (joinedChannels)
                {
                    var channel = this.joinedChannels.Find(chnl => chnl.Type == ChannelType.Group);
                    if (channel == null)
                    {
                        return new SendChatResponse(operation.OperationCode)
                               {
                                   ReturnCode = (short)ResultCode.ChannelNotAvailable, MessageType = operation.MessageType
                               }
                    }
                    ;

                    // TODO: Normalize content and prevent spam
                    var message = operation.Message;
                    if (string.IsNullOrEmpty(message))
                    {
                        return(operation.GetErrorResponse((short)ResultCode.MessageIsEmpty));
                    }

                    channel.Publish(message, this);
                }
            }
            break;

            case MessageType.Guild:
            {
                lock (joinedChannels)
                {
                    var channel = this.joinedChannels.Find(chnl => chnl.Type == ChannelType.Guild);
                    if (channel == null)
                    {
                        return new SendChatResponse(operation.OperationCode)
                               {
                                   ReturnCode = (short)ResultCode.ChannelNotAvailable, MessageType = operation.MessageType
                               }
                    }
                    ;

                    // TODO: Normalize content and prevent spam
                    var message = operation.Message;
                    if (string.IsNullOrEmpty(message))
                    {
                        return(operation.GetErrorResponse((short)ResultCode.MessageIsEmpty));
                    }

                    channel.Publish(message, this);
                }
            }
            break;

            case MessageType.Local:
            {
                lock (joinedChannels)
                {
                    var channel = this.joinedChannels.Find(chnl => chnl.Type == ChannelType.Local);
                    if (channel == null)
                    {
                        return new SendChatResponse(operation.OperationCode)
                               {
                                   ReturnCode = (short)ResultCode.ChannelNotAvailable, MessageType = operation.MessageType
                               }
                    }
                    ;

                    // TODO: Normalize content and prevent spam
                    var message = operation.Message;
                    if (string.IsNullOrEmpty(message))
                    {
                        return(operation.GetErrorResponse((short)ResultCode.MessageIsEmpty));
                    }

                    channel.Publish(message, this);
                }
            }
            break;

            case MessageType.Trade:
            {
                lock (joinedChannels)
                {
                    var channel = this.joinedChannels.Find(chnl => chnl.Type == ChannelType.Trade);
                    if (channel == null)
                    {
                        return new SendChatResponse(operation.OperationCode)
                               {
                                   ReturnCode = (short)ResultCode.ChannelNotAvailable, MessageType = operation.MessageType
                               }
                    }
                    ;

                    // TODO: Normalize content and prevent spam
                    var message = operation.Message;
                    if (string.IsNullOrEmpty(message))
                    {
                        return(operation.GetErrorResponse((short)ResultCode.MessageIsEmpty));
                    }

                    channel.Publish(message, this);
                }
            }
            break;

            case MessageType.Tell:
            {
                var receiverName = operation.Receiver;
                if (string.IsNullOrEmpty(receiverName))
                {
                    return(operation.GetErrorResponse((short)ResultCode.PlayerNotFound));
                }

                ChatSession receiver;
                if (!chat.SessionCache.TryGetSessionBySessionName(receiverName, out receiver))
                {
                    return(operation.GetErrorResponse((short)ResultCode.PlayerNotFound));
                }

                // TODO: Normalize content and prevent spam
                var message = operation.Message;
                if (string.IsNullOrEmpty(message))
                {
                    return(operation.GetErrorResponse((short)ResultCode.MessageIsEmpty));
                }

                receiver.ReceiveTell(this, message);
            }
            break;

            default:
            {
#if MMO_DEBUG
                _logger.DebugFormat("[HandleOperationSendChat]: Session (Name={0}) sent an unhandled Message (Type={1})", name,
                                    (MessageType)operation.MessageType);
#endif
            }
            break;
            }

            return(null);
        }

        /// <summary>
        /// Call this to handle client operation requests
        /// </summary>
        void OnOperationRequest(GameOperationRequest operationRequest, MessageParameters messageParameters)
        {
            GameOperationResponse response;

            switch ((GameOperationCode)operationRequest.OperationCode)
            {
            case GameOperationCode.SendChat:
                response = this.HandleOperationSendChat(operationRequest);
                break;

            default:
                response = new GameErrorResponse(operationRequest.OperationCode)
                {
                    ReturnCode = (short)ResultCode.OperationNotAvailable
                };
                break;
            }

            if (response != null)
            {
                this.SendOperationResponse(response, messageParameters);
            }
        }

        #endregion

        #region Helper Methods

        void DoAddSession()
        {
            // adding session to the chat
            while (!chat.AddSession(this))
            {
                ChatSession exisitingSession;
                if (chat.SessionCache.TryGetSessionBySessionId(sessionId, out exisitingSession))
                {
                    // this shouldn't happen because the master won't let the same player login twice it will disconnect the exisitng player
                    // we are handling it to satisfy Murphy's Law
#if MMO_DEBUG
                    _logger.DebugFormat("[DoAddSession]: ChatSession (Name={0}) cannot be added because an existing ChatSession (Name={1}) is found",
                                        this.Name, exisitingSession.Name);
#endif
                    exisitingSession.Disconnect();
                    this.Disconnect();
                    this.Destroy(DestroySessionReason.KickedByExistingSession);
                    return;
                }
            }
        }

        #endregion
    }
Esempio n. 16
0
 public UseInventorySlot(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 17
0
 public AddActionbarSpell(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 18
0
 public SendChat(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 19
0
 public DisbandGroup(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 20
0
 public Rotate(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 21
0
 public LogoutUser(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 22
0
 public RemoveFriend(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 23
0
 public DeclineFriendRequest(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 24
0
 public CreateCharacter(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 25
0
 public SpRemoveSpell(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 26
0
 public CloseInteraction(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 27
0
 public SendGroupInvite(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 28
0
 public SpAddGold(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 29
0
 public RetrieveCharacters(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }
Esempio n. 30
0
 public SellItem(IRpcProtocol protocol, GameOperationRequest request)
     : base(protocol, request)
 {
 }