Beispiel #1
0
        public MainWindow()
        {
            InitializeComponent();

            string version = Assembly.GetEntryAssembly().GetName().Version.ToString();

            MainForm.Title = string.Format("{0} ver. {1}", MainForm.Title, version);
            logger.Info("VersaCraft Launcher ver. {0}", version);

            ControlsManager.MainForm        = this;
            ControlsManager.UpdateProgress  = updateBar;
            ControlsManager.ClientsComboBox = clients;
            ControlsManager.StatusLabel     = status;
            ControlsManager.LoginButton     = login;

            logger.Info("Loading config");
            Config.Instance.Load(); // TODO: not read config before launcher update?

            logger.Info("Preparing UI");
            username.Text                  = Config.Instance.Username;
            password.Password              = Config.Instance.PassHash;
            isSavingPassword.IsChecked     = Config.Instance.IsSavingPassword;
            isWindowedFullscreen.IsChecked = Config.Instance.WindowedFullscreen;
            ControlsManager.UpdateClientsComboBox(Config.Instance.Clients);
        }
Beispiel #2
0
        public static void Exception(string error)
        {
            Console.WriteLine(error);

            using (StreamWriter writer = new StreamWriter(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "error.txt"), true))
                writer.WriteLine("[{0}] {1}", DateTime.Now.ToString("o"), error);

            logger.Error(error);
            ControlsManager.SetStatus("Fatal error occured! Please, send logs to developers.");
        }
Beispiel #3
0
        public static void SelfUpdate(FileData fileData)
        {
            logger.Info("Launcher self updating");
            ControlsManager.DisableLoginButton();

            if (fileData.FileSize == -1) // up to date
            {
                LauncherUpdate.Set();
                logger.Info("No launcher update required");
                return;
            }

            byte[] launcher = fileData.File;

            string currentLauncherPath = Assembly.GetExecutingAssembly().Location;
            string backupLauncherPath  = currentLauncherPath + backupPostfix;
            string newLauncherPath     = currentLauncherPath + updatedPostfix;

            if (File.Exists(newLauncherPath))
            {
                logger.Warn("File with name of new launcher already exist for some reason! Removing file first: \"{0}\"", newLauncherPath);
                File.Delete(newLauncherPath);
            }

            logger.Info("Writing new launcher as \"{0}\"", newLauncherPath);
            using (FileStream stream = File.OpenWrite(newLauncherPath))
                stream.Write(launcher, 0, launcher.Length);

            if (File.Exists(backupLauncherPath))
            {
                logger.Info("Removing backup launcher file: \"{0}\"", backupLauncherPath);
                File.Delete(backupLauncherPath);
            }

            logger.Info("Forming update CLI for cmd.exe");
            string args = $"/C taskkill /PID {Process.GetCurrentProcess().Id} & move \"{currentLauncherPath}\" \"{backupLauncherPath}\" & move \"{newLauncherPath}\" \"{currentLauncherPath}\" & start \"\" \"{currentLauncherPath}\" & exit";

            logger.Info("Launching external updater");
            Process.Start("cmd", args);
        }
Beispiel #4
0
        private void MainForm_Loaded(object sender, RoutedEventArgs e)
        {
            ControlsManager.DisableLoginButton();

            Task.Run(() =>
            {
                logger.Info("Connecting to server");
                ControlsManager.SetStatus("Connecting to auth&login server...");
                Client.Connect();

                logger.Info("Waiting for connection");
                ControlsManager.SetStatus("Waiting for connection...");
                while (!Client.IsConnected() && Client.State != Client.ClientState.Offline)
                {
                }

                if (Client.IsConnected())
                {
                    logger.Info("Requesting launcher update");
                    Client.RequestLauncherUpdate();

                    logger.Info("Waiting launcher to update");
                    UpdateManager.LauncherUpdate.WaitOne();

                    logger.Info("Requesting clients data");
                    Client.RequestClients();

                    logger.Info("Requesting clients files data");
                    Client.RequestClientsFiles();
                }
                else
                {
                    ControlsManager.SetLoginButtonOffline();
                }

                ControlsManager.SetStatus("Ready");
                ControlsManager.EnableLoginButton();
            });
        }
Beispiel #5
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
        }
Beispiel #6
0
 public static void HideLauncher()
 {
     ControlsManager.HideForm();
 }