/// <summary> /// Destroys all resources in the connection listener. /// </summary> public void Destroy() { Stop(); mListener = null; mManager = null; mFactory = null; }
/// <summary> /// Constructs an IonTcpConnection listener and binds it to a given local IP address and TCP port. /// </summary> /// <param name="sLocalIP">The IP address string to parse and bind the listener to.</param> /// <param name="Port">The TCP port number to parse the listener to.</param> public IonTcpConnectionListener(string sLocalIP, int Port, IonTcpConnectionManager pManager) { IPAddress pIP = null; if(!IPAddress.TryParse(sLocalIP, out pIP)) { pIP = IPAddress.Loopback; IonEnvironment.GetLog().WriteWarning(string.Format("Connection listener was unable to parse the given local IP address '{0}', now binding listener to '{1}'.", sLocalIP, pIP.ToString())); } mListener = new TcpListener(pIP, Port); mConnectionRequestCallback = new AsyncCallback(ConnectionRequest); mFactory = new IonTcpConnectionFactory(); mManager = pManager; IonEnvironment.GetLog().WriteLine(string.Format("IonTcpConnectionListener initialized and bound to {0}:{1}.", pIP.ToString(), Port.ToString())); }
/// <summary> /// Constructs an IonTcpConnection listener and binds it to a given local IP address and TCP port. /// </summary> /// <param name="sLocalIP">The IP address string to parse and bind the listener to.</param> /// <param name="Port">The TCP port number to parse the listener to.</param> public IonTcpConnectionListener(string sLocalIP, int Port, IonTcpConnectionManager pManager) { IPAddress pIP = null; if (!IPAddress.TryParse(sLocalIP, out pIP)) { pIP = IPAddress.Loopback; IonEnvironment.GetLog().WriteWarning(string.Format("Connection listener was unable to parse the given local IP address '{0}', now binding listener to '{1}'.", sLocalIP, pIP.ToString())); } mListener = new TcpListener(pIP, Port); mConnectionRequestCallback = new AsyncCallback(ConnectionRequest); mFactory = new IonTcpConnectionFactory(); mManager = pManager; IonEnvironment.GetLog().WriteLine(string.Format("IonTcpConnectionListener initialized and bound to {0}:{1}.", pIP.ToString(), Port.ToString())); }
/// <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); } }