Example #1
0
    public void Launch()
    {
        playButton.Sensitive = false;
        var monitor = new MainWindowGameMonitor(this);

        var installDialog = new InstallationDialog();
        installDialog.Parent = this;
        installDialog.Show();
        installDialog.GdkWindow.Raise();

        // Run syncing in installation dialog as a separate thread,
        // and wait until it is done while processing UI events for it

        var thread = new Thread(delegate() {
            var listener = new InstallationDialogStatusListener(installDialog);
            Instance.Sync(listener);
            var mc = Instance.CreateMinecraft();
            mc.Setup(listener);
        });
        thread.IsBackground = true;
        thread.Name = "GameSync";
        thread.Start();
        GLib.Timeout.Add(100, delegate() {
            if (!thread.IsAlive) {
                Application.Quit();
                return false;
            }

            return true;
        });
        Gtk.Application.Run();

        // Run the game

        installDialog.Log ("");
        installDialog.Log ("Getting ready to start Minecraft!");
        installDialog.Status = "All updates completed!";
        installDialog.Title = "All updates completed!";
        installDialog.Destroy ();

        monitor.OutputLine(GameMessageType.Output, "");
        monitor.OutputLine(GameMessageType.Output, "Starting Minecraft...");

        playButton.Sensitive = true;
        GameIsActive = true;
        thread = new Thread(delegate() {
            var mc = Instance.CreateMinecraft();
            GameProcess = mc.Start(Session, monitor);

            DedicatedLauncher.Singleton.EnqueueUxJob(delegate() {
                this.minecraftStatus.Text = string.Format("Minecraft is running (Process #{0})", GameProcess.Id);
            });

            Console.WriteLine("Game launched from seperate thread!");
        });
        thread.IsBackground = true;
        thread.Name = "GameLauncher";
        thread.Start();

        Console.WriteLine("Control returned.");
    }
        protected void OnConnectBtnActivated(object sender, EventArgs ev)
        {
            var dialog = new ChooseServerDialog();
            int response = dialog.Run();

            if (response == (int)Gtk.ResponseType.Cancel) {
                dialog.Destroy();
                return;
            }

            var serverHost = dialog.Server;
            string urlHttp80 = string.Format("http://{0}/craftalyst/instance.json", serverHost);
            string urlHttp8080 = string.Format("http://{0}:8080/craftalyst/instance.json", serverHost);
            InstanceDescription instanceDescription = null;

            dialog.Destroy();

            try {
                instanceDescription = DownloadDescription(urlHttp80);
            } catch (Exception) {
                Logger.Debug("Failed to retrieve URL '{0}', this might not be an error.", urlHttp80);
            }

            if (instanceDescription == null) {
                try {
                    instanceDescription = DownloadDescription(urlHttp8080);
                } catch (Exception) {
                    Logger.Debug("Failed to retrieve URL '{0}'", urlHttp8080);
                }
            }

            if (instanceDescription == null) {
                DedicatedLauncher.MessageBox("Failed to connect to Craftalyst server {0}", serverHost);
                return;
            }

            string localId = string.Format("{0}_{1}", serverHost, instanceDescription.Id);
            Instance instance = null;

            try {
                instance = Context.CreateInstance(localId, instanceDescription);
            } catch (Exception e) {
                DedicatedLauncher.MessageBox("Failed to create local instance {0}: "+e.Message);
                Logger.Debug(e);
            }

            if (instance == null) {
                DedicatedLauncher.MessageBox("Failed to create Craftalyst instance!");
                return;
            }

            var installDialog = new InstallationDialog();
            installDialog.Parent = this;
            installDialog.Present();
            var listener = new InstallationDialogStatusListener(installDialog);

            // Run install dialog as a separate thread,
            // and wait until it is done while processing UI events for it

            var thread = new Thread(delegate() {
                instance.Install(listener);
                var mc = instance.CreateMinecraft();
                mc.Setup(listener);
            });
            thread.IsBackground = true;
            thread.Name = "GameSync";
            thread.Start();
            GLib.Timeout.Add(100, delegate() {
                if (!thread.IsAlive) {
                    Gtk.Application.Quit();
                    return false;
                }

                return true;
            });

            DedicatedLauncher.Singleton.RunUx();
            installDialog.Destroy();

            RefreshInstances();
        }