コード例 #1
0
        /// <summary>
        /// Intializes the player identification with CWSRestart
        /// </summary>
        /// <param name="c"></param>
        private static void EnablePlayerIdentification(CWSProtocol.Client c)
        {
            string database;

            if ((database = c.GetPlayersDatabase()) != null && c.SetPlayerIdentification(true))
            {
                Helper.Settings.Instance.Logger.AddMessage(MessageType.INFO, String.Format("Playerdatabase: {0}", database));
                knownPlayers = new KnownPlayers(database);

                knownPlayers.ClearConnectedPlayers();

                foreach (KeyValuePair <string, MITMMessageHandler> kvp in ConnectedPlayers)
                {
                    knownPlayers.AddConnectedPlayer(kvp.Value.IP, kvp.Value.Name);
                }

#if DEBUG
                knownPlayers.AddKnownPlayer("192.168.178.1", "Name 1-1");
                knownPlayers.AddKnownPlayer("192.168.178.2", "Name 2-2");
                knownPlayers.AddKnownPlayer("192.168.178.2", "Name 3-2");
                knownPlayers.AddKnownPlayer("192.168.178.3", "Name 4-3");
                knownPlayers.AddKnownPlayer("192.168.178.3", "Name 5-3");
                knownPlayers.AddKnownPlayer("192.168.178.5", "Name 6-5");
#endif
            }
        }
コード例 #2
0
        public AccessManager(ref Dictionary <string, MITMMessageHandler> ConnectedPlayers, ref Dictionary <string, MITMMessageHandler> PremiumPlayers)
        {
            this.connectedPlayers = ConnectedPlayers;
            this.premiumPlayers   = PremiumPlayers;

            client = new CWSProtocol.Client("CubeWorldMITM access list updater");

            interval           = new Timer(15000);
            interval.AutoReset = true;
            interval.Elapsed  += interval_Elapsed;
        }
コード例 #3
0
ファイル: AccessManager.cs プロジェクト: ChrisK91/CWSRestart
        public AccessManager(ref Dictionary<string, MITMMessageHandler> ConnectedPlayers, ref Dictionary<string, MITMMessageHandler> PremiumPlayers)
        {
            this.connectedPlayers = ConnectedPlayers;
            this.premiumPlayers = PremiumPlayers;

            client = new CWSProtocol.Client("CubeWorldMITM access list updater");

            interval = new Timer(15000);
            interval.AutoReset = true;
            interval.Elapsed += interval_Elapsed;
        }
コード例 #4
0
        private static void EnablePremiumPlayers(CWSProtocol.Client c)
        {
            string database;

            if ((database = c.GetPremiumDatabase()) != null && c.SetPremiumslots(true))
            {
                Helper.Settings.Instance.Logger.AddMessage(MessageType.INFO, String.Format("Premium database: {0}", database));
                premiumPlayers = new PremiumPlayers(database);

                premiumPlayers.ClearPremiumPlayers();
            }
        }
コード例 #5
0
ファイル: Bridge.cs プロジェクト: ChrisK91/CuwoCWS
        public Bridge()
        {
            string directory = Directory.GetCurrentDirectory();
            int wsize = IntPtr.Size;
            string libdir = (wsize == 4) ? "x86" : "x64";
            SetDllDirectory(Path.Combine(directory,"dll", libdir));

            ConsoleWrite("CWSRestart bridge initializes...");
            c = new CWSProtocol.Client("CuWo");

            bool finished = false;

            for (int i = 0; i < 10 && finished == false; i++)
            {
                if (c.Test())
                {
                    ConsoleWrite("Connection to CWSRestart succesful");

                    string playerDb = c.GetPlayersDatabase();

                    if (playerDb != null && c.SetPlayerIdentification(true))
                    {
                        knownPlayers = new ServerService.Database.KnownPlayers(playerDb);
                        knownPlayers.ClearConnectedPlayers();
                    }

                    finished = true;
                }
                else
                {
                    ConsoleWrite("Connection to CWSRestart not possible");
                }
                System.Threading.Thread.Sleep(100);
            }
            ConsoleWrite("Initialization complete!");
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: ChrisK91/CWSRestart
        /// <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();
            }
        }
コード例 #7
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();
            }
        }
