Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Server"/> class.
        /// </summary>
        /// <exception cref="NotSupportedException">NetGore does not support systems that are not in Little Endian mode!</exception>
        public Server()
        {
            ThreadAsserts.IsMainThread();

            // Check for some system settings
            if (!BitConverter.IsLittleEndian)
            {
                const string errmsg = "NetGore does not support systems that are not in Little Endian mode!";
                log.Fatal(errmsg);
                throw new NotSupportedException(errmsg);
            }

            // Check if patching is needed
            int numMissingPatches = -1;

            try
            {
                numMissingPatches = ServerDbPatcher.GetMissingPatches().Length;
            }
            catch (Exception ex)
            {
                log.WarnFormat("Failed to find DbPatches directory, so could not check if patching is required. Exception: {0}", ex);
            }

            if (numMissingPatches > 0)
            {
                log.ErrorFormat("There are `{0}` NetGore db patches not applied. Please backup your database then run /DemoGame.Server/DbPatches/Patch.bat.", numMissingPatches);
                log.ErrorFormat("Server will auto-close after 10 seconds, and will keep doing this until you patch.");
                Thread.Sleep(10 * 1000);
                return;
            }

            // Initialize the engine settings
            EngineSettingsInitializer.Initialize();

            // Create the DbController
            _dbController = CreateDbController();

            // Add the query stats tracker
            var queryStats = new BasicQueryStatsTracker {
                LogFilePath = ContentPaths.Build.Root.Join("querystats.txt")
            };

            queryStats.LogFileFrequency             = 1000 * 5;
            _dbController.ConnectionPool.QueryStats = queryStats;

            // Validate the database
            DbTableValidator.ValidateTables(_dbController);
            ValidateDbControllerQueryAttributes();

            // Clean-up
            var cleaner = new ServerCleaner(this);

            cleaner.Run();

            // Create some objects
            _consoleCommands    = new ConsoleCommands(this);
            _groupManager       = new GroupManager((gm, x) => new Group(x));
            _userAccountManager = new UserAccountManager(DbController);
            _world   = new World(this);
            _sockets = new ServerSockets(this);

            WorldStatsTracker.Instance.NetPeerToTrack = _sockets.GetNetServer();

            // Check for the password salt
            if (string.IsNullOrEmpty(ServerSettings.Default.PasswordSalt))
            {
                const string errmsg =
                    "No password salt has been defined in the server settings file. Make sure you define one before releasing.";
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat(errmsg);
                }
            }

            // Set the thread priority
            SetThreadPriority(ServerSettings.Default.ThreadPriority);

            // Validate the server's settings
            var ssv = new ServerSettingsValidator();

            ssv.Check(this);

            if (log.IsInfoEnabled)
            {
                log.Info("Server loaded.");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Server"/> class.
        /// </summary>
        /// <exception cref="NotSupportedException">NetGore does not support systems that are not in Little Endian mode!</exception>
        public Server()
        {
            // Check for some system settings
            if (!BitConverter.IsLittleEndian)
            {
                const string errmsg = "NetGore does not support systems that are not in Little Endian mode!";
                log.Fatal(errmsg);
                throw new NotSupportedException(errmsg);
            }

            // Initialize the engine settings
            EngineSettingsInitializer.Initialize();

            // Create the DbController
            var settings = new DbConnectionSettings();
            _dbController =
                settings.CreateDbControllerPromptEditWhenInvalid(x => new ServerDbController(x.GetMySqlConnectionString()),
                    x => PromptEditDbSettingsFile(settings, x));

            if (_dbController == null)
                return;

            // Add the query stats tracker
            var queryStats = new BasicQueryStatsTracker { LogFilePath = ContentPaths.Build.Root.Join("querystats.txt") };
            queryStats.LogFileFrequency = 1000 * 5;
            _dbController.ConnectionPool.QueryStats = queryStats;

            // Validate the database
            DbTableValidator.ValidateTables(_dbController);
            ValidateDbControllerQueryAttributes();

            // Clean-up
            var cleaner = new ServerCleaner(this);
            cleaner.Run();

            // Load the game data and such
            InitializeScripts();

            // Create some objects
            _consoleCommands = new ConsoleCommands(this);
            _groupManager = new GroupManager((gm, x) => new Group(x));
            _userAccountManager = new UserAccountManager(DbController);
            _world = new World(this);
            _sockets = new ServerSockets(this);

            WorldStatsTracker.Instance.NetPeerToTrack = _sockets.GetNetServer();

            // Check for the password salt
            if (string.IsNullOrEmpty(ServerSettings.Default.PasswordSalt))
            {
                const string errmsg =
                    "No password salt has been defined in the server settings file. Make sure you define one before releasing.";
                if (log.IsWarnEnabled)
                    log.WarnFormat(errmsg);
            }

            // Set the thread priority
            SetThreadPriority(ServerSettings.Default.ThreadPriority);

            // Validate the server's settings
            var ssv = new ServerSettingsValidator();
            ssv.Check(this);

            if (log.IsInfoEnabled)
                log.Info("Server loaded.");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Server"/> class.
        /// </summary>
        /// <exception cref="NotSupportedException">NetGore does not support systems that are not in Little Endian mode!</exception>
        public Server()
        {
            ThreadAsserts.IsMainThread();

            // Check for some system settings
            if (!BitConverter.IsLittleEndian)
            {
                const string errmsg = "NetGore does not support systems that are not in Little Endian mode!";
                log.Fatal(errmsg);
                throw new NotSupportedException(errmsg);
            }

            // Check if patching is needed
            int numMissingPatches = -1;
            try
            {
                numMissingPatches = ServerDbPatcher.GetMissingPatches().Length;
            }
            catch (Exception ex)
            {
                log.WarnFormat("Failed to find DbPatches directory, so could not check if patching is required. Exception: {0}", ex);
            }

            if (numMissingPatches > 0)
            {
                log.ErrorFormat("There are `{0}` NetGore db patches not applied. Please backup your database then run /DemoGame.Server/DbPatches/Patch.bat.", numMissingPatches);
                log.ErrorFormat("Server will auto-close after 10 seconds, and will keep doing this until you patch.");
                Thread.Sleep(10 * 1000);
                return;
            }

            // Initialize the engine settings
            EngineSettingsInitializer.Initialize();

            // Create the DbController
            _dbController = CreateDbController();

            // Add the query stats tracker
            var queryStats = new BasicQueryStatsTracker { LogFilePath = ContentPaths.Build.Root.Join("querystats.txt") };
            queryStats.LogFileFrequency = 1000 * 5;
            _dbController.ConnectionPool.QueryStats = queryStats;

            // Validate the database
            DbTableValidator.ValidateTables(_dbController);
            ValidateDbControllerQueryAttributes();

            // Clean-up
            var cleaner = new ServerCleaner(this);
            cleaner.Run();

            // Create some objects
            _consoleCommands = new ConsoleCommands(this);
            _groupManager = new GroupManager((gm, x) => new Group(x));
            _userAccountManager = new UserAccountManager(DbController);
            _world = new World(this);
            _sockets = new ServerSockets(this);

            WorldStatsTracker.Instance.NetPeerToTrack = _sockets.GetNetServer();

            // Check for the password salt
            if (string.IsNullOrEmpty(ServerSettings.Default.PasswordSalt))
            {
                const string errmsg =
                    "No password salt has been defined in the server settings file. Make sure you define one before releasing.";
                if (log.IsWarnEnabled)
                    log.WarnFormat(errmsg);
            }

            // Set the thread priority
            SetThreadPriority(ServerSettings.Default.ThreadPriority);

            // Validate the server's settings
            var ssv = new ServerSettingsValidator();
            ssv.Check(this);

            if (log.IsInfoEnabled)
                log.Info("Server loaded.");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Server"/> class.
        /// </summary>
        /// <exception cref="NotSupportedException">NetGore does not support systems that are not in Little Endian mode!</exception>
        public Server()
        {
            // Check for some system settings
            if (!BitConverter.IsLittleEndian)
            {
                const string errmsg = "NetGore does not support systems that are not in Little Endian mode!";
                log.Fatal(errmsg);
                throw new NotSupportedException(errmsg);
            }

            // Initialize the engine settings
            EngineSettingsInitializer.Initialize();

            // Create the DbController
            var settings = new DbConnectionSettings();

            _dbController =
                settings.CreateDbControllerPromptEditWhenInvalid(x => new ServerDbController(x.GetMySqlConnectionString()),
                                                                 x => PromptEditDbSettingsFile(settings, x));

            if (_dbController == null)
            {
                return;
            }

            // Add the query stats tracker
            var queryStats = new BasicQueryStatsTracker {
                LogFilePath = ContentPaths.Build.Root.Join("querystats.txt")
            };

            queryStats.LogFileFrequency             = 1000 * 5;
            _dbController.ConnectionPool.QueryStats = queryStats;

            // Validate the database
            DbTableValidator.ValidateTables(_dbController);
            ValidateDbControllerQueryAttributes();

            // Clean-up
            var cleaner = new ServerCleaner(this);

            cleaner.Run();

            // Load the game data and such
            InitializeScripts();

            // Create some objects
            _consoleCommands    = new ConsoleCommands(this);
            _groupManager       = new GroupManager((gm, x) => new Group(x));
            _userAccountManager = new UserAccountManager(DbController);
            _world   = new World(this);
            _sockets = new ServerSockets(this);

            WorldStatsTracker.Instance.NetPeerToTrack = _sockets.GetNetServer();

            // Check for the password salt
            if (string.IsNullOrEmpty(ServerSettings.Default.PasswordSalt))
            {
                const string errmsg =
                    "No password salt has been defined in the server settings file. Make sure you define one before releasing.";
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat(errmsg);
                }
            }

            // Set the thread priority
            SetThreadPriority(ServerSettings.Default.ThreadPriority);

            // Validate the server's settings
            var ssv = new ServerSettingsValidator();

            ssv.Check(this);

            if (log.IsInfoEnabled)
            {
                log.Info("Server loaded.");
            }
        }