void ReceiveEvent(string data) { string[] strs = data.Split('\n'); foreach (string str in strs) { #if DEBUG if (m_showOutputDebug) { ChiConsole.WriteLineLow("rcv: " + str.Replace("\x1b", "<esc>")); } #endif ColorMessage colorMsg = Ansi.ParseAnsi(str, ref m_currentStyle); colorMsg = m_baseServicesDispatcher.DispatchReceiveColorMessage(colorMsg); if (colorMsg == null) { return; } ChiConsole.WriteLine(colorMsg); } }
public void Connect(string address, int port) { Disconnect(); ChiConsole.WriteLine("Connecting to {0}:{1}", address, port); m_telnet.Connect(address, port); }
public void HandleInput(string input) { if (input == "/py" || input.StartsWith("/py ")) { m_pythonMode = !m_pythonMode; if (m_pythonMode) { ChiConsole.WriteLine("Python mode enabled."); m_mainWindow.PromptTextBox.Prompt = "python >"; } else { ChiConsole.WriteLine("Python mode disabled."); m_mainWindow.PromptTextBox.Prompt = ""; } return; } if (m_pythonMode) { m_mainWindow.PromptTextBox.Prompt = "python >"; if (input == null || input.Length == 0) { return; } if (input[0] != '/') { EvalCommandHandler(input); return; } } if (input.Length > 1 && input.StartsWith("\\")) { input = input.Substring(1); EvalCommandHandler(input); return; } input = m_baseServicesDispatcher.DispatchInputEvent(input); if (input == null) { return; } if (m_telnet.IsConnected) { SendLine(input); } else { WriteLine("Not connected."); } }
public void Disconnect() { if (m_telnet.IsConnected) { ChiConsole.WriteLine("Disconnecting {0}:{1}", m_telnet.Address, m_telnet.Port); } m_telnet.Disconnect(); }
void DisconnectEvent(string address, int port) { m_baseServicesDispatcher.DispatchDisconnectEvent(); ChiConsole.WriteLine("Disconnected from {0}:{1}", address, port); ChiConsole.Prompt = ""; //m_mainWindow.PromptTextBox.PromptPassword = false; }
public void Run() { Thread m_signalThread = new Thread(SignalThread); m_signalThread.Start(); Pollfd[] fds = new Pollfd[2]; while (m_exit == false) { fds[0].fd = Mono.Unix.UnixStream.StandardInputFileDescriptor; fds[0].events = PollEvents.POLLIN; fds[0].revents = 0; fds[1].fd = m_netPipe.Reading.Handle; fds[1].events = PollEvents.POLLIN; fds[1].revents = 0; int ret = Syscall.poll(fds, -1); if (ret == 0) { //ChiConsole.Prompt = String.Format("pr{0}> ", z++); ChiConsole.WriteLine("timeout"); } else if (ret > 0) { if (fds[0].revents != 0) { m_textConsole.ReadChars(); string str; while ((str = m_textConsole.GetLine()) != null) { //m_textConsole.WriteLine("Tuli {0}", str); HandleInput(str); } } if (fds[1].revents != 0) { m_netPipe.Reading.ReadByte(); m_synchronizedInvoke.DispatchInvokes(); } } } Dbg.WriteLine("Exiting"); m_sigThreadStop = true; if (m_signalThread.Join(1000) == false) { m_signalThread.Abort(); } m_textConsole.UnInit(); }
static public bool GetSize(out int width, out int height) { D("GetSize"); if (GNUReadLine.mono_rl_get_window_size(out width, out height) == false) { ChiConsole.WriteLine("Failed to get win size"); return(false); } else { D(" Size {0}x{1}", width, height); return(true); } //return Console.WindowWidth; //return TGetNum("columns"); }
public void HandleInput(string input) { if (input == "/py") { m_pythonMode = !m_pythonMode; if (m_pythonMode) { ChiConsole.WriteLine("Python mode enabled. Use /py to exit python mode."); ChiConsole.Prompt = "python> "; } else { ChiConsole.WriteLine("Python mode disabled."); ChiConsole.Prompt = ""; } return; } if (m_pythonMode) { if (input == null) { return; } EvalCommandHandler(input); return; } input = m_baseServicesDispatcher.DispatchInputEvent(input); if (input == null) { return; } if (m_telnet.IsConnected) { SendLine(input); ChiConsole.Prompt = ""; } else { ChiConsole.WriteLine("Not connected."); } }
void ConnectEvent(Exception exception, string address, int port) { m_baseServicesDispatcher.DispatchConnectEvent(exception); if (exception == null) { if (address == "batmud.bat.org") { // Send version string as the first thing, so batmud recognizes us correctly // hcbat doesn't support this m_telnet.Send(String.Format("\x1b<v{0}>\n", typeof(ClientCore).Assembly.GetName().Version)); } ChiConsole.WriteLine("Connected to {0}:{1}", address, port); } else { ChiConsole.WriteLine("Connect failed to {0}:{1} : {2}", address, port, exception.Message); } }
void CheckClientVersionFinished(object sender, OpenReadCompletedEventArgs e) { Stream reply = null; StreamReader s = null; try { reply = (Stream)e.Result; s = new StreamReader(reply); string versionString = s.ReadToEnd(); Version currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; Version v = new Version(versionString); if (v > currentVersion) { ChiConsole.WriteLine("There is a new version of Chiroptera available."); ChiConsole.WriteLine("You can get new versions at http://www.bat.org/~tomba/chiroptera.html."); } } catch (Exception) { ChiConsole.WriteLine("Failed to check for new version."); ChiConsole.WriteLine("You can get new versions at http://www.bat.org/~tomba/chiroptera.html."); } finally { if (s != null) { s.Close(); } if (reply != null) { reply.Close(); } } }
public void Initialize(string[] args) { if (args.Length == 1 && args[0] == "/reset") { Properties.Settings.Default.Reset(); } m_baseServicesDispatcher = new BaseServicesDispatcher(); // Init mainwindow and display m_mainWindow = new MainWindow(this); m_paragraphContainer = new ParagraphContainer(); m_mainWindow.TextView.ParagraphContainer = m_paragraphContainer; ChiConsole.SetChiConsole(this); // Initialize ironpython IronPython.Compiler.Options.GenerateModulesAsSnippets = true; /* IronPython.Compiler.Options.GenerateDynamicMethods = false; * IronPython.Compiler.Options.DebugMode = true; * IronPython.Compiler.Options.EngineDebug = true; * IronPython.Compiler.Options.ILDebug = true; * IronPython.Compiler.Options.Frames = true; */ m_pythonEngine = new PythonEngine(); //m_pythonEngine.CreateModule("globals", true); ChiPythonStream s = new ChiPythonStream(); m_pythonEngine.SetStandardOutput(s); m_pythonEngine.SetStandardError(s); m_pythonEngine.SetStandardInput(s); m_pythonEngine.AddToPath(Application.StartupPath + "/lib"); #if DEBUG m_pythonEngine.AddToPath(@"../../../scripts/lib"); #endif m_pythonEngine.LoadAssembly(typeof(TriggerManager).Assembly); // load ChiropteraBase m_pythonEngine.LoadAssembly(typeof(System.Drawing.Bitmap).Assembly); // load System.Drawing m_pythonEngine.LoadAssembly(typeof(System.Windows.Forms.Keys).Assembly); // load System.Windows.Forms // Network m_telnet = new Telnet(); m_telnet.connectEvent += new Telnet.ConnectDelegate(_ConnectEvent); m_telnet.disconnectEvent += new Telnet.DisconnectDelegate(_DisconnectEvent); m_telnet.receiveEvent += new Telnet.ReceiveDelegate(_ReceiveEvent); m_telnet.promptEvent += new Telnet.PromptDelegate(_PromptEvent); m_telnet.telnetEvent += new Telnet.TelnetDelegate(_TelnetEvent); m_commandManager = new CommandManager(m_baseServicesDispatcher); AddBuiltinCommands(); m_triggerManager = new TriggerManager(m_baseServicesDispatcher); m_triggerManager.SetTriggers(Properties.Settings.Default.Triggers); m_hiliteManager = new HiliteManager(m_triggerManager); m_keyManager = new KeyManager(m_baseServicesDispatcher); m_keyManager.SetKeyBindings(Properties.Settings.Default.KeyBindings); PythonInterface.Initialize(m_baseServicesDispatcher, m_triggerManager, m_commandManager, this, this, m_pythonEngine, m_keyManager, m_hiliteManager); try { #if DEBUG PythonInterface.RunScript(Path.GetFullPath("../../../scripts/std/init_std.bc")); #else PythonInterface.RunScript(Path.Combine(Environment.CurrentDirectory, "std/init_std.bc")); #endif } catch (Exception e) { ChiConsole.WriteError("Error running init_std.bc", e); } try { string userScript = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Chiroptera/init.bc"); if (File.Exists(userScript)) { PythonInterface.RunScript(userScript); } } catch (Exception e) { ChiConsole.WriteError("Error running init.bc", e); } Version currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; Version baseVersion = System.Reflection.Assembly.GetAssembly(typeof(Telnet)).GetName().Version; ChiConsole.WriteLine("Chiroptera version {0} (base {1})", currentVersion.ToString(2), baseVersion.ToString(2)); ChiConsole.WriteLine("Using {0}", PythonEngine.VersionString); CheckClientVersion(); }
public ClientCore() { s_clientCore = this; //Ansi.SendAnsiInit(); m_synchronizedInvoke = new SynchronizedInvoke(); // Services m_baseServicesDispatcher = new BaseServicesDispatcher(); // Init console m_textConsole = new TextConsole(); ChiConsole.SetChiConsole(m_textConsole); // Initialize ironpython IronPython.Compiler.Options.GenerateModulesAsSnippets = true; m_pythonEngine = new PythonEngine(); ChiPythonStream s = new ChiPythonStream(); m_pythonEngine.SetStandardOutput(s); m_pythonEngine.SetStandardError(s); m_pythonEngine.SetStandardInput(s); //m_pythonEngine.AddToPath(Environment.CurrentDirectory); //m_pythonEngine.AddToPath(Application.StartupPath + "/lib"); #if DEBUG m_pythonEngine.AddToPath(@"../../../scripts/lib"); #endif m_pythonEngine.LoadAssembly(typeof(TriggerManager).Assembly); // load BatClientBase m_pythonEngine.LoadAssembly(typeof(System.Drawing.Bitmap).Assembly); // load System.Drawing m_pythonEngine.LoadAssembly(typeof(System.Windows.Forms.Keys).Assembly); // load System.Windows.Forms // Network m_telnet = new Telnet(); m_telnet.connectEvent += new Telnet.ConnectDelegate(_ConnectEvent); m_telnet.disconnectEvent += new Telnet.DisconnectDelegate(_DisconnectEvent); m_telnet.receiveEvent += new Telnet.ReceiveDelegate(_ReceiveEvent); m_telnet.promptEvent += new Telnet.PromptDelegate(_PromptEvent); m_telnet.telnetEvent += new Telnet.TelnetDelegate(_TelnetEvent); m_netPipe = UnixPipes.CreatePipes(); m_commandManager = new CommandManager(m_baseServicesDispatcher); AddBuiltinCommands(); m_triggerManager = new TriggerManager(m_baseServicesDispatcher); m_keyManager = new KeyManager(m_baseServicesDispatcher); m_hiliteManager = new HiliteManager(m_triggerManager); PythonInterface.Initialize(m_baseServicesDispatcher, m_triggerManager, m_commandManager, this, m_textConsole, m_pythonEngine, m_keyManager, m_hiliteManager); // run init script Version currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; Version baseVersion = System.Reflection.Assembly.GetAssembly(typeof(Telnet)).GetName().Version; ChiConsole.WriteLine("Chiroptera version {0} (base {1})", currentVersion.ToString(2), baseVersion.ToString(2)); ChiConsole.WriteLine("Using {0}", PythonEngine.VersionString); try { #if DEBUG PythonInterface.RunScript(Path.GetFullPath("../../../scripts/std/init_std.bc")); #else PythonInterface.RunScript(Path.Combine(Environment.CurrentDirectory, "std/init_std.bc")); #endif } catch (Exception e) { ChiConsole.WriteError("Error running init_std.bc", e); } /* * m_pythonEngine.Import("site"); * * try * { * m_pythonEngine.ExecuteFile("init.py"); * } * catch (Exception e) * { * ChiConsole.WriteError("Eval failed", e); * } */ }