diff options
| author | RogueAI42 <[email protected]> | 2017-07-31 19:44:51 +1000 |
|---|---|---|
| committer | RogueAI42 <[email protected]> | 2017-07-31 19:44:51 +1000 |
| commit | 23bd15d7cf7522fb05a5f2ea8e0a89d3a80efdc8 (patch) | |
| tree | fa5dc08a89014d79565f30b22c94403845239cc3 /ShiftOS.Frontend | |
| parent | d953797369cd72a718b801e0036ce9ebb181f24f (diff) | |
| parent | 6366721315d8a62febeb5c0c0340f15ab7d35963 (diff) | |
| download | shiftos_thereturn-23bd15d7cf7522fb05a5f2ea8e0a89d3a80efdc8.tar.gz shiftos_thereturn-23bd15d7cf7522fb05a5f2ea8e0a89d3a80efdc8.tar.bz2 shiftos_thereturn-23bd15d7cf7522fb05a5f2ea8e0a89d3a80efdc8.zip | |
Merge remote-tracking branch 'upstream/monogame' into monogame
Diffstat (limited to 'ShiftOS.Frontend')
| -rw-r--r-- | ShiftOS.Frontend/Apps/Terminal.cs | 55 | ||||
| -rw-r--r-- | ShiftOS.Frontend/Commands.cs | 61 | ||||
| -rw-r--r-- | ShiftOS.Frontend/Hacking/HackerTestCommands.cs | 3 | ||||
| -rw-r--r-- | ShiftOS.Frontend/Hacking/HackingCommands.cs | 44 |
4 files changed, 105 insertions, 58 deletions
diff --git a/ShiftOS.Frontend/Apps/Terminal.cs b/ShiftOS.Frontend/Apps/Terminal.cs index 343bb5d..4af1196 100644 --- a/ShiftOS.Frontend/Apps/Terminal.cs +++ b/ShiftOS.Frontend/Apps/Terminal.cs @@ -164,34 +164,37 @@ namespace ShiftOS.Frontend.Apps /// <returns>An absolute fucking mess. Seriously, can someone fix this method so it uhh WORKS PROPERLY?</returns> public System.Drawing.Point GetPointAtIndex(Graphics gfx) { - int vertMeasure = 2; + var font = new Font(LoadedSkin.TerminalFont.Name, LoadedSkin.TerminalFont.Size * _zoomFactor, LoadedSkin.TerminalFont.Style); + + int _textHeight = (int)gfx.SmartMeasureString("#", font).Height; + float vertMeasure = 2; int horizMeasure = 2; if (string.IsNullOrEmpty(Text)) - return new System.Drawing.Point(horizMeasure, vertMeasure); + return new System.Drawing.Point(horizMeasure, (int)vertMeasure); int lineindex = 0; int line = GetCurrentLine(); for (int l = 0; l < line; l++) { - if (string.IsNullOrEmpty(Lines[l])) + lineindex += Lines[l].Length; + if (string.IsNullOrWhiteSpace(Lines[l])) { - vertMeasure += LoadedSkin.TerminalFont.Height * _zoomFactor; + vertMeasure += _textHeight; continue; } - lineindex += Lines[l].Length; - var stringMeasure = gfx.SmartMeasureString(Lines[l] == "\r" ? " " : Lines[l], LoadedSkin.TerminalFont, Width - 4); - vertMeasure += (int)stringMeasure.Height * _zoomFactor; - + var stringMeasure = gfx.SmartMeasureString(Lines[l], font, Width - 4); + vertMeasure += (int)(stringMeasure.Height); + } - var lnMeasure = gfx.SmartMeasureString(Text.Substring(lineindex, Index - lineindex), LoadedSkin.TerminalFont); - int w = (int)Math.Floor(lnMeasure.Width) * _zoomFactor; + var lnMeasure = gfx.SmartMeasureString(Text.Substring(lineindex, Index - lineindex), font); + int w = (int)Math.Floor(lnMeasure.Width); while (w > Width - 4) { w = w - (Width - 4); - vertMeasure += (int)lnMeasure.Height * _zoomFactor; + vertMeasure += (int)lnMeasure.Height; } horizMeasure += w; - return new System.Drawing.Point(horizMeasure, vertMeasure); + return new System.Drawing.Point(horizMeasure, (int)vertMeasure); } private PointF CaretPosition = new PointF(2, 2); @@ -199,7 +202,7 @@ namespace ShiftOS.Frontend.Apps protected override void OnKeyEvent(KeyEvent a) { - if(a.ControlDown && (a.Key == Keys.OemPlus || a.Key == Keys.Add)) + if (a.ControlDown && (a.Key == Keys.OemPlus || a.Key == Keys.Add)) { _zoomFactor *= 2; RecalculateLayout(); @@ -209,7 +212,7 @@ namespace ShiftOS.Frontend.Apps if (a.ControlDown && (a.Key == Keys.OemMinus || a.Key == Keys.Subtract)) { - _zoomFactor = Math.Max(1, _zoomFactor/2); + _zoomFactor = Math.Max(1, _zoomFactor / 2); RecalculateLayout(); Invalidate(); return; @@ -221,7 +224,7 @@ namespace ShiftOS.Frontend.Apps if (!PerformTerminalBehaviours) { Text = Text.Insert(Index, Environment.NewLine); - Index+=2; + Index += 2; RecalculateLayout(); Invalidate(); return; @@ -239,12 +242,12 @@ namespace ShiftOS.Frontend.Apps var text2 = text[text.Length - 1]; var text3 = ""; var text4 = Regex.Replace(text2, @"\t|\n|\r", ""); - WriteLine(""); + WriteLine(""); - if (TerminalBackend.PrefixEnabled) - { - text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length); - } + if (TerminalBackend.PrefixEnabled) + { + text3 = text4.Remove(0, TerminalBackend.ShellOverride.Length); + } if (!string.IsNullOrWhiteSpace(text3)) { TerminalBackend.LastCommand = text3; @@ -288,7 +291,7 @@ namespace ShiftOS.Frontend.Apps { var tostring3 = Lines[Lines.Length - 1]; var tostringlen = tostring3.Length + 1; - var workaround = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "; + var workaround = TerminalBackend.ShellOverride; var derp = workaround.Length + 1; if (tostringlen != derp) { @@ -310,9 +313,9 @@ namespace ShiftOS.Frontend.Apps Debug.WriteLine("Drunky alert in terminal."); } } - else if(a.Key == Keys.Right) + else if (a.Key == Keys.Right) { - if(Index < Text.Length) + if (Index < Text.Length) { Index++; AppearanceManager.CurrentPosition++; @@ -326,7 +329,7 @@ namespace ShiftOS.Frontend.Apps { var getstring = Lines[Lines.Length - 1]; var stringlen = getstring.Length + 1; - var header = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "; + var header = TerminalBackend.ShellOverride; var headerlen = header.Length + 1; var selstart = Index; var remstrlen = Text.Length - stringlen; @@ -343,7 +346,7 @@ namespace ShiftOS.Frontend.Apps else if (a.Key == Keys.Up && PerformTerminalBehaviours) { var tostring3 = Lines[Lines.Length - 1]; - if (tostring3 == $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ") + if (tostring3 == TerminalBackend.ShellOverride) Console.Write(TerminalBackend.LastCommand); ConsoleEx.OnFlush?.Invoke(); return; @@ -360,7 +363,7 @@ namespace ShiftOS.Frontend.Apps Text = Text.Insert(Index, a.KeyChar.ToString()); Index++; AppearanceManager.CurrentPosition++; -// RecalculateLayout(); + // RecalculateLayout(); InvalidateTopLevel(); } } diff --git a/ShiftOS.Frontend/Commands.cs b/ShiftOS.Frontend/Commands.cs index 012d0b0..da1d1c1 100644 --- a/ShiftOS.Frontend/Commands.cs +++ b/ShiftOS.Frontend/Commands.cs @@ -47,6 +47,7 @@ namespace ShiftOS.Frontend [TutorialLock] public static class TerminalCommands { + [MetaCommand] [Command("clear", description = "{DESC_CLEAR}")] public static bool Clear() { @@ -60,14 +61,21 @@ namespace ShiftOS.Frontend public static class ShiftOSCommands { +#if DEBUG + [Command("debug")] + public static void EnterDebug() + { + TerminalBackend.SetShellOverride("shiftos_debug> "); + } +#endif - [Command("setsfxenabled", description = "{DESC_SETSFXENABLED}")] - [RequiresArgument("value")] + [Command("setsfxenabled", description = "{DESC_SETSFXENABLED}")] + [RequiresArgument("id")] public static bool SetSfxEnabled(Dictionary<string, object> args) { try { - bool value = Convert.ToBoolean(args["value"].ToString()); + bool value = Convert.ToBoolean(args["id"].ToString()); SaveSystem.CurrentSave.SoundEnabled = value; SaveSystem.SaveGame(); } @@ -81,12 +89,12 @@ namespace ShiftOS.Frontend [Command("setmusicenabled", description = "{DESC_SETMUSICENABLED}")] - [RequiresArgument("value")] + [RequiresArgument("id")] public static bool SetMusicEnabled(Dictionary<string, object> args) { try { - bool value = Convert.ToBoolean(args["value"].ToString()); + bool value = Convert.ToBoolean(args["id"].ToString()); SaveSystem.CurrentSave.MusicEnabled = value; SaveSystem.SaveGame(); } @@ -100,10 +108,10 @@ namespace ShiftOS.Frontend [Command("setvolume", description ="{DESC_SETVOLUME}")] - [RequiresArgument("value")] + [RequiresArgument("id")] public static bool SetSfxVolume(Dictionary<string, object> args) { - int value = int.Parse(args["value"].ToString()); + int value = int.Parse(args["id"].ToString()); if(value >= 0 && value <= 100) { SaveSystem.CurrentSave.MusicVolume = value; @@ -127,14 +135,14 @@ namespace ShiftOS.Frontend } [Command("lang", description = "{DESC_LANG}")] - [RequiresArgument("language")] + [RequiresArgument("id")] public static bool SetLanguage(Dictionary<string, object> userArgs) { try { string lang = ""; - lang = (string)userArgs["language"]; + lang = (string)userArgs["id"]; if (Localization.GetAllLanguages().Contains(lang)) { @@ -152,7 +160,8 @@ namespace ShiftOS.Frontend } } - [Command("commands", "", "{DESC_COMMANDS}")] + [MetaCommand] + [Command("help", "", "{DESC_COMMANDS}")] public static bool Commands() { var sb = new StringBuilder(); @@ -160,7 +169,7 @@ namespace ShiftOS.Frontend sb.AppendLine("================="); sb.AppendLine(); //print all unique namespaces. - foreach (var n in TerminalBackend.Commands.Where(x => !(x is TerminalBackend.WinOpenCommand) && Shiftorium.UpgradeInstalled(x.Dependencies) && x.CommandInfo.hide == false).OrderBy(x => x.CommandInfo.name)) + foreach (var n in TerminalBackend.Commands.Where(x => !(x is TerminalBackend.WinOpenCommand) && Shiftorium.UpgradeInstalled(x.Dependencies) && x.CommandInfo.hide == false && x.MatchShell() == true).OrderBy(x => x.CommandInfo.name)) { sb.Append(" - " + n.CommandInfo.name); if (!string.IsNullOrWhiteSpace(n.CommandInfo.description)) @@ -174,13 +183,6 @@ namespace ShiftOS.Frontend return true; } - [Command("help", description = "{DESC_HELP}")] - public static bool Help() - { - Commands(); - WindowCommands.Programs(); - return true; - } [MultiplayerOnly] @@ -237,14 +239,14 @@ namespace ShiftOS.Frontend public static class ShiftoriumCommands { [Command("buy", description = "{DESC_BUY}")] - [RequiresArgument("upgrade")] + [RequiresArgument("id")] public static bool BuyUpgrade(Dictionary<string, object> userArgs) { try { string upgrade = ""; - upgrade = (string)userArgs["upgrade"]; + upgrade = (string)userArgs["id"]; var upg = Shiftorium.GetAvailable().FirstOrDefault(x => x.ID == upgrade); if(upg != null) @@ -267,12 +269,12 @@ namespace ShiftOS.Frontend [RequiresUpgrade("shiftorium_bulk_buy")] [Command("bulkbuy", description = "{DESC_BULKBUY}")] - [RequiresArgument("upgrades")] + [RequiresArgument("id")] public static bool BuyBulk(Dictionary<string, object> args) { - if (args.ContainsKey("upgrades")) + if (args.ContainsKey("id")) { - string[] upgrade_list = (args["upgrades"] as string).Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); + string[] upgrade_list = (args["id"] as string).Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach (var upg in upgrade_list) { var dict = new Dictionary<string, object>(); @@ -285,14 +287,14 @@ namespace ShiftOS.Frontend [Command("upgradeinfo", description ="{DESC_UPGRADEINFO}")] - [RequiresArgument("upgrade")] + [RequiresArgument("id")] public static bool ViewInfo(Dictionary<string, object> userArgs) { try { string upgrade = ""; - upgrade = (string)userArgs["upgrade"]; + upgrade = (string)userArgs["id"]; foreach (var upg in Shiftorium.GetDefaults()) { @@ -447,14 +449,13 @@ namespace ShiftOS.Frontend } [RemoteLock] - [Command("close", usage = "{win:integer32}", description ="{DESC_CLOSE}")] - [RequiresArgument("win")] - [RequiresUpgrade("close_command")] + [Command("close", description ="{DESC_CLOSE}")] + [RequiresArgument("id")] public static bool CloseWindow(Dictionary<string, object> args) { int winNum = -1; - if (args.ContainsKey("win")) - winNum = Convert.ToInt32(args["win"].ToString()); + if (args.ContainsKey("id")) + winNum = Convert.ToInt32(args["id"].ToString()); string err = null; if (winNum < 0 || winNum >= AppearanceManager.OpenForms.Count) diff --git a/ShiftOS.Frontend/Hacking/HackerTestCommands.cs b/ShiftOS.Frontend/Hacking/HackerTestCommands.cs index 1b6a1c1..72c648e 100644 --- a/ShiftOS.Frontend/Hacking/HackerTestCommands.cs +++ b/ShiftOS.Frontend/Hacking/HackerTestCommands.cs @@ -10,6 +10,7 @@ namespace ShiftOS.Frontend { public static class HackerTestCommands { + [ShellConstraint("shiftos_debug> ")] [Command("lsports")] public static void ListAllPorts() { @@ -19,6 +20,7 @@ namespace ShiftOS.Frontend } } + [ShellConstraint("shiftos_debug> ")] [Command("describehackable")] [RequiresArgument("id")] public static void DescribeHackable(Dictionary<string, object> args) @@ -41,6 +43,7 @@ namespace ShiftOS.Frontend Console.WriteLine(hackable.WelcomeMessage); } + [ShellConstraint("shiftos_debug> ")] [Command("describeport")] [RequiresArgument("id")] public static void DescribePort(Dictionary<string, object> args) diff --git a/ShiftOS.Frontend/Hacking/HackingCommands.cs b/ShiftOS.Frontend/Hacking/HackingCommands.cs index d07b174..9ebb824 100644 --- a/ShiftOS.Frontend/Hacking/HackingCommands.cs +++ b/ShiftOS.Frontend/Hacking/HackingCommands.cs @@ -9,8 +9,21 @@ namespace ShiftOS.Frontend { class HackingCommands { + [Command("sploitset")] + public static void SploitSetEnter(Dictionary<string, object> args) + { + TerminalBackend.SetShellOverride("sploitset> "); + } + + [Command("ftp")] + public static void FTPEnter(Dictionary<string, object> args) + { + TerminalBackend.SetShellOverride("SimplFTP> "); + } + //TODO: Implement firewall cracking [Command("connect")] + [MetaCommand] [RequiresArgument("id")] public static void Connect(Dictionary<string, object> args) { @@ -25,6 +38,7 @@ namespace ShiftOS.Frontend } [Command("exploit")] + [ShellConstraint("sploitset> ")] [RequiresArgument("id")] [RequiresArgument("port")] public static void Exploit(Dictionary<string, object> args) @@ -32,6 +46,7 @@ namespace ShiftOS.Frontend if (Hacking.CurrentHackable == null) { Console.WriteLine("[connectlib] not connected"); + return; } string Port = args["port"].ToString(); string ExploitName = args["id"].ToString(); @@ -58,12 +73,14 @@ namespace ShiftOS.Frontend } [Command("inject")] + [ShellConstraint("sploitset> ")] [RequiresArgument("id")] public static void InjectPayload(Dictionary<string, object> args) { if (Hacking.CurrentHackable == null) { Console.WriteLine("[connectlib] not connected"); + return; } string PayloadName = args["id"].ToString(); var PayloadID = Hacking.AvailablePayloads.FirstOrDefault(x => x.ID == PayloadName); @@ -83,11 +100,13 @@ namespace ShiftOS.Frontend } [Command("listports")] + [ShellConstraint("sploitset> ")] public static void ListPorts(Dictionary<string, object> args) { if (Hacking.CurrentHackable == null) { Console.WriteLine("[connectlib] not connected"); + return; } foreach (var port in Hacking.CurrentHackable.PortsToUnlock) { @@ -96,6 +115,7 @@ namespace ShiftOS.Frontend } [Command("devicescan")] + [ShellConstraint("sploitset> ")] public static void ScanDevices() { Console.WriteLine("[sploitset] found " + Hacking.AvailableToHack.Length + " devices on the network"); @@ -106,6 +126,7 @@ namespace ShiftOS.Frontend } [Command("exploits")] + [ShellConstraint("sploitset> ")] public static void ScanExploits() { Console.WriteLine("[sploitset] found " + Hacking.AvailableExploits.Length + " exploits installed"); @@ -116,6 +137,7 @@ namespace ShiftOS.Frontend } [Command("payloads")] + [ShellConstraint("sploitset> ")] public static void ListAllPayloads() { Console.WriteLine("[sploitset] found " + Hacking.AvailablePayloads.Length + " payloads"); @@ -126,11 +148,13 @@ namespace ShiftOS.Frontend } [Command("disconnect")] + [MetaCommand] public static void Disconnect(Dictionary<string, object> args) { if (Hacking.CurrentHackable == null) { Console.WriteLine("[connectlib] not connected"); + return; } if (Hacking.CurrentHackable.PayloadExecuted.Count == 0) { @@ -140,12 +164,20 @@ namespace ShiftOS.Frontend Hacking.FinishHack(); } - [Command("ftp-list")] + [Command("list")] + [ShellConstraint("SimplFTP> ")] public static void ListAllFTP(Dictionary<string, object> args) { if (Hacking.CurrentHackable == null) { Console.WriteLine("[connectlib] not connected"); + return; + } + var PayloadID = Hacking.CurrentHackable.PayloadExecuted.FirstOrDefault(x => x.EffectiveAgainst.HasFlag(Objects.SystemType.FileServer)); + if (PayloadID == null) + { + Console.WriteLine("[SimplFTP] Not authorised."); + return; } foreach (var loot in Hacking.CurrentHackable.ServerFTPLoot) { @@ -153,13 +185,21 @@ namespace ShiftOS.Frontend } } - [Command("ftp-download")] + [Command("download")] + [ShellConstraint("SimplFTP> ")] [RequiresArgument("file")] public static void DownloadFTP(Dictionary<string, object> args) { if (Hacking.CurrentHackable == null) { Console.WriteLine("[connectlib] not connected"); + return; + } + var PayloadID = Hacking.CurrentHackable.PayloadExecuted.FirstOrDefault(x => x.EffectiveAgainst.HasFlag(Objects.SystemType.FileServer)); + if (PayloadID == null) + { + Console.WriteLine("[SimplFTP] Not authorised."); + return; } string FindName = args["file"].ToString(); var LootID = Hacking.AvailableLoot.FirstOrDefault(x => x.LootName == FindName); |