コード例 #8
0
ファイル: Admin.cs プロジェクト: gatekeeper1122/CWSRestart
        public Admin()
            : base("/admin")
        {
            CWSProtocol.Client     c = new CWSProtocol.Client("AdminModule");
            IReadOnlyList <string> requiredClaims = new List <string> {
                Helper.Users.Authentication.ADMINISTRATOR
            };


            this.RequiresAuthentication();
            this.RequiresClaims(requiredClaims);

            Get["/"] = parameters =>
            {
                var message = Session.FirstOrDefault(o => o.Key == "toggleMessage");

                if (message.Key != null)
                {
                    Context.ViewBag["toggleMessage"] = message.Value;
                    Session.Delete("toggleMessage");
                }

                message = Session.FirstOrDefault(o => o.Key == "requiresDelay");
                Models.Admin.ControlPanel m = new Models.Admin.ControlPanel(null, false, true, 0, false, false, false);

                if (message.Key != null)
                {
                    Context.ViewBag["requiresDelay"] = true;
                    Session.Delete("requiresDelay");
                }
                else
                {
                    Collection <string> logEntries = new Collection <string>(c.GetLogMessages());
                    logEntries.Reverse();

                    Dictionary <string, object> watcherSettings = c.GetWatcherStatus();

                    if (watcherSettings != null)
                    {
                        m = new Models.Admin.ControlPanel(logEntries,
                                                          watcherSettings.ContainsKey("ENABLED") ? Boolean.Parse(watcherSettings["ENABLED"].ToString()) : false,
                                                          watcherSettings.ContainsKey("BLOCKED") ? Boolean.Parse(watcherSettings["BLOCKED"].ToString()) : false,
                                                          watcherSettings.ContainsKey("TIMEOUT") ? UInt32.Parse(watcherSettings["TIMEOUT"].ToString()) : 0,
                                                          watcherSettings.ContainsKey("CHECKINTERNET") ? Boolean.Parse(watcherSettings["CHECKINTERNET"].ToString()) : false,
                                                          watcherSettings.ContainsKey("CHECKLAN") ? Boolean.Parse(watcherSettings["CHECKLAN"].ToString()) : false,
                                                          watcherSettings.ContainsKey("CHECKLOOPBACK") ? Boolean.Parse(watcherSettings["CHECKLOOPBACK"].ToString()) : false);
                    }
                }

                return(View["index.cshtml", m]);
            };

            Get["/toggle/{action}"] = parameters =>
            {
                string action = parameters["action"].ToString();

                switch (action.ToLower())
                {
                case "start":
                    c.SendStart();
                    Session["toggleMessage"] = "The server will now be started. Please refresh the page in a few seconds.";
                    Session["requiresDelay"] = true;
                    break;

                case "stop":
                    c.SendStop();
                    Session["toggleMessage"] = "The server will now be stopped. Please refresh the page in a few seconds.";
                    Session["requiresDelay"] = true;
                    break;

                case "restart":
                    c.SendRestart();
                    Session["toggleMessage"] = "The server will now be restarted. Please refresh the page in a few seconds.";
                    Session["requiresDelay"] = true;
                    break;

                case "kill":
                    c.SendKill();
                    Session["toggleMessage"] = "The server will now be killed. Please refresh the page in a few seconds.";
                    Session["requiresDelay"] = true;
                    break;
                }
                Helper.CachedVariables.UpdateCachedVariables();
                return(Response.AsRedirect("/admin"));
            };

            Get["/statistics"] = parameters =>
            {
                return(View["statistics.cshtml"]);
            };

            Get["/log/clear"] = parameters =>
            {
                c.ClearLogMessage();
                return(Response.AsRedirect("/admin"));
            };

            Get["/watcher/{action}"] = parameters =>
            {
                string action = parameters["action"].ToString();
                switch (action.ToLower())
                {
                case "start":
                    c.StartWatcher();
                    break;

                case "stop":
                    c.StopWatcher();
                    break;
                }
                return(Response.AsRedirect("/admin"));
            };

            Post["/watcher"] = parameters =>
            {
                string timeout = (string)Request.Form.Timeout;
                int    seconds;

                string checkInternet = (string)Request.Form.CheckInternet;
                string checkLan      = (string)Request.Form.CheckLAN;
                string checkLoopback = (string)Request.Form.CheckLoopback;

                if (Int32.TryParse(timeout, out seconds))
                {
                    c.SetWatcherTimeout(seconds);
                }

                c.SetWatcherCheckAccess(
                    checkInternet == "on" ? true : false,
                    checkLan == "on" ? true : false,
                    checkLoopback == "on" ? true : false
                    );

                Session["toggleMessage"] = "The configuration has been updated.";
                Session["requiresDelay"] = true;
                return(Response.AsRedirect("/admin"));
            };

            Get["/access"] = parameters =>
            {
                var message = Session.FirstOrDefault(o => o.Key == "kickMessage");

                if (message.Key != null)
                {
                    Context.ViewBag["kickMessage"] = message.Value;
                    Session.Delete("kickMessage");
                }

                Collection <string> connected  = new Collection <string>(c.GetConnectedPlayers());
                Collection <string> accessList = new Collection <string>(c.GetAccessListEntries());

                /*if (Helper.CachedVariables.PlayeridentificationEnabled)
                 *  Helper.PlayerIdentification.IdentifyPlayers(ref accessList);*/

                AccessMode mode = c.GetAccessMode();

                Models.Admin.Access m = new Models.Admin.Access(connected, accessList, mode);
                return(View["access", m]);
            };

            Post["/access"] = parameters =>
            {
                AccessMode mode    = AccessMode.Blacklist;
                string     modeRaw = (string)Request.Form.Mode;

                if (modeRaw != null)
                {
                    mode = (AccessMode)Enum.Parse(typeof(AccessMode), modeRaw);
                }

                List <string> accessList = null;

                string rawAccess = (string)Request.Form.List;
                if (rawAccess != null)
                {
                    accessList = new List <string>();

                    using (StringReader sr = new StringReader(rawAccess))
                    {
                        string line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            accessList.Add(line);
                        }
                    }
                }

                if (rawAccess != null)
                {
                    c.SetAccess(accessList, mode);
                }

                return(Response.AsRedirect("/admin/access"));
            };

            Get["/access/kick/{ip}"] = parameters =>
            {
                string    raw = parameters["ip"].ToString();
                IPAddress ip;

                if (IPAddress.TryParse(raw, out ip))
                {
                    c.KickPlayer(ip.ToString());
                    Session["kickMessage"] = String.Format("The player {0} should now be kicked", ip.ToString());
                }

                return(Response.AsRedirect("/admin/access"));
            };
        }
