Example #1
0
        /// <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);
        }