/// <summary> /// Constructs a DatabaseManager for given database server and database details. /// </summary> /// <param name="sServer">The network host of the database server, eg 'localhost' or '127.0.0.1'.</param> /// <param name="Port">The network port of the database server as an unsigned 32 bit integer.</param> /// <param name="sUser">The username to use when connecting to the database.</param> /// <param name="sPassword">The password to use in combination with the username when connecting to the database.</param> /// <param name="sDatabase">The name of the database to connect to.</param> /// <param name="minPoolSize">The minimum connection pool size for the database.</param> /// <param name="maxPoolSize">The maximum connection pool size for the database.</param> public DatabaseManager(string sServer, uint Port, string sUser, string sPassword, string sDatabase, uint minPoolSize, uint maxPoolSize) { mServer = new DatabaseServer(sServer, Port, sUser, sPassword); mDatabase = new Database(sDatabase, minPoolSize, maxPoolSize); mClientMonitor = new Thread(MonitorClientsLoop); mClientMonitor.Priority = ThreadPriority.Lowest; mClientMonitor.Start(); }
/// <summary> /// Constructs a DatabaseManager for a given DatabaseServer and Database. /// </summary> /// <param name="pServer">The DatabaseServer for this database proxy.</param> /// <param name="pDatabase">The Database for this database proxy.</param> public DatabaseManager(DatabaseServer pServer, Database pDatabase) { mServer = pServer; mDatabase = pDatabase; }
/// <summary> /// Nulls all instance fields of the database manager. /// </summary> public void DestroyManager() { mServer = null; mDatabase = null; mClients = null; mClientAvailable = null; mClientMonitor = null; }
/// <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); } }