diff --git a/ShiftOS.Objects/UserConfig.cs b/ShiftOS.Objects/UserConfig.cs index 579ce00..8232230 100644 --- a/ShiftOS.Objects/UserConfig.cs +++ b/ShiftOS.Objects/UserConfig.cs @@ -14,24 +14,27 @@ namespace ShiftOS.Objects public string DigitalSocietyAddress { get; set; } public int DigitalSocietyPort { get; set; } - public static UserConfig Get() - { - var conf = new UserConfig + private static UserConfig def = new UserConfig { Language = "english", DigitalSocietyAddress = "michaeltheshifter.me", DigitalSocietyPort = 13370 }; - if (!File.Exists("servers.json")) - { - File.WriteAllText("servers.json", JsonConvert.SerializeObject(conf, Formatting.Indented)); - } + public static UserConfig current = null; + + public static UserConfig Get() + { + if (current != null) + return current; + if (File.Exists("servers.json")) + current = JsonConvert.DeserializeObject(File.ReadAllText("servers.json")); else { - conf = JsonConvert.DeserializeObject(File.ReadAllText("servers.json")); + File.WriteAllText("servers.json", JsonConvert.SerializeObject(def, Formatting.Indented)); + current = def; } - return conf; + return current; } } } diff --git a/ShiftOS.WinForms/Applications/ButtonMaster.Designer.cs b/ShiftOS.WinForms/Applications/ButtonMaster.Designer.cs new file mode 100644 index 0000000..0ba9b96 --- /dev/null +++ b/ShiftOS.WinForms/Applications/ButtonMaster.Designer.cs @@ -0,0 +1,181 @@ +namespace ShiftOS.WinForms.Applications +{ + partial class ButtonMaster + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ButtonMaster)); + this.startpnl = new System.Windows.Forms.Panel(); + this.quitbtn = new System.Windows.Forms.Button(); + this.playbtn = new System.Windows.Forms.Button(); + this.difficultysel = new System.Windows.Forms.ListBox(); + this.label3 = new System.Windows.Forms.Label(); + this.desclabel = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.scorecounter = new System.Windows.Forms.Label(); + this.startpnl.SuspendLayout(); + this.SuspendLayout(); + // + // startpnl + // + this.startpnl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.startpnl.Controls.Add(this.quitbtn); + this.startpnl.Controls.Add(this.playbtn); + this.startpnl.Controls.Add(this.difficultysel); + this.startpnl.Controls.Add(this.label3); + this.startpnl.Controls.Add(this.desclabel); + this.startpnl.Controls.Add(this.label2); + this.startpnl.Controls.Add(this.label1); + this.startpnl.Location = new System.Drawing.Point(27, 31); + this.startpnl.Name = "startpnl"; + this.startpnl.Size = new System.Drawing.Size(580, 409); + this.startpnl.TabIndex = 0; + // + // quitbtn + // + this.quitbtn.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.quitbtn.Location = new System.Drawing.Point(291, 303); + this.quitbtn.Name = "quitbtn"; + this.quitbtn.Size = new System.Drawing.Size(58, 23); + this.quitbtn.TabIndex = 7; + this.quitbtn.Text = "Quit"; + this.quitbtn.UseVisualStyleBackColor = true; + this.quitbtn.Click += new System.EventHandler(this.quitbtn_Click); + // + // playbtn + // + this.playbtn.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.playbtn.Location = new System.Drawing.Point(229, 303); + this.playbtn.Name = "playbtn"; + this.playbtn.Size = new System.Drawing.Size(56, 23); + this.playbtn.TabIndex = 6; + this.playbtn.Text = "Play"; + this.playbtn.UseVisualStyleBackColor = true; + this.playbtn.Click += new System.EventHandler(this.playbtn_Click); + // + // difficultysel + // + this.difficultysel.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.difficultysel.FormattingEnabled = true; + this.difficultysel.Location = new System.Drawing.Point(152, 202); + this.difficultysel.Name = "difficultysel"; + this.difficultysel.Size = new System.Drawing.Size(276, 95); + this.difficultysel.TabIndex = 5; + // + // label3 + // + this.label3.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label3.Location = new System.Drawing.Point(243, 179); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(79, 20); + this.label3.TabIndex = 4; + this.label3.Tag = "header2"; + this.label3.Text = "Difficulty"; + // + // desclabel + // + this.desclabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.desclabel.Location = new System.Drawing.Point(3, 67); + this.desclabel.Name = "desclabel"; + this.desclabel.Size = new System.Drawing.Size(577, 112); + this.desclabel.TabIndex = 2; + this.desclabel.Tag = ""; + this.desclabel.Text = resources.GetString("desclabel.Text"); + this.desclabel.TextAlign = System.Drawing.ContentAlignment.TopCenter; + // + // label2 + // + this.label2.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(235, 37); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(105, 13); + this.label2.TabIndex = 1; + this.label2.Text = "by Appscape Games"; + // + // label1 + // + this.label1.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(211, 12); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(152, 25); + this.label1.TabIndex = 0; + this.label1.Tag = "header1"; + this.label1.Text = "ButtonMaster"; + // + // scorecounter + // + this.scorecounter.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.scorecounter.BackColor = System.Drawing.Color.Transparent; + this.scorecounter.Font = new System.Drawing.Font("Courier New", 15.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.scorecounter.ForeColor = System.Drawing.Color.Red; + this.scorecounter.Location = new System.Drawing.Point(548, 454); + this.scorecounter.Name = "scorecounter"; + this.scorecounter.Size = new System.Drawing.Size(92, 26); + this.scorecounter.TabIndex = 1; + this.scorecounter.Tag = "keepfont keepfg keepbg"; + this.scorecounter.Text = "score"; + this.scorecounter.TextAlign = System.Drawing.ContentAlignment.BottomRight; + this.scorecounter.Visible = false; + // + // ButtonMaster + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackgroundImage = global::ShiftOS.WinForms.Properties.Resources.BlueBlueVerticalGradient; + this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.Controls.Add(this.scorecounter); + this.Controls.Add(this.startpnl); + this.Name = "ButtonMaster"; + this.Size = new System.Drawing.Size(640, 480); + this.startpnl.ResumeLayout(false); + this.startpnl.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel startpnl; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label desclabel; + private System.Windows.Forms.ListBox difficultysel; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Button playbtn; + private System.Windows.Forms.Button quitbtn; + private System.Windows.Forms.Label scorecounter; + } +} diff --git a/ShiftOS.WinForms/Applications/ButtonMaster.cs b/ShiftOS.WinForms/Applications/ButtonMaster.cs new file mode 100644 index 0000000..722bb14 --- /dev/null +++ b/ShiftOS.WinForms/Applications/ButtonMaster.cs @@ -0,0 +1,176 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShiftOS.Engine; + +namespace ShiftOS.WinForms.Applications +{ + // Behold... The ShiftOS program that doesn't use threading. + [WinOpen("buttonmaster")] + [Launcher("Button Master", false, "", "Games")] + [AppscapeEntry("buttonmaster", "ButtonMaster", "Can you click all the buttons in 60 seconds?", 300, 10000)] + public partial class ButtonMaster : UserControl, IShiftOSWindow + { + public ushort Buttons; + public double Codepoints, Loss; + private ulong RoundedCodepoints { get { return (ulong) Math.Round(Codepoints); } } + public Timer clock = new Timer(); + private ButtonObject[] ButtonObjects; + private static ButtonMasterDifficulty[] difficulties = new ButtonMasterDifficulty[] + { + new ButtonMasterDifficulty("Easy", 24, 500), + new ButtonMasterDifficulty("Medium", 48, 1000), + new ButtonMasterDifficulty("Hard", 100, 2000), + new ButtonMasterDifficulty("Super Hard", 500, 10000) + }; + public ButtonMaster() + { + InitializeComponent(); + difficultysel.Items.AddRange(difficulties); + difficultysel.SelectedIndex = 0; + clock.Interval = 20; + clock.Tick += gameloop; + } + + public void OnLoad() + { + } + + public void OnSkinLoad() + { + + } + + public bool OnUnload() + { + return true; + } + + public void OnUpgrade() + { + + } + + private void quitbtn_Click(object sender, EventArgs e) + { + AppearanceManager.Close(this); + } + + private void playbtn_Click(object sender, EventArgs e) + { + var difficulty = difficultysel.SelectedItem as ButtonMasterDifficulty; + Buttons = difficulty.Buttons; + Codepoints = difficulty.Codepoints; + Loss = difficulty.Codepoints / 3000.0; + startpnl.Hide(); + scorecounter.Text = difficulty.Codepoints.ToString(); + scorecounter.Show(); + ButtonObjects = new ButtonObject[Buttons]; + for (ushort i = 0; i < Buttons; i++) + ButtonObjects[i] = new ButtonObject(this); + Controls.AddRange(ButtonObjects.Select(b => b.ctl).ToArray()); + clock.Start(); + } + + private void StopGame(string text) + { + desclabel.Text = text; + startpnl.Show(); + clock.Stop(); + scorecounter.Hide(); + foreach (var b in ButtonObjects) + { + clock.Tick -= b.move; + Controls.Remove(b.ctl); + } + } + + private void gameloop(object sender, EventArgs e) + { + if (Codepoints <= 0) + { + Codepoints = 0; + string text = String.Format("You lost. There were {0} buttons to go.", Buttons); + if (difficultysel.SelectedIndex > 0) + text += " Try an easier difficulty?"; + StopGame(text); + } + else if (Buttons <= 0) + { + SaveSystem.CurrentSave.Codepoints += RoundedCodepoints; + string text = String.Format("You won! {0} Codepoints have been transferred to your system.", RoundedCodepoints); + StopGame(text); + } + else + { + Codepoints -= Loss; + scorecounter.Text = RoundedCodepoints.ToString(); + } + } + } + public class ButtonMasterDifficulty + { + public string Name { get; private set; } + public ushort Buttons { get; private set; } + public uint Codepoints { get; private set; } + public string Display { get; private set; } + public override string ToString() + { + return Display; + } + public ButtonMasterDifficulty(string in_Name, ushort in_Buttons, uint in_Codepoints) + { + Name = in_Name; + Buttons = in_Buttons; + Codepoints = in_Codepoints; + Display = String.Format("{0} ({1} Buttons, {2} Codepoints)", Name, Buttons, Codepoints); + } + } + + public class ButtonObject + { + public Button ctl; + public sbyte xspeed, yspeed; + public ButtonMaster parent; + private static Random rnd = new Random(); + public void move(object sender, EventArgs e) + { + ctl.Top += yspeed; + if (ctl.Top < 0 || ctl.Bottom > parent.Height) + yspeed = (sbyte)(Math.Abs(yspeed) * -(ctl.Top / Math.Abs(ctl.Top))); // Change the sign of yspeed to be the opposite of that of ctl.Top + ctl.Left += xspeed; + if (ctl.Left < 0 || ctl.Right > parent.Width) + xspeed = (sbyte)(Math.Abs(xspeed) * -(ctl.Left / Math.Abs(ctl.Left))); + } + public void click(object sender, EventArgs e) + { + parent.Buttons--; + ctl.Hide(); + parent.clock.Tick -= move; + } + public ButtonObject(ButtonMaster in_parent) + { + xspeed = (sbyte) rnd.Next(10, 20); + yspeed = (sbyte) rnd.Next(10, 20); + parent = in_parent; + parent.clock.Tick += move; + ctl = new Button(); + ctl.Click += click; + ctl.Top = rnd.Next(parent.Height); + ctl.Left = rnd.Next(parent.Width); + ctl.Width = 75; + ctl.Height = 23; + ctl.Text = "Click"; + // Time to invoke a private method using reflection. What could possibly go wrong? + // This stops the player from just holding down space to beat the level. + typeof(Button).GetMethod("SetStyle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(ctl, new object[] { ControlStyles.Selectable, false }); + } + + } +} diff --git a/ShiftOS.WinForms/Applications/ButtonMaster.resx b/ShiftOS.WinForms/Applications/ButtonMaster.resx new file mode 100644 index 0000000..6742cee --- /dev/null +++ b/ShiftOS.WinForms/Applications/ButtonMaster.resx @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + In the game of ButtonMaster, dozens of buttons bounce +around the window. Your task is to click all of them in +60 seconds. The quicker you pull it off, the more points +you earn. + +In this special ShiftOS version, any points you earn are +added to your Codepoints balance at the end of the game. +So, what are you waiting for? + + \ No newline at end of file diff --git a/ShiftOS.WinForms/Program.cs b/ShiftOS.WinForms/Program.cs index 9ec0ede..c73f067 100644 --- a/ShiftOS.WinForms/Program.cs +++ b/ShiftOS.WinForms/Program.cs @@ -71,7 +71,7 @@ namespace ShiftOS.WinForms Action completed = null; completed = () => { - SaveSystem.Ready = true; + SaveSystem.Ready.Set(); Engine.AudioManager.PlayCompleted -= completed; AudioManager.StartAmbientLoop(); }; diff --git a/ShiftOS.WinForms/Properties/Resources.Designer.cs b/ShiftOS.WinForms/Properties/Resources.Designer.cs index 9d233ff..9dcd2fd 100644 --- a/ShiftOS.WinForms/Properties/Resources.Designer.cs +++ b/ShiftOS.WinForms/Properties/Resources.Designer.cs @@ -388,6 +388,16 @@ namespace ShiftOS.WinForms.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap BlueBlueVerticalGradient { + get { + object obj = ResourceManager.GetObject("BlueBlueVerticalGradient", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// @@ -1150,7 +1160,8 @@ namespace ShiftOS.WinForms.Properties { /// "ReadAccessToLowUsers": false, /// "permissions": 0 /// }, - /// [rest of string was truncated]";. + /// { + /// "Name" [rest of string was truncated]";. /// internal static string PebcakDevelFS { get { @@ -1184,7 +1195,7 @@ namespace ShiftOS.WinForms.Properties { /// Name: "NetXtreme Hyper Edition", /// CostPerMonth: 150, /// DownloadSpeed: 524288, //512 kb/s - /// Description: "It's time to supercharge your Shift [rest of string was truncated]";. + /// Description: "It's time to supercharge your Shiftnet experience. [rest of string was truncated]";. /// internal static string ShiftnetServices { get { @@ -1206,7 +1217,8 @@ namespace ShiftOS.WinForms.Properties { /// Name: "Icon Manager", /// Cost: 450, /// Description: "This tool allows you to add and edit application icons within ShiftOS for the small prive of 450 Codepoints!", - /// Dependencies: "skinning [rest of string was truncated]";. + /// Dependencies: "skinning", + /// Category [rest of string was truncated]";. /// internal static string Shiftorium { get { @@ -1216,7 +1228,7 @@ namespace ShiftOS.WinForms.Properties { /// /// Looks up a localized string similar to {\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff0\deff0\stshfdbch31505\stshfloch31506\stshfhich31506\stshfbi0\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;} - ///{\f37\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;}{\f38\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0302020204030204}Calibri Light;}{\fl [rest of string was truncated]";. + ///{\f37\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;}{\f38\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0302020204030204}Calibri Light;}{\flo [rest of string was truncated]";. /// internal static string ShiftOS { get { @@ -1365,7 +1377,8 @@ namespace ShiftOS.WinForms.Properties { ///Eine kurze Erklärung wie du das Terminal benutzt lautet wiefolgt. Du kannst das command 'sos.help' benutzen um eine Liste aller commands aufzurufen. Schreib es ///einfach in das Terminal und drücke <enter> um alle commands anzuzeigen. /// - ///Commands können mit argumenten versehen werden, indem du ein key-value Paar in einem {} Block hinter dem command angibst. Zum Be [rest of string was truncated]";. + ///Commands können mit argumenten versehen werden, indem du ein key-value Paar in einem {} Block hinter dem command angibst. Zum Beispiel: + /// [rest of string was truncated]";. /// internal static string strings_de { get { @@ -1390,7 +1403,7 @@ namespace ShiftOS.WinForms.Properties { /// "{GEN_WELCOME}": "Welcome to ShiftOS.", /// "{GEN_SYSTEMNAME}": "System name", /// "{GEN_PASSWORD}": "Password", - /// "{GEN_LPROMPT [rest of string was truncated]";. + /// "{GEN_LPROMPT}": "%sysname lo [rest of string was truncated]";. /// internal static string strings_en { get { @@ -1414,7 +1427,8 @@ namespace ShiftOS.WinForms.Properties { /// "{GEN_CURRENTPROCESSES}": "Les procèdures actuelles", /// "{GEN_WELCOME}": "Bienvenue au ShiftOS.", /// "{GEN_SYSTEMNAME}": "Nom de système", - /// "{GEN_PASSWORD}": "Mot de [rest of string was truncated]";. + /// "{GEN_PASSWORD}": "Mot de passe", + /// "{GEN [rest of string was truncated]";. /// internal static string strings_fr { get { @@ -1602,7 +1616,7 @@ namespace ShiftOS.WinForms.Properties { /// "Before you can begin with ShiftOS, you'll need to know a few things about it.", /// "One: Terminal command syntax.", /// "Inside ShiftOS, the bulk of your time is going to be spent within the Terminal.", - /// "The Terminal is an application that starts up when you turn on your computer. It allows you to execute system commands, ope [rest of string was truncated]";. + /// "The Terminal is an application that starts up when you turn on your computer. It allows you to execute system commands, open program [rest of string was truncated]";. /// internal static string sys_shiftoriumstory { get { diff --git a/ShiftOS.WinForms/Properties/Resources.resx b/ShiftOS.WinForms/Properties/Resources.resx index d1264e8..1e47fbf 100644 --- a/ShiftOS.WinForms/Properties/Resources.resx +++ b/ShiftOS.WinForms/Properties/Resources.resx @@ -34631,4 +34631,7 @@ ..\Resources\PebcakDevelFS.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + ..\Resources\BlueBlueVerticalGradient.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/ShiftOS.WinForms/Resources/BlueBlueVerticalGradient.png b/ShiftOS.WinForms/Resources/BlueBlueVerticalGradient.png new file mode 100644 index 0000000..bf65ce7 Binary files /dev/null and b/ShiftOS.WinForms/Resources/BlueBlueVerticalGradient.png differ diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index 5fcf349..92cbf28 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -71,6 +71,12 @@ About.cs + + UserControl + + + ButtonMaster.cs + UserControl @@ -483,6 +489,9 @@ About.cs + + ButtonMaster.cs + Clock.cs @@ -876,6 +885,7 @@ + diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index 8cfea4a..b767605 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -66,7 +66,7 @@ namespace ShiftOS.Engine /// /// Boolean representing whether the save system is ready to be used. /// - public static bool Ready = false; + public static AutoResetEvent Ready = new AutoResetEvent(false); public static bool IsSandbox = false; /// @@ -154,25 +154,17 @@ namespace ShiftOS.Engine { Console.WriteLine("{MISC_CONNECTINGTONETWORK}"); - Ready = false; + Ready.Reset(); if (PreDigitalSocietyConnection != null) { PreDigitalSocietyConnection?.Invoke(); - - while (!Ready) - { - Thread.Sleep(10); - } + Ready.WaitOne(); } - - - bool guidReceived = false; ServerManager.GUIDReceived += (str) => { //Connection successful! Stop waiting! - guidReceived = true; Console.WriteLine("{MISC_CONNECTIONSUCCESSFUL}"); Thread.Sleep(100); Console.WriteLine("{LOADINGMSG2_" + loadingJoke2 + "}"); @@ -184,37 +176,25 @@ namespace ShiftOS.Engine if (ServerManager.ServerOnline) { ServerManager.Initiate(UserConfig.Get().DigitalSocietyAddress, UserConfig.Get().DigitalSocietyPort); - //This haults the client until the connection is successful. - while (ServerManager.thisGuid == new Guid()) - { - Thread.Sleep(10); - } + // This halts the client until the connection is successful. + ServerManager.guidReceiveARE.WaitOne(); Console.WriteLine("{MISC_DHCPHANDSHAKEFINISHED}"); - FinishBootstrap(); } else { Console.WriteLine("{MISC_NONETWORK}"); Console.WriteLine("{LOADINGMSG2_" + loadingJoke2 + "}"); - FinishBootstrap(); } + FinishBootstrap(); } catch (Exception ex) { - //No errors, this never gets called. + // "No errors, this never gets called." Console.WriteLine("[inetd] SEVERE: " + ex.Message); + string dest = "Startup Exception " + DateTime.Now.ToString() + ".txt"; + System.IO.File.WriteAllText(dest, ex.ToString()); + Console.WriteLine("[inetd] Full exception details have been saved to: " + dest); Thread.Sleep(3000); - Console.WriteLine("[sys] SEVERE: Cannot connect to server. Shutting down in 5..."); - Thread.Sleep(1000); - Console.WriteLine("[sys] 4..."); - Thread.Sleep(1000); - Console.WriteLine("[sys] 3..."); - Thread.Sleep(1000); - Console.WriteLine("[sys] 2..."); - Thread.Sleep(1000); - Console.WriteLine("[sys] 1..."); - Thread.Sleep(1000); - Console.WriteLine("[sys] Bye bye."); System.Diagnostics.Process.GetCurrentProcess().Kill(); } @@ -571,8 +551,6 @@ namespace ShiftOS.Engine /// The amount of Codepoints to deduct. public static void TransferCodepointsToVoid(ulong amount) { - if (amount < 0) - throw new ArgumentOutOfRangeException("We see what you did there. Trying to pull Codepoints from the void? That won't work."); CurrentSave.Codepoints -= amount; NotificationDaemon.AddNotification(NotificationType.CodepointsSent, amount); } @@ -591,36 +569,35 @@ namespace ShiftOS.Engine /// public static void ReadSave() { + string path; + + path = "C:\\ShiftOS2\\"; //Migrate old saves. - if (System.IO.Directory.Exists("C:\\ShiftOS2")) + if (System.IO.Directory.Exists(path) && !System.IO.File.Exists(path + "havemigrated")) { Console.WriteLine("Old save detected. Migrating filesystem to MFS..."); - foreach (string file in System.IO.Directory.EnumerateDirectories("C:\\ShiftOS2") -.Select(d => new DirectoryInfo(d).FullName)) + foreach (string file in System.IO.Directory.EnumerateFileSystemEntries(path)) { - if (!Utils.DirectoryExists(file.Replace("C:\\ShiftOS2\\", "0:/").Replace("\\", "/"))) - Utils.CreateDirectory(file.Replace("C:\\ShiftOS2\\", "0:/").Replace("\\", "/")); + string dest = file.Replace(path, "0:/").Replace("\\", "/"); + if (System.IO.File.GetAttributes(file).HasFlag(FileAttributes.Directory)) + if (!Utils.DirectoryExists(dest)) + Utils.CreateDirectory(dest); + else + { + string rfile = Path.GetFileName(file); + Utils.WriteAllBytes(dest, System.IO.File.ReadAllBytes(file)); + Console.WriteLine("Exported file " + file); + } } - foreach (string file in System.IO.Directory.EnumerateFiles("C:\\ShiftOS2")) - { - - string rfile = Path.GetFileName(file); - Utils.WriteAllBytes(file.Replace("C:\\ShiftOS2\\", "0:/").Replace("\\", "/"), System.IO.File.ReadAllBytes(file)); - Console.WriteLine("Exported file " + file); - } - + System.IO.File.WriteAllText(path + "havemigrated", "1.0 BETA"); } - string path = Path.Combine(Paths.SaveDirectory, "autosave.save"); + path = Path.Combine(Paths.SaveDirectory, "autosave.save"); - if (System.IO.File.Exists(Path.Combine(Paths.SaveDirectory, "autosave.save"))) - { + if (System.IO.File.Exists(path)) CurrentSave = JsonConvert.DeserializeObject(System.IO.File.ReadAllText(path)); - } else - { NewSave(); - } } @@ -667,11 +644,8 @@ namespace ShiftOS.Engine }) { IsBackground = false }.Start(); if (!System.IO.Directory.Exists(Paths.SaveDirectory)) - { System.IO.Directory.CreateDirectory(Paths.SaveDirectory); - } - System.IO.File.WriteAllText(Path.Combine(Paths.SaveDirectory, "autosave.save"), serialisedSaveFile); } if (!Shiftorium.Silent) @@ -688,8 +662,6 @@ namespace ShiftOS.Engine /// The amount of Codepoints. public static void TransferCodepointsFrom(string who, ulong amount) { - if (amount < 0) - throw new ArgumentOutOfRangeException("We see what you did there... You can't just give a fake character Codepoints like that. It's better if you transfer them to the void."); NotificationDaemon.AddNotification(NotificationType.CodepointsReceived, amount); CurrentSave.Codepoints += amount; } diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index df3e463..66a0d37 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -89,6 +89,8 @@ Ping: {ServerManager.DigitalSocietyPing} ms /// public static Guid thisGuid { get; private set; } + public static AutoResetEvent guidReceiveARE = new AutoResetEvent(false); + /// /// Gets the underlying NetSockets client for this connection. /// @@ -241,6 +243,7 @@ Ping: {ServerManager.DigitalSocietyPing} ms { thisGuid = new Guid(msg.Contents); GUIDReceived?.Invoke(msg.Contents); + guidReceiveARE.Set(); TerminalBackend.PrefixEnabled = true; TerminalBackend.PrintPrompt(); }