From a531cefa00923cc89fe94750bb1b4af12a50df93 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 21 Jan 2017 16:23:10 -0500 Subject: Terminal remote control! --- ShiftOS.WinForms/Applications/Terminal.cs | 46 ++++++++++++++++++++++++------- ShiftOS.WinForms/Commands.cs | 24 ++++++++++++++++ ShiftOS.WinForms/Resources/Shiftorium.txt | 6 ++++ 3 files changed, 66 insertions(+), 10 deletions(-) (limited to 'ShiftOS.WinForms') diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 01ed194..2708e85 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -42,6 +42,7 @@ using System.Text.RegularExpressions; using System.Collections; using static ShiftOS.Engine.SkinEngine; using ShiftOS.Engine; +using ShiftOS.Objects; namespace ShiftOS.WinForms.Applications { @@ -55,6 +56,10 @@ namespace ShiftOS.WinForms.Applications public static string latestCommmand = ""; + + public static bool IsInRemoteSystem = false; + public static string RemoteGuid = ""; + [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] public static bool PrefixEnabled { @@ -110,6 +115,7 @@ namespace ShiftOS.WinForms.Applications [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] public static void InvokeCommand(string text) { + TerminalBackend.InvokeCommand(text); } @@ -245,19 +251,29 @@ namespace ShiftOS.WinForms.Applications var text3 = ""; var text4 = Regex.Replace(text2, @"\t|\n|\r", ""); - if (TerminalBackend.PrefixEnabled) + if (IsInRemoteSystem == true) { - text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length); + ServerManager.SendMessage("trm_invcmd", $@"{{ + guid = ""{RemoteGuid}"", + command: ""{text4}"" +}}"); } - TerminalBackend.LastCommand = text3; - TextSent?.Invoke(text4); - if (TerminalBackend.InStory == false) - { - TerminalBackend.InvokeCommand(text3); - } - if (TerminalBackend.PrefixEnabled) + else { - Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); + if (TerminalBackend.PrefixEnabled) + { + text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length); + } + TerminalBackend.LastCommand = text3; + TextSent?.Invoke(text4); + if (TerminalBackend.InStory == false) + { + TerminalBackend.InvokeCommand(text3); + } + if (TerminalBackend.PrefixEnabled) + { + Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); + } } } catch @@ -337,12 +353,22 @@ namespace ShiftOS.WinForms.Applications private void Terminal_Load(object sender, EventArgs e) { + ServerManager.MessageReceived += (msg) => + { + if(msg.Name == "trm_handshake_guid") + { + IsInRemoteSystem = true; + RemoteGuid = msg.GUID; + } + }; } private void Terminal_FormClosing(object sender, FormClosingEventArgs e) { ti.Stop(); + IsInRemoteSystem = false; + RemoteGuid = ""; } public void OnLoad() diff --git a/ShiftOS.WinForms/Commands.cs b/ShiftOS.WinForms/Commands.cs index a0a1692..ba0ed31 100644 --- a/ShiftOS.WinForms/Commands.cs +++ b/ShiftOS.WinForms/Commands.cs @@ -32,12 +32,36 @@ using System.IO; using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; +using Newtonsoft.Json; /// /// Coherence commands. /// namespace ShiftOS.WinForms { + [Namespace("trm")] + public static class TerminalExtensions + { + [Command("setpass", true)] + [RequiresArgument("pass")] + public static bool setPass(Dictionary args) + { + SaveSystem.CurrentSave.Password = args["pass"] as string; + return true; + } + + [Command("remote", "username:,sysname:,pass:", "Allows you to control a remote system on the multi-user domain given a username, password and system name.")] + [RequiresArgument("username")] + [RequiresArgument("sysname")] + [RequiresArgument("pass")] + public static bool RemoteControl(Dictionary args) + { + ServerManager.SendMessage("trm_handshake_request", JsonConvert.SerializeObject(args)); + return true; + } + } + + [Namespace("coherence")] [RequiresUpgrade("kernel_coherence")] public static class CoherenceCommands diff --git a/ShiftOS.WinForms/Resources/Shiftorium.txt b/ShiftOS.WinForms/Resources/Shiftorium.txt index 614c668..575cfaa 100644 --- a/ShiftOS.WinForms/Resources/Shiftorium.txt +++ b/ShiftOS.WinForms/Resources/Shiftorium.txt @@ -302,6 +302,12 @@ Description: "Adds an app launcher entry for the MUD chat application.", Dependencies: "mud_fundamentals;app_launcher" }, + { + Name: "Another test upgrade", + Cost: 1, + Description: "Read the ID or Name", + Dependencies: "test_upgrade" + }, { Name: "Draggable windows", Cost: 400, -- cgit v1.2.3