From 17957f9bb8b3c7fd06cf39a01cd172343cd98a9a Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 7 Mar 2017 10:06:20 -0500 Subject: [PATCH] Fix bootstrapper bug. --- ShiftOS.WinForms/Controls/TerminalBox.cs | 4 +- ShiftOS_TheReturn/SaveSystem.cs | 122 +++++++++++++---------- 2 files changed, 70 insertions(+), 56 deletions(-) diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index ffc3f86..200c1d7 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -52,12 +52,12 @@ namespace ShiftOS.WinForms.Controls public void Write(string text) { - this.Text += Localization.Parse(text); + this.AppendText(Localization.Parse(text)); } public void WriteLine(string text) { - this.Text += Localization.Parse(text) + Environment.NewLine; + this.AppendText(Localization.Parse(text) + Environment.NewLine); } } } diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index 9f0b9b7..b9633e5 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -109,6 +109,7 @@ namespace ShiftOS.Engine bool guidReceived = false; ServerManager.GUIDReceived += (str) => { + //Connection successful! Stop waiting! guidReceived = true; Console.WriteLine("Connection successful."); }; @@ -117,20 +118,26 @@ namespace ShiftOS.Engine { ServerManager.Initiate("secondary4162.cloudapp.net", 13370); - while(guidReceived == false) + //This haults the client until the connection is successful. + while (ServerManager.thisGuid == new Guid()) { } + Console.WriteLine("GUID received - bootstrapping complete."); + FinishBootstrap(); } catch (Exception ex) { + //No errors, this never gets called. Console.WriteLine("{ERROR}: " + ex.Message); Thread.Sleep(3000); ServerManager.StartLANServer(); - while (guidReceived == false) + while (ServerManager.thisGuid == new Guid()) { } + Console.WriteLine("GUID received - bootstrapping complete."); + FinishBootstrap(); } } else @@ -138,64 +145,71 @@ namespace ShiftOS.Engine ServerManager.StartLANServer(); } - ServerManager.MessageReceived += (msg) => - { - if(msg.Name == "mud_savefile") - { - CurrentSave = JsonConvert.DeserializeObject(msg.Contents); - } - else if(msg.Name == "mud_login_denied") - { - oobe.PromptForLogin(); - } - }; + //Nothing happens past this point - but the client IS connected! It shouldn't be stuck in that while loop above. - ReadSave(); - - while(CurrentSave == null) - { - - } - - Shiftorium.Init(); - - while (CurrentSave.StoryPosition < 1) - { - - } - - Thread.Sleep(75); - - Thread.Sleep(50); - Console.WriteLine("{SYSTEM_INITIATED}"); - - TerminalBackend.InStory = false; - TerminalBackend.PrefixEnabled = true; - Shiftorium.LogOrphanedUpgrades = true; - Desktop.InvokeOnWorkerThread(new Action(() => - { - ShiftOS.Engine.Scripting.LuaInterpreter.RunSft(Paths.GetPath("kernel.sft")); - })); - Desktop.InvokeOnWorkerThread(new Action(() => Desktop.PopulateAppLauncher())); - if (CurrentSave.StoryPosition == 1) - { - Desktop.InvokeOnWorkerThread(new Action(() => - { - TutorialManager.StartTutorial(); - - })); - while(TutorialManager.IsInTutorial == true) { } - GameReady?.Invoke(); - } - else - { - GameReady?.Invoke(); - } + })); thread.IsBackground = true; thread.Start(); } + public static void FinishBootstrap() + { + ServerManager.MessageReceived += (msg) => + { + if (msg.Name == "mud_savefile") + { + CurrentSave = JsonConvert.DeserializeObject(msg.Contents); + } + else if (msg.Name == "mud_login_denied") + { + oobe.PromptForLogin(); + } + }; + + ReadSave(); + + while (CurrentSave == null) + { + + } + + Shiftorium.Init(); + + while (CurrentSave.StoryPosition < 1) + { + + } + + Thread.Sleep(75); + + Thread.Sleep(50); + Console.WriteLine("{SYSTEM_INITIATED}"); + + TerminalBackend.InStory = false; + TerminalBackend.PrefixEnabled = true; + Shiftorium.LogOrphanedUpgrades = true; + Desktop.InvokeOnWorkerThread(new Action(() => + { + ShiftOS.Engine.Scripting.LuaInterpreter.RunSft(Paths.GetPath("kernel.sft")); + })); + Desktop.InvokeOnWorkerThread(new Action(() => Desktop.PopulateAppLauncher())); + if (CurrentSave.StoryPosition == 1) + { + Desktop.InvokeOnWorkerThread(new Action(() => + { + TutorialManager.StartTutorial(); + + })); + while (TutorialManager.IsInTutorial == true) { } + GameReady?.Invoke(); + } + else + { + GameReady?.Invoke(); + } + } + public delegate void EmptyEventHandler(); public static List Users