// This method transmits a series of instructions to NASA's Horizons system, requesting the name, mass and radius values of a specific object // as well as the specific position and velocity vectors at a specific point in time. // This request is done in relation to the Sun, meaning that the Sun is at 0,0,0 in this co-ordinate system. private void HandleMessageReceived(object sender, string message) { Console.WriteLine(message); output.Add(message); if (message.Contains("System news updated")) { telnetClient.Send(Planet.ToString()); Thread.Sleep(50); telnetClient.Send("E"); Thread.Sleep(50); telnetClient.Send("v"); Thread.Sleep(50); telnetClient.Send("@sun"); Thread.Sleep(50); telnetClient.Send("eclip"); Thread.Sleep(50); telnetClient.Send("2018AD-Nov-11 00:00"); Thread.Sleep(50); telnetClient.Send("2018AD-Nov-11 00:01"); Thread.Sleep(50); telnetClient.Send("1d"); Thread.Sleep(50); telnetClient.Send("y"); } else if (message.Contains("$$EOE")) { telnetClient.Disconnect(); } }
public async void ReadTest() { string expected = "/instrumentation/heading-indicator/indicated-heading-deg = (double)\r\n/> "; string expected1 = "/controls/engines/current-engine/throttle = (double)\r\n/> "; TelnetClient client = new TelnetClient(); client.Connect("127.0.0.1", 5402); client.Send("get /instrumentation/heading-indicator/indicated-heading-deg \r\n"); string result = await client.Read(); client.Send("set /controls/engines/current-engine/throttle 1 \r\n"); string result1 = await client.Read(); int index = result.IndexOf('\''); int end = result.IndexOf('\'', index + 1); result = result.Remove(index, end - index + 1); index = result1.IndexOf('\''); end = result1.IndexOf('\'', index + 1); result1 = result1.Remove(index, end - index + 1); Assert.AreEqual(expected, result); Assert.AreEqual(expected1, result1); }
private void MessageReceivedEvent(object sender, string e) { switch (_serverData.TelnetState) { case TelnetState.connecting: if (this.InvokeRequired) { this.BeginInvoke((MethodInvoker) delegate() { this.Text = "Connected to " + _serverEndpoint;; }); this.BeginInvoke((MethodInvoker) delegate() { this.buttonConnect.Text = "Disconnect";; }); } string telnetPass = ""; if (Utilities.ShowInputDialog(ref telnetPass, "Password", true) == DialogResult.OK) { _serverData.TelnetState = TelnetState.loggingIn; Logger.AddLog("Attempting to login.."); _server.Send(telnetPass + "\n"); return; } break; case TelnetState.loggingIn: //Data received here should be responses to the password field //Wait for "Press 'help' to get a list of all commands.Press 'exit' to end session." //Process lines received before the above line, then set to connected state. try { if (AuthParser.ParseWelcomeLine(e, ref _serverData.ServerInfo)) { return; } } catch (Exception ex) { Logger.AddLog(ex.Message); } break; case TelnetState.connected: //Process commands with regex from this point forward Regex reg = new Regex(@"^(\d{4}-\d{2}-\d{2}T\S+) (?:\S+) (?<log>\w+)"); var match = reg.Match(e); string logData; if (match.Success) { string logType = match.Groups[2].ToString(); logData = e.Substring(match.Index + match.Length).Trim(); //Logger.AddLog("LogType: " + logType + logData); switch (logType) { case "INF": //returns true if the passed line is a server status tick if (ServerStatusParser.ParseStatusLine(logData, ref _serverData.ServerStats)) { return; } if (ChatParser.ParseChatLine(logData)) { return; } break; case "WRN": Logger.AddLog("Warning: " + logData); return; break; default: Logger.AddLog("Unknown logType: " + logType + ":" + logData); break; } Logger.AddLog("Initial match found, but no matches found for this data."); } break; } Logger.AddLog(e); }
private void OnSendCommand() { commandHistory.Add(UserInput); TelnetClient.Send(UserInput); UserInput = string.Empty; }