/// <summary> /// Master server constructor. Initialises child objects, helpers and listeners /// </summary> /// <param name="statusDisplay"></param> /// <param name="commandInterface"></param> private MasterServer(IStatusDisplay statusDisplay, ICommandInterface commandInterface, ICDKeyValidator cdKeyValidator, IGameStatsLog gameStats, ILogWriter logWriter) { if (MasterServer.instance != null) { throw new InvalidOperationException("Attempted to create a Master Server instance whilst another instance was still active"); } // Assign static references MasterServer.instance = this; MasterServer.logWriter = logWriter; // Assign instance references this.statusDisplay = statusDisplay; this.commandInterface = commandInterface; this.cdKeyValidator = cdKeyValidator; this.gameStats = gameStats; // Initialise the command interface if we have one if (commandInterface != null) { commandInterface.OnChange += new EventHandler(DisplayCommandInterface); } // GeoIP resolver is used to resolve IP addresses to locations geoIP = new GeoIP(); // MD5 database is used to download new MD5 package data to connecting servers md5Manager = new MD5Manager(); // IP ban manager used to ban clients from accessing the server banManager = new IPBanManager(); // Create the Server List object serverList = new ServerList(this); // Create the web server webServer = new WebServer(banManager); // Initialise the status display module if we have one if (statusDisplay != null) { logBufferSize = statusDisplay.LogBufferSize; logBufferWrap = statusDisplay.LogBufferWrap; displayTimer = new Timer(new TimerCallback(this.Display)); Display(null); } // Load the GeoIP database, MD5 database and ban list from the files (this happens last because they may take a while) geoIP.Load(MasterServer.Settings.GeoIPDataFile); md5Manager.Load(MasterServer.Settings.MD5DataFile); banManager.Load(MasterServer.Settings.BanListFile); }
/// <summary> /// Shut down the master server instance /// </summary> private void Shutdown() { // End listen thread and close the listen sockets EndListening(); // Web server if (webServer != null) { webServer.Dispose(); webServer = null; } // Shut down the server list if (serverList != null) { serverList.Shutdown(); serverList = null; } // Ban manager if (banManager != null) { banManager.Dispose(); banManager = null; } // MD5 database if (md5Manager != null) { md5Manager.Dispose(); md5Manager = null; } // GeoIP resolver if (geoIP != null) { geoIP.Dispose(); geoIP = null; } // Display update timer if (displayTimer != null) { displayTimer.Change(Timeout.Infinite, Timeout.Infinite); displayTimer.Dispose(); displayTimer = null; } // Shut down the status display if we have one if (statusDisplay != null) { statusDisplay.Notify("EXIT"); ModuleManager.ReleaseModule <IStatusDisplay>(); statusDisplay = null; } // Shut down the command interface if we have one if (commandInterface != null) { commandInterface.OnChange -= new EventHandler(DisplayCommandInterface); ModuleManager.ReleaseModule <ICommandInterface>(); commandInterface = null; } }