aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS_TheReturn')
-rw-r--r--ShiftOS_TheReturn/CommandParser.cs3
-rw-r--r--ShiftOS_TheReturn/Commands.cs2
-rw-r--r--ShiftOS_TheReturn/SaveSystem.cs123
-rw-r--r--ShiftOS_TheReturn/ShiftOS.Engine.csproj2
-rw-r--r--ShiftOS_TheReturn/TerminalBackend.cs112
-rw-r--r--ShiftOS_TheReturn/UniteClient.cs83
-rw-r--r--ShiftOS_TheReturn/UniteTestCommands.cs64
7 files changed, 323 insertions, 66 deletions
diff --git a/ShiftOS_TheReturn/CommandParser.cs b/ShiftOS_TheReturn/CommandParser.cs
index 7a190df..868d27a 100644
--- a/ShiftOS_TheReturn/CommandParser.cs
+++ b/ShiftOS_TheReturn/CommandParser.cs
@@ -98,8 +98,6 @@ namespace ShiftOS.Engine
int firstValuePos = -1;
int lastValuePos = -1;
- string syntaxError = "";
-
for (int ii = 0; ii < parts.Count; ii++)
{
CommandFormat part = parts[ii];
@@ -184,7 +182,6 @@ namespace ShiftOS.Engine
else
{
position = text.Length;
- syntaxError = "Syntax Error";
command = "+FALSE+";
}
help = -1;
diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs
index 7980635..87aacd6 100644
--- a/ShiftOS_TheReturn/Commands.cs
+++ b/ShiftOS_TheReturn/Commands.cs
@@ -73,7 +73,7 @@ namespace ShiftOS.Engine
TerminalBackend.IsForwardingConsoleWrites = forwarding;
TerminalBackend.ForwardGUID = (forwarding == true) ? fGuid : null;
string resultFriendly = (result == true) ? "yes" : "no";
- Console.WriteLine($"{SaveSystem.CurrentSave.Username} says {resultFriendly}.");
+ Console.WriteLine($"{SaveSystem.CurrentUser.Username} says {resultFriendly}.");
TerminalBackend.IsForwardingConsoleWrites = false;
};
Desktop.InvokeOnWorkerThread(new Action(() =>
diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs
index 3e68a70..a27b04f 100644
--- a/ShiftOS_TheReturn/SaveSystem.cs
+++ b/ShiftOS_TheReturn/SaveSystem.cs
@@ -50,6 +50,9 @@ namespace ShiftOS.Engine
{
public static bool ShuttingDown = false;
+ public static ClientSave CurrentUser { get; set; }
+
+
public static Save CurrentSave { get; set; }
/// <summary>
@@ -156,17 +159,23 @@ namespace ShiftOS.Engine
{
KernelWatchdog.Log("mud_handshake", "handshake successful: kernel watchdog access code is \"" + ServerManager.thisGuid.ToString() + "\"");
- ServerManager.MessageReceived += (msg) =>
+ ServerMessageReceived savehandshake = null;
+
+ savehandshake = (msg) =>
{
if (msg.Name == "mud_savefile")
{
CurrentSave = JsonConvert.DeserializeObject<Save>(msg.Contents);
+ ServerManager.MessageReceived -= savehandshake;
}
else if (msg.Name == "mud_login_denied")
{
oobe.PromptForLogin();
+ ServerManager.MessageReceived -= savehandshake;
}
};
+ ServerManager.MessageReceived += savehandshake;
+
ReadSave();
@@ -189,28 +198,96 @@ namespace ShiftOS.Engine
Thread.Sleep(50);
Console.WriteLine("{SYSTEM_INITIATED}");
+
+
+ if(CurrentSave.Users.Count == 0)
+ {
+ CurrentSave.Users.Add(new ClientSave
+ {
+ Username = "root",
+ Password = "",
+ Permissions = UserPermissions.Root
+ });
+ Console.WriteLine("No users found. Creating new user with username \"root\", with no password.");
+ }
TerminalBackend.InStory = false;
+
+ TerminalBackend.PrefixEnabled = false;
+
+ Login:
+ string username = "";
+ int progress = 0;
+ bool goback = false;
+ TextSentEventHandler ev = null;
+ ev = (text) =>
+ {
+ if (progress == 0)
+ {
+ if (!string.IsNullOrWhiteSpace(text))
+ {
+ if (CurrentSave.Users.FirstOrDefault(x => x.Username == text) == null)
+ {
+ Console.WriteLine("User not found.");
+ goback = true;
+ progress++;
+ TerminalBackend.TextSent -= ev;
+ return;
+ }
+ username = text;
+ progress++;
+ }
+ else
+ {
+ Console.WriteLine("Username not provided.");
+ TerminalBackend.TextSent -= ev;
+ goback = true;
+ progress++;
+ }
+ }
+ else if (progress == 1)
+ {
+ var user = CurrentSave.Users.FirstOrDefault(x => x.Username == username);
+ if (user.Password == text)
+ {
+ Console.WriteLine("Welcome to ShiftOS.");
+ CurrentUser = user;
+ Thread.Sleep(2000);
+ progress++;
+ }
+ else
+ {
+ Console.WriteLine("Access denied.");
+ goback = true;
+ progress++;
+ }
+ TerminalBackend.TextSent -= ev;
+ }
+ };
+ TerminalBackend.TextSent += ev;
+ Console.WriteLine(CurrentSave.SystemName + " login:");
+ while(progress == 0)
+ {
+ Thread.Sleep(10);
+ }
+ if (goback)
+ goto Login;
+ Console.WriteLine("password:");
+ while (progress == 1)
+ Thread.Sleep(10);
+ if (goback)
+ goto Login;
+
+
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();
- }
+
+ Desktop.InvokeOnWorkerThread(new Action(() => Desktop.PopulateAppLauncher()));
+ GameReady?.Invoke();
}
public delegate void EmptyEventHandler();
@@ -266,12 +343,9 @@ namespace ShiftOS.Engine
{
if (Utils.FileExists(Paths.GetPath("user.dat")))
{
- var userdat = JsonConvert.DeserializeObject<ClientSave>(Utils.ReadAllText(Paths.GetPath("user.dat")));
+ string token = Utils.ReadAllText(Paths.GetPath("user.dat"));
- ServerManager.SendMessage("mud_login", $@"{{
- username: ""{userdat.Username}"",
- password: ""{userdat.Password}""
-}}");
+ ServerManager.SendMessage("mud_token_login", token);
}
else
{
@@ -301,14 +375,7 @@ namespace ShiftOS.Engine
Console.Write("{SE_SAVING}... ");
if (SaveSystem.CurrentSave != null)
{
- string username = CurrentSave.Username;
- string password = CurrentSave.Password;
-
- Utils.WriteAllText(Paths.GetPath("user.dat"), $@"{{
- username: ""{username}"",
- password: ""{password}""
-}}");
-
+ Utils.WriteAllText(Paths.GetPath("user.dat"), CurrentSave.UniteAuthToken);
ServerManager.SendMessage("mud_save", JsonConvert.SerializeObject(CurrentSave, Formatting.Indented));
}
if (!Shiftorium.Silent)
diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj
index f7b730f..5cd6c68 100644
--- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj
+++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj
@@ -131,6 +131,8 @@
<Compile Include="TerminalBackend.cs" />
<Compile Include="TerminalTextWriter.cs" />
<Compile Include="TutorialManager.cs" />
+ <Compile Include="UniteClient.cs" />
+ <Compile Include="UniteTestCommands.cs" />
<Compile Include="VirusEngine.cs" />
<Compile Include="WinOpenAttribute.cs" />
<EmbeddedResource Include="Infobox.resx">
diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs
index 318c818..6911feb 100644
--- a/ShiftOS_TheReturn/TerminalBackend.cs
+++ b/ShiftOS_TheReturn/TerminalBackend.cs
@@ -32,21 +32,26 @@ using System.Threading.Tasks;
using Newtonsoft.Json;
using static ShiftOS.Engine.SaveSystem;
-namespace ShiftOS.Engine {
- public static class TerminalBackend {
+namespace ShiftOS.Engine
+{
+ public static class TerminalBackend
+ {
public static event Action<string, string> CommandProcessed;
public static bool Elevated { get; set; }
- public static Dictionary<string, string> GetArgs(ref string text) {
+ public static Dictionary<string, string> GetArgs(ref string text)
+ {
bool shouldParse = false;
int argStart = 0;
- if (text.Contains("{")) {
+ if (text.Contains("{"))
+ {
shouldParse = true;
argStart = text.IndexOf('{');
}
- if (shouldParse == false) {
+ if (shouldParse == false)
+ {
string replacement = Regex.Replace(text, @"\t|\n|\r", "");
text = replacement + "{}";
shouldParse = true;
@@ -61,15 +66,18 @@ namespace ShiftOS.Engine {
public static string LastCommand = "";
- public static void InvokeCommand(string ns, string command, Dictionary<string, string> arguments, bool isRemote = false) {
- try {
+ public static void InvokeCommand(string ns, string command, Dictionary<string, string> arguments, bool isRemote = false)
+ {
+ try
+ {
if (string.IsNullOrWhiteSpace(ns))
return;
bool commandWasClient = RunClient(ns, command, arguments, isRemote);
- if (!commandWasClient && !string.IsNullOrWhiteSpace(ns)) {
+ if (!commandWasClient && !string.IsNullOrWhiteSpace(ns))
+ {
PrefixEnabled = false;
ServerManager.SendMessage("script", $@"{{
@@ -80,23 +88,29 @@ namespace ShiftOS.Engine {
}
CommandProcessed?.Invoke(ns + "." + command, JsonConvert.SerializeObject(arguments));
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
Console.WriteLine($"Command parse error: {ex.Message}"); // This shouldn't ever be called now
PrefixEnabled = true;
}
}
- public static string GetSentArgs(Dictionary<string, string> argss) {
+ public static string GetSentArgs(Dictionary<string, string> argss)
+ {
Dictionary<string, object> args = new Dictionary<string, object>();
- foreach (KeyValuePair<string, string> arg in argss) {
+ foreach (KeyValuePair<string, string> arg in argss)
+ {
args[arg.Key] = arg.Value;
}
return JsonConvert.SerializeObject(args);
}
- public static void InvokeCommand(string text, bool isRemote = false) {
- try {
+ public static void InvokeCommand(string text, bool isRemote = false)
+ {
+ try
+ {
if (string.IsNullOrWhiteSpace(text))
return;
@@ -104,7 +118,8 @@ namespace ShiftOS.Engine {
bool commandWasClient = RunClient(text, args, isRemote);
- if (!commandWasClient) {
+ if (!commandWasClient)
+ {
PrefixEnabled = false;
ServerManager.SendMessage("script", $@"{{
@@ -114,7 +129,9 @@ namespace ShiftOS.Engine {
}}");
}
CommandProcessed?.Invoke(text, GetSentArgs(args));
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
Console.WriteLine($"Command parse error: {ex.Message}");
PrefixEnabled = true;
@@ -129,15 +146,18 @@ namespace ShiftOS.Engine {
public static event EmptyEventHandler TerminalRequested;
- internal static void OpenTerminal() {
+ internal static void OpenTerminal()
+ {
TerminalRequested?.Invoke();
}
- public static bool CanRunRemotely(MethodInfo mth, bool isRemote) {
+ public static bool CanRunRemotely(MethodInfo mth, bool isRemote)
+ {
if (!isRemote)
return true;
- foreach (var attr in mth.GetCustomAttributes(false)) {
+ foreach (var attr in mth.GetCustomAttributes(false))
+ {
if (attr is RemoteLockAttribute)
return false;
}
@@ -145,26 +165,32 @@ namespace ShiftOS.Engine {
return true;
}
- public static bool RunClient(string ns, string cmd, Dictionary<string, string> args, bool isRemote = false) {
+ public static bool RunClient(string ns, string cmd, Dictionary<string, string> args, bool isRemote = false)
+ {
return RunClient(ns + "." + cmd, args, isRemote);
}
- public static bool RunClient(string text, Dictionary<string, string> argss, bool isRemote = false) {
+ public static bool RunClient(string text, Dictionary<string, string> argss, bool isRemote = false)
+ {
Dictionary<string, object> args = new Dictionary<string, object>();
- foreach (KeyValuePair<string, string> arg in argss) {
+ foreach (KeyValuePair<string, string> arg in argss)
+ {
args[arg.Key] = arg.Value;
}
return RunClient(text, args, isRemote);
}
- public static bool RunClient(string text, Dictionary<string, object> args, bool isRemote = false) {
+ public static bool RunClient(string text, Dictionary<string, object> args, bool isRemote = false)
+ {
latestCommmand = text;
//Console.WriteLine(text + " " + "{" + string.Join(",", args.Select(kv => kv.Key + "=" + kv.Value).ToArray()) + "}" + " " + isRemote);
- foreach (var asmExec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) {
- try {
+ foreach (var asmExec in System.IO.Directory.GetFiles(Environment.CurrentDirectory))
+ {
+ try
+ {
var asm = Assembly.LoadFile(asmExec);
var types = asm.GetTypes();
@@ -315,7 +341,9 @@ namespace ShiftOS.Engine {
}
}
- } else {
+ }
+ else
+ {
Console.WriteLine(text + " cannot be ran in a remote session");
return true;
}
@@ -360,13 +388,14 @@ namespace ShiftOS.Engine {
}
}
}
- } catch { }
+ }
+ catch { }
}
return false;
}
public static void PrintPrompt()
{
- if (SaveSystem.CurrentSave != null)
+ if (SaveSystem.CurrentSave != null && CurrentUser != null)
{
ConsoleEx.BackgroundColor = SkinEngine.LoadedSkin.TerminalBackColorCC;
ConsoleEx.Italic = false;
@@ -375,7 +404,7 @@ namespace ShiftOS.Engine {
ConsoleEx.ForegroundColor = ConsoleColor.Magenta;
ConsoleEx.Bold = true;
- Console.Write(SaveSystem.CurrentSave.Username);
+ Console.Write(SaveSystem.CurrentUser.Username);
ConsoleEx.Bold = false;
ConsoleEx.ForegroundColor = ConsoleColor.Gray;
Console.Write("@");
@@ -410,26 +439,34 @@ namespace ShiftOS.Engine {
string text3 = "";
string text4 = msg.Contents;
- if (TerminalBackend.PrefixEnabled) {
+ if (TerminalBackend.PrefixEnabled)
+ {
text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length);
}
IsForwardingConsoleWrites = true;
- if (TerminalBackend.InStory == false) {
+ if (TerminalBackend.InStory == false)
+ {
TerminalBackend.InvokeCommand(text3, true);
}
- if (TerminalBackend.PrefixEnabled) {
+ if (TerminalBackend.PrefixEnabled)
+ {
Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ");
}
IsForwardingConsoleWrites = false;
- } else if (msg.Name == "pleasewrite") {
+ }
+ else if (msg.Name == "pleasewrite")
+ {
Console.Write(msg.Contents);
- } else if (msg.Name == "handshake_from") {
+ }
+ else if (msg.Name == "handshake_from")
+ {
var a = JsonConvert.DeserializeObject<Dictionary<string, object>>(msg.Contents);
string uName = a["username"] as string;
string pass = a["password"] as string;
string sys = a["sysname"] as string;
string guid = msg.GUID;
- if (SaveSystem.CurrentSave.Username == uName && SaveSystem.CurrentSave.Password == pass && CurrentSave.SystemName == sys) {
+ if (SaveSystem.CurrentSave.Username == uName && SaveSystem.CurrentSave.Password == pass && CurrentSave.SystemName == sys)
+ {
ForwardGUID = guid;
ServerManager.SendMessage("trm_handshake_accept", $@"{{
guid: ""{ServerManager.thisGuid}"",
@@ -450,5 +487,12 @@ namespace ShiftOS.Engine {
public static bool IsForwardingConsoleWrites { get; internal set; }
public static string ForwardGUID { get; internal set; }
+ public static event TextSentEventHandler TextSent;
+
+ public static void SendText(string text)
+ {
+ TextSent?.Invoke(text);
+ }
+
}
}
diff --git a/ShiftOS_TheReturn/UniteClient.cs b/ShiftOS_TheReturn/UniteClient.cs
new file mode 100644
index 0000000..88e44af
--- /dev/null
+++ b/ShiftOS_TheReturn/UniteClient.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShiftOS.Unite
+{
+ public class UniteClient
+ {
+ public string Token { get; private set; }
+ public string BaseURL { get; private set; }
+
+ public UniteClient(string baseurl, string usertoken)
+ {
+ BaseURL = baseurl;
+ Token = usertoken;
+ }
+
+ internal string MakeCall(string url)
+ {
+ var webrequest = WebRequest.Create(BaseURL + url);
+ webrequest.Headers.Add("Authentication: Token " + Token);
+ using (var response = webrequest.GetResponse())
+ {
+ using (var stream = response.GetResponseStream())
+ {
+ using (var reader = new System.IO.StreamReader(stream))
+ {
+ return reader.ReadToEnd();
+ }
+ }
+ }
+ }
+
+ public string GetEmail()
+ {
+ return MakeCall("/API/GetEmail");
+ }
+
+ public string GetSysName()
+ {
+ return MakeCall("/API/GetSysName");
+ }
+
+ public void SetSysName(string value)
+ {
+ MakeCall("/API/SetSysName/" + value);
+ }
+
+ public string GetDisplayName()
+ {
+ return MakeCall("/API/GetDisplayName");
+ }
+
+ public void SetDisplayName(string value)
+ {
+ MakeCall("/API/SetDisplayName/" + value.ToString());
+ }
+
+ public string GetFullName()
+ {
+ return MakeCall("/API/GetFullName");
+ }
+
+ public void SetFullName(string value)
+ {
+ MakeCall("/API/SetFullName/" + value.ToString());
+ }
+
+
+ public long GetCodepoints()
+ {
+ return Convert.ToInt64(MakeCall("/API/GetCodepoints"));
+ }
+
+ public void SetCodepoints(long value)
+ {
+ MakeCall("/API/SetCodepoints/" + value.ToString());
+ }
+ }
+}
diff --git a/ShiftOS_TheReturn/UniteTestCommands.cs b/ShiftOS_TheReturn/UniteTestCommands.cs
new file mode 100644
index 0000000..37ab1ee
--- /dev/null
+++ b/ShiftOS_TheReturn/UniteTestCommands.cs
@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShiftOS.Engine
+{
+ [Namespace("unite")]
+ public static class UniteTestCommands
+ {
+ [Command("login")]
+ [RequiresArgument("username")]
+ [RequiresArgument("password")]
+ public static bool LoginTest(Dictionary<string, object> args)
+ {
+ string u = args["username"].ToString();
+ string p = args["password"].ToString();
+ var webrequest = HttpWebRequest.Create("http://getshiftos.ml/Auth/Login?appname=ShiftOS&appdesc=ShiftOS+client&version=1_0_beta_2_4");
+ string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{u}:{p}"));
+ webrequest.Headers.Add("Authentication: Basic " + base64);
+ var response = webrequest.GetResponse();
+ var str = response.GetResponseStream();
+ var reader = new System.IO.StreamReader(str);
+ string result = reader.ReadToEnd();
+ Console.WriteLine("Server returned: " + result);
+ reader.Close();
+ str.Close();
+ str.Dispose();
+ response.Dispose();
+
+ return true;
+ }
+
+ [Command("linklogin")]
+ [RequiresArgument("username")]
+ [RequiresArgument("password")]
+ public static bool LinkLogin(Dictionary<string, object> args)
+ {
+ string u = args["username"].ToString();
+ string p = args["password"].ToString();
+ var webrequest = HttpWebRequest.Create("http://getshiftos.ml/Auth/Login?appname=ShiftOS&appdesc=ShiftOS+client&version=1_0_beta_2_4");
+ string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{u}:{p}"));
+ webrequest.Headers.Add("Authentication: Basic " + base64);
+ var response = webrequest.GetResponse();
+ var str = response.GetResponseStream();
+ var reader = new System.IO.StreamReader(str);
+ string result = reader.ReadToEnd();
+ //If we get this far, the token is OURS. :D
+ SaveSystem.CurrentSave.UniteAuthToken = result;
+ Console.WriteLine("Unite says \"Access Granted!\"");
+ SaveSystem.SaveGame();
+ reader.Close();
+ str.Close();
+ str.Dispose();
+ response.Dispose();
+
+ return true;
+ }
+
+
+ }
+}