diff options
| author | Michael <[email protected]> | 2017-01-21 16:23:10 -0500 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-01-21 16:23:10 -0500 |
| commit | a531cefa00923cc89fe94750bb1b4af12a50df93 (patch) | |
| tree | 7c56b04db83b6d21351fff375e4311a264f16c12 /ShiftOS_TheReturn | |
| parent | 5c9629c4c61d823dfc49693355072b38c09ffb7a (diff) | |
| download | shiftos_thereturn-a531cefa00923cc89fe94750bb1b4af12a50df93.tar.gz shiftos_thereturn-a531cefa00923cc89fe94750bb1b4af12a50df93.tar.bz2 shiftos_thereturn-a531cefa00923cc89fe94750bb1b4af12a50df93.zip | |
Terminal remote control!
Diffstat (limited to 'ShiftOS_TheReturn')
| -rw-r--r-- | ShiftOS_TheReturn/ServerManager.cs | 2 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/TerminalBackend.cs | 55 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/TerminalTextWriter.cs | 44 |
3 files changed, 94 insertions, 7 deletions
diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index 13c4ffa..aad63ef 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -49,7 +49,7 @@ namespace ShiftOS.Engine {JsonConvert.SerializeObject(client, Formatting.Indented)}"); } - private static Guid thisGuid { get; set; } + public static Guid thisGuid { get; private set; } private static NetObjectClient client { get; set; } public static void Disconnect() diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index 156a916..0d2f386 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -240,6 +240,61 @@ namespace ShiftOS.Engine return false; } + static TerminalBackend() + { + ServerMessageReceived onMessageReceived = (msg) => + { + if (msg.Name == "trm_invokecommand") + { + string text3 = ""; + string text4 = msg.Contents; + + if (TerminalBackend.PrefixEnabled) + { + text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length); + } + IsForwardingConsoleWrites = true; + if (TerminalBackend.InStory == false) + { + TerminalBackend.InvokeCommand(text3); + } + if (TerminalBackend.PrefixEnabled) + { + Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); + } + IsForwardingConsoleWrites = false; + } + else if(msg.Name == "pleasewrite") + { + Console.Write(msg.Contents); + } + else if(msg.Name == "handshake_from") + { + var a = JsonConvert.DeserializeObject<Dictionary<string, object>>(msg.Contents); + string uName = a["username"] as string; + string pass = a["password"] as string; + string sys = a["sysname"] as string; + string guid = msg.GUID; + if(SaveSystem.CurrentSave.Username == uName && SaveSystem.CurrentSave.Password == pass && CurrentSave.SystemName == sys) + { + ForwardGUID = guid; + ServerManager.SendMessage("trm_handshake_accept", $@"{{ + guid: ""{ServerManager.thisGuid}"" +}}"); + IsForwardingConsoleWrites = true; + InvokeCommand("sos.status"); + Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); + IsForwardingConsoleWrites = false; + } + } + }; + + ServerManager.MessageReceived += onMessageReceived; + } + + public static bool IsForwardingConsoleWrites { get; private set; } + public static string ForwardGUID { get; private set; } + } } diff --git a/ShiftOS_TheReturn/TerminalTextWriter.cs b/ShiftOS_TheReturn/TerminalTextWriter.cs index 78959d5..bc242a9 100644 --- a/ShiftOS_TheReturn/TerminalTextWriter.cs +++ b/ShiftOS_TheReturn/TerminalTextWriter.cs @@ -65,20 +65,41 @@ namespace ShiftOS.Engine public override void Write(char value) { - Desktop.InvokeOnWorkerThread(new Action(() => + if (TerminalBackend.IsForwardingConsoleWrites) { - UnderlyingControl.Write(value.ToString()); - select(); - })); + ServerManager.SendMessage("write", $@"{{ + guid: ""{TerminalBackend.ForwardGUID}"", + text: ""{value}"" +}}"); + } + else + { + Desktop.InvokeOnWorkerThread(new Action(() => + { + UnderlyingControl.Write(value.ToString()); + select(); + })); + } } public override void WriteLine(string value) { - Desktop.InvokeOnWorkerThread(new Action(() => + if (TerminalBackend.IsForwardingConsoleWrites) + { + ServerManager.SendMessage("write", $@"{{ + guid: ""{TerminalBackend.ForwardGUID}"", + text: ""{value + Environment.NewLine}"" +}}"); + } + else + { + + Desktop.InvokeOnWorkerThread(new Action(() => { UnderlyingControl.WriteLine(value); select(); })); + } } public void SetLastText() @@ -87,11 +108,22 @@ namespace ShiftOS.Engine public override void Write(string value) { - Desktop.InvokeOnWorkerThread(new Action(() => + if (TerminalBackend.IsForwardingConsoleWrites) + { + ServerManager.SendMessage("write", $@"{{ + guid: ""{TerminalBackend.ForwardGUID}"", + text: ""{value}"" +}}"); + } + else + { + + Desktop.InvokeOnWorkerThread(new Action(() => { UnderlyingControl.Write(value.ToString()); select(); })); + } } |
