1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
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;
namespace ShiftOS.WinForms
{
[Namespace("test")]
public class OobeStory
{
[Command("test")]
[RequiresArgument("num")]
public static bool TestThingy(Dictionary<string, object> args)
{
long num = Convert.ToInt64(args["num"].ToString());
string hex = num.ToString("X");
string bin = Convert.ToString(num, 2);
Console.WriteLine("Hex: " + hex);
Console.WriteLine("Bin: " + bin);
return true;
}
[Story("mud_fundamentals")]
public static void DoStory()
{
Applications.Terminal term = null;
TerminalBackend.PrefixEnabled = false;
Desktop.InvokeOnWorkerThread(() =>
{
term = new Applications.Terminal();
AppearanceManager.SetupWindow(term);
ConsoleEx.Bold = true;
ConsoleEx.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Welcome to ShiftOS.");
Console.WriteLine();
ConsoleEx.Bold = false;
ConsoleEx.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Before we can bring you to your new system, we must perform some system tasks.");
Console.WriteLine();
Console.WriteLine("Here's the installation outline.");
Console.WriteLine();
Console.Write(" - ");
ConsoleEx.Bold = true;
Console.Write("Storage preparation");
ConsoleEx.Bold = false;
Console.Write(" First, we have to prepare your computer's storage device for ShiftOS. This \r\nincludes formatting your drive with the ShiftFS file \r\nsystem, creating system directories, and generating system files.");
Console.WriteLine();
Console.Write(" - ");
ConsoleEx.Bold = true;
Console.Write("User configuration");
ConsoleEx.Bold = false;
Console.Write(" Next it's up to you to set up a system hostname, create a user account, and personalize it.");
Console.WriteLine();
Console.Write(" - ");
ConsoleEx.Bold = true;
Console.Write("System tutorial");
ConsoleEx.Bold = false;
Console.WriteLine("Finally, we'll teach you how to use ShiftOS.");
Console.WriteLine();
ConsoleEx.Bold = true;
ConsoleEx.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Let's get started!");
});
int position = 0;
Thread.Sleep(5000);
ConsoleEx.Bold = true;
Console.WriteLine("System preparation");
Console.WriteLine();
ConsoleEx.Bold = false;
ConsoleEx.ForegroundColor = ConsoleColor.White;
Console.WriteLine(@"We'll now begin formatting your drive. Please be patient.");
Console.WriteLine();
var dinf = new DriveInfo("C:\\");
decimal bytesFree = ((dinf.AvailableFreeSpace / 1024) / 1024) / 1024;
decimal totalBytes = ((dinf.TotalSize / 1024) / 1024) / 1024;
string type = dinf.DriveType.ToString();
string name = dinf.Name;
ConsoleEx.Bold = true;
Console.Write("Drive name: ");
ConsoleEx.Bold = false;
Console.WriteLine(name);
ConsoleEx.Bold = true;
Console.Write("Drive type: ");
ConsoleEx.Bold = false;
Console.WriteLine(type);
ConsoleEx.Bold = true;
Console.Write("Total space: ");
ConsoleEx.Bold = false;
Console.WriteLine(totalBytes.ToString() + " GB");
ConsoleEx.Bold = true;
Console.Write("Free space: ");
Console.WriteLine(bytesFree.ToString() + " GB");
Console.WriteLine();
ConsoleEx.Bold = false;
ConsoleEx.BackgroundColor = ConsoleColor.Black;
Console.Write("Formatting: [");
int formatProgress = 0;
while (formatProgress <= 100)
{
if (formatProgress % 3 == 0)
{
ConsoleEx.BackgroundColor = ConsoleColor.White;
Console.Write(" ");
ConsoleEx.BackgroundColor = ConsoleColor.Black;
}
Engine.AudioManager.PlayStream(Properties.Resources.typesound);
formatProgress++;
Thread.Sleep(175);
}
Console.WriteLine("] ..done.");
Thread.Sleep(1000);
ConsoleEx.Bold = true;
Console.WriteLine("Creating directories...");
ConsoleEx.Bold = false;
foreach (var dir in Paths.GetAllWithoutKey())
{
if (!dir.Contains(".") && dir.StartsWith("0:/"))
{
Console.WriteLine("Creating: " + dir);
Thread.Sleep(125);
Engine.AudioManager.PlayStream(Properties.Resources.writesound);
}
}
Console.WriteLine();
Console.WriteLine("Next, let's get user information.");
Console.WriteLine();
Console.WriteLine("Please enter a system hostname.");
string allowed_chars = "abcdefghijklmnopqrstuvwxyz1234567890_";
bool userExists = false;
Applications.Terminal.TextSent += (text) =>
{
if(position == 0)
{
if(text.Length < 5)
{
Console.WriteLine("Your hostname must be at least 5 characters long.");
return;
}
if(!isValid(text, allowed_chars))
{
Console.WriteLine("Your hostname contains illegal characters. You can only use these characters: " + allowed_chars);
return;
}
SaveSystem.CurrentSave.SystemName = text;
position = 1;
}
else if(position == 1)
{
if (text.Length < 5)
{
Console.WriteLine("Your username must be at least 5 characters long.");
return;
}
if (!isValid(text, allowed_chars))
{
Console.WriteLine("Your username contains illegal characters. You can only use these characters: " + allowed_chars);
return;
}
SaveSystem.CurrentSave.Username = text;
position = 2;
}
else if(position == 3)
{
if (!userExists)
{
if (text.Length < 5)
{
Console.WriteLine("Your password must be at least 5 characters long.");
return;
}
SaveSystem.CurrentSave.Password = text;
position = 4;
}
else
{
ServerManager.SendMessage("mud_login", JsonConvert.SerializeObject(new
{
username = SaveSystem.CurrentSave.Username,
password = text
}));
}
}
};
TerminalBackend.InStory = false;
while (position == 0)
Thread.Sleep(10);
Console.WriteLine("Connecting to the multi-user domain as " + SaveSystem.CurrentSave.SystemName + "...");
Engine.AudioManager.PlayStream(Properties.Resources.dial_up_modem_02);
Console.WriteLine("Connection successful, system spinning up...");
Thread.Sleep(200);
UsernameWait:
Console.WriteLine("No users associated with this system. Please enter a username.");
Console.WriteLine(" - If the username is registered as a digital being, you will be prompted for your password. Else, you will be prompted to create a new account.");
while(position == 1)
{
Thread.Sleep(10);
}
bool goBack = false;
int incorrectChances = 2;
Console.WriteLine("Checking sentience records...");
ServerMessageReceived smr = (msg) =>
{
if (position == 2)
{
if (msg.Name == "mud_found")
{
Console.WriteLine("Your username has been taken by another sentient being within the digital society.");
Console.WriteLine("If you are that sentience, you have two chances to type the correct password.");
userExists = true;
}
else if (msg.Name == "mud_notfound")
{
Console.WriteLine("Please enter a password for this new user.");
userExists = false;
}
position = 3;
}
else if (position == 3)
{
if(userExists == true)
{
if(msg.Name == "mud_savefile")
{
Console.WriteLine("Your sentience profile has been assigned to your system successfully. We will bring you to your system shortly.");
SaveSystem.CurrentSave = JsonConvert.DeserializeObject<Save>(msg.Contents);
position = 4;
}
else if(msg.Name == "mud_login_denied")
{
if (incorrectChances > 0)
{
incorrectChances--;
Console.WriteLine("Access denied. Chances: " + incorrectChances);
}
else
{
Console.WriteLine("Access denied.");
position = 2;
goBack = true;
}
}
}
}
};
ServerManager.MessageReceived += smr;
ServerManager.SendMessage("mud_checkuserexists", JsonConvert.SerializeObject(new { username = SaveSystem.CurrentSave.Username }));
while (position == 2)
{
Thread.Sleep(10);
}
while (position == 3)
{
Thread.Sleep(10);
}
if (goBack)
{
ServerManager.MessageReceived -= smr;
goto UsernameWait;
}
Console.WriteLine("Sentience linkup successful.");
Console.WriteLine("We will bring you to your system in 5 seconds.");
Thread.Sleep(5000);
Desktop.InvokeOnWorkerThread(() =>
{
SaveSystem.CurrentSave.StoryPosition = 3;
SaveSystem.SaveGame();
while (!Shiftorium.IsInitiated)
{
Thread.Sleep(10);
}
if (!Shiftorium.UpgradeInstalled("desktop"))
{
SaveSystem.GameReady += () =>
{
term.ClearText();
TerminalBackend.PrintPrompt();
Console.Write("sos.status");
TerminalBackend.InvokeCommand("sos.status");
TerminalBackend.PrintPrompt();
Console.Write("sos.help");
TerminalBackend.InvokeCommand("sos.help");
};
}
});
}
private static bool isValid(string text, string chars)
{
foreach(var c in text)
{
if (!chars.Contains(c))
return false;
}
return true;
}
}
}
|