Пример #1
0
        public bool TryDecodePackage(HttpListenerRequest request, out RequestPackage package, out int statusCode)
        {
            statusCode = 200;
            package    = null;
            string RawUrl   = request.RawUrl;
            bool   NetPayCb = RawUrl.IndexOf("Pay") > 0;

            if (NetPayCb) // Pay for 3rd
            {
                string data = "";
                if (String.Compare(request.HttpMethod, "get", StringComparison.OrdinalIgnoreCase) == 0 ||
                    String.Compare(request.HttpMethod, "post", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    data = request.RawUrl.Substring("Service.aspx".Length + 1);
                    data = HttpUtility.UrlDecode(data);
                }

                int    MsgId     = -1;
                string SessionId = "";
                int    ActionId  = -1;
                int    UserId    = -1;
                string content   = "";
                package = null;
                content = data;
                if (data.Contains("Pay360"))
                {
                    ActionId = 2500;
                    content  = data.Substring(data.IndexOf('?') + 1);
                }
                if (data.Contains("GuccangGuard"))
                {
                    ActionId = 4000;
                    content  = "guccang";
                }
                if (data.Contains("BaiDu"))
                {
                    //if(String.Compare(request.HttpMethod, "get", StringComparison.OrdinalIgnoreCase) == 0)
                    //{
                    //    Console.WriteLine("BaiDu this is get method" + request.RemoteEndPoint);
                    //}
                    //if (String.Compare(request.HttpMethod, "post", StringComparison.OrdinalIgnoreCase) == 0)
//                    {
//                       Console.WriteLine("BaiDu this is post method" + request.RemoteEndPoint);
//                  }


                    ActionId = 2502;
                    content  = "";
                    using (var br = new System.IO.BinaryReader(request.InputStream))
                    {
                        int contentLenght = (int)request.ContentLength64;
                        content = System.Text.Encoding.UTF8.GetString(br.ReadBytes(contentLenght));
                    }
                }
                if (ActionId < 0)
                {
                    return(false);
                }
                package = new RequestPackage(MsgId, SessionId, ActionId, UserId)
                {
                    Message = content
                };
                return(true);
            }
            else if (RawUrl.IndexOf("webBackOffice") > 0)
            {
                // web back-office
                using (var br = new System.IO.BinaryReader(request.InputStream))
                {
                    int    contentLenght = (int)request.ContentLength64;
                    string content       = System.Text.Encoding.UTF8.GetString(br.ReadBytes(contentLenght));
                    package = new RequestPackage(0, "", 4000, 0)
                    {
                        Message = content
                    };
                    System.Console.WriteLine(content);
                }
                return(true);
            }
            else // GameServer Logic
            {
                byte[]      content;
                var         bytes = GetRequestStream(request.InputStream);
                MessagePack head  = ReadMessageHead(bytes, out content);
                if (head == null)
                {
                    return(false);
                }
                package = new RequestPackage(head.MsgId, head.SessionId, head.ActionId, head.UserId)
                {
                    Message = content
                };
                return(true);
            }
        }