Пример #1
0
    public override void Initialize(DownloadState downloadState, ServerConfiguration serverConfiguration, DownloadPresenter downloadPresenter)
    {
        base.Initialize(downloadState, serverConfiguration, downloadPresenter);

        pathToSaveFiles = serverConfiguration.GetPathToSaveFiles();
        port            = int.Parse(serverConfiguration.FileDownloadServerPort);
        filesToDownload = downloadState.FilesToDownload;
        resourcePathForFilesToDownload = downloadState.ResourcePathForFilesToDownload ?? "";
        numberOfFilesToDownload        = filesToDownload.Count;
        downloadPresenter.SetFileList(filesToDownload);
        downloadCoroutine = downloadPresenter.StartCoroutine(DownloadFiles());
    }
Пример #2
0
    public void Enter()
    {
        Screen.sleepTimeout = SleepTimeout.NeverSleep;
        serverConfiguration = ServerConfigurationModel.ActiveConfiguration;
        pathToSaveFiles     = serverConfiguration.GetPathToSaveFiles();
        Debug.Log($"Downloading files to {pathToSaveFiles}");
        port = int.Parse(serverConfiguration.FileDownloadServerPort);

        if (serverConfiguration.AllFilesDownloaded || (Application.isEditor && forceDownloadsInEditor == false))
        {
            StateManager.GoToState <GameState>();
        }
        else
        {
            downloadPresenter.gameObject.SetActive(true);
            //Get list of files to download from server
            var uri     = GetUri(serverConfiguration.FileDownloadServerUrl, port);
            var request = UnityWebRequest.Get(uri);
            request.SendWebRequest().completed += operation =>
            {
                if (request.isHttpError || request.isNetworkError)
                {
                    var error = $"Error while getting list of files from server: {request.error}";
                    Debug.LogError(error);
                    downloadPresenter.ShowError(error);
                    return;
                }

                downloadingFilesList = new List <string>(Regex
                                                         .Matches(request.downloadHandler.text, H_REF_PATTERN, RegexOptions.IgnoreCase).Cast <Match>()
                                                         .Select(match => match.Groups[1].Value)
                                                         .Where(text => text.Contains(".") &&
                                                                text.Contains(".exe") == false &&
                                                                text.Contains(".app") == false &&
                                                                text.Contains(".dll") == false &&
                                                                text.Contains(".pdb") == false &&
                                                                text.Contains("/") == false));
                numberOfFilesToDownload = downloadingFilesList.Count;
                downloadPresenter.SetFileList(downloadingFilesList);
                downloadCoroutine = downloadPresenter.StartCoroutine(DownloadFiles());
            };
        }
    }
Пример #3
0
    private IEnumerator DownloadFiles(List <string> filesList)
    {
        int index = 0;

        var pathToSaveFiles = serverConfiguration.GetPathToSaveFiles();
        var directoryInfo   = new DirectoryInfo(pathToSaveFiles);

        if (directoryInfo.Exists == false)
        {
            directoryInfo.Create();
        }

        while (index < filesList.Count)
        {
            while (concurrentDownloadCounter < maxConcurrentDownloads && index < filesList.Count)
            {
                var fileName            = filesList[index++];
                var uriBuilder          = new UriBuilder("http", serverConfiguration.FileDownloadServerUrl, 8080, fileName);
                var request             = UnityWebRequest.Get(uriBuilder.Uri);
                var filePath            = Path.Combine(pathToSaveFiles, fileName);
                var fileDownloadHandler = new DownloadHandlerFile(filePath);
                fileDownloadHandler.removeFileOnAbort = true;
                request.downloadHandler = fileDownloadHandler;
                request.SendWebRequest().completed += operation => SingleFileDownloadFinished(request, fileName);
                ++concurrentDownloadCounter;
            }

            yield return(new WaitUntil(() => concurrentDownloadCounter < maxConcurrentDownloads));
        }

        //Wait until final downloads finish
        yield return(new WaitUntil(() => concurrentDownloadCounter == 0));

        serverConfiguration.AllFilesDownloaded = true;
        ServerConfigurationModel.SaveServerConfigurations();

        StateManager.GoToState <GameState>();
    }
