Exemplo n.º 1
0
        private void TimeoutSendback(object state)
        {
            HttpClientConnection clientConnection = (HttpClientConnection)state;
            NameValueCollection  requestParam     = clientConnection.Param;
            var responseData = RequestParse.CtorErrMsg(errmsg, requestParam);

            TraceLog.WriteError("超时无法连接游服:{0}", RequestParse.ToQueryString(requestParam));
            SendDataBack(clientConnection.SSID, responseData, 0, responseData.Length);
        }
Exemplo n.º 2
0
        private void TimeoutSendback(object state)
        {
            HttpClientConnection clientConnection = (HttpClientConnection)state;
            NameValueCollection  requestParam     = clientConnection.Param;

            Logger.Error("超时无法连接游服");
            var responseData = RequestParse.CtorErrMsg(errmsg, requestParam);

            SendDataBack(clientConnection.SSID, responseData, 0, responseData.Length);
        }
Exemplo n.º 3
0
 private void TimeoutSendback(object state)
 {
     try
     {
         HttpClientConnection clientConnection = (HttpClientConnection)state;
         NameValueCollection  requestParam     = clientConnection.Param;
         var responseData = RequestParse.CtorErrMsg(10000, RequestParse.ErrorMsgConnectTimeout, requestParam);
         TraceLog.WriteError("超时无法连接游服:{0}", RequestParse.ToQueryString(requestParam));
         SendDataBack(clientConnection.SSID, responseData, 0, responseData.Length);
     }
     catch (Exception ex)
     {
         TraceLog.WriteError("Http Proxy Timeout Sendback:{0}", ex);
     }
 }
Exemplo n.º 4
0
        public void ListenerCallback(IAsyncResult result)
        {
            HttpListener listener = (HttpListener)result.AsyncState;
            HttpListenerContext context = listener.EndGetContext(result);
            listener.BeginGetContext(ListenerCallback, listener);

            var ssid = Guid.NewGuid();
            HttpListenerRequest request = context.Request;
            HttpListenerResponse response = context.Response;

            string data = "";
            if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                if (string.Compare(request.HttpMethod, "get", true) == 0)
                {
                    data = request.RawUrl.Substring(8);
                    data = HttpUtility.UrlDecode(data);
                }
            }
            else
            {
                data = request.QueryString["d"];
            }

            if (string.IsNullOrEmpty(data))
            {
                using (var reader = new StreamReader(request.InputStream, request.ContentEncoding))
                {
                    data = reader.ReadToEnd();
                    data = HttpUtility.ParseQueryString(data)["d"];
                }
            }

            int gameId, serverId, statuscode;
            var requestParam = RequestParse.Parse(request.RemoteEndPoint.Address.ToString(), request.RawUrl, data,out gameId, out serverId, out statuscode);
            if (statuscode != (int)HttpStatusCode.OK)
            {
                response.StatusCode = statuscode;
                response.Close();
                return;
            }

            requestParam["UserHostAddress"] = request.RemoteEndPoint.Address.ToString();
            requestParam["ssid"] = ssid.ToString("N");
            requestParam["http"] = "1";

            var clientConnection = new HttpClientConnection { Context = context, SSID = ssid, Param = requestParam };
            clientConnection.TimeoutTimer = new Timer(TimeoutSendback, clientConnection, httpProxyTimeout, Timeout.Infinite);
            byte[] paramData = Encoding.ASCII.GetBytes(RequestParse.ToQueryString(requestParam));
            pool[ssid] = clientConnection;

            try
            {
                gsConnectionManager.Send(gameId,serverId, paramData);
            }
            catch (Exception ex)
            {
                Logger.Error("无法连接游服", ex);
                var responseData = RequestParse.CtorErrMsg(errmsg, requestParam);
                SendDataBack(ssid, responseData, 0, responseData.Length);
            }
        }
Exemplo n.º 5
0
        public void ListenerCallback(IAsyncResult result)
        {
            HttpListener        listener = (HttpListener)result.AsyncState;
            HttpListenerContext context  = listener.EndGetContext(result);

            listener.BeginGetContext(ListenerCallback, listener);

            var ssid = Guid.NewGuid();
            HttpListenerRequest  request  = context.Request;
            HttpListenerResponse response = context.Response;

            string data = "";

            if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                if (string.Compare(request.HttpMethod, "get", true) == 0)
                {
                    data = request.RawUrl.Substring(8);
                    data = HttpUtility.UrlDecode(data);
                }
            }
            else
            {
                data = request.QueryString["d"];
            }

            if (string.IsNullOrEmpty(data))
            {
                using (var reader = new StreamReader(request.InputStream, request.ContentEncoding))
                {
                    data = reader.ReadToEnd();
                    data = HttpUtility.ParseQueryString(data)["d"];
                }
            }

            int gameId, serverId, statuscode;
            var requestParam = RequestParse.Parse(request.RemoteEndPoint.Address.ToString(), request.RawUrl, data, out gameId, out serverId, out statuscode);

            if (statuscode != (int)HttpStatusCode.OK)
            {
                response.StatusCode = statuscode;
                response.Close();
                return;
            }

            requestParam["UserHostAddress"] = request.RemoteEndPoint.Address.ToString();
            requestParam["ssid"]            = ssid.ToString("N");
            requestParam["http"]            = "1";

            var clientConnection = new HttpClientConnection {
                Context = context, SSID = ssid, Param = requestParam
            };

            clientConnection.TimeoutTimer = new Timer(TimeoutSendback, clientConnection, httpProxyTimeout, Timeout.Infinite);
            byte[] paramData = Encoding.ASCII.GetBytes(RequestParse.ToQueryString(requestParam));
            pool[ssid] = clientConnection;

            try
            {
                gsConnectionManager.Send(gameId, serverId, paramData);
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("无法连接游服error:{0}", ex);
                var responseData = RequestParse.CtorErrMsg(errmsg, requestParam);
                SendDataBack(ssid, responseData, 0, responseData.Length);
            }
        }