예제 #1
0
        private void RequestParser(TcpClient Client)
        {
            string sBuffer = "";

            ConId++;

            MainStats.TriggerConnection(Client.Client.RemoteEndPoint.ToString());
            string Temp = Client.Client.RemoteEndPoint.ToString();

            Byte[] bReceive = new Byte[1024 * 8];

            try
            {
                int i = Client.Client.Receive(bReceive, bReceive.Length, 0);
            }
            catch { }

            sBuffer = Encoding.UTF8.GetString(bReceive);

            if (sBuffer.Substring(0, 3) != "GET")
            {
                Client.Client.Disconnect(false);
                Client.Client.Close();
                MainStats.TriggerConnectionEnd(Temp);
                return;
            }

            string sRequest = string.Empty;

            string[] UrlParts = { "", "", "", "", "" };

            try
            {
                sRequest = sBuffer.Substring(0, sBuffer.IndexOf("HTTP", 1) - 1).Substring(4);
                UrlParts = sRequest.Split('/');
            }
            catch
            {
                Client.Client.Disconnect(false);
                Client.Client.Close();
                MainStats.TriggerConnectionEnd(Temp);
                return;
            }
            Response output;

            if (sRequest == "/")
            {
                output = new Stats(Client);
            }
            else if (sRequest == "/favicon.ico")
            {
                output = new Favicon(Client);
            }
            else if ((UrlParts[1] == "r" || UrlParts[1] == "h") && UrlParts.Length >= 3)
            {
                output = new FileUpload(Client, UrlParts[2], UrlParts);
            }
            else if (UrlParts[1] == "servercmd" && UrlParts.Length >= 3)
            {
                output = new ServerCMD(Client, UrlParts);
            }
            else
            {
                output = new Unknown(Client);
            }

            output.Send();

            if (sRequest != "/" && sRequest != "/favicon.ico")
            {
                Log.Add(String.Format("OUT > {1,22} {0,13} bytes [ took: {3,8}s at {4,9}kb/s] -> {2}", output.Size, Temp, sRequest, Math.Round(output.Time / 1000, 3), Math.Round(output.Speed / 1024, 3)), LogType.Info, true);
            }

            MainStats.TriggerConnectionEnd(Temp);
        }