Esempio n. 1
0
        /// <summary>
        /// Handles the console loop
        /// </summary>
        private static void messageLoop()
        {
            CWSProtocol.Client c = new CWSProtocol.Client("CubeWorldMITM");

            if (Helper.Settings.Instance.AutoIdentifyPlayers)
                EnablePlayerIdentification(c);

            while (shouldExit != true)
            {
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine("Enter one of the following options");
                Console.WriteLine("c - to receive a list of every currently connected player");
                Console.WriteLine("n - to receive a list of every name that we know and the corresponding IP");
                Console.WriteLine("a - about");
                Console.WriteLine("s - to save a list of every known player");
                Console.WriteLine("t - to enable/disable autosaving of playernames");
                Console.WriteLine("x - to configure CWSRestart via CWSProtocol");
                Console.WriteLine("d - to enable sharing connected players with CWSRestart");
                Console.WriteLine("p - to set the number of premium slots");
                Console.WriteLine("l - to enable/disable blacklist/whitelist usage from inside MITM");
                Console.WriteLine("quit - to quit");
                Console.ForegroundColor = ConsoleColor.White;

                string action = Console.ReadLine();
                Console.Clear();

                switch (action.ToLower())
                {
                    case "c":
                        centerText("--------------------------");
                        centerText("Connected players");
                        centerText("--------------------------");

                        Dictionary<string, MITMMessageHandler> tmpC = new Dictionary<string, MITMMessageHandler>(ConnectedPlayers);

                        foreach (KeyValuePair<string, MITMMessageHandler> h in tmpC)
                        {
                            if (h.Value.Name != null)
                                Console.WriteLine("{0}: {1} (Level: {2})", h.Key, h.Value.Name, h.Value.Level);
                            else
                                Console.WriteLine("{0}: Unknown name", h.Key);
                        }

                        break;

                    case "n":
                        centerText("--------------------------");
                        centerText("Known players");
                        centerText("--------------------------");

                        Dictionary<string, List<string>> tmpK = new Dictionary<string, List<string>>(KnownNames);

                        foreach (KeyValuePair<string, List<string>> h in tmpK)
                        {
                            Console.WriteLine("{0} has visited us with the following names:", h.Key);

                            foreach (string s in h.Value)
                                Console.Write("{0} ", s);

                            Console.WriteLine();
                        }

                        break;

                    case "b":
                        Utilities.Logging.ConsoleLogger.Beep();
                        break;

                    case "a":
                        centerText("--------------------------");
                        centerText("About");
                        centerText("--------------------------");

                        centerText("CubeWorldMITM - (c) 2013 ChrisK91 licensed under the GPL3.");
                        centerText("You can view a copy of the license at http://www.gnu.org/licenses/gpl-3.0.html");
                        Console.WriteLine();
                        centerText("Additional information:");
                        centerText("CubeWorldMITM is based on code from Cube. (c) by the respective owners");
                        centerText("Project page: https://github.com/amPerl/Coob");
                        centerText("Cube is licensed under the GPL2.");
                        centerText("You can view the license at: http://www.gnu.org/licenses/gpl-2.0.html");
                        Console.WriteLine();
                        centerText("This software uses Ionic.Zlib");
                        centerText("Ionic.Zlib is licensed under the Microsoft Public License");
                        centerText("You can view the license at:");
                        centerText("https://github.com/jstedfast/Ionic.Zlib/blob/master/License.txt");
                        Console.WriteLine();

                        break;

                    case "s":
                        centerText("--------------------------");
                        centerText("Saving players");
                        centerText("--------------------------");

                        savePlayers();

                        break;

                    case "t":
                        if (autosaveEnabled)
                        {
                            autosaveEnabled = false;
                            autosave.Enabled = false;
                            Console.WriteLine("Autosaving is now disabled.");
                        }
                        else
                        {
                            autosave.Elapsed += autosave_Elapsed;

                            double timeout;
                            Console.WriteLine("Enter the desired interval in seconds:");
                            if (Double.TryParse(Console.ReadLine(), out timeout) && timeout > 0)
                            {
                                timeout = timeout * 1000;
                                autosave.Interval = timeout;
                                autosave.AutoReset = true;
                                autosave.Enabled = true;
                                autosaveEnabled = true;

                                Console.WriteLine("Autosaving is now enabled.");
                            }
                            else
                            {
                                Console.WriteLine("The timeout is not valid.");
                            }
                        }
                        break;

                    case "x":

                        Dictionary<string, bool> checks = new Dictionary<string, bool>();
                        checks.Add(Utilities.Preset.InternetAccess, false);
                        checks.Add(Utilities.Preset.NetworkAccess, true);
                        checks.Add(Utilities.Preset.LoopbackAccess, true);

                        Utilities.Preset p = new Utilities.Preset("CWSProtocol", Helper.Launcher.ServerLocation, Helper.Launcher.ServerName, (int?)serverPort, null, null, null, checks);

                        string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                        Guid name = Guid.NewGuid();

                        folder = Path.Combine(folder, "CubeWorldMITM");

                        if (!Directory.Exists(folder))
                            Directory.CreateDirectory(folder);

                        string filename = Path.Combine(folder, name.ToString() + ".xml");

                        p.Save(filename);

                        if (!c.SendPreset(filename, true))
                        {
                            File.Delete(filename);
                            Helper.Settings.Instance.Logger.AddMessage(Utilities.Logging.MessageType.WARNING, String.Format("Could not send preset."));
                        }

                        break;

                    case "d":
                        EnablePlayerIdentification(c);
                        break;

                    case "p":
                        int i = 0;

                        centerText("--------------------------");
                        centerText("Premium slots");
                        centerText("--------------------------");
                        Console.WriteLine();
                        Console.WriteLine("Premium slots are added to the number of maximum players. Please enter the number of premium slots:");

                        if (Int32.TryParse(Console.ReadLine(), out i) && i >= 0)
                        {
                            Helper.Settings.Instance.PrivateSlots = i;
                        }
                        EnablePremiumPlayers(c);

                        break;

                    case "quit":
                        shouldExit = true;
                        break;

                    case "l":

                        if (!accessManager.Working)
                        {
                            if (accessManager.Enabled)
                                accessManager.StopTimer();
                            else
                                accessManager.StartTimer();

                            Helper.Settings.Instance.Logger.AddMessage(MessageType.INFO, String.Format("Access manager {0}", accessManager.Enabled ? "is running" : "is stopped"));
                        }
                        else
                        {
                            Helper.Settings.Instance.Logger.AddMessage(MessageType.INFO, "The access manager is currently working. Please retry in a few seconds.");
                        }

                        break;
                }

                Console.WriteLine();
            }
        }