Пример #4
0
    public void StartGame(ServerConfiguration config)
    {
        CUOEnviroment.ExecutablePath = config.GetPathToSaveFiles();

        //Load and adjust settings
        var settingsFilePath = Settings.GetSettingsFilepath();

        if (File.Exists(settingsFilePath))
        {
            Settings.GlobalSettings = JsonConvert.DeserializeObject <Settings>(File.ReadAllText(settingsFilePath));
        }
        else
        {
            Settings.GlobalSettings = JsonConvert.DeserializeObject <Settings>(Resources.Load <TextAsset>("settings").text);
        }

        Settings.GlobalSettings.IP   = config.UoServerUrl;
        Settings.GlobalSettings.Port = ushort.Parse(config.UoServerPort);

        //Reset static encryption type variable
        EncryptionHelper.Type = ENCRYPTION_TYPE.NONE;
        Settings.GlobalSettings.Encryption = (byte)(config.UseEncryption ? 1 : 0);

        //Empty the plugins array because no plugins are working at the moment
        Settings.GlobalSettings.Plugins = new string[0];

        //If connecting to UO Outlands, set shard type to 2 for outlands
        Settings.GlobalSettings.ShardType = config.UoServerUrl.ToLower().Contains("uooutlands") ? 2 : 0;

        //Try to detect old client version to set ShardType to 1, for using StatusGumpOld. Otherwise, it's possible
        //to get null-refs in StatusGumpModern.
        if (ClientVersionHelper.IsClientVersionValid(config.ClientVersion, out var clientVersion))
        {
            if (clientVersion < ClientVersion.CV_308Z)
            {
                Settings.GlobalSettings.ShardType = 1;
            }
        }

        CUOEnviroment.IsOutlands = Settings.GlobalSettings.ShardType == 2;

        Settings.GlobalSettings.ClientVersion = config.ClientVersion;

        if (Application.isMobilePlatform == false && string.IsNullOrEmpty(config.ClientPathForUnityEditor) == false)
        {
            Settings.GlobalSettings.UltimaOnlineDirectory = config.ClientPathForUnityEditor;
        }
        else
        {
            Settings.GlobalSettings.UltimaOnlineDirectory = config.GetPathToSaveFiles();
        }

        //This flag is tied to whether the GameCursor gets drawn, in a convoluted way
        //On mobile platform, set this flag to true to prevent the GameCursor from being drawn
        Settings.GlobalSettings.RunMouseInASeparateThread = Application.isMobilePlatform;

        //Some mobile specific overrides need to be done on the Profile but they can only be done once the Profile has been loaded
        ProfileManager.ProfileLoaded += OnProfileLoaded;

        // Add an audio source and tell the media player to use it for playing sounds
        Log.Start(LogTypes.All);

        try
        {
            Client.SceneChanged += OnSceneChanged;
            Client.Run();
#if ENABLE_INTERNAL_ASSISTANT
            if (UserPreferences.EnableAssistant.CurrentValue == (int)PreferenceEnums.EnableAssistant.On)
            {
                Plugin.LoadInternalAssistant();
            }
#endif
            Client.Game.Exiting += OnGameExiting;
            ApplyScalingFactor();

            if (UserPreferences.ShowModifierKeyButtons.CurrentValue == (int)PreferenceEnums.ShowModifierKeyButtons.On)
            {
                modifierKeyButtonsParent.SetActive(true);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            OnError?.Invoke(e.ToString());
        }
    }
Пример #5
0
    public void Enter()
    {
        Screen.sleepTimeout = SleepTimeout.NeverSleep;
        serverConfiguration = ServerConfigurationModel.ActiveConfiguration;
        Debug.Log($"Downloading files to {serverConfiguration.GetPathToSaveFiles()}");
        var port = int.Parse(serverConfiguration.FileDownloadServerPort);

        if (serverConfiguration.AllFilesDownloaded || Application.isEditor && string.IsNullOrEmpty(serverConfiguration.ClientPathForUnityEditor) == false)
        {
            StateManager.GoToState <GameState>();
        }
        else
        {
            downloadPresenter.gameObject.SetActive(true);

            //Figure out what kind of downloader we should use
            if (serverConfiguration.FileDownloadServerUrl.ToLowerInvariant().Contains("uooutlands.com"))
            {
                downloader = new OutlandsDownloader();
                downloader.Initialize(this, serverConfiguration, downloadPresenter);
            }
            else if (serverConfiguration.FileDownloadServerUrl.ToLowerInvariant().Contains("uorenaissance.com"))
            {
                downloader = new RenaissanceDownloader();
                downloader.Initialize(this, serverConfiguration, downloadPresenter);
            }
            else
            {
                //Get list of files to download from server
                var uri     = GetUri(serverConfiguration.FileDownloadServerUrl, port);
                var request = UnityWebRequest.Get(uri);
                //This request should not take more than 5 seconds, the amount of data being received is very small
                request.timeout = 5;
                request.SendWebRequest().completed += operation =>
                {
                    if (request.isHttpError || request.isNetworkError)
                    {
                        var error = $"Error while making initial request to server: {request.error}";
                        StopAndShowError(error);
                        return;
                    }

                    var headers = request.GetResponseHeaders();

                    if (headers.TryGetValue("Content-Type", out var contentType))
                    {
                        if (contentType.Contains("application/json"))
                        {
                            //Parse json response to get list of files
                            Debug.Log($"Json response: {request.downloadHandler.text}");
                            FilesToDownload = Newtonsoft.Json.JsonConvert.DeserializeObject <List <string> >(request.downloadHandler.text);
                        }
                        else if (contentType.Contains("text/html"))
                        {
                            FilesToDownload = new List <string>(Regex
                                                                .Matches(request.downloadHandler.text, H_REF_PATTERN, RegexOptions.IgnoreCase)
                                                                .Cast <Match>()
                                                                .Select(match => match.Groups[1].Value));
                        }
                    }

                    if (FilesToDownload != null)
                    {
                        FilesToDownload.RemoveAll(file => NeededUoFileExtensions.Any(file.Contains) == false);
                        SetFileListAndDownload(FilesToDownload);
                    }
                    else
                    {
                        StopAndShowError("Could not determine file list to download");
                    }
                };
            }
        }
    }