/// <summary> /// Initializes a new instance of the <see cref="GlobalState"/> class. /// </summary> GlobalState() { ThreadAsserts.IsMainThread(); // Load all sorts of stuff _contentManager = NetGore.Content.ContentManager.Create(); var dbConnSettings = new DbConnectionSettings(); _dbController = dbConnSettings.CreateDbControllerPromptEditWhenInvalid(x => new ServerDbController(x.GetMySqlConnectionString()), x => dbConnSettings.PromptEditFileMessageBox(x)); _defaultRenderFont = ContentManager.LoadFont("Font/Arial", 16, ContentLevel.Global); Character.NameFont = DefaultRenderFont; GrhInfo.Load(ContentPaths.Dev, ContentManager); AutomaticGrhDataSizeUpdater.Instance.UpdateSizes(); _mapGrhWalls = new MapGrhWalls(ContentPaths.Dev, x => new WallEntity(x)); // Load the child classes _mapState = new MapState(this); // Grab the audio manager instances, which will ensure that they are property initialized // before something that can't pass it an ContentManager tries to get an instance AudioManager.GetInstance(ContentManager); // Set the custom UITypeEditors CustomUITypeEditors.AddEditors(DbController); // Set up the timer _timer = new Timer { Interval = 1000 / 60 }; _timer.Tick += _timer_Tick; }
/// <summary> /// Creates a new DbController instance if one does not already exist. Do not use this to just acquire a DbController instance when one may already exist - /// use DbControllerBase.GetInstance() instead. /// </summary> /// <returns></returns> public static ServerDbController CreateDbController() { ServerDbController db = null; // See if the instance already exists try { db = DbControllerBase.GetInstance() as ServerDbController; } catch (MemberAccessException) { } if (db == null) { var settings = new DbConnectionSettings(); db = (ServerDbController)settings.CreateDbControllerPromptEditWhenInvalid(x => new ServerDbController(x.GetMySqlConnectionString()), x => PromptEditDbSettingsFile(settings, x)); } return db; }
/// <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."); }