Ejemplo n.º 1
0
        public override void Start()
        {
            _handlers = new Handlers(this);
            WebAdminManager webAdminManager = CoreManager.ServerCore.GetWebAdminManager();

            webAdminManager.AddPathHandler("/admin/stdout", _handlers.PageIndex);
            webAdminManager.AddPathHandler("/admin/stdout/send", _handlers.PageMessage);
            webAdminManager.AddPathHandler("/admin/stdout/update", _handlers.PageUpdate);
        }
Ejemplo n.º 2
0
        public void Shutdown(bool directShutdown = false)
        {
            Console.TreatControlCAsInput = true;

            // If Config is not set then nothing is and we are already done.
            if (Config == null)
            {
                return;
            }

            lock (_bootInProgressLocker)
            {
                if (directShutdown)
                {
                    Console.Beep(1000, 100);
                    Console.Beep(1000, 100);

                    // Clear out previous input.
                    while (Console.KeyAvailable)
                    {
                        Console.ReadKey(true);
                    }

                    Console.WriteLine();
                    Console.WriteLine("Are you sure you want to shutdown?");
                    Console.WriteLine("Press Y to confirm!");
                    Console.WriteLine();

                    if (Console.ReadKey(true).Key != ConsoleKey.Y)
                    {
                        Console.TreatControlCAsInput = false;
                        Console.WriteLine("Shutdown cancelled.");
                        return;
                    }
                    Console.WriteLine("Shutting down. Please wait...");
                }

                Thread forceThread = new Thread(new ThreadStart(ForceShutdown));
                forceThread.IsBackground = true;
                forceThread.Start();

                CoreManager.ServerCore.OfficalEventFirer.Fire("shutdown", EventPriority.Before, this, EventArgs.Empty);
                CoreManager.ServerCore.OfficalEventFirer.Fire("shutdown", EventPriority.After, this, EventArgs.Empty);

                WebAdminManager.Stop();


                Console.Beep(4000, 100);
                Console.Beep(3500, 100);
                Console.Beep(3000, 100);
                Console.Beep(2500, 100);
                Console.Beep(2000, 100);
                Console.Beep(1500, 100);
                Console.Beep(1000, 100);
            }
        }
