Ejemplo n.º 1
0
        public byte[] HandleQuery(string sourceUserID, int contractaID, byte[] info)
        {
            ICustomizeHandler customizeHandler = this.FindHandler(contractaID);

            byte[] result;
            if (customizeHandler != null)
            {
                result = customizeHandler.HandleQuery(sourceUserID, contractaID, info);
            }
            else
            {
                result = null;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public void Process(RequestInfo request)
        {
            var message = request.MessagePacket;

            try
            {
                #region Noraml
                if (message.MessageHeader.MessageType == MessageType.Noraml)
                {
                    if (message.MessageHeader.DestUserID == GloblParams.DefaultServerID)
                    {
                        customizeHandler.Handle(message.MessageHeader.SourceUserID, message.ContractID, message.BodyContent);
                    }
                    else
                    {
                        basicController.Send(message.MessageHeader.DestUserID, message);
                    }
                }
                #endregion

                #region Ack_Req
                else if (message.MessageHeader.MessageType == MessageType.Ack_Req)
                {
                    if (message.MessageHeader.DestUserID == GloblParams.DefaultServerID)
                    {
                        ResponseAck(request.Channel, message);
                        customizeHandler.Handle(message.MessageHeader.SourceUserID, message.ContractID, message.BodyContent);
                    }
                    else
                    {
                        basicController.Send(message.MessageHeader.DestUserID, message);
                    }
                }
                #endregion

                #region Blob
                else if (message.MessageHeader.MessageType == MessageType.Blob)
                {
                    if (message.MessageHeader.DestUserID == GloblParams.DefaultServerID)
                    {
                        BlobContract contract = BlobContract.Parser.ParseFrom(message.BodyContent);
                        string       keyStr   = message.MessageHeader.SourceUserID + contract.BlobID.ToString();
                        BlobItem     item     = hotDic.Get(keyStr);
                        if (item == null)
                        {
                            item = new BlobItem();
                            hotDic.Add(keyStr, item);
                        }
                        item.Add(contract.FragmentIndex, contract.Fragment);
                        if (contract.IsLast)
                        {
                            BlobItem     blob   = this.hotDic.GetAndRemove(keyStr);
                            MemoryStream stream = new MemoryStream();
                            foreach (var blobItem in blob)
                            {
                                blobItem.Value.WriteTo(stream);
                            }
                            byte[] bytes = stream.ToArray();
                            stream.Dispose();
                            customizeHandler.Handle(message.MessageHeader.SourceUserID, message.ContractID, bytes);
                        }
                    }
                    else
                    {
                        basicController.Send(message.MessageHeader.DestUserID, message);
                    }
                }
                #endregion

                #region Ack_Resp
                else if (message.MessageHeader.MessageType == MessageType.Ack_Resp)
                {
                    basicController.Send(message.MessageHeader.DestUserID, message);
                }
                #endregion

                #region Query_Req
                else if (message.MessageHeader.MessageType == MessageType.Query_Req)
                {
                    if (message.MessageHeader.DestUserID == GloblParams.DefaultServerID)
                    {
                        byte[] result = customizeHandler.HandleQuery(message.MessageHeader.SourceUserID, message.ContractID, message.BodyContent);
                        ResponseQuery(request.Channel, MessageType.Query_Resp, message, result);
                    }
                    else
                    {
                        basicController.Send(message.MessageHeader.DestUserID, message);
                    }
                }
                #endregion

                #region Query_Resp
                else if (message.MessageHeader.MessageType == MessageType.Query_Resp)
                {
                    basicController.Send(message.MessageHeader.DestUserID, message);
                }
                #endregion

                #region Login
                else if (message.MessageHeader.MessageType == MessageType.Login)
                {
                    LoginContract       loginContract = LoginContract.Parser.ParseFrom(message.BodyContent);
                    string              cause;
                    LoginResultContract result = null;
                    bool verResult             = basicHandler.VerifyUser(loginContract, request.Channel, out cause);
                    this.basicController.userManager.Add(loginContract.Uid, request.Channel);
                    result = new LoginResultContract()
                    {
                        Result  = verResult ? 0 : 1,
                        Failure = cause
                    };
                    ResponseQuery(request.Channel, MessageType.LoginResp, message, result.ToByteArray());
                }
                #endregion

                else
                {
                    //handler.HandleQuery(request);
                }
            }
            catch
            {
            }
        }