diff options
| author | Michael <[email protected]> | 2017-03-11 09:04:45 -0500 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-03-11 09:04:45 -0500 |
| commit | 49812bf46cb153af6bab8e2a095024da84fcc149 (patch) | |
| tree | 2f357da244276f2576089f03d65a00d8acc65c72 | |
| parent | b9c3a0e30f6a939b1e1e3142cb507dfe7993b683 (diff) | |
| download | shiftos_thereturn-49812bf46cb153af6bab8e2a095024da84fcc149.tar.gz shiftos_thereturn-49812bf46cb153af6bab8e2a095024da84fcc149.tar.bz2 shiftos_thereturn-49812bf46cb153af6bab8e2a095024da84fcc149.zip | |
Lock down various commands while offline.
| -rw-r--r-- | ShiftOS.WinForms/HackerCommands.cs | 6 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/Commands.cs | 50 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/KernelWatchdog.cs | 26 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/TerminalBackend.cs | 205 |
4 files changed, 168 insertions, 119 deletions
diff --git a/ShiftOS.WinForms/HackerCommands.cs b/ShiftOS.WinForms/HackerCommands.cs index 59d0f4e..f9d3bcc 100644 --- a/ShiftOS.WinForms/HackerCommands.cs +++ b/ShiftOS.WinForms/HackerCommands.cs @@ -351,6 +351,7 @@ namespace ShiftOS.WinForms const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-_"; + [MultiplayerOnly] [Command("breach_user_password")] [KernelMode] [RequiresArgument("user")] @@ -413,6 +414,8 @@ namespace ShiftOS.WinForms return true; } + + [MultiplayerOnly] [Command("print_user_info")] [KernelMode] [RequiresArgument("pass")] @@ -475,6 +478,7 @@ namespace ShiftOS.WinForms return true; } + [MultiplayerOnly] [Command("steal_codepoints")] [KernelMode] [RequiresArgument("amount")] @@ -551,6 +555,7 @@ namespace ShiftOS.WinForms return true; } + [MultiplayerOnly] [Command("purge_user")] [KernelMode] [RequiresArgument("pass")] @@ -646,6 +651,7 @@ namespace ShiftOS.WinForms } } + [MultiplayerOnly] [Namespace("storydev")] public static class StoryDevCommands { diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index 0ea00e5..12c371f 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -133,6 +133,7 @@ namespace ShiftOS.Engine [Namespace("mud")] public static class MUDCommands { + [MultiplayerOnly] [Command("status")] public static bool Status() { @@ -174,6 +175,7 @@ namespace ShiftOS.Engine return true; } + [MultiplayerOnly] [Command("disconnect")] [RequiresUpgrade("hacker101_deadaccts")] public static bool Disconnect() @@ -183,6 +185,7 @@ namespace ShiftOS.Engine return true; } + [MultiplayerOnly] [Command("sendmsg")] [KernelMode] [RequiresUpgrade("hacker101_deadaccts")] @@ -195,48 +198,6 @@ namespace ShiftOS.Engine } } - [RequiresUpgrade("mud_fundamentals")] - [Namespace("chat")] - public static class ChatCommands - { - [RequiresArgument("id")] - [RequiresArgument("name")] - [RequiresArgument("topic")] - [Command("create")] - public static bool CreateChat(Dictionary<string, object> args) - { - string id = ""; - string topic = ""; - string name = ""; - int max_users = 0; - - id = args["id"] as string; - name = args["topic"] as string; - topic = args["name"] as string; - - bool valid = true; - - if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(topic)) - valid = false; - - if (valid) - { - ServerManager.SendMessage("chat_create", $@"{{ - id: ""{id}"", - name: ""{name}"", - topic: ""{topic}"", - max_users: {max_users} -}}"); - } - else - { - Console.WriteLine("{CHAT_PLEASE_PROVIDE_VALID_CHANNEL_DATA}"); - } - return true; - } - - } - [TutorialLock] [Namespace("trm")] public static class TerminalCommands @@ -266,6 +227,7 @@ namespace ShiftOS.Engine } } + [MultiplayerOnly] [Namespace("dev")] public static class ShiftOSDevCommands { @@ -474,6 +436,7 @@ namespace ShiftOS.Engine return true; } + [MultiplayerOnly] [Command("save")] public static bool Save() { @@ -481,6 +444,7 @@ namespace ShiftOS.Engine return true; } + [MultiplayerOnly] [Command("status")] public static bool Status() { @@ -493,7 +457,7 @@ Upgrades: {SaveSystem.CurrentSave.CountUpgrades()} installed, } } - + [MultiplayerOnly] [Namespace("shiftorium")] public static class ShiftoriumCommands { diff --git a/ShiftOS_TheReturn/KernelWatchdog.cs b/ShiftOS_TheReturn/KernelWatchdog.cs index e69c9ba..cc03f5a 100644 --- a/ShiftOS_TheReturn/KernelWatchdog.cs +++ b/ShiftOS_TheReturn/KernelWatchdog.cs @@ -102,5 +102,31 @@ namespace ShiftOS.Engine InKernelMode = false; Console.WriteLine("<kernel> Kernel mode disabled."); } + + internal static bool CanRunOffline(Type method) + { + if (MudConnected) + return true; + + foreach (var attr in method.GetCustomAttributes(false)) + { + if (attr is MultiplayerOnlyAttribute) + return false; + } + return true; + } + + internal static bool CanRunOffline(MethodInfo method) + { + if (MudConnected) + return true; + + foreach(var attr in method.GetCustomAttributes(false)) + { + if (attr is MultiplayerOnlyAttribute) + return false; + } + return true; + } } } diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index 5022cd1..c7852f1 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -148,128 +148,181 @@ namespace ShiftOS.Engine { if (KernelWatchdog.IsSafe(type)) { - foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) + if (KernelWatchdog.CanRunOffline(type)) { - 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 (CanRunRemotely(method, isRemote)) { - if (ma is Command) + foreach (var ma in method.GetCustomAttributes(false)) { - var cmd = ma as Command; - if (text.Split('.')[1] == cmd.name) + if (ma is Command) { - if (KernelWatchdog.IsSafe(method)) + var cmd = ma as Command; + if (text.Split('.')[1] == cmd.name) { - - var attr = method.GetCustomAttribute<CommandObsolete>(); - - if (attr != null) + if (KernelWatchdog.IsSafe(method)) { - string newcommand = attr.newcommand; - if (attr.warn) + if (KernelWatchdog.CanRunOffline(method)) { - 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 + } + if (newcommand != "") + { + // redo the entire process running newcommand - return RunClient(newcommand, args); - } - } - - 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}"); - } + else + { + Console.Write("<"); + ConsoleEx.Bold = true; + ConsoleEx.ForegroundColor = ConsoleColor.DarkRed; + Console.Write("session_mgr"); + ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC; + ConsoleEx.Bold = false; + Console.Write(">"); + ConsoleEx.Italic = true; + ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; + Console.WriteLine(" You cannot run this command while disconnected from the multi-user domain.."); + return true; - try - { - return (bool)method.Invoke(null, new[] { args }); + } } - catch (TargetInvocationException e) + else { - Console.WriteLine(Localization.Parse("{ERROR_EXCEPTION_THROWN_IN_METHOD}")); - Console.WriteLine(e.InnerException.Message); - Console.WriteLine(e.InnerException.StackTrace); + Console.Write("<"); + ConsoleEx.Bold = true; + ConsoleEx.ForegroundColor = ConsoleColor.DarkRed; + Console.Write("watchdog"); + ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC; + ConsoleEx.Bold = false; + Console.Write(">"); + ConsoleEx.Italic = true; + ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; + Console.WriteLine(" You cannot run this command."); + KernelWatchdog.Log("potential_sys_breach", "user attempted to run kernel mode command " + text + " - watchdog has prevented this, good sir."); return true; } - catch - { - return (bool)method.Invoke(null, new object[] { }); - } } - else - { - Console.WriteLine("<watchdog> You cannot run this command."); - KernelWatchdog.Log("potential_sys_breach", "user attempted to run kernel mode command " + text + " - watchdog has prevented this, good sir."); - return true; - } - } + } } } + 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; - } - } + } } + else + { + Console.Write("<"); + ConsoleEx.Bold = true; + ConsoleEx.ForegroundColor = ConsoleColor.DarkRed; + Console.Write("session_mgr"); + ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC; + ConsoleEx.Bold = false; + Console.Write(">"); + ConsoleEx.Italic = true; + ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; + Console.WriteLine(" You cannot run this command while disconnected from the multi-user domain.."); + return true; + } } else { - Console.WriteLine("<watchdog> You cannot run this command."); + + Console.Write("<"); + ConsoleEx.Bold = true; + ConsoleEx.ForegroundColor = ConsoleColor.DarkRed; + Console.Write("watchdog"); + ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC; + ConsoleEx.Bold = false; + Console.Write(">"); + ConsoleEx.Italic = true; + ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; + Console.WriteLine(" You cannot run this command."); KernelWatchdog.Log("potential_sys_breach", "user attempted to run kernel mode command " + text + " - watchdog has prevented this, good sir."); return true; } |
