Exemplo n.º 1
0
        /// <summary>
        /// Loads a ConfigurationModule from a file at a given path.
        /// </summary>
        /// <param name="sPath">The path of the configuration file to load.</param>
        /// <returns>ConfigurationModule holding the loaded configurations.</returns>
        public static ConfigurationModule LoadFromFile(string sPath)
        {
            if (!File.Exists(sPath))
                throw new FileNotFoundException("File at path \"" + sPath + "\" does not exist.");

            ConfigurationModule pConfig = new ConfigurationModule();
            using (StreamReader pReader = new StreamReader(sPath))
            {
                string sLine = null;
                while ((sLine = pReader.ReadLine()) != null)
                {
                    if (sLine.Length == 0 || sLine[0] == '#')
                        continue; // This line is empty/a comment

                    int indexOfDelimiter = sLine.IndexOf('=');
                    if (indexOfDelimiter != -1)
                    {
                        string sKey = sLine.Substring(0, indexOfDelimiter);
                        if (!pConfig.mContent.ContainsKey(sKey))
                        {
                            string sValue = sLine.Substring(indexOfDelimiter + 1);
                            pConfig.mContent.Add(sKey, sValue);
                        }
                    }
                }
                pReader.Close();
            }

            return pConfig;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the Ion server environment.
        /// </summary>
        public static void Initialize()
        {
            mLog.MinimumLogImportancy = LogType.Debug;
            mLog.WriteLine("Initializing Ion environment.");

            try
            {
                // Try to initialize configuration
                try
                {
                    mConfig = ConfigurationModule.LoadFromFile("settings");
                }
                catch (FileNotFoundException ex)
                {
                    mLog.WriteError("Failed to load configuration file, exception message was: " + ex.Message);
                    IonEnvironment.Destroy();
                    return;
                }

                // Initialize database and test a connection by getting & releasing it
                DatabaseServer pDatabaseServer = new DatabaseServer(
                    IonEnvironment.Configuration["db1.server.host"],
                    IonEnvironment.Configuration.TryParseUInt32("db1.server.port"),
                    IonEnvironment.Configuration["db1.server.uid"],
                    IonEnvironment.Configuration["db1.server.pwd"]);

                Database pDatabase = new Database(
                    IonEnvironment.Configuration["db1.name"],
                    IonEnvironment.Configuration.TryParseUInt32("db1.minpoolsize"),
                    IonEnvironment.Configuration.TryParseUInt32("db1.maxpoolsize"));

                mDatabaseManager = new DatabaseManager(pDatabaseServer, pDatabase);
                mDatabaseManager.SetClientAmount(2);
                mDatabaseManager.ReleaseClient(mDatabaseManager.GetClient().Handle);
                mDatabaseManager.StartMonitor();

                // Initialize TCP listener
                mTcconnectionManager = new IonTcpConnectionManager(
                    IonEnvironment.Configuration["net.tcp.localip"],
                    IonEnvironment.Configuration.TryParseInt32("net.tcp.port"),
                    IonEnvironment.Configuration.TryParseInt32("net.tcp.maxcon"));
                mTcconnectionManager.GetListener().Start();

                // Try to initialize Habbo Hotel
                mHabboHotel = new Ion.HabboHotel.HabboHotel();

                IonEnvironment.GetLog().WriteLine("Initialized Ion environment.");
            }
            catch (Exception ex) // Catch all other exceptions
            {
                mLog.WriteError("Unhandled exception occurred during initialization of Ion environment. Exception message: " + ex.Message);
            }
        }