示例#1
0
文件: ServerCore.cs 项目: habb0/IHI
        private void SaveConfigInstallation()
        {
            Install.Core installer = CoreManager.InstallerCore;


            _standardOut.PrintImportant("Updating configuration file... (Install)");

            XmlDocument doc         = _config.GetInternalDocument();
            XmlNode     rootElement = doc.SelectSingleNode("/config");

            XmlElement standardOutElement = doc.CreateElement("standardout");
            XmlElement mySQLElement       = doc.CreateElement("mysql");
            XmlElement networkElement     = doc.CreateElement("network");
            XmlElement webAdminElement    = doc.CreateElement("webadmin");

            #region StandardOut

            #region Importance

            XmlElement valueElement = doc.CreateElement("importance");
            valueElement.InnerText = installer.GetInstallerOutputValue("StandardOut", "Importance").ToString();
            standardOutElement.AppendChild(valueElement);

            #endregion

            #endregion

            #region MySQL

            #region Host

            valueElement           = doc.CreateElement("host");
            valueElement.InnerText = installer.GetInstallerOutputValue("Database", "Host").ToString();
            mySQLElement.AppendChild(valueElement);

            #endregion

            #region Port

            valueElement           = doc.CreateElement("port");
            valueElement.InnerText = installer.GetInstallerOutputValue("Database", "Port").ToString();
            mySQLElement.AppendChild(valueElement);

            #endregion

            #region User

            valueElement           = doc.CreateElement("user");
            valueElement.InnerText = installer.GetInstallerOutputValue("Database", "Username").ToString();
            mySQLElement.AppendChild(valueElement);

            #endregion

            #region Password

            valueElement           = doc.CreateElement("password");
            valueElement.InnerText = installer.GetInstallerOutputValue("Database", "Password").ToString();
            mySQLElement.AppendChild(valueElement);

            #endregion

            #region Database

            valueElement           = doc.CreateElement("database");
            valueElement.InnerText = installer.GetInstallerOutputValue("Database", "DatebaseName").ToString();
            mySQLElement.AppendChild(valueElement);

            #endregion

            #region MinPoolSize

            valueElement           = doc.CreateElement("minpoolsize");
            valueElement.InnerText = installer.GetInstallerOutputValue("Database", "MinimumPoolSize").ToString();
            mySQLElement.AppendChild(valueElement);

            #endregion

            #region MaxPoolSize

            valueElement           = doc.CreateElement("maxpoolsize");
            valueElement.InnerText = installer.GetInstallerOutputValue("Database", "MaximumPoolSize").ToString();
            mySQLElement.AppendChild(valueElement);

            #endregion

            #endregion

            #region Network

            #region Host

            valueElement           = doc.CreateElement("host");
            valueElement.InnerText = installer.GetInstallerOutputValue("Network", "GameHost").ToString();
            networkElement.AppendChild(valueElement);

            #endregion

            #region Port

            valueElement           = doc.CreateElement("port");
            valueElement.InnerText = installer.GetInstallerOutputValue("Network", "GamePort").ToString();
            networkElement.AppendChild(valueElement);

            #endregion

            #endregion

            #region WebAdmin

            #region Port

            valueElement           = doc.CreateElement("port");
            valueElement.InnerText = installer.GetInstallerOutputValue("Network", "WebAdminPort").ToString();
            webAdminElement.AppendChild(valueElement);

            #endregion

            #endregion

            rootElement.AppendChild(standardOutElement);
            rootElement.AppendChild(mySQLElement);
            rootElement.AppendChild(networkElement);
            rootElement.AppendChild(webAdminElement);

            _config.Save();
            _standardOut.PrintImportant("Configuration file saved!");
        }
示例#2
0
文件: ServerCore.cs 项目: habb0/IHI
        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;
            }
        }
示例#3
0
文件: ServerCore.cs 项目: habb0/IHI
        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);
            }
        }