ShiftOS_TheReturn/ShiftOS.WinForms/Oobe.cs

603 lines
26 KiB
C#
Raw Normal View History

2017-01-08 15:17:07 +00:00
/*
* MIT License
*
* Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
using System;
2017-01-08 14:57:10 +00:00
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
using ShiftOS.Engine;
using ShiftOS.Objects;
using ShiftOS.Objects.ShiftFS;
2017-04-30 21:50:50 +00:00
using ShiftOS.Unite;
2017-04-17 19:10:34 +00:00
using ShiftOS.WinForms.Tools;
2017-01-08 14:57:10 +00:00
namespace ShiftOS.WinForms
{
public partial class Oobe : Form, IOobe, ITutorial
2017-01-08 14:57:10 +00:00
{
public Oobe()
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
this.BackColor = Color.Black;
2017-04-17 19:10:34 +00:00
this.Load += (o, a) =>
{
ControlManager.SetupControls(this);
};
2017-01-08 14:57:10 +00:00
}
string rtext;
string gtexttotype;
int charcount;
int slashcount;
Label textgeninput;
public bool upgraded = false;
2017-02-26 15:24:27 +00:00
private bool typing = false;
public void TextType(string texttotype)
2017-01-08 14:57:10 +00:00
{
2017-04-17 19:10:34 +00:00
textgeninput.TextAlign = ContentAlignment.MiddleCenter;
while(typing == true)
{
2017-04-03 22:36:13 +00:00
//JESUS CHRIST PAST MICHAEL.
2017-04-03 22:36:13 +00:00
//We should PROBABLY block the thread... You know... not everyone has a 10-core processor.
Thread.Sleep(100);
}
charcount = texttotype.Length;
gtexttotype = texttotype;
slashcount = 1;
foreach (var c in gtexttotype)
2017-01-08 14:57:10 +00:00
{
typing = true;
rtext += c;
2017-01-08 14:57:10 +00:00
this.Invoke(new Action(() =>
{
textgeninput.Text = rtext + "|";
2017-01-08 14:57:10 +00:00
}));
slashcount++;
if (slashcount == 5)
slashcount = 1;
2017-06-04 19:18:53 +00:00
Engine.AudioManager.PlayStream(Properties.Resources.writesound);
2017-02-23 20:41:22 +00:00
Thread.Sleep(50);
2017-01-08 14:57:10 +00:00
}
rtext += Environment.NewLine;
typing = false;
2017-01-08 14:57:10 +00:00
}
public Save MySave = null;
public event EventHandler OnComplete;
private int tutPrg = 0;
public int TutorialProgress
{
get
{
return tutPrg;
}
set
{
tutPrg = value;
}
}
public void StartShowing(Save save)
2017-01-08 14:57:10 +00:00
{
var t = new Thread(new ThreadStart(() =>
2017-01-08 14:57:10 +00:00
{
2017-02-05 18:55:27 +00:00
try
2017-01-08 14:57:10 +00:00
{
2017-02-05 18:55:27 +00:00
textgeninput = this.lblhackwords;
this.Invoke(new Action(() =>
{
lblHijack.Hide();
2017-05-20 19:32:39 +00:00
lblhackwords.Font = new Font("Courier New", lblhackwords.Font.Size, FontStyle.Bold);
2017-02-05 18:55:27 +00:00
}));
2017-04-17 19:10:34 +00:00
2017-05-20 19:32:39 +00:00
TextType("Hello, unsuspecting user.");
Thread.Sleep(2000);
Clear();
TextType("Welcome to the Shifted Operating System.");
Thread.Sleep(2000);
Clear();
TextType("Your computer has been taken over by ShiftOS, and is currently being wiped clean of all existing files and programs.");
Thread.Sleep(2000);
Clear();
2017-06-04 19:18:53 +00:00
TextType("I will not share my identity or my intentions at this moment.");
Thread.Sleep(2000);
Clear();
TextType("I will just proceed with the installation.There<72>s nothing you can do to stop it.");
2017-05-20 19:32:39 +00:00
Thread.Sleep(2000);
Clear();
TextType("All I will say, is I need your help.Once ShiftOS is installed, I will explain.");
Thread.Sleep(5000);
2017-04-17 19:10:34 +00:00
while(this.Opacity > 0f)
2017-02-05 18:55:27 +00:00
{
2017-04-17 19:10:34 +00:00
this.Invoke(new Action(() =>
2017-02-23 20:41:22 +00:00
{
2017-04-17 19:10:34 +00:00
this.Opacity -= 0.01f;
2017-02-23 20:41:22 +00:00
}));
2017-04-17 19:10:34 +00:00
Thread.Sleep(25);
2017-02-23 20:41:22 +00:00
}
2017-04-17 19:10:34 +00:00
Story.Start("mud_fundamentals");
this.Invoke(new Action(this.Close));
}
catch (Exception e)
2017-01-08 14:57:10 +00:00
{
2017-02-05 18:55:27 +00:00
TextType("I have experienced an error.");
TextType(e.ToString());
}
}));
2017-01-08 14:57:10 +00:00
this.Show();
this.BringToFront();
2017-01-08 14:57:10 +00:00
this.TopMost = true;
t.IsBackground = true;
t.Start();
2017-01-08 14:57:10 +00:00
}
public void Clear()
2017-01-08 14:57:10 +00:00
{
this.Invoke(new Action(() =>
2017-01-08 14:57:10 +00:00
{
2017-01-18 23:09:48 +00:00
rtext = "";
textgeninput.Text = "";
}));
2017-01-08 14:57:10 +00:00
}
public void ShowSaveTransfer(Save save)
2017-01-08 14:57:10 +00:00
{
//Stub.
2017-01-08 14:57:10 +00:00
}
2017-04-30 21:50:50 +00:00
public void PerformUniteLogin()
{
}
public void PromptForLogin()
{
2017-04-30 21:50:50 +00:00
Infobox.Show("Login", "Since the last time you've played ShiftOS, some changes have been made to the login system. You must now login using your website credentials.", () =>
{
2017-04-30 21:50:50 +00:00
Infobox.PromptYesNo("Website account", "Do you have an account at http://getshiftos.ml?", (hasAccount) =>
2017-04-29 00:01:04 +00:00
{
2017-04-30 21:50:50 +00:00
if(hasAccount == true)
{
var loginDialog = new UniteLoginDialog((success)=>
{
string token = success;
var uClient = new UniteClient("http://getshiftos.ml", token);
Infobox.Show("Welcome to ShiftOS.", $"Hello, {uClient.GetDisplayName()}! We've signed you into your account. We'll now try to link your ShiftOS account with your save file.", () =>
{
ServerMessageReceived smr = null;
smr = (msg) =>
{
if (msg.Name == "mud_savefile")
{
2017-05-29 20:08:59 +00:00
ServerManager.MessageReceived -= smr;
2017-04-30 21:50:50 +00:00
SaveSystem.CurrentSave = JsonConvert.DeserializeObject<Save>(msg.Contents);
SaveSystem.SaveGame();
}
2017-05-01 00:44:26 +00:00
else if(msg.Name=="mud_login_denied")
2017-04-30 21:50:50 +00:00
{
2017-05-29 20:08:59 +00:00
ServerManager.MessageReceived -= smr;
2017-04-30 21:50:50 +00:00
LinkSaveFile(token);
}
};
ServerManager.MessageReceived += smr;
ServerManager.SendMessage("mud_token_login", token);
});
});
AppearanceManager.SetupDialog(loginDialog);
}
2017-04-30 22:50:54 +00:00
else
{
var signupDialog = new UniteSignupDialog((token) =>
{
2017-04-30 23:26:00 +00:00
ServerMessageReceived smr = null;
smr = (msg) =>
{
ServerManager.MessageReceived -= smr;
if (msg.Name == "mud_savefile")
{
SaveSystem.CurrentSave = JsonConvert.DeserializeObject<Save>(msg.Contents);
SaveSystem.SaveGame();
}
2017-05-01 00:44:26 +00:00
else if (msg.Name == "mud_login_denied")
2017-04-30 23:26:00 +00:00
{
LinkSaveFile(token);
}
};
ServerManager.MessageReceived += smr;
ServerManager.SendMessage("mud_token_login", token);
2017-04-30 22:50:54 +00:00
});
AppearanceManager.SetupDialog(signupDialog);
}
2017-04-30 21:50:50 +00:00
});
});
}
public void LinkSaveFile(string token)
{
2017-04-30 22:50:54 +00:00
if (Utils.FileExists(Paths.GetPath("user.dat")))
2017-04-29 00:01:04 +00:00
{
2017-04-30 22:50:54 +00:00
try
2017-04-29 00:01:04 +00:00
{
2017-04-30 22:50:54 +00:00
var details = JsonConvert.DeserializeObject<ClientSave>(Utils.ReadAllText(Paths.GetPath("user.dat")));
ServerMessageReceived smr = null;
bool msgreceived = false;
bool found = false;
smr = (msg) =>
2017-04-29 00:01:04 +00:00
{
2017-04-30 22:50:54 +00:00
if (msg.Name == "mud_savefile")
2017-04-29 00:01:04 +00:00
{
2017-04-30 22:50:54 +00:00
var save = JsonConvert.DeserializeObject<Save>(msg.Contents);
2017-04-30 21:50:50 +00:00
save.UniteAuthToken = token;
2017-04-30 22:50:54 +00:00
Infobox.Show("Migration complete.", "We have migrated your old save file to the new system successfully. You can still log in using the old system on old builds of ShiftOS.", () =>
2017-04-29 00:01:04 +00:00
{
2017-04-30 21:50:50 +00:00
SaveSystem.CurrentSave = save;
SaveSystem.SaveGame();
2017-04-30 22:50:54 +00:00
found = true;
msgreceived = true;
2017-04-30 21:50:50 +00:00
});
}
2017-05-01 00:44:26 +00:00
else if (msg.Name == "mud_login_denied")
2017-04-30 21:50:50 +00:00
{
2017-04-30 22:50:54 +00:00
found = false;
msgreceived = true;
2017-04-30 21:50:50 +00:00
}
2017-04-30 22:50:54 +00:00
ServerManager.MessageReceived -= smr;
2017-04-30 21:50:50 +00:00
};
2017-04-30 22:50:54 +00:00
ServerManager.MessageReceived += smr;
2017-04-30 21:50:50 +00:00
ServerManager.SendMessage("mud_login", JsonConvert.SerializeObject(new
2017-04-29 00:01:04 +00:00
{
2017-04-30 22:50:54 +00:00
username = details.Username,
password = details.Password
2017-04-30 21:50:50 +00:00
}));
2017-04-30 22:50:54 +00:00
while (msgreceived == false)
Thread.Sleep(10);
2017-05-01 00:39:21 +00:00
if (found == true)
2017-04-30 22:50:54 +00:00
return;
}
catch
{
}
}
var client = new UniteClient("http://getshiftos.ml", token);
var sve = new Save();
2017-05-29 15:38:11 +00:00
sve.Username = client.GetEmail();
2017-04-30 22:50:54 +00:00
sve.Password = Guid.NewGuid().ToString();
sve.SystemName = client.GetSysName();
sve.UniteAuthToken = token;
sve.Codepoints = 0;
sve.Upgrades = new Dictionary<string, bool>();
sve.ID = Guid.NewGuid();
2017-05-08 16:12:22 +00:00
sve.StoriesExperienced = new List<string>();
sve.StoriesExperienced.Add("mud_fundamentals");
2017-04-30 22:50:54 +00:00
Infobox.Show("Welcome to ShiftOS.", "Welcome to ShiftOS, " + client.GetDisplayName() + ". We have created a save file for you. Now, go on and Shift It Your Way.", () =>
{
sve.StoryPosition = 8675309;
SaveSystem.CurrentSave = sve;
2017-05-08 16:09:45 +00:00
Shiftorium.Silent = true;
2017-04-30 22:50:54 +00:00
SaveSystem.SaveGame();
2017-05-08 16:09:45 +00:00
Shiftorium.Silent = false;
2017-04-30 22:50:54 +00:00
2017-04-29 00:01:04 +00:00
});
2017-04-30 21:50:50 +00:00
}
public void ForceReboot()
{
string json = Utils.ExportMount(0);
System.IO.File.WriteAllText(Paths.SaveFile, json);
System.Diagnostics.Process.Start(Application.ExecutablePath);
Environment.Exit(0);
}
2017-01-18 23:09:48 +00:00
public void StartTrailer()
{
while(AppearanceManager.OpenForms.Count > 0)
{
AppearanceManager.OpenForms[0].Close();
}
this.Show();
this.TopMost = true;
this.TransparencyKey = Color.Magenta;
this.BackColor = this.TransparencyKey;
textgeninput = lblHijack;
textgeninput.BackColor = Color.Black;
textgeninput.Font = new Font("Lucida Console", 13F, FontStyle.Bold);
textgeninput.AutoSize = true;
textgeninput.TextAlign = ContentAlignment.MiddleCenter;
textgeninput.TextChanged += (o, a) =>
{
textgeninput.Location = new Point(
(this.Width - textgeninput.Width) / 2,
(this.Height - textgeninput.Height) / 2
);
};
var t = new Thread(() =>
{
Clear();
Thread.Sleep(5000);
TextType("Michael VanOverbeek");
TextType("presents...");
Thread.Sleep(2000);
Clear();
Thread.Sleep(1000);
TextType("A community-developed game");
Thread.Sleep(3000);
Clear();
Thread.Sleep(1000);
this.Invoke(new Action(() =>
{
textgeninput.Font = new Font("Lucida Console", 14F, FontStyle.Bold);
this.BackColor = Color.Black;
}));
TextType("Welcome to ShiftOS.");
Thread.Sleep(4000);
Clear();
textgeninput = lblhackwords;
TextType("Hello.");
Thread.Sleep(500);
TextType("You have been cordially and involuntarily selected to participate in the development and testing of an experimental operating system called ShiftOS.");
Thread.Sleep(500);
TextType("I want ShiftOS to be the most advanced operating system in the world.");
Thread.Sleep(500);
TextType("In ShiftOS, you start out with nothing.");
Thread.Sleep(500);
TextType("And your goal is to upgrade the operating system from a barebones command line to a fully graphical operating system.");
Thread.Sleep(500);
TextType("Along the way, you'll meet many people - hackers, rebels, programmers, administrators and many more.");
Thread.Sleep(500);
TextType("You'll meet new friends and foes.");
Thread.Sleep(500);
TextType("Your goal: Take it over. Upgrade the operating system, and take over its multi-user domain.");
Thread.Sleep(500);
TextType("I won't reveal quite what you have to do, but if you can handle it, head over to http://getshiftos.ml/ and download the operating system now.");
Thread.Sleep(5000);
Clear();
textgeninput = lblHijack;
TextType("Think you can handle it?");
});
t.IsBackground = false;
t.Start();
}
public void Start()
{
2017-02-05 18:55:27 +00:00
Shiftorium.Silent = false;
foreach(var frm in AppearanceManager.OpenForms)
{
(frm as Form).Invoke(new Action(() => {
frm.Close();
}));
}
TerminalBackend.CommandProcessed += (cmd, args) =>
{
if(cmd == "sos.help")
{
if (TutorialProgress == 0)
TutorialProgress = 1;
}
else if(cmd == "sos.status")
{
if (TutorialProgress == 1)
TutorialProgress = 2;
}
else if(cmd == "shiftorium.list")
{
if (TutorialProgress == 2)
2017-02-10 13:59:24 +00:00
{
TutorialProgress = 3;
2017-02-10 13:59:24 +00:00
SaveSystem.TransferCodepointsFrom("sys", 50);
}
}
else if(cmd == "shiftorium.info" && args == "{\"upgrade\":\"mud_fundamentals\"}")
{
if (TutorialProgress == 3)
TutorialProgress = 4;
}
else if(cmd == "win.open")
{
if (TutorialProgress == 4)
TutorialProgress = 5;
}
};
2017-02-05 18:55:27 +00:00
if(this.Visible == false)
this.Show();
var t = new Thread(() =>
{
textgeninput = lblHijack;
Clear();
textgeninput = lblhackwords;
Clear();
2017-04-02 18:26:25 +00:00
this.Invoke(new Action(() =>
{
textgeninput.Font = SkinEngine.LoadedSkin.TerminalFont;
}));
TextType("ShiftOS has been installed successfully.");
Thread.Sleep(500);
TextType("Before you can continue to the operating system, here's a little tutorial on how to use it.");
Thread.Sleep(500);
TextType("Starting a Terminal...");
Applications.Terminal term = null;
this.Invoke(new Action(() =>
{
term = new Applications.Terminal();
this.Controls.Add(term);
term.Location = new Point(
(this.Width - term.Width) / 2,
(this.Height - term.Height) / 2
);
term.Show();
term.OnLoad();
term.OnSkinLoad();
term.OnUpgrade();
}));
TextType("This little text box is called a Terminal.");
Thread.Sleep(500);
TextType("Normally, it would appear in full-screen, but this window is hosting it as a control so you can see this text as well.");
Thread.Sleep(500);
TextType("In ShiftOS, the Terminal is your main control centre for the operating system. You can see system status, check Codepoints, open other programs, buy upgrades, and more.");
Thread.Sleep(500);
TextType("Go ahead and type 'sos.help' to see a list of commands.");
2017-04-02 18:26:25 +00:00
while (TutorialProgress == 0)
{
2017-04-03 22:36:13 +00:00
//JESUS CHRIST PAST MICHAEL.
//We should PROBABLY block the thread... You know... not everyone has a 10-core processor.
Thread.Sleep(100);
}
TextType("As you can see, sos.help gives you a list of all commands in the system.");
Thread.Sleep(500);
TextType("You can run any command, by typing in their Namespace, followed by a period (.), followed by their Command Name.");
Thread.Sleep(500);
TextType("Go ahead and run the 'status' command within the 'sos' namespace to see what the command does.");
2017-04-02 18:26:25 +00:00
while (TutorialProgress == 1)
{
2017-04-03 22:36:13 +00:00
//JESUS CHRIST PAST MICHAEL.
//We should PROBABLY block the thread... You know... not everyone has a 10-core processor.
Thread.Sleep(100);
}
TextType("Brilliant. The sos.status command will tell you how many Codepoints you have, as well as how many upgrades you have installed and how many are available.");
Thread.Sleep(500);
TextType("Codepoints, as you know, are a special currency within ShiftOS. They are used to buy things within the multi-user domain, such as upgrades, scripts, and applications.");
Thread.Sleep(500);
TextType("You can earn Codepoints by doing things in ShiftOS - such as completing jobs for other users, making things like skins, scripts, documents, etc, and playing games like Pong.");
Thread.Sleep(500);
TextType("At times, you'll be given Codepoints to help complete a task. You will receive Codepoints from 'sys' - the multi-user domain itself.");
2017-02-10 13:59:24 +00:00
//SaveSystem.TransferCodepointsFrom("sys", 50);
TextType("Right now, you don't have any upgrades. Upgrades can give ShiftOS additional features and capabilities - like new core applications, supported file types, and new Terminal commands.");
Thread.Sleep(500);
TextType("You can easily get upgrades using the Shiftorium - a repository of approved ShiftOS upgrades.");
Thread.Sleep(500);
TextType("To start using the Shiftorium, simply type 'shiftorium.list' to see available upgrades.");
2017-04-02 18:26:25 +00:00
while (TutorialProgress == 2)
{
2017-04-03 22:36:13 +00:00
//JESUS CHRIST PAST MICHAEL.
//We should PROBABLY block the thread... You know... not everyone has a 10-core processor.
Thread.Sleep(100);
}
Clear();
TextType("Right now, you have enough Codepoints to buy the 'mud_fundamentals' upgrade. You can use shiftorium.info to see information about this upgrade.");
Thread.Sleep(500);
TextType("Some commands, like shiftorium.info, require you to pass information to them in the form of arguments.");
Thread.Sleep(500);
TextType("Argument pairs sit at the end of the command, and are enclosed in curly braces.");
Thread.Sleep(500);
TextType("Inside these curly braces, you can input an argument key, followed by a colon, followed by the value. Then, if you need multiple arguments, you can put a comma after the value, and then insert another argument pair.");
Thread.Sleep(500);
TextType("There are different value types - numeric values, which can be any positive or negative 32-bit integer");
Thread.Sleep(500);
TextType("Then there are boolean values which can be either 'true' or 'false'");
Thread.Sleep(500);
TextType("Then there are string values, which are enclosed in double-quotes.");
Thread.Sleep(500);
TextType(" If for some reason you need to use a double-quote inside a string, you must escape it using a single backslash followed by the quote, like this: key:\"My \\\"awesome\\\" value.\"");
Thread.Sleep(500);
TextType("If you want to escape a backslash inside a string, simply type two backslashes instead of one - for example key:\"Back\\\\slash.\"");
Thread.Sleep(500);
TextType("shiftorium.info requires an upgrade argument, which is a string type. Go ahead and give shiftorium.info's upgrade argument the 'mud_fundamentals' upgrade's ID.");
2017-04-02 18:26:25 +00:00
while (TutorialProgress == 3)
{
2017-04-03 22:36:13 +00:00
//JESUS CHRIST PAST MICHAEL.
//We should PROBABLY block the thread... You know... not everyone has a 10-core processor.
Thread.Sleep(100);
2017-04-02 18:26:25 +00:00
}
TextType("As you can see, mud_fundamentals is very useful. In fact, a lot of useful upgrades depend on it. You should buy it!");
Thread.Sleep(500);
TextType("shiftorium.info already gave you a command that will let you buy the upgrade - go ahead and run that command!");
while (!Shiftorium.UpgradeInstalled("mud_fundamentals"))
2017-04-03 22:36:13 +00:00
{ //JESUS CHRIST PAST MICHAEL.
//We should PROBABLY block the thread... You know... not everyone has a 10-core processor.
Thread.Sleep(100);
2017-04-02 18:26:25 +00:00
}
TextType("Hooray! You now have the MUD Fundamentals upgrade.");
Thread.Sleep(500);
TextType("You can also earn more Codepoints by playing Pong. To open Pong, you can use the win.open command.");
Thread.Sleep(500);
TextType("If you run win.open without arguments, you can see a list of applications that you can open.");
Thread.Sleep(500);
TextType("Just run win.open without arguments, and this tutorial will be completed!");
2017-04-02 18:26:25 +00:00
while (TutorialProgress == 4)
{
2017-04-03 22:36:13 +00:00
//JESUS CHRIST PAST MICHAEL.
//We should PROBABLY block the thread... You know... not everyone has a 10-core processor.
Thread.Sleep(100);
}
TextType("This concludes the ShiftOS beginners' guide brought to you by the multi-user domain. Stay safe in a connected world.");
Thread.Sleep(2000);
2017-04-02 18:26:25 +00:00
Desktop.InvokeOnWorkerThread(() =>
{
OnComplete?.Invoke(this, EventArgs.Empty);
SaveSystem.CurrentSave.StoryPosition = 2;
2017-04-03 22:36:13 +00:00
this.Close();
SaveSystem.SaveGame();
AppearanceManager.SetupWindow(new Applications.Terminal());
2017-04-02 18:26:25 +00:00
});
});
t.IsBackground = true;
t.Start();
}
2017-01-08 14:57:10 +00:00
}
}