Exemple #1
0
        /// <summary>
        /// Initialize the game resource information
        /// The original Window_Loaded(object sender, RoutedEventArgs e)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void InitServer()
        {
            InitProgramExtName();

            System.Console.WriteLine("The language file is being initialized");

            Global.LoadLangDict();

            XElement xml = null;

            System.Console.WriteLine("The system configuration file is being initialized");

            try
            {
                xml = XElement.Load(@"AppConfig.xml");
            }
            catch (Exception)
            {
                throw new Exception(string.Format("Load xml file at startup: {0} failed", @"AppConfig.xml"));
            }

            // Program log level
            LogManager.LogTypeToWrite = (LogTypes)(int)Global.GetSafeAttributeLong(xml, "Server", "LogType");

            // Event log level
            GameDBManager.SystemServerSQLEvents.EventLevel = (EventLevels)(int)Global.GetSafeAttributeLong(xml, "Server", "EventLevel");

            int dbLog = Math.Max(0, (int)Global.GetSafeAttributeLong(xml, "DBLog", "DBLogEnable"));

            //Write the log in the cache to the file
            //GameDBManager.DBEventsWriter.Enable = (dbLog > 0);
            //GameDBManager.DBEventsWriter.EventDiskWriter.EventRootPath = Global.GetSafeAttributeStr(xml, "DBLog", "Path");
            //GameDBManager.DBEventsWriter.MaxCacheCount = 10000 * 10;

            GameDBManager.ZoneID = (int)Global.GetSafeAttributeLong(xml, "Zone", "ID");

            string uname   = StringEncrypt.Decrypt(Global.GetSafeAttributeStr(xml, "Database", "uname"), "eabcix675u49,/", "3&3i4x4^+-0");
            string upasswd = StringEncrypt.Decrypt(Global.GetSafeAttributeStr(xml, "Database", "upasswd"), "eabcix675u49,/", "3&3i4x4^+-0");

            System.Console.WriteLine("The number of data connection pools the server is building: {0}", (int)Global.GetSafeAttributeLong(xml, "Database", "maxConns"));
            System.Console.WriteLine("Database address: {0}", Global.GetSafeAttributeStr(xml, "Database", "ip"));
            System.Console.WriteLine("Name database: {0}", Global.GetSafeAttributeStr(xml, "Database", "dname"));
            System.Console.WriteLine("Database character set: {0}", Global.GetSafeAttributeStr(xml, "Database", "names"));

            DBConnections.dbNames = Global.GetSafeAttributeStr(xml, "Database", "names");

            System.Console.WriteLine("The database connection is being initialized");

            //long ticks = DateTime.Now.Ticks;
            _DBManger.LoadDatabase(new MySQLConnectionString(
                                       Global.GetSafeAttributeStr(xml, "Database", "ip"),
                                       Global.GetSafeAttributeStr(xml, "Database", "dname"),
                                       uname,
                                       upasswd),
                                   (int)Global.GetSafeAttributeLong(xml, "Database", "maxConns"),
                                   (int)Global.GetSafeAttributeLong(xml, "Database", "codePage"));

            //Verify area code
            ValidateZoneID();

            //Prepare the necessary data sheet
            GameDBManager.DBName = Global.GetSafeAttributeStr(xml, "Database", "dname");
            DBWriter.ValidateDatabase(_DBManger, GameDBManager.DBName);

            //Initialize the database since the growth value
            if (!Global.InitDBAutoIncrementValues(_DBManger))
            {
                System.Console.WriteLine("There is a fatal error. Please enter exit and y to exit");
                return;
            }

            //DBWriter.ClearUnusedGoodsData(_DBManger, true);
            //MessageBox.Show(string.Format("Add a total cost: {0}", (DateTime.Now.Ticks - ticks) / 10000));

            //Line management
            LineManager.LoadConfig(xml);

            System.Console.WriteLine("The network is being initialized");

//             _TCPManager = new TCPManager((int)Global.GetSafeAttributeLong(xml, "Socket", "capacity"));

            _TCPManager = TCPManager.getInstance();
            _TCPManager.initialize((int)Global.GetSafeAttributeLong(xml, "Socket", "capacity"));

            //Start the communication management object
            _TCPManager.DBMgr      = _DBManger;
            _TCPManager.RootWindow = this;
            _TCPManager.Start(Global.GetSafeAttributeStr(xml, "Socket", "ip"),
                              (int)Global.GetSafeAttributeLong(xml, "Socket", "port"));

            System.Console.WriteLine("Configuring background threads");

            //Set the background worker thread
            eventWorker         = new BackgroundWorker();
            eventWorker.DoWork += eventWorker_DoWork;

            updateMoneyWorker         = new BackgroundWorker();
            updateMoneyWorker.DoWork += updateMoneyWorker_DoWork;

            releaseMemoryWorker         = new BackgroundWorker();
            releaseMemoryWorker.DoWork += releaseMemoryWorker_DoWork;

            updateLiPinMaWorker         = new BackgroundWorker();
            updateLiPinMaWorker.DoWork += updateLiPinMaWorker_DoWork;

            updatePreNamesWorker         = new BackgroundWorker();
            updatePreNamesWorker.DoWork += updatePreNamesWorker_DoWork;

            updatePaiHangWorker         = new BackgroundWorker();
            updatePaiHangWorker.DoWork += updatePaiHangWorker_DoWork;

            dbWriterWorker         = new BackgroundWorker();
            dbWriterWorker.DoWork += dbWriterWorker_DoWork;

            updateLastMailWorker         = new BackgroundWorker();
            updateLastMailWorker.DoWork += updateLastMail_DoWork;

            MainDispatcherWorker         = new BackgroundWorker();
            MainDispatcherWorker.DoWork += MainDispatcherWorker_DoWork;

            //Whether to display the exception when the dialog box
            UnhandedException.ShowErrMsgBox = false;

            //Start the Global Service Manager
            GlobalServiceManager.initialize();
            GlobalServiceManager.startup();

            //Start the main loop scheduling thread
            if (!MainDispatcherWorker.IsBusy)
            {
                MainDispatcherWorker.RunWorkerAsync();
            }

            //ProgramExtName = string.Format("{0}@{1}", Global.GetSafeAttributeStr(xml, "Database", "dname"), GameDBManager.ZoneID);
            DBWriter.UpdateGameConfig(_DBManger, "gamedb_version", GetVersionDateTime());

            System.Console.WriteLine("The system is finished");
        }