Esempio n. 2
0
        public void LoadPreset(string filename, string name)
        {
            string message = String.Format("Would you like to load the preset from {0}?", name);

            if (AutoPresetLoading || System.Windows.Forms.MessageBox.Show(message, "Load preset", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Exclamation, System.Windows.Forms.MessageBoxDefaultButton.Button2, (System.Windows.Forms.MessageBoxOptions) 0x40000) == System.Windows.Forms.DialogResult.Yes)
            {
                try
                {
                    Utilities.Preset p = Utilities.Preset.Load(filename);

                    if (p.ProcessName != null)
                    {
                        ServerService.Helper.Settings.Instance.ServerProcessName = p.ProcessName;
                    }

                    if (p.ServerLocation != null)
                    {
                        ServerService.Helper.Settings.Instance.ServerPath = p.ServerLocation;
                    }

                    if (p.Port != null)
                    {
                        ServerService.Helper.Settings.Instance.Port = (int)p.Port;
                    }

                    if (p.DoNotRedirectOutput != null)
                    {
                        ServerService.Helper.Settings.Instance.DoNotRedirectOutput = (bool)p.DoNotRedirectOutput;
                    }

                    if (p.BypassSendQuit != null)
                    {
                        ServerService.Helper.Settings.Instance.BypassSendQuit = (bool)p.BypassSendQuit;
                    }

                    if (p.Checks.ContainsKey(Utilities.Preset.InternetAccess))
                    {
                        ServerService.Helper.Settings.Instance.CheckInternet = p.Checks[Utilities.Preset.InternetAccess];
                    }

                    if (p.Checks.ContainsKey(Utilities.Preset.NetworkAccess))
                    {
                        ServerService.Helper.Settings.Instance.CheckInternet = p.Checks[Utilities.Preset.NetworkAccess];
                    }

                    if (p.Checks.ContainsKey(Utilities.Preset.LoopbackAccess))
                    {
                        ServerService.Helper.Settings.Instance.CheckInternet = p.Checks[Utilities.Preset.LoopbackAccess];
                    }

                    foreach (string s in p.AdditionalProcesses)
                    {
                        if (!ServerService.Helper.Settings.Instance.AdditionalProcesses.Contains(s))
                        {
                            ServerService.Helper.Settings.Instance.AdditionalProcesses.Add(s);
                        }
                    }

                    Logging.OnLogMessage(String.Format("Loaded preset {0}", p.Name), ServerService.MessageType.Info);
                }
                catch (Exception)
                {
                    Logging.OnLogMessage(String.Format("Could not load preset {0}", filename), ServerService.MessageType.Error);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Handles the console loop
        /// </summary>
        private static void messageLoop()
        {
            CWSProtocol.Client c = new CWSProtocol.Client("CubeWorldMITM");

            if (Helper.Settings.Instance.AutoIdentifyPlayers)
            {
                EnablePlayerIdentification(c);
            }

            while (shouldExit != true)
            {
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine("Enter one of the following options");
                Console.WriteLine("c - to receive a list of every currently connected player");
                Console.WriteLine("n - to receive a list of every name that we know and the corresponding IP");
                Console.WriteLine("a - about");
                Console.WriteLine("s - to save a list of every known player");
                Console.WriteLine("t - to enable/disable autosaving of playernames");
                Console.WriteLine("x - to configure CWSRestart via CWSProtocol");
                Console.WriteLine("d - to enable sharing connected players with CWSRestart");
                Console.WriteLine("p - to set the number of premium slots");
                Console.WriteLine("l - to enable/disable blacklist/whitelist usage from inside MITM");
                Console.WriteLine("quit - to quit");
                Console.ForegroundColor = ConsoleColor.White;

                string action = Console.ReadLine();
                Console.Clear();

                switch (action.ToLower())
                {
                case "c":
                    centerText("--------------------------");
                    centerText("Connected players");
                    centerText("--------------------------");

                    Dictionary <string, MITMMessageHandler> tmpC = new Dictionary <string, MITMMessageHandler>(ConnectedPlayers);

                    foreach (KeyValuePair <string, MITMMessageHandler> h in tmpC)
                    {
                        if (h.Value.Name != null)
                        {
                            Console.WriteLine("{0}: {1} (Level: {2})", h.Key, h.Value.Name, h.Value.Level);
                        }
                        else
                        {
                            Console.WriteLine("{0}: Unknown name", h.Key);
                        }
                    }

                    break;

                case "n":
                    centerText("--------------------------");
                    centerText("Known players");
                    centerText("--------------------------");

                    Dictionary <string, List <string> > tmpK = new Dictionary <string, List <string> >(KnownNames);

                    foreach (KeyValuePair <string, List <string> > h in tmpK)
                    {
                        Console.WriteLine("{0} has visited us with the following names:", h.Key);

                        foreach (string s in h.Value)
                        {
                            Console.Write("{0} ", s);
                        }

                        Console.WriteLine();
                    }

                    break;

                case "b":
                    Utilities.Logging.ConsoleLogger.Beep();
                    break;

                case "a":
                    centerText("--------------------------");
                    centerText("About");
                    centerText("--------------------------");

                    centerText("CubeWorldMITM - (c) 2013 ChrisK91 licensed under the GPL3.");
                    centerText("You can view a copy of the license at http://www.gnu.org/licenses/gpl-3.0.html");
                    Console.WriteLine();
                    centerText("Additional information:");
                    centerText("CubeWorldMITM is based on code from Cube. (c) by the respective owners");
                    centerText("Project page: https://github.com/amPerl/Coob");
                    centerText("Cube is licensed under the GPL2.");
                    centerText("You can view the license at: http://www.gnu.org/licenses/gpl-2.0.html");
                    Console.WriteLine();
                    centerText("This software uses Ionic.Zlib");
                    centerText("Ionic.Zlib is licensed under the Microsoft Public License");
                    centerText("You can view the license at:");
                    centerText("https://github.com/jstedfast/Ionic.Zlib/blob/master/License.txt");
                    Console.WriteLine();

                    break;

                case "s":
                    centerText("--------------------------");
                    centerText("Saving players");
                    centerText("--------------------------");

                    savePlayers();

                    break;

                case "t":
                    if (autosaveEnabled)
                    {
                        autosaveEnabled  = false;
                        autosave.Enabled = false;
                        Console.WriteLine("Autosaving is now disabled.");
                    }
                    else
                    {
                        autosave.Elapsed += autosave_Elapsed;

                        double timeout;
                        Console.WriteLine("Enter the desired interval in seconds:");
                        if (Double.TryParse(Console.ReadLine(), out timeout) && timeout > 0)
                        {
                            timeout            = timeout * 1000;
                            autosave.Interval  = timeout;
                            autosave.AutoReset = true;
                            autosave.Enabled   = true;
                            autosaveEnabled    = true;

                            Console.WriteLine("Autosaving is now enabled.");
                        }
                        else
                        {
                            Console.WriteLine("The timeout is not valid.");
                        }
                    }
                    break;

                case "x":

                    Dictionary <string, bool> checks = new Dictionary <string, bool>();
                    checks.Add(Utilities.Preset.InternetAccess, false);
                    checks.Add(Utilities.Preset.NetworkAccess, true);
                    checks.Add(Utilities.Preset.LoopbackAccess, true);

                    Utilities.Preset p = new Utilities.Preset("CWSProtocol", Helper.Launcher.ServerLocation, Helper.Launcher.ServerName, (int?)serverPort, null, null, null, checks);

                    string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                    Guid   name   = Guid.NewGuid();

                    folder = Path.Combine(folder, "CubeWorldMITM");

                    if (!Directory.Exists(folder))
                    {
                        Directory.CreateDirectory(folder);
                    }

                    string filename = Path.Combine(folder, name.ToString() + ".xml");

                    p.Save(filename);

                    if (!c.SendPreset(filename, true))
                    {
                        File.Delete(filename);
                        Helper.Settings.Instance.Logger.AddMessage(Utilities.Logging.MessageType.WARNING, String.Format("Could not send preset."));
                    }

                    break;

                case "d":
                    EnablePlayerIdentification(c);
                    break;

                case "p":
                    int i = 0;

                    centerText("--------------------------");
                    centerText("Premium slots");
                    centerText("--------------------------");
                    Console.WriteLine();
                    Console.WriteLine("Premium slots are added to the number of maximum players. Please enter the number of premium slots:");

                    if (Int32.TryParse(Console.ReadLine(), out i) && i >= 0)
                    {
                        Helper.Settings.Instance.PrivateSlots = i;
                    }
                    EnablePremiumPlayers(c);

                    break;

                case "quit":
                    shouldExit = true;
                    break;

                case "l":

                    if (!accessManager.Working)
                    {
                        if (accessManager.Enabled)
                        {
                            accessManager.StopTimer();
                        }
                        else
                        {
                            accessManager.StartTimer();
                        }

                        Helper.Settings.Instance.Logger.AddMessage(MessageType.INFO, String.Format("Access manager {0}", accessManager.Enabled ? "is running" : "is stopped"));
                    }
                    else
                    {
                        Helper.Settings.Instance.Logger.AddMessage(MessageType.INFO, "The access manager is currently working. Please retry in a few seconds.");
                    }

                    break;
                }

                Console.WriteLine();
            }
        }