aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS_TheReturn')
-rw-r--r--ShiftOS_TheReturn/Command.cs6
-rw-r--r--ShiftOS_TheReturn/Commands.cs28
-rw-r--r--ShiftOS_TheReturn/KernelWatchdog.cs70
-rw-r--r--ShiftOS_TheReturn/SaveSystem.cs4
-rw-r--r--ShiftOS_TheReturn/ServerManager.cs7
-rw-r--r--ShiftOS_TheReturn/ShiftOS.Engine.csproj1
-rw-r--r--ShiftOS_TheReturn/Shiftorium.cs7
-rw-r--r--ShiftOS_TheReturn/TerminalBackend.cs156
8 files changed, 202 insertions, 77 deletions
diff --git a/ShiftOS_TheReturn/Command.cs b/ShiftOS_TheReturn/Command.cs
index 85da6ca..a5924ed 100644
--- a/ShiftOS_TheReturn/Command.cs
+++ b/ShiftOS_TheReturn/Command.cs
@@ -30,6 +30,12 @@ using System.Threading.Tasks;
namespace ShiftOS.Engine
{
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)]
+ public class KernelModeAttribute : Attribute
+ {
+
+ }
+
public class Command : Attribute
{
public string name;
diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs
index 76aa42f..0ea00e5 100644
--- a/ShiftOS_TheReturn/Commands.cs
+++ b/ShiftOS_TheReturn/Commands.cs
@@ -164,7 +164,35 @@ namespace ShiftOS.Engine
}
}
+ [Command("reconnect")]
+ [RequiresUpgrade("hacker101_deadaccts")]
+ public static bool Reconnect()
+ {
+ Console.WriteLine("--reconnecting to multi-user domain...");
+ KernelWatchdog.MudConnected = true;
+ Console.WriteLine("--done.");
+ return true;
+ }
+
+ [Command("disconnect")]
+ [RequiresUpgrade("hacker101_deadaccts")]
+ public static bool Disconnect()
+ {
+ Console.WriteLine("--connection to multi-user domain severed...");
+ KernelWatchdog.MudConnected = false;
+ return true;
+ }
+ [Command("sendmsg")]
+ [KernelMode]
+ [RequiresUpgrade("hacker101_deadaccts")]
+ [RequiresArgument("header")]
+ [RequiresArgument("body")]
+ public static bool SendMessage(Dictionary<string, object> args)
+ {
+ ServerManager.SendMessage(args["header"].ToString(), args["body"].ToString());
+ return true;
+ }
}
[RequiresUpgrade("mud_fundamentals")]
diff --git a/ShiftOS_TheReturn/KernelWatchdog.cs b/ShiftOS_TheReturn/KernelWatchdog.cs
new file mode 100644
index 0000000..1b59b25
--- /dev/null
+++ b/ShiftOS_TheReturn/KernelWatchdog.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using static ShiftOS.Objects.ShiftFS.Utils;
+
+namespace ShiftOS.Engine
+{
+ public static class KernelWatchdog
+ {
+ public static void Log(string e, string desc)
+ {
+ string line = $"[{DateTime.Now}] <{e}> {desc}";
+ if (FileExists("0:/system/data/kernel.log"))
+ {
+ string contents = ReadAllText("0:/system/data/kernel.log");
+ contents += Environment.NewLine + line;
+ WriteAllText("0:/system/data/kernel.log", contents);
+ }
+ else
+ {
+ WriteAllText("0:/system/data/kernel.log", line);
+ }
+ }
+
+ public static bool InKernelMode { get; private set; }
+ public static bool MudConnected { get; set; }
+
+ public static bool IsSafe(Type type)
+ {
+ if (InKernelMode == true)
+ return true;
+
+ foreach (var attrib in type.GetCustomAttributes(false))
+ {
+ if (attrib is KernelModeAttribute)
+ return false;
+ }
+ return true;
+ }
+
+ public static bool IsSafe(MethodInfo type)
+ {
+ if (InKernelMode == true)
+ return true;
+
+ foreach (var attrib in type.GetCustomAttributes(false))
+ {
+ if (attrib is KernelModeAttribute)
+ return false;
+ }
+ return true;
+ }
+
+
+ public static void EnterKernelMode()
+ {
+ InKernelMode = true;
+ Console.WriteLine("<kernel> Watchdog deactivated, system-level access granted.");
+ }
+
+ public static void LeaveKernelMode()
+ {
+ InKernelMode = false;
+ Console.WriteLine("<kernel> Kernel mode disabled.");
+ }
+ }
+}
diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs
index b9633e5..df4c6d6 100644
--- a/ShiftOS_TheReturn/SaveSystem.cs
+++ b/ShiftOS_TheReturn/SaveSystem.cs
@@ -155,6 +155,8 @@ namespace ShiftOS.Engine
public static void FinishBootstrap()
{
+ KernelWatchdog.Log("mud_handshake", "handshake successful: kernel watchdog access code is \"" + ServerManager.thisGuid.ToString() + "\"");
+
ServerManager.MessageReceived += (msg) =>
{
if (msg.Name == "mud_savefile")
@@ -313,7 +315,7 @@ namespace ShiftOS.Engine
System.IO.File.WriteAllText(Paths.SaveFile, Utils.ExportMount(0));
}
- public static void TransferCodepointsFrom(string who, int amount)
+ public static void TransferCodepointsFrom(string who, long amount)
{
NotificationDaemon.AddNotification(NotificationType.CodepointsReceived, amount);
CurrentSave.Codepoints += amount;
diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs
index 3059391..a121ab6 100644
--- a/ShiftOS_TheReturn/ServerManager.cs
+++ b/ShiftOS_TheReturn/ServerManager.cs
@@ -126,6 +126,13 @@ namespace ShiftOS.Engine
thisGuid = new Guid(msg.Contents);
GUIDReceived?.Invoke(msg.Contents);
}
+ else if(msg.Name == "allusers")
+ {
+ foreach(var acc in JsonConvert.DeserializeObject<string[]>(msg.Contents))
+ {
+ Console.WriteLine(acc);
+ }
+ }
else if(msg.Name == "update_your_cp")
{
var args = JsonConvert.DeserializeObject<Dictionary<string, object>>(msg.Contents);
diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj
index 3702b18..20ca879 100644
--- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj
+++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj
@@ -107,6 +107,7 @@
<Compile Include="FileSkimmerBackend.cs" />
<Compile Include="Infobox.cs" />
<Compile Include="IShiftOSWindow.cs" />
+ <Compile Include="KernelWatchdog.cs" />
<Compile Include="Localization.cs" />
<Compile Include="NotificationDaemon.cs" />
<Compile Include="OutOfBoxExperience.cs" />
diff --git a/ShiftOS_TheReturn/Shiftorium.cs b/ShiftOS_TheReturn/Shiftorium.cs
index 198dcc7..0bdd9f4 100644
--- a/ShiftOS_TheReturn/Shiftorium.cs
+++ b/ShiftOS_TheReturn/Shiftorium.cs
@@ -210,9 +210,12 @@ namespace ShiftOS.Engine
if (SaveSystem.CurrentSave.StoriesExperienced == null)
SaveSystem.CurrentSave.StoriesExperienced = new List<string>();
- if (!SaveSystem.CurrentSave.StoriesExperienced.Contains(id))
- return SaveSystem.CurrentSave.Upgrades[id];
+ bool upgInstalled = false;
+ if(SaveSystem.CurrentSave.Upgrades.ContainsKey(id))
+ upgInstalled = SaveSystem.CurrentSave.Upgrades[id];
+ if(upgInstalled == false)
+ return SaveSystem.CurrentSave.StoriesExperienced.Contains(id);
return true;
}
catch
diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs
index 3c8e62a..8be54d0 100644
--- a/ShiftOS_TheReturn/TerminalBackend.cs
+++ b/ShiftOS_TheReturn/TerminalBackend.cs
@@ -139,121 +139,129 @@ namespace ShiftOS.Engine
{
if (Shiftorium.UpgradeAttributesUnlocked(type))
{
- foreach (var a in type.GetCustomAttributes(false))
+ if (KernelWatchdog.IsSafe(type))
{
- if (a is Namespace)
+ foreach (var a in type.GetCustomAttributes(false))
{
- var ns = a as Namespace;
- if (text.Split('.')[0] == ns.name)
+ if (a is Namespace)
{
- foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
+ var ns = a as Namespace;
+ if (text.Split('.')[0] == ns.name)
{
- if (Shiftorium.UpgradeAttributesUnlocked(method))
+ foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
{
- if (CanRunRemotely(method, isRemote))
+ if (Shiftorium.UpgradeAttributesUnlocked(method))
{
- foreach (var ma in method.GetCustomAttributes(false))
+ if (KernelWatchdog.IsSafe(method))
{
- if (ma is Command)
+ if (CanRunRemotely(method, isRemote))
{
- var cmd = ma as Command;
- if (text.Split('.')[1] == cmd.name)
+ foreach (var ma in method.GetCustomAttributes(false))
{
-
- var attr = method.GetCustomAttribute<CommandObsolete>();
-
- if (attr != null)
+ if (ma is Command)
{
- string newcommand = attr.newcommand;
- if (attr.warn)
+ var cmd = ma as Command;
+ if (text.Split('.')[1] == cmd.name)
{
- Console.WriteLine(Localization.Parse((newcommand == "" ? "{ERROR}" : "{WARN}") + attr.reason, new Dictionary<string, string>() {
+
+ var attr = method.GetCustomAttribute<CommandObsolete>();
+
+ if (attr != null)
+ {
+ string newcommand = attr.newcommand;
+ if (attr.warn)
+ {
+ Console.WriteLine(Localization.Parse((newcommand == "" ? "{ERROR}" : "{WARN}") + attr.reason, new Dictionary<string, string>() {
{"%newcommand", newcommand}
}));
- }
- if (newcommand != "")
- {
- // redo the entire process running newcommand
-
- return RunClient(newcommand, args);
- }
- }
+ }
+ if (newcommand != "")
+ {
+ // redo the entire process running newcommand
- var requiresArgs = method.GetCustomAttributes<RequiresArgument>();
+ return RunClient(newcommand, args);
+ }
+ }
- bool error = false;
- bool providedusage = false;
+ var requiresArgs = method.GetCustomAttributes<RequiresArgument>();
- foreach (RequiresArgument argument in requiresArgs)
- {
- if (!args.ContainsKey(argument.argument))
- {
+ bool error = false;
+ bool providedusage = false;
- if (!providedusage)
+ foreach (RequiresArgument argument in requiresArgs)
{
- string usageparse = "{COMMAND_" + ns.name.ToUpper() + "_" + cmd.name.ToUpper() + "_USAGE}";
- if (usageparse == Localization.Parse(usageparse))
- usageparse = "";
- else
- usageparse = Shiftorium.UpgradeInstalled("help_usage") ? Localization.Parse("{ERROR}{USAGE}" + usageparse, new Dictionary<string, string>() {
+ if (!args.ContainsKey(argument.argument))
+ {
+
+ if (!providedusage)
+ {
+ string usageparse = "{COMMAND_" + ns.name.ToUpper() + "_" + cmd.name.ToUpper() + "_USAGE}";
+ if (usageparse == Localization.Parse(usageparse))
+ usageparse = "";
+ else
+ usageparse = Shiftorium.UpgradeInstalled("help_usage") ? Localization.Parse("{ERROR}{USAGE}" + usageparse, new Dictionary<string, string>() {
{"%ns", ns.name},
{"%cmd", cmd.name}
}) : "";
- Console.WriteLine(usageparse);
+ Console.WriteLine(usageparse);
- providedusage = true;
- }
+ providedusage = true;
+ }
- if (Shiftorium.UpgradeInstalled("help_usage"))
- {
- Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED}", new Dictionary<string, string>() {
+ if (Shiftorium.UpgradeInstalled("help_usage"))
+ {
+ Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED}", new Dictionary<string, string>() {
{"%argument", argument.argument}
}));
+ }
+ else
+ {
+ Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED_NO_USAGE}"));
+ }
+
+ error = true;
+ }
}
- else
+
+ if (error)
{
- Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED_NO_USAGE}"));
+ throw new Exception("{ERROR_COMMAND_WRONG}");
}
- error = true;
+ try
+ {
+ return (bool)method.Invoke(null, new[] { args });
+ }
+ catch (TargetInvocationException e)
+ {
+ Console.WriteLine(Localization.Parse("{ERROR_EXCEPTION_THROWN_IN_METHOD}"));
+ Console.WriteLine(e.InnerException.Message);
+ Console.WriteLine(e.InnerException.StackTrace);
+ return true;
+ }
+ catch
+ {
+ return (bool)method.Invoke(null, new object[] { });
+ }
}
}
-
- if (error)
- {
- throw new Exception("{ERROR_COMMAND_WRONG}");
- }
-
- try
- {
- return (bool)method.Invoke(null, new[] { args });
- }
- catch (TargetInvocationException e)
- {
- Console.WriteLine(Localization.Parse("{ERROR_EXCEPTION_THROWN_IN_METHOD}"));
- Console.WriteLine(e.InnerException.Message);
- Console.WriteLine(e.InnerException.StackTrace);
- return true;
- }
- catch
- {
- return (bool)method.Invoke(null, new object[] { });
- }
}
}
+ else
+ {
+ Console.WriteLine(text + " cannot be ran in a remote session");
+ return true;
+ }
}
- }
- else
- {
- Console.WriteLine(text + " cannot be ran in a remote session");
- return true;
+
}
}
}
}
}
}
+
}
}
}