コード例 #9
0
ファイル: Admin.cs プロジェクト: ChrisK91/CWSRestart
        public Admin()
            : base("/admin")
        {
            CWSProtocol.Client c = new CWSProtocol.Client("AdminModule");
            IReadOnlyList<string> requiredClaims = new List<string> { Helper.Users.Authentication.ADMINISTRATOR };

            this.RequiresAuthentication();
            this.RequiresClaims(requiredClaims);

            Get["/"] = parameters =>
            {
                var message = Session.FirstOrDefault(o => o.Key == "toggleMessage");

                if (message.Key != null)
                {
                    Context.ViewBag["toggleMessage"] = message.Value;
                    Session.Delete("toggleMessage");
                }

                message = Session.FirstOrDefault(o => o.Key == "requiresDelay");
                Models.Admin.ControlPanel m = new Models.Admin.ControlPanel(null, false, true, 0, false, false, false);

                if (message.Key != null)
                {
                    Context.ViewBag["requiresDelay"] = true;
                    Session.Delete("requiresDelay");
                }
                else
                {
                    Collection<string> logEntries = new Collection<string>(c.GetLogMessages());
                    logEntries.Reverse();

                    Dictionary<string, object> watcherSettings = c.GetWatcherStatus();

                    if (watcherSettings != null)
                        m = new Models.Admin.ControlPanel(logEntries,
                            watcherSettings.ContainsKey("ENABLED") ? Boolean.Parse(watcherSettings["ENABLED"].ToString()) : false,
                            watcherSettings.ContainsKey("BLOCKED") ? Boolean.Parse(watcherSettings["BLOCKED"].ToString()) : false,
                            watcherSettings.ContainsKey("TIMEOUT") ? UInt32.Parse(watcherSettings["TIMEOUT"].ToString()) : 0,
                            watcherSettings.ContainsKey("CHECKINTERNET") ? Boolean.Parse(watcherSettings["CHECKINTERNET"].ToString()) : false,
                            watcherSettings.ContainsKey("CHECKLAN") ? Boolean.Parse(watcherSettings["CHECKLAN"].ToString()) : false,
                            watcherSettings.ContainsKey("CHECKLOOPBACK") ? Boolean.Parse(watcherSettings["CHECKLOOPBACK"].ToString()) : false);
                }

                return View["index.cshtml", m];
            };

            Get["/toggle/{action}"] = parameters =>
            {
                string action = parameters["action"].ToString();

                switch (action.ToLower())
                {
                    case "start":
                        c.SendStart();
                        Session["toggleMessage"] = "The server will now be started. Please refresh the page in a few seconds.";
                        Session["requiresDelay"] = true;
                        break;
                    case "stop":
                        c.SendStop();
                        Session["toggleMessage"] = "The server will now be stopped. Please refresh the page in a few seconds.";
                        Session["requiresDelay"] = true;
                        break;
                    case "restart":
                        c.SendRestart();
                        Session["toggleMessage"] = "The server will now be restarted. Please refresh the page in a few seconds.";
                        Session["requiresDelay"] = true;
                        break;
                    case "kill":
                        c.SendKill();
                        Session["toggleMessage"] = "The server will now be killed. Please refresh the page in a few seconds.";
                        Session["requiresDelay"] = true;
                        break;
                }
                Helper.CachedVariables.UpdateCachedVariables();
                return Response.AsRedirect("/admin");
            };

            Get["/statistics"] = parameters =>
            {
                return View["statistics.cshtml"];
            };

            Get["/log/clear"] = parameters =>
            {
                c.ClearLogMessage();
                return Response.AsRedirect("/admin");
            };

            Get["/watcher/{action}"] = parameters =>
            {
                string action = parameters["action"].ToString();
                switch (action.ToLower())
                {
                    case "start":
                        c.StartWatcher();
                        break;
                    case "stop":
                        c.StopWatcher();
                        break;
                }
                return Response.AsRedirect("/admin");
            };

            Post["/watcher"] = parameters =>
            {
                string timeout = (string)Request.Form.Timeout;
                int seconds;

                string checkInternet = (string)Request.Form.CheckInternet;
                string checkLan = (string)Request.Form.CheckLAN;
                string checkLoopback = (string)Request.Form.CheckLoopback;

                if (Int32.TryParse(timeout, out seconds))
                    c.SetWatcherTimeout(seconds);

                c.SetWatcherCheckAccess(
                    checkInternet == "on" ? true : false,
                    checkLan == "on" ? true : false,
                    checkLoopback == "on" ? true : false
                    );

                Session["toggleMessage"] = "The configuration has been updated.";
                Session["requiresDelay"] = true;
                return Response.AsRedirect("/admin");
            };

            Get["/access"] = parameters =>
            {
                var message = Session.FirstOrDefault(o => o.Key == "kickMessage");

                if (message.Key != null)
                {
                    Context.ViewBag["kickMessage"] = message.Value;
                    Session.Delete("kickMessage");
                }

                Collection<string> connected = new Collection<string>(c.GetConnectedPlayers());
                Collection<string> accessList = new Collection<string>(c.GetAccessListEntries());

                /*if (Helper.CachedVariables.PlayeridentificationEnabled)
                    Helper.PlayerIdentification.IdentifyPlayers(ref accessList);*/

                AccessMode mode = c.GetAccessMode();

                Models.Admin.Access m = new Models.Admin.Access(connected, accessList, mode);
                return View["access", m];
            };

            Post["/access"] = parameters =>
                {
                    AccessMode mode = AccessMode.Blacklist;
                    string modeRaw = (string)Request.Form.Mode;

                    if (modeRaw != null)
                        mode = (AccessMode)Enum.Parse(typeof(AccessMode), modeRaw);

                    List<string> accessList = null;

                    string rawAccess = (string)Request.Form.List;
                    if (rawAccess != null)
                    {
                        accessList = new List<string>();

                        using (StringReader sr = new StringReader(rawAccess))
                        {
                            string line;
                            while ((line = sr.ReadLine()) != null)
                                accessList.Add(line);
                        }
                    }

                    if (rawAccess != null)
                        c.SetAccess(accessList, mode);

                    return Response.AsRedirect("/admin/access");
                };

            Get["/access/kick/{ip}"] = parameters =>
            {
                string raw = parameters["ip"].ToString();
                IPAddress ip;

                if (IPAddress.TryParse(raw, out ip))
                {
                    c.KickPlayer(ip.ToString());
                    Session["kickMessage"] = String.Format("The player {0} should now be kicked", ip.ToString());
                }

                return Response.AsRedirect("/admin/access");
            };
        }