Ejemplo n.º 3
0
        internal void PageIndex(HttpListenerContext context)
        {
            if (context.Request.IsLocal)
            {
                WebAdminManager.SendResponse(context.Response, _plugin.Name,
                                             @"<!DOCTYPE html>
<html>
	<head>
		<title>IHI Web Admin Example</title>
		<style type='text/css'>
			body
			{
				background-color: #DDD;
			}
		</style>
		<script type='text/javascript' src='http://code.jquery.com/jquery-1.6.1.min.js'></script>
		<script type='text/javascript'>
			function Send(event)
			{
				if(event.keyCode == 13)
				{
					jQuery.get('/admin/stdout/send?level=' + $('#importancea')[0].value + '&data=' + $('#textbox')[0].value);
				}
			}
			function Update()
			{
			    jQuery.get('/admin/stdout/update?level=' + $('#importanceb')[0].value);
			}
		</script>
	</head>
	<body>
        <b>Send</b>
		<select id='importancea'>
			<option value='0'>Debug</option>
			<option value='1'>Notice</option>
			<option value='2'>Important</option>
			<option value='3'>Warning</option>
			<option value='4'>Error</option>
		</select>
		<input id='textbox' type='textbox' size='100' onkeydown='Send(event)'><br>
        <br>
        <b>Importance Filter</b>
        <select id='importanceb' onchange='Update()'>
			<option value='0'>Debug</option>
			<option value='1'>Notice</option>
			<option value='2'>Important</option>
			<option value='3'>Warning</option>
			<option value='4'>Error</option>
		</select>
	</body>
</html>");
            }
        }
Ejemplo n.º 4
0
        internal void PageMessage(HttpListenerContext context)
        {
            if (!context.Request.IsLocal)
            {
                return;
            }
            string level = context.Request.QueryString["level"];
            string data  = context.Request.QueryString["data"];
            byte   levelByte;

            if (byte.TryParse(level, out levelByte))
            {
                switch (levelByte)
                {
                case 0:
                    CoreManager.ServerCore.GetStandardOut().PrintDebug(data);
                    break;

                case 1:
                    CoreManager.ServerCore.GetStandardOut().PrintNotice(data);
                    break;

                case 2:
                    CoreManager.ServerCore.GetStandardOut().PrintImportant(data);
                    break;

                case 3:
                    CoreManager.ServerCore.GetStandardOut().PrintWarning(data);
                    break;

                case 4:
                    CoreManager.ServerCore.GetStandardOut().PrintError(data);
                    break;

                default:
                {
                    WebAdminManager.SendResponse(context.Response,
                                                 _plugin.Name,
                                                 "FAILURE");
                    return;
                }
                }
                WebAdminManager.SendResponse(context.Response, _plugin.Name,
                                             "SUCCESS");
                return;
            }
            WebAdminManager.SendResponse(context.Response, _plugin.Name,
                                         "FAILURE");
        }
Ejemplo n.º 5
0
        internal void PageUpdate(HttpListenerContext context)
        {
            if (!context.Request.IsLocal)
            {
                return;
            }
            string level = context.Request.QueryString["level"];
            byte   levelByte;

            if (byte.TryParse(level, out levelByte))
            {
                if (levelByte <= 4)
                {
                    CoreManager.ServerCore.GetStandardOut().SetImportance((StandardOutImportance)levelByte);
                    WebAdminManager.SendResponse(context.Response, _plugin.Name,
                                                 "SUCCESS");
                    return;
                }
            }
            WebAdminManager.SendResponse(context.Response, _plugin.Name,
                                         "FAILURE");
        }
Ejemplo n.º 6
0
        public void Shutdown(bool terminate = true)
        {
            lock (_bootInProgressLocker)
            {
                if (ConsoleManager == null)
                {
                    return;
                }

                ConsoleManager.Warning("Core", "Shutting down IHI!");

                if (CoreManager.ServerCore.OfficalEventFirer == null)
                {
                    return;
                }

                IHIEventArgs eventArgs = new IHIEventArgs();
                CoreManager.ServerCore.OfficalEventFirer.Fire("shutdown:before", eventArgs);
                CoreManager.ServerCore.OfficalEventFirer.Fire("shutdown:after", eventArgs);

                if (WebAdminManager == null)
                {
                    return;
                }

                WebAdminManager.Stop();

                Config = null;

                System.Console.Beep(4000, 100);
                System.Console.Beep(3500, 100);
                System.Console.Beep(3000, 100);
                System.Console.Beep(2500, 100);
                System.Console.Beep(2000, 100);
                System.Console.Beep(1500, 100);
                System.Console.Beep(1000, 100);
            }
        }
Ejemplo n.º 7
0
 public void BootTaskStartWebAdmin()
 {
     StandardOut.Notice("Web Admin", StringLocale.GetString("CORE:BOOT_WEBADMIN_PREPARE"));
     WebAdminManager = new WebAdminManager(Config.ValueAsUshort("/config/webadmin/port", 14480));
     StandardOut.Notice("Web Admin", StringLocale.GetString("CORE:BOOT_WEBADMIN_READY"));
 }
Ejemplo n.º 8
0
        internal BootResult Boot(string configPath)
        {
            try
            {
                _textEncoding = Encoding.UTF8; // TODO: Move this to an external config.

                #region Standard Out

                _standardOut = new StandardOut();
                _standardOut.PrintNotice("Text Encoding => Set to " + _textEncoding.EncodingName);
                _standardOut.PrintNotice("Standard Out => Ready");

                #endregion

                _config = new XmlConfig(configPath);

                bool mainInstallRequired = PreInstall(); // Register the main installation if required.

                #region Load Plugins

                _standardOut.PrintNotice("Plugin Manager => Loading plugins...");
                _pluginManager = new PluginManager();

                XmlNodeList pluginNodes = GetConfig().GetInternalDocument().SelectNodes("/config/plugins/plugin");
                foreach (XmlNode pluginNode in pluginNodes)
                {
                    GetPluginManager().LoadPluginAtPath(
                        Path.Combine(
                            Directory.GetCurrentDirectory(),
                            "plugins",
                            pluginNode.Attributes["filename"].InnerText));
                }
                _standardOut.PrintNotice("Plugin Manager => Plugins loaded!");

                #endregion

                CoreManager.InstallerCore.Run();

                if (mainInstallRequired)
                {
                    SaveConfigInstallation();
                }

                #region Config

                _standardOut.PrintNotice("Config File => Loaded");
                _standardOut.SetImportance(
                    (StandardOutImportance)
                    _config.ValueAsByte("/config/standardout/importance", (byte)StandardOutImportance.Debug));

                #endregion

                #region Database

                _standardOut.PrintNotice("MySQL => Preparing database connection settings...");

                try
                {
                    MySqlConnectionStringBuilder connectionString = new MySqlConnectionStringBuilder
                    {
                        Server =
                            _config.ValueAsString(
                                "/config/mysql/host"),
                        Port =
                            _config.ValueAsUint(
                                "/config/mysql/port", 3306),
                        UserID =
                            _config.ValueAsString(
                                "/config/mysql/user"),
                        Password =
                            _config.ValueAsString(
                                "/config/mysql/password"),
                        Database =
                            _config.ValueAsString(
                                "/config/mysql/database"),
                        Pooling         = true,
                        MinimumPoolSize =
                            _config.ValueAsUint(
                                "/config/mysql/minpoolsize", 1),
                        MaximumPoolSize =
                            _config.ValueAsUint(
                                "/config/mysql/maxpoolsize", 25)
                    };

                    PrepareSessionFactory(connectionString.ConnectionString);

                    _standardOut.PrintNotice("MySQL => Testing connection...");

                    using (ISession db = GetDatabaseSession())
                    {
                        if (!db.IsConnected)
                        {
                            throw new Exception("Unknown cause");
                        }
                    }
                }
                catch (Exception ex)
                {
                    _standardOut.PrintError("MySQL => Connection failed!");
                    throw;
                }
                _standardOut.PrintNotice("MySQL => Connected!");

                #endregion

                #region Distributors

                _standardOut.PrintNotice("Habbo Distributor => Constructing...");
                _habboDistributor = new HabboDistributor();
                _standardOut.PrintNotice("Habbo Distributor => Ready");

                #endregion

                #region Figure Factory

                _standardOut.PrintNotice("Habbo Figure Factory => Constructing...");
                _habboFigureFactory = new HabboFigureFactory();
                _standardOut.PrintNotice("Habbo Figure Factory => Ready");

                #endregion

                // TODO: Download Requirements

                #region Permissions

                _standardOut.PrintNotice("Permission Manager => Constructing...");
                _permissionManager = new PermissionManager();
                _standardOut.PrintNotice("Permission Manager => Ready");

                #endregion

                // TODO: Write Dynamic Client Files
                // TODO: Authenticate with IHINet

                #region Network

                _standardOut.PrintNotice("Connection Manager => Starting...");
                _connectionManager = new IonTcpConnectionManager(_config.ValueAsString("/config/network/host"),
                                                                 _config.ValueAsInt("/config/network/port", 14478));
                _connectionManager.GetListener().Start();
                _standardOut.PrintNotice("Connection Manager => Ready!");

                _standardOut.PrintNotice("Web Admin => Starting...");
                _webAdminManager = new WebAdminManager(_config.ValueAsUshort("/config/webadmin/port", 14480));
                _standardOut.PrintNotice("Web Admin => Ready!");

                #endregion

                #region Start Plugins

                PluginManager pluginManager = GetPluginManager();
                _standardOut.PrintNotice("Plugin Manager => Starting plugins...");

                foreach (Plugin plugin in pluginManager.GetLoadedPlugins())
                {
                    pluginManager.StartPlugin(plugin);
                }
                _standardOut.PrintNotice("Plugin Manager => Plugins started!");

                #endregion

                _standardOut.PrintImportant("IHI is now functional!");

                return(BootResult.AllClear);
            }
            catch (Exception e)
            {
                _standardOut.PrintException(e);


                if (e is MappingException)
                {
                    return(BootResult.MySQLMappingFailure);
                }

                return(BootResult.UnknownFailure);
            }
        }
Ejemplo n.º 9
0
 public void BootTaskStartWebAdmin()
 {
     ConsoleManager.Notice("Web Admin", StringLocale.GetString("CORE:BOOT_WEBADMIN_PREPARE"));
     WebAdminManager = new WebAdminManager(Config.GetValue <ushort>("webadmin:port", 14480).Value);
     ConsoleManager.Notice("Web Admin", StringLocale.GetString("CORE:BOOT_WEBADMIN_READY"));
 }