Exemple #1
0
        void LoginButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (Core != null)
                {
                    return;
                }

                StatusLabel.Text = "Loading core...";

                Core                = Context.LoadCore(UserPath, Password);
                Core.RunInGui      += Core_RunInGui;
                Core.UpdateConsole += Core_UpdateConsole;
            }
            catch (Exception ex)
            {
                StatusLabel.Text = "Login error: " + ex.Message;
            }
        }
Exemple #2
0
        bool ProcessInput(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return(true);
            }

            try
            {
                LogFile.WriteLine("> " + input);
                LogFile.Flush();

                if (input.CompareNoCase("exit"))
                {
                    return(false);
                }

                else if (input.CompareNoCase("list"))
                {
                    var profiles = GetProfiles(StartupPath);

                    for (int i = 0; i < profiles.Length; i++)
                    {
                        WriteOut("{0}. {1}", i + 1, Path.GetFileName(profiles[i]));
                    }

                    if (profiles.Length == 0)
                    {
                        WriteOut("No profiles in startup directory found");
                    }
                }

                else if (input.StartsWith("load", StringComparison.OrdinalIgnoreCase))
                {
                    var parts = input.Split(' ');

                    var profiles = GetProfiles(StartupPath);

                    var userPath = profiles[int.Parse(parts[1]) - 1];
                    var pass     = parts[2];

                    var core = Context.LoadCore(userPath, pass);

                    WriteOut("Loaded op: {0}, user: {1}", core.User.Settings.Operation, core.User.Settings.UserName);
                }

                else if (input.CompareNoCase("ident"))
                {
                    Context.Cores.SafeForEach(c =>
                                              WriteOut(c.GetIdentity(c.UserID))
                                              );
                }

                else if (input.CompareNoCase("address"))
                {
                    Context.Cores.SafeForEach(c =>
                                              WriteOut(c.GetMyAddress())
                                              );

                    if (Context.Lookup != null)
                    {
                        WriteOut(Context.Lookup.GetMyAddress());
                    }
                }

                else if (input.CompareNoCase("status"))
                {
                    Action <OpCore> showStatus = c =>
                    {
                        WriteOut("{0} - {1}:{2}:{3} - {4}",
                                 (c.User != null) ? c.User.Settings.Operation : "Lookup",
                                 c.LocalIP,
                                 c.Network.TcpControl.ListenPort,
                                 c.Network.UdpControl.ListenPort,
                                 c.Network.Established ? "Connected" : "Connecting...");
                    };

                    if (Context.Lookup != null)
                    {
                        showStatus(Context.Lookup);
                    }

                    Context.Cores.SafeForEach(c => showStatus(c));
                }

                else if (input.StartsWith("sleep"))
                {
                    var parts = input.Split(' ');

                    Thread.Sleep(int.Parse(parts[1]) * 1000);
                }

                else if (input.CompareNoCase("help"))
                {
                    WriteOut(HelpText);
                }

                else
                {
                    WriteOut("unknown command: " + input);
                }
            }
            catch (Exception ex)
            {
                WriteOut("Exception: " + ex.Message);
            }

            return(true);
        }