Пример #1
0
        public static async Task UpdateClient(ClientsData.Client client)
        {
            logger.Info("Updating client placed in \"{0}\"", client.Path);
            List <string> filesToUpdate = new List <string>();

            if (Config.Instance.ClientsFiles.Files == null || Config.Instance.ClientsFiles.Files.Length == 0)
            {
                logger.Error("No clients files data available!");
                return;
            }

            await Task.Run(() =>
            {
                List <string> nonlistedFiles = null;
                if (Directory.Exists(client.Path))
                {
                    nonlistedFiles = new List <string>(Directory.GetFiles(client.Path, "*", SearchOption.AllDirectories));
                }

                var remoteClientFiles = Config.Instance.ClientsFiles.Files.Where(f => f.Filepath.StartsWith(client.Path + Path.DirectorySeparatorChar) || f.Filepath.StartsWith(client.Path + Path.AltDirectorySeparatorChar));
                foreach (var remoteFile in remoteClientFiles)
                {
                    if (File.Exists(remoteFile.Filepath))
                    {
                        nonlistedFiles?.Remove(remoteFile.Filepath);                              // filter valid file

                        if (CryptoUtils.CalculateFileMD5(remoteFile.Filepath) == remoteFile.Hash) // file exist and up to date, no reason to update it
                        {
                            continue;
                        }
                    }

                    filesToUpdate.Add(remoteFile.Filepath);
                }

                if (nonlistedFiles != null && nonlistedFiles.Count > 0)
                {
                    string[] blacklistedFolders = new string[]
                    {
                        Path.Combine(client.Path, MinecraftLauncher.VersionsFolder) + Path.DirectorySeparatorChar,
                        Path.Combine(client.Path, MinecraftLauncher.LibrariesFolder) + Path.DirectorySeparatorChar,
                        Path.Combine(client.Path, MinecraftLauncher.NativesFolder) + Path.DirectorySeparatorChar,
                        Path.Combine(client.Path, MinecraftLauncher.ModsFolder) + Path.DirectorySeparatorChar,
                        Path.Combine(client.Path, MinecraftLauncher.AssetIndexFolder) + Path.DirectorySeparatorChar,
                    };

                    foreach (var file in nonlistedFiles)
                    {
                        if (blacklistedFolders.Any(file.StartsWith))
                        {
                            logger.Warn("Deleting unknown file \"{0}\" in blacklisted folder!", file);
                            File.Delete(file);
                        }
                    }
                }

                TotalFilesToUpdate     = filesToUpdate.Count;
                FilesRemainingToUpdate = filesToUpdate.Count;

                foreach (var file in filesToUpdate)
                {
                    Client.RequestFile(file);
                }
            });
        }
Пример #2
0
        public static async Task Login(string username, string password)
        {
            if (Client.IsConnected())
            {
                if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
                {
                    logger.Warn("No login data entered to request auth");
                    ControlsManager.SetStatus("Enter login and password!");
                    return;
                }

                string clientName = ControlsManager.GetSelectedClientName();
                if (string.IsNullOrEmpty(clientName))
                {
                    logger.Error("Client not selected!");
                    ControlsManager.SetStatus("Select client!");
                    return;
                }

                ControlsManager.DisableLoginButton();
                logger.Info("Requesting client update");
                ClientsData.Client client = Config.Instance.Clients.Clients.First(c => c.Name == clientName);

                ControlsManager.SetStatus("Checking for updates...");
                await UpdateManager.UpdateClient(client);

                logger.Info("Waiting client updates to finish");
                ControlsManager.SetStatus("Updating...");
                await Task.Run(() => { UpdateManager.ClientUpdate.WaitOne(); });

                logger.Info("Client updating done");
                ControlsManager.SetStatus("Ready");

                logger.Info("Updating config with current login data");
                Config.Instance.Username = username;

                string passHash = Config.Instance.PassHash == password ? Config.Instance.PassHash : CryptoUtils.CalculateStringVersaHash(password);
                Config.Instance.PassHash = passHash;

                string session = Anticheat.Session;

                logger.Info("Requesting auth");
                ControlsManager.SetStatus("Requesting auth...");
                Client.SendAuth(session, username, passHash);

                logger.Info("Launching Minecraft");
                ControlsManager.SetStatus("Launching Minecraft...");
                Anticheat.HideLauncher();
                var minecraft = Start(username, session, client.Server, client.Path);

                if (Config.Instance.WindowedFullscreen)
                {
                    EnableWindowedFullscreen(minecraft);
                }

                Anticheat.Protect();

                logger.Info("All jobs done");
                System.Windows.Application.Current.Shutdown();
            }

            // TODO: offline mode
        }