Beispiel #1
0
        public ListenerContextData(HttpListenerContext context)
        {
            this.m_Context = context;
            string httpMethod = this.m_Context.Request.HttpMethod;
            Uri    uri        = this.m_Context.Request.Url;

            Console.WriteLine($"Uri: host-{uri.Host}, port-{uri.Port}, userinfo-{uri.UserInfo}");
            switch (httpMethod.ToUpper())
            {
            case "GET":
                m_type = MethodType.GET;
                Console.WriteLine(this.m_Context.Request.UserHostAddress + " -> Use Get Request.");
                m_httpMethodData = new HttpMethodGetData(this.m_Context.Request, this.m_Context.Response);
                break;

            case "POST":
                m_type = MethodType.POST;
                Console.WriteLine(this.m_Context.Request.UserHostAddress + " -> Use Post Request.");
                m_httpMethodData = new HttpMethodPostData(this.m_Context.Request, this.m_Context.Response);
                break;

            default:
                m_errorData = new ErrorData(this.m_Context.Response, ErrorType.None, "ListenerContextData Unknow Error.");
                break;
            }
        }
Beispiel #2
0
        public HttpMethodGetData(HttpListenerRequest request, HttpListenerResponse response)
        {
            this.m_request  = request;
            this.m_response = response;

            //NameValueCollection headers = this.m_request.Headers;
            //CookieCollection cookies = this.m_request.Cookies;
            //if (headers != null)
            //{
            //    string[] values = headers.GetValues("Content-Function");
            //    if (values != null)
            //    {
            //        m_function = values.FirstOrDefault();
            //    }
            //}

            Console.WriteLine(this.m_request.RawUrl.Trim('/'));
            m_function = this.m_request.RawUrl.Trim('/');
            switch (m_function)
            {
            case "AssetBundles":
                m_functionData = new AssetBundleDownloadData(request, response);
                break;

            case "ServerTime":
                m_functionData = new ServerTimeData(response);
                break;

            case "PackageUpdate":
                m_functionData = new PackageUpdateData(request, response);
                break;

            case "favicon.ico":
                ErrorData = new ErrorData(this.m_response, ErrorType.FaviconIcon, "HttpMethodGetData favicon.ico Request.");
                break;

            default:
                ErrorData = new ErrorData(this.m_response, ErrorType.None, "HttpMethodGetData Unknow Error.");
                break;
            }
        }
