From abe535200bb348af6288b7cc7d3405b2fea8ffa6 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 8 Mar 2017 19:38:18 -0500 Subject: Kernel watchdog watches you more... :notjustabluesmileyface: --- ShiftOS_TheReturn/TerminalBackend.cs | 50 +++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 18 deletions(-) (limited to 'ShiftOS_TheReturn/TerminalBackend.cs') diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index 8be54d0..f78d7a5 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -139,29 +139,29 @@ namespace ShiftOS.Engine { if (Shiftorium.UpgradeAttributesUnlocked(type)) { - if (KernelWatchdog.IsSafe(type)) + foreach (var a in type.GetCustomAttributes(false)) { - foreach (var a in type.GetCustomAttributes(false)) + if (a is Namespace) { - if (a is Namespace) + var ns = a as Namespace; + if (text.Split('.')[0] == ns.name) { - var ns = a as Namespace; - if (text.Split('.')[0] == ns.name) + if (KernelWatchdog.IsSafe(type)) { foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) { if (Shiftorium.UpgradeAttributesUnlocked(method)) { - if (KernelWatchdog.IsSafe(method)) + if (CanRunRemotely(method, isRemote)) { - if (CanRunRemotely(method, isRemote)) + foreach (var ma in method.GetCustomAttributes(false)) { - foreach (var ma in method.GetCustomAttributes(false)) + if (ma is Command) { - if (ma is Command) + var cmd = ma as Command; + if (text.Split('.')[1] == cmd.name) { - var cmd = ma as Command; - if (text.Split('.')[1] == cmd.name) + if (KernelWatchdog.IsSafe(method)) { var attr = method.GetCustomAttribute(); @@ -245,23 +245,37 @@ namespace ShiftOS.Engine return (bool)method.Invoke(null, new object[] { }); } } + else + { + 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; + } } + + } } - 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.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; } } } } - } } } -- cgit v1.2.3 From 251521835b60024dec292a759d738e2b81bf1417 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 9 Mar 2017 16:46:34 -0500 Subject: Console colors! --- ShiftOS.WinForms/Applications/Terminal.cs | 4 ++-- ShiftOS.WinForms/Controls/TerminalBox.cs | 16 +++++++++++++++ ShiftOS_TheReturn/ServerManager.cs | 11 +++++++--- ShiftOS_TheReturn/TerminalBackend.cs | 34 ++++++++++++++++++++++++++++++- 4 files changed, 59 insertions(+), 6 deletions(-) (limited to 'ShiftOS_TheReturn/TerminalBackend.cs') diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 7bab213..65a8f0f 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -134,7 +134,7 @@ namespace ShiftOS.WinForms.Applications rtbterm.Text = ""; TerminalBackend.PrefixEnabled = true; TerminalBackend.InStory = false; - Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); + TerminalBackend.PrintPrompt(); if (Shiftorium.UpgradeInstalled("wm_free_placement")) { this.ParentForm.Width = 640; @@ -276,7 +276,7 @@ namespace ShiftOS.WinForms.Applications } if (TerminalBackend.PrefixEnabled) { - Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); + TerminalBackend.PrintPrompt(); } } } diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index 7c0da57..9e4c61c 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -24,6 +24,7 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; using System.Threading; @@ -56,16 +57,31 @@ namespace ShiftOS.WinForms.Controls { this.HideSelection = true; this.Select(this.TextLength, 0); + this.SelectionFont = ConstructFont(); this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor); this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor); this.AppendText(Localization.Parse(text)); this.HideSelection = false; } + private Font ConstructFont() + { + FontStyle fs = FontStyle.Regular; + if (ConsoleEx.Bold) + fs = fs | FontStyle.Bold; + if (ConsoleEx.Italic) + fs = fs | FontStyle.Italic; + if (ConsoleEx.Underline) + fs = fs | FontStyle.Underline; + + return new Font(this.Font, fs); + } + public void WriteLine(string text) { this.HideSelection = true; this.Select(this.TextLength, 0); + this.SelectionFont = ConstructFont(); this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor); this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor); this.AppendText(Localization.Parse(text) + Environment.NewLine); diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index 7da09f1..4d599cd 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -132,6 +132,7 @@ namespace ShiftOS.Engine { Console.WriteLine(acc); } + TerminalBackend.PrintPrompt(); } else if(msg.Name == "update_your_cp") { @@ -154,11 +155,15 @@ namespace ShiftOS.Engine { var ex = JsonConvert.DeserializeObject(msg.Contents); TerminalBackend.PrefixEnabled = true; + ConsoleEx.ForegroundColor = ConsoleColor.Red; + ConsoleEx.Bold = true; + Console.Write($@"{{MUD_ERROR}}: "); + ConsoleEx.Bold = false; + ConsoleEx.Italic = true; ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; - Console.WriteLine($@"{{MUD_ERROR}}: {ex.Message}"); - ConsoleEx.ForegroundColor = ConsoleColor.White; + Console.WriteLine(ex.Message); TerminalBackend.PrefixEnabled = true; - Console.Write($"{SaveSystem.CurrentSave.Username}@{CurrentSave.SystemName}:~$ "); + TerminalBackend.PrintPrompt(); } else { diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index f78d7a5..841fd6a 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -283,7 +283,39 @@ namespace ShiftOS.Engine } return false; } - + + public static void PrintPrompt() + { + ConsoleEx.Italic = false; + ConsoleEx.Underline = false; + + ConsoleEx.ForegroundColor = ConsoleColor.Magenta; + ConsoleEx.Bold = true; + Console.Write(SaveSystem.CurrentSave.Username); + ConsoleEx.Bold = false; + ConsoleEx.ForegroundColor = ConsoleColor.Gray; + Console.Write("@"); + ConsoleEx.Italic = true; + ConsoleEx.Bold = true; + ConsoleEx.ForegroundColor = ConsoleColor.Yellow; + Console.Write(SaveSystem.CurrentSave.SystemName); + ConsoleEx.Italic = false; + ConsoleEx.Bold = false; + ConsoleEx.ForegroundColor = ConsoleColor.Gray; + Console.Write(":~"); + Console.ForegroundColor = ConsoleColor.White; + ConsoleEx.Italic = true; + if (KernelWatchdog.InKernelMode == true) + Console.Write("#"); + else + Console.Write("$"); + ConsoleEx.Italic = false; + ConsoleEx.Bold = false; + ConsoleEx.ForegroundColor = ConsoleColor.White; + Console.Write(" "); + } + + static TerminalBackend() { ServerMessageReceived onMessageReceived = (msg) => -- cgit v1.2.3 From a9b08eb21676a6c59b0c8bb6046b40bd42e078d5 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 9 Mar 2017 18:15:29 -0500 Subject: FULLY COMPLETE TERMINAL COLORS --- ShiftOS.WinForms/Applications/Shifter.cs | 24 ++++++++++++++++++++++++ ShiftOS.WinForms/Applications/Shiftnet.cs | 7 +++++-- ShiftOS.WinForms/Applications/Terminal.cs | 12 ++++++------ ShiftOS_TheReturn/Skinning.cs | 4 ++-- ShiftOS_TheReturn/TerminalBackend.cs | 3 ++- 5 files changed, 39 insertions(+), 11 deletions(-) (limited to 'ShiftOS_TheReturn/TerminalBackend.cs') diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs index 4d29cf8..1adc75a 100644 --- a/ShiftOS.WinForms/Applications/Shifter.cs +++ b/ShiftOS.WinForms/Applications/Shifter.cs @@ -446,6 +446,30 @@ namespace ShiftOS.WinForms.Applications flbody.Controls.Add(color); color.Show(); } + else if(c.Field.FieldType.IsEnum == true) + { + var cBox = new ComboBox(); + cBox.Width = 150; + ControlManager.SetupControl(cBox); + + foreach(var itm in Enum.GetNames(c.Field.FieldType)) + { + cBox.Items.Add(itm); + } + + cBox.Text = c.Field.GetValue(LoadedSkin).ToString(); + + cBox.SelectedIndexChanged += (o, a) => + { + c.Field.SetValue(LoadedSkin, Enum.Parse(c.Field.FieldType, cBox.Text)); + }; + + labelHeight = cBox.Height; + + flbody.Controls.Add(cBox); + cBox.Show(); + flbody.SetFlowBreak(cBox, true); + } else if(c.Field.FieldType == typeof(int)) { if (c.Field.HasShifterEnumMask()) diff --git a/ShiftOS.WinForms/Applications/Shiftnet.cs b/ShiftOS.WinForms/Applications/Shiftnet.cs index 9540794..45f37d4 100644 --- a/ShiftOS.WinForms/Applications/Shiftnet.cs +++ b/ShiftOS.WinForms/Applications/Shiftnet.cs @@ -34,6 +34,7 @@ using System.Windows.Forms; using ShiftOS.Engine; using Newtonsoft.Json; using static ShiftOS.Engine.SkinEngine; +using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { [Launcher("Shiftnet", false, null, "Networking")] @@ -62,6 +63,8 @@ namespace ShiftOS.WinForms.Applications { } public string ConstructHtml(string markdown) { + var TerminalForeColor = ControlManager.ConvertColor(SkinEngine.LoadedSkin.TerminalForeColorCC); + var TerminalBackColor = ControlManager.ConvertColor(SkinEngine.LoadedSkin.TerminalBackColorCC); string html = $@" diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 65a8f0f..06a6e8d 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -43,6 +43,7 @@ using System.Collections; using static ShiftOS.Engine.SkinEngine; using ShiftOS.Engine; using ShiftOS.Objects; +using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { @@ -350,8 +351,8 @@ namespace ShiftOS.WinForms.Applications txt.Focus(); txt.Font = LoadedSkin.TerminalFont; - txt.ForeColor = LoadedSkin.TerminalForeColor; - txt.BackColor = LoadedSkin.TerminalBackColor; + txt.ForeColor = ControlManager.ConvertColor(LoadedSkin.TerminalForeColorCC); + txt.BackColor = ControlManager.ConvertColor(LoadedSkin.TerminalBackColorCC); } @@ -391,8 +392,7 @@ namespace ShiftOS.WinForms.Applications rtbterm.Text = AppearanceManager.LastTerminalText; rtbterm.Select(rtbterm.TextLength, 0); } - Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); - + TerminalBackend.PrintPrompt(); } @@ -403,8 +403,8 @@ namespace ShiftOS.WinForms.Applications try { rtbterm.Font = LoadedSkin.TerminalFont; - rtbterm.ForeColor = LoadedSkin.TerminalForeColor; - rtbterm.BackColor = LoadedSkin.TerminalBackColor; + rtbterm.ForeColor = ControlManager.ConvertColor(LoadedSkin.TerminalForeColorCC); + rtbterm.BackColor = ControlManager.ConvertColor(LoadedSkin.TerminalBackColorCC); } catch { diff --git a/ShiftOS_TheReturn/Skinning.cs b/ShiftOS_TheReturn/Skinning.cs index 43e0b5d..800b107 100644 --- a/ShiftOS_TheReturn/Skinning.cs +++ b/ShiftOS_TheReturn/Skinning.cs @@ -865,12 +865,12 @@ namespace ShiftOS.Engine { [ShifterMeta("System")] [ShifterCategory("General")] [ShifterName("Terminal text color")] - public Color TerminalForeColor = DefaultForeground; + public ConsoleColor TerminalForeColorCC = ConsoleColor.White; [ShifterMeta("System")] [ShifterCategory("General")] [ShifterName("Terminal background color")] - public Color TerminalBackColor = DesktopBG; + public ConsoleColor TerminalBackColorCC = ConsoleColor.Black; [ShifterMeta("Desktop")] [ShifterCategory("Desktop Panel")] diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index 841fd6a..5c08cfe 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -286,6 +286,7 @@ namespace ShiftOS.Engine public static void PrintPrompt() { + ConsoleEx.BackgroundColor = SkinEngine.LoadedSkin.TerminalBackColorCC; ConsoleEx.Italic = false; ConsoleEx.Underline = false; @@ -311,7 +312,7 @@ namespace ShiftOS.Engine Console.Write("$"); ConsoleEx.Italic = false; ConsoleEx.Bold = false; - ConsoleEx.ForegroundColor = ConsoleColor.White; + ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC; Console.Write(" "); } -- cgit v1.2.3 From fa83ec01d2ae3623648cd4b055e5be069b87ec96 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 11 Mar 2017 08:11:27 -0500 Subject: even more uhhhhhhhhh --- ShiftOS_TheReturn.sln | 12 ++++++++++++ ShiftOS_TheReturn/TerminalBackend.cs | 1 + 2 files changed, 13 insertions(+) (limited to 'ShiftOS_TheReturn/TerminalBackend.cs') diff --git a/ShiftOS_TheReturn.sln b/ShiftOS_TheReturn.sln index 7f7acdf..a3eb2a0 100644 --- a/ShiftOS_TheReturn.sln +++ b/ShiftOS_TheReturn.sln @@ -21,6 +21,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModLauncher", "ModLauncher\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShiftOS.Server.WebAdmin", "ShiftOS.Server.WebAdmin\ShiftOS.Server.WebAdmin.csproj", "{B29FDD06-E6FE-40A2-8258-283728CED81A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gwen", "Gwen\Gwen.csproj", "{ADDA2F43-96C0-497F-8216-29C67ABC9806}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gwen.Renderer.OpenTK", "Gwen.Renderer.OpenTK\Gwen.Renderer.OpenTK.csproj", "{41650C82-D630-4E5C-845A-F1513C8FDC99}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -63,6 +67,14 @@ Global {B29FDD06-E6FE-40A2-8258-283728CED81A}.Debug|Any CPU.Build.0 = Debug|Any CPU {B29FDD06-E6FE-40A2-8258-283728CED81A}.Release|Any CPU.ActiveCfg = Release|Any CPU {B29FDD06-E6FE-40A2-8258-283728CED81A}.Release|Any CPU.Build.0 = Release|Any CPU + {ADDA2F43-96C0-497F-8216-29C67ABC9806}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ADDA2F43-96C0-497F-8216-29C67ABC9806}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ADDA2F43-96C0-497F-8216-29C67ABC9806}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ADDA2F43-96C0-497F-8216-29C67ABC9806}.Release|Any CPU.Build.0 = Release|Any CPU + {41650C82-D630-4E5C-845A-F1513C8FDC99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {41650C82-D630-4E5C-845A-F1513C8FDC99}.Debug|Any CPU.Build.0 = Debug|Any CPU + {41650C82-D630-4E5C-845A-F1513C8FDC99}.Release|Any CPU.ActiveCfg = Release|Any CPU + {41650C82-D630-4E5C-845A-F1513C8FDC99}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index 5c08cfe..5022cd1 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -292,6 +292,7 @@ namespace ShiftOS.Engine ConsoleEx.ForegroundColor = ConsoleColor.Magenta; ConsoleEx.Bold = true; + Console.Write(SaveSystem.CurrentSave.Username); ConsoleEx.Bold = false; ConsoleEx.ForegroundColor = ConsoleColor.Gray; -- cgit v1.2.3 From 49812bf46cb153af6bab8e2a095024da84fcc149 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 11 Mar 2017 09:04:45 -0500 Subject: Lock down various commands while offline. --- ShiftOS.WinForms/HackerCommands.cs | 6 + ShiftOS_TheReturn/Commands.cs | 50 ++------- ShiftOS_TheReturn/KernelWatchdog.cs | 26 +++++ ShiftOS_TheReturn/TerminalBackend.cs | 205 ++++++++++++++++++++++------------- 4 files changed, 168 insertions(+), 119 deletions(-) (limited to 'ShiftOS_TheReturn/TerminalBackend.cs') 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 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 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(); - - 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() { + var attr = method.GetCustomAttribute(); + + if (attr != null) + { + string newcommand = attr.newcommand; + if (attr.warn) + { + Console.WriteLine(Localization.Parse((newcommand == "" ? "{ERROR}" : "{WARN}") + attr.reason, new Dictionary() { {"%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(); + return RunClient(newcommand, args); + } + } - bool error = false; - bool providedusage = false; + var requiresArgs = method.GetCustomAttributes(); - 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() { + 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() { {"%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() { + if (Shiftorium.UpgradeInstalled("help_usage")) + { + Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED}", new Dictionary() { {"%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(" 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(" 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; } -- cgit v1.2.3 From 01420ff329ab1819f1be1ea444c46785328b44cb Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 11 Mar 2017 10:28:16 -0500 Subject: fix mud.connect deadlock --- ShiftOS.WinForms/HackerCommands.cs | 3 +- ShiftOS_TheReturn/Commands.cs | 2 ++ ShiftOS_TheReturn/ServerManager.cs | 2 ++ ShiftOS_TheReturn/TerminalBackend.cs | 61 +++++++++++++++++++----------------- 4 files changed, 37 insertions(+), 31 deletions(-) (limited to 'ShiftOS_TheReturn/TerminalBackend.cs') diff --git a/ShiftOS.WinForms/HackerCommands.cs b/ShiftOS.WinForms/HackerCommands.cs index e2c4d12..107343b 100644 --- a/ShiftOS.WinForms/HackerCommands.cs +++ b/ShiftOS.WinForms/HackerCommands.cs @@ -158,8 +158,7 @@ namespace ShiftOS.WinForms int tutPos = 0; Action ondec = () => { - if (tutPos == 2) - tutPos++; + tutPos++; }; TerminalBackend.CommandProcessed += (o, a) => { diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index 12c371f..7e517c1 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -156,6 +156,8 @@ namespace ShiftOS.Engine { Console.WriteLine("{ERROR}: " + ex.Message); } + + TerminalBackend.PrefixEnabled = false; return true; } catch (Exception ex) diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index 4d599cd..31b3129 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -125,6 +125,8 @@ namespace ShiftOS.Engine { thisGuid = new Guid(msg.Contents); GUIDReceived?.Invoke(msg.Contents); + TerminalBackend.PrefixEnabled = true; + TerminalBackend.PrintPrompt(); } else if(msg.Name == "allusers") { diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index c7852f1..e4bad33 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -339,35 +339,38 @@ namespace ShiftOS.Engine public static void PrintPrompt() { - ConsoleEx.BackgroundColor = SkinEngine.LoadedSkin.TerminalBackColorCC; - ConsoleEx.Italic = false; - ConsoleEx.Underline = false; - - ConsoleEx.ForegroundColor = ConsoleColor.Magenta; - ConsoleEx.Bold = true; - - Console.Write(SaveSystem.CurrentSave.Username); - ConsoleEx.Bold = false; - ConsoleEx.ForegroundColor = ConsoleColor.Gray; - Console.Write("@"); - ConsoleEx.Italic = true; - ConsoleEx.Bold = true; - ConsoleEx.ForegroundColor = ConsoleColor.Yellow; - Console.Write(SaveSystem.CurrentSave.SystemName); - ConsoleEx.Italic = false; - ConsoleEx.Bold = false; - ConsoleEx.ForegroundColor = ConsoleColor.Gray; - Console.Write(":~"); - Console.ForegroundColor = ConsoleColor.White; - ConsoleEx.Italic = true; - if (KernelWatchdog.InKernelMode == true) - Console.Write("#"); - else - Console.Write("$"); - ConsoleEx.Italic = false; - ConsoleEx.Bold = false; - ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC; - Console.Write(" "); + if (SaveSystem.CurrentSave != null) + { + ConsoleEx.BackgroundColor = SkinEngine.LoadedSkin.TerminalBackColorCC; + ConsoleEx.Italic = false; + ConsoleEx.Underline = false; + + ConsoleEx.ForegroundColor = ConsoleColor.Magenta; + ConsoleEx.Bold = true; + + Console.Write(SaveSystem.CurrentSave.Username); + ConsoleEx.Bold = false; + ConsoleEx.ForegroundColor = ConsoleColor.Gray; + Console.Write("@"); + ConsoleEx.Italic = true; + ConsoleEx.Bold = true; + ConsoleEx.ForegroundColor = ConsoleColor.Yellow; + Console.Write(SaveSystem.CurrentSave.SystemName); + ConsoleEx.Italic = false; + ConsoleEx.Bold = false; + ConsoleEx.ForegroundColor = ConsoleColor.Gray; + Console.Write(":~"); + Console.ForegroundColor = ConsoleColor.White; + ConsoleEx.Italic = true; + if (KernelWatchdog.InKernelMode == true) + Console.Write("#"); + else + Console.Write("$"); + ConsoleEx.Italic = false; + ConsoleEx.Bold = false; + ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC; + Console.Write(" "); + } } -- cgit v1.2.3