Exemple #1
0
        /// <summary>
        /// Initialize the gaming server environment.
        /// </summary>
        public static void Initialize()
        {
            Program.Logger.WriteInfo("Initializing a new gaming environment...");
            try
            {
                try
                {
                    // Load "general" settings from runescape.ini.
                    Configuration = Configuration.Load(@"..\data\runescape.ini");
                }
                catch (Exception) // Most likely error in config file or no file found.
                {
                    throw;
                }

                // Initialize the database server.
                SqlDatabaseServer databaseServer = new SqlDatabaseServer(
                    Configuration["Master.Database.Host"],
                    Configuration["Master.Database.Port"],
                    Configuration["Master.Database.User"],
                    Configuration["Master.Database.Pass"]);

                // Initialize a database from the database server.
                SqlDatabase database = new SqlDatabase(
                    Configuration["Master.Database.Name"],
                    Configuration["Master.Database.MinPoolSize"],
                    Configuration["Master.Database.MaxPoolSize"]);

                //  Initialize the database manager and test connection.
                databaseManager = new SqlDatabaseManager(database, databaseServer);
                databaseManager.SetClientAmount(10);
                databaseManager.ReleaseClient(databaseManager.GetClient().Handle);
                databaseManager.StartMonitor();

                // Initialize the tcp connection manager and start listening.
                connectionManager = new ConnectionManager(
                    Configuration["TcpConnection.LocalIP"],
                    Configuration["TcpConnection.Port"],
                    Configuration["TcpConnection.MaxConnections"]);

                // Start the connection manager's core listener with user-specified logging/checking.
                connectionManager.Listener.Start(Configuration["TcpConnection.CheckBlacklist"]);

                // Initialize the remote connection manager and start listening.
                remoteManager = new RemoteManager(
                    Configuration["RemoteConnection.LocalIP"],
                    Configuration["RemoteConnection.Port"]);
                remoteManager.Listener.Start(false);

                // Initialize the scripting manager.
                scriptManager = new ScriptManager();
                scriptManager.Initialize();

                // Check to make sure database verion is valid.
                if (!(bool)Database.Execute(new DatabaseVersionCheck()))
                {
                    throw new Exception("The jolt database you are using, is outdated.");
                }

                /*
                 *  Engine is now able to run cause the connections have been initialized
                 *  with no errors (yet!), so we will initialize the game engine.
                 */
                IsRunning = true;

                // Initilize the game engine.
                GameEngine.Initialize();

                Program.Logger.WriteInfo("Initialized a new runescape gaming environment.");
            }
            catch (Exception ex)
            {
                Program.Logger.WriteException(ex);
                Program.Logger.WriteError("Could not set up server correctly."
                                          + "\nPlease referr to the error message above. Shutting down...");
                Thread.Sleep(5000);
                Environment.Exit(0);
                Terminate(false);
            }
        }