Beispiel #3
0
        public AssetBundleDownloadData(HttpListenerRequest request, HttpListenerResponse response)
        {
            m_request  = request;
            m_response = response;

            NameValueCollection headers = this.m_request.Headers;
            CookieCollection    cookies = this.m_request.Cookies;

            if (headers != null)
            {
                string[] gameIDs = headers.GetValues("Content-GameID");
                if (gameIDs != null)
                {
                    m_gameID = gameIDs.FirstOrDefault();
                }
                string[] platforms = headers.GetValues("Content-Platform");
                if (platforms != null)
                {
                    m_platform = platforms.FirstOrDefault();
                }
                string[] versions = headers.GetValues("Content-Version");
                if (versions != null)
                {
                    m_version = versions.FirstOrDefault();
                }
                string[] checks = headers.GetValues("Content-VersionCheck");
                if (checks != null)
                {
                    m_versionCheck = Convert.ToBoolean(checks.FirstOrDefault());
                }
            }
            if (!string.IsNullOrEmpty(m_platform) && !string.IsNullOrEmpty(m_gameID) && !string.IsNullOrEmpty(m_version))
            {
                string m_fileDir = new DirectoryInfo(m_assetBundlesPath + "/" + m_gameID + "/" + m_platform).FullName;
                if (!Directory.Exists(m_fileDir))
                {
                    m_errorData = new ErrorData(this.m_response, ErrorType.None, "AssetBundleDownloadData Error: file Directory not exists.");
                }
                else
                {
                    DirectoryInfo infoDir = new DirectoryInfo(m_fileDir);
                    if (m_versionCheck)
                    {
                        FileInfo[] versions = infoDir.GetFiles();
                        if (versions == null || versions.Length <= 0)
                        {
                            m_errorData = new ErrorData(this.m_response, ErrorType.None, "AssetBundleDownloadData Error: not version.");
                            return;
                        }
                        int        index            = m_version.LastIndexOf('.');
                        string     versionName      = m_version.Substring(0, index);
                        string     versionExt       = m_version.Substring(index, m_version.Length - index);
                        FileInfo[] versionArrayData = versions.Where(info => { return(info.Extension == versionExt); }).ToArray();
                        if (versionArrayData == null || versionArrayData.Length <= 0)
                        {
                            m_errorData = new ErrorData(this.m_response, ErrorType.FileNotExists, "AssetBundleDownloadData Error: version arrary data is null.");
                            return;
                        }
                        FileInfo[] versionArray      = versions.OrderBy(file => { return(file.Name); }).ToArray();
                        FileInfo   latestVersionInfo = versionArray[versionArray.Length - 1];
                        string     latestVersion     = Path.GetFileNameWithoutExtension(latestVersionInfo.FullName);
                        int        result            = latestVersion.CompareTo(versionName);
                        if (result == 0)
                        {
                            // 最新版
                            m_versionCheckData = new VersionCheckData(m_response, VersionCheckType.LatestType, latestVersionInfo.Name);
                        }
                        else if (result > 0)
                        {
                            // 可更新
                            m_versionCheckData = new VersionCheckData(m_response, VersionCheckType.UpdateType, latestVersionInfo.Name);
                        }
                        else
                        {
                            // 本地大于服务器
                            m_versionCheckData = new VersionCheckData(m_response, VersionCheckType.None, latestVersionInfo.Name);
                        }
                    }
                    else
                    {
                        string fileName = infoDir.FullName + "/" + m_version;
                        if (!File.Exists(fileName))
                        {
                            m_errorData = new ErrorData(this.m_response, ErrorType.None, "AssetBundleDownloadData Error: version file not exists.");
                        }
                        else
                        {
                            m_fileBuffer = new FileInfo(fileName);
                        }
                        //SharpZipUtility.ZipFie(strFilePath, m_fileName);
                    }
                }
            }
            else
            {
                m_errorData = new ErrorData(this.m_response, ErrorType.None, "AssetBundleDownloadData Error: Unknow error.");
            }
        }
        public PackageUpdateData(HttpListenerRequest request, HttpListenerResponse response)
        {
            m_request  = request;
            m_response = response;

            NameValueCollection headers = this.m_request.Headers;
            CookieCollection    cookies = this.m_request.Cookies;

            if (headers != null)
            {
                string[] gameIDs = headers.GetValues("Content-GameID");
                if (gameIDs != null)
                {
                    m_gameID = gameIDs.FirstOrDefault();
                }
                string[] platforms = headers.GetValues("Content-Platform");
                if (platforms != null)
                {
                    m_platform = platforms.FirstOrDefault();
                }
                string[] versions = headers.GetValues("Content-Version");
                if (versions != null)
                {
                    m_version = versions.FirstOrDefault();
                }
                string[] checks = headers.GetValues("Content-VersionCheck");
                if (checks != null)
                {
                    m_versionCheck = Convert.ToBoolean(checks.FirstOrDefault());
                }
            }
            if (!string.IsNullOrEmpty(m_platform) && !string.IsNullOrEmpty(m_gameID) && !string.IsNullOrEmpty(m_version))
            {
                // 包含 包名(com.android.softliu.huawei) - 版本号(0.1.0)
                string[] inputVersions = m_version.Split('-');
                if (inputVersions.Length < 2)
                {
                    m_errorData = new ErrorData(this.m_response, ErrorType.None, "PackageUpdateData Error: Input Versions Length < 2");
                    return;
                }
                string packName    = inputVersions[0];
                string versionName = inputVersions[1];

                string m_fileDir = new DirectoryInfo(m_packagePath + "/" + m_platform + "/" + m_gameID + "/" + packName).FullName;
                if (!Directory.Exists(m_fileDir))
                {
                    m_errorData = new ErrorData(this.m_response, ErrorType.None, "PackageUpdateData Error: m_fileDir path not existis.");
                }
                else
                {
                    DirectoryInfo infoDir  = new DirectoryInfo(m_fileDir);
                    FileInfo[]    versions = infoDir.GetFiles();
                    if (versions == null || versions.Length <= 0)
                    {
                        m_errorData = new ErrorData(this.m_response, ErrorType.None, "PackageUpdateData Error: Version Directory not versions.");
                        return;
                    }
                    FileInfo[] versionArray  = versions.OrderBy(file => { return(file.Name); }).ToArray();
                    FileInfo   latestVersion = versionArray[versionArray.Length - 1];
                    if (m_versionCheck)
                    {
                        string latestVersionName = Path.GetFileNameWithoutExtension(latestVersion.FullName);
                        int    result            = latestVersionName.CompareTo(versionName);
                        if (result == 0)
                        {
                            // 最新版
                            m_versionCheckData = new VersionCheckData(m_response, VersionCheckType.LatestType, latestVersion.Name);
                        }
                        else if (result > 0)
                        {
                            // 可更新
                            m_versionCheckData = new VersionCheckData(m_response, VersionCheckType.UpdateType, latestVersion.Name);
                        }
                        else
                        {
                            // 本地大于服务器
                            m_versionCheckData = new VersionCheckData(m_response, VersionCheckType.None, latestVersion.Name);
                        }
                    }
                    else
                    {
                        string extensionName = Path.GetExtension(latestVersion.FullName);
                        string fullPath      = m_fileDir + "/" + versionName + extensionName;
                        if (File.Exists(fullPath))
                        {
                            m_fileBuffer = new FileInfo(fullPath);
                        }
                        else
                        {
                            m_errorData = new ErrorData(m_response, ErrorType.FileNotExists, "PackageUpdateData Error: not find lastest version file.");
                        }
                    }
                }
            }
            else
            {
                m_errorData = new ErrorData(m_response, ErrorType.None, "PackageUpdateData Error: Unknow Error.");
            }
        }