コード例 #1
0
ファイル: Program.cs プロジェクト: songxiaopeng/mu_server
 public void ExitServer()
 {
     if (!Program.NeedExitServer)
     {
         this._TCPManager.Stop();
         GlobalServiceManager.showdown();
         GlobalServiceManager.destroy();
         this.Window_Closing();
         Console.WriteLine("正在尝试关闭服务器,看到服务器关闭完毕提示后回车退出系统");
         if (0 == Program.GetServerPIDFromFile())
         {
             string cmd = Console.ReadLine();
             while (this.MainDispatcherWorker.IsBusy)
             {
                 Console.WriteLine("正在尝试关闭服务器");
                 cmd = Console.ReadLine();
             }
         }
     }
 }
コード例 #2
0
        //Close the server
        public void ExitServer()
        {
            if (NeedExitServer)
            {
                return;
            }

            _TCPManager.Stop(); //Stop TCP listening, otherwise the mono can not exit normally

            //Close the Global Service Manager
            GlobalServiceManager.showdown();
            GlobalServiceManager.destroy();

            Window_Closing();

            System.Console.WriteLine("Trying to shut down the server, see the server closed after the completion of the prompts to exit the system");

            if (0 == GetServerPIDFromFile())
            {
                String cmd = System.Console.ReadLine();

                while (true)
                {
                    if (MainDispatcherWorker.IsBusy)
                    {
                        System.Console.WriteLine("Trying to shut down the server");
                        cmd = System.Console.ReadLine();
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
コード例 #3
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");
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: songxiaopeng/mu_server
        public void InitServer()
        {
            Program.InitProgramExtName();
            Console.WriteLine("正在初始化语言文件");
            Global.LoadLangDict();
            if (!IpLibrary.loadIpLibrary("qqwry.dat"))
            {
                throw new Exception(string.Format("启动时加载IP库: {0} 失败", "qqwry.dat"));
            }
            XElement xml = null;

            Console.WriteLine("正在初始化系统配置文件");
            try
            {
                xml = XElement.Load("AppConfig.xml");
            }
            catch (Exception)
            {
                throw new Exception(string.Format("启动时加载xml文件: {0} 失败", "AppConfig.xml"));
            }
            LogManager.LogTypeToWrite = (LogTypes)Global.GetSafeAttributeLong(xml, "Server", "LogType");
            GameDBManager.SystemServerSQLEvents.EventLevel = (EventLevels)Global.GetSafeAttributeLong(xml, "Server", "EventLevel");
            int dbLog = Math.Max(0, (int)Global.GetSafeAttributeLong(xml, "DBLog", "DBLogEnable"));

            GameDBManager.ZoneID = (int)Global.GetSafeAttributeLong(xml, "Zone", "ID");
            string startURL  = null;
            string chargeKey = "";
            string serverKey = "";

            try
            {
                startURL  = Global.GetSafeAttributeStr(xml, "Zone", "URL");
                chargeKey = Global.GetSafeAttributeStr(xml, "Platform", "GameKey");
                serverKey = Global.GetSafeAttributeStr(xml, "Platform", "ServerKey");
            }
            catch (Exception ex)
            {
                LogManager.WriteLog(LogTypes.Fatal, "读取AppConfig.xml配置文件出错" + ex.Message, ex, true);
            }
            if (!string.IsNullOrEmpty(startURL))
            {
                GetCDBInfoReq cdbServerReq = new GetCDBInfoReq();
                cdbServerReq.PTID     = Global.GetSafeAttributeStr(xml, "Zone", "PTID");
                cdbServerReq.ServerID = GameDBManager.ZoneID.ToString();
                cdbServerReq.Gamecode = Global.GetSafeAttributeStr(xml, "Zone", "GameCode");
                byte[] responseData = null;
                byte[] clientBytes  = DataHelper.ObjectToBytes <GetCDBInfoReq>(cdbServerReq);
                for (int i = 1; i <= 5; i++)
                {
                    responseData = WebHelper.RequestByPost(startURL, clientBytes, 5000, 30000);
                    if (responseData != null)
                    {
                        break;
                    }
                    Console.WriteLine("第{0}次获取启动信息失败,2秒后重试", i);
                    Thread.Sleep(2000);
                }
                if (responseData == null)
                {
                    throw new Exception(string.Format("请求启动信息失败", new object[0]));
                }
                ServerDBInfo databaseInfo = DataHelper.BytesToObject <ServerDBInfo>(responseData, 0, responseData.Length);
                if (databaseInfo == null)
                {
                    throw new Exception(string.Format("请求启动信息 解析失败", new object[0]));
                }
                GameDBManager.serverDBInfo           = databaseInfo;
                GameDBManager.serverDBInfo.userName  = StringEncrypt.Decrypt(GameDBManager.serverDBInfo.userName, "eabcix675u49,/", "3&3i4x4^+-0");
                GameDBManager.serverDBInfo.uPassword = StringEncrypt.Decrypt(GameDBManager.serverDBInfo.uPassword, "eabcix675u49,/", "3&3i4x4^+-0");
                if (GameDBManager.serverDBInfo.InternalIP != Global.GetInternalIP())
                {
                    throw new Exception(string.Format("请求启动信息 内网IP不匹配", new object[0]));
                }
                string tmpName = string.Format("{0}_game_{1}", cdbServerReq.Gamecode, cdbServerReq.ServerID);
                if (tmpName != GameDBManager.serverDBInfo.dbName)
                {
                    throw new Exception(string.Format("请求启动信息 dbName不匹配", new object[0]));
                }
            }
            else
            {
                GameDBManager.serverDBInfo            = new ServerDBInfo();
                GameDBManager.serverDBInfo.userName   = StringEncrypt.Decrypt(Global.GetSafeAttributeStr(xml, "Database", "uname"), "eabcix675u49,/", "3&3i4x4^+-0");
                GameDBManager.serverDBInfo.uPassword  = StringEncrypt.Decrypt(Global.GetSafeAttributeStr(xml, "Database", "upasswd"), "eabcix675u49,/", "3&3i4x4^+-0");
                GameDBManager.serverDBInfo.strIP      = Global.GetSafeAttributeStr(xml, "Database", "ip");
                GameDBManager.serverDBInfo.Port       = (int)Global.GetSafeAttributeLong(xml, "Database", "port");
                GameDBManager.serverDBInfo.dbName     = Global.GetSafeAttributeStr(xml, "Database", "dname");
                GameDBManager.serverDBInfo.maxConns   = (int)Global.GetSafeAttributeLong(xml, "Database", "maxConns");
                GameDBManager.serverDBInfo.InternalIP = Global.GetInternalIP();
                GameDBManager.serverDBInfo.ChargeKey  = chargeKey;
                GameDBManager.serverDBInfo.ServerKey  = serverKey;
            }
            GameDBManager.serverDBInfo.ChargeKey = StringEncrypt.Decrypt(GameDBManager.serverDBInfo.ChargeKey, "eabcix675u49,/", "3&3i4x4^+-0");
            GameDBManager.serverDBInfo.ServerKey = StringEncrypt.Decrypt(GameDBManager.serverDBInfo.ServerKey, "eabcix675u49,/", "3&3i4x4^+-0");
            GameDBManager.serverDBInfo.DbNames   = Global.GetSafeAttributeStr(xml, "Database", "names");
            GameDBManager.serverDBInfo.CodePage  = (int)Global.GetSafeAttributeLong(xml, "Database", "codePage");
            Console.WriteLine("服务器正在建立数据链接池个数: {0}", GameDBManager.serverDBInfo.maxConns);
            Console.WriteLine("数据库地址: {0}", GameDBManager.serverDBInfo.strIP);
            Console.WriteLine("数据库名称: {0}", GameDBManager.serverDBInfo.dbName);
            Console.WriteLine("数据库字符集: {0}", GameDBManager.serverDBInfo.DbNames);
            Console.WriteLine("数据库代码页: {0}", GameDBManager.serverDBInfo.CodePage);
            DBConnections.dbNames = GameDBManager.serverDBInfo.DbNames;
            Console.WriteLine("正在初始化数据库链接");
            MySQLConnectionString connectStr = new MySQLConnectionString(GameDBManager.serverDBInfo.strIP, GameDBManager.serverDBInfo.dbName, GameDBManager.serverDBInfo.userName, GameDBManager.serverDBInfo.uPassword);

            this._DBManger.LoadDatabase(connectStr, GameDBManager.serverDBInfo.maxConns, GameDBManager.serverDBInfo.CodePage);
            Program.ValidateZoneID();
            GameDBManager.DBName = Global.GetSafeAttributeStr(xml, "Database", "dname");
            DBWriter.ValidateDatabase(this._DBManger, GameDBManager.DBName);
            if (!Global.InitDBAutoIncrementValues(this._DBManger))
            {
                Console.WriteLine("存在致命错误,请输入exit 和 y 退出");
            }
            else
            {
                LineManager.LoadConfig();
                Console.WriteLine("正在初始化网络");
                this._TCPManager = TCPManager.getInstance();
                this._TCPManager.initialize((int)Global.GetSafeAttributeLong(xml, "Socket", "capacity"));
                this._TCPManager.DBMgr      = this._DBManger;
                this._TCPManager.RootWindow = this;
                this._TCPManager.Start(Global.GetSafeAttributeStr(xml, "Socket", "ip"), (int)Global.GetSafeAttributeLong(xml, "Socket", "port"));
                PlatTCPManager.getInstance().initialize((int)Global.GetSafeAttributeLong(xml, "Platform", "capacity"));
                PlatTCPManager.getInstance().Start(Global.GetSafeAttributeStr(xml, "Platform", "ip"), (int)Global.GetSafeAttributeLong(xml, "Platform", "port"));
                Console.WriteLine("正在配置后台线程");
                this.eventWorker                   = new BackgroundWorker();
                this.eventWorker.DoWork           += this.eventWorker_DoWork;
                this.updateMoneyWorker             = new BackgroundWorker();
                this.updateMoneyWorker.DoWork     += this.updateMoneyWorker_DoWork;
                this.releaseMemoryWorker           = new BackgroundWorker();
                this.releaseMemoryWorker.DoWork   += this.releaseMemoryWorker_DoWork;
                this.updateLiPinMaWorker           = new BackgroundWorker();
                this.updateLiPinMaWorker.DoWork   += this.updateLiPinMaWorker_DoWork;
                this.updatePreDeleteWorker         = new BackgroundWorker();
                this.updatePreDeleteWorker.DoWork += this.updatePreDeleteRoleWorker_DoWork;
                this.updatePreNamesWorker          = new BackgroundWorker();
                this.updatePreNamesWorker.DoWork  += this.updatePreNamesWorker_DoWork;
                this.updatePaiHangWorker           = new BackgroundWorker();
                this.updatePaiHangWorker.DoWork   += this.updatePaiHangWorker_DoWork;
                this.dbWriterWorker                = new BackgroundWorker();
                this.dbWriterWorker.DoWork        += new DoWorkEventHandler(this.dbWriterWorker_DoWork);
                this.dbGoodsBakTableWorker         = new BackgroundWorker();
                this.dbGoodsBakTableWorker.DoWork += new DoWorkEventHandler(this.dbGoodsBakTableWorker_DoWork);
                this.updateLastMailWorker          = new BackgroundWorker();
                this.updateLastMailWorker.DoWork  += this.updateLastMail_DoWork;
                this.updateGroupMailWorker         = new BackgroundWorker();
                this.updateGroupMailWorker.DoWork += this.updateGroupMail_DoWork;
                this.updateFacebookWorker          = new BackgroundWorker();
                this.updateFacebookWorker.DoWork  += this.updateFacebook_DoWork;
                this.MainDispatcherWorker          = new BackgroundWorker();
                this.MainDispatcherWorker.DoWork  += new DoWorkEventHandler(this.MainDispatcherWorker_DoWork);
                this.userReturnCheckWorker         = new BackgroundWorker();
                this.userReturnCheckWorker.DoWork += this.UserReturnCheckWorker_DoWork;
                this.updateTenWorker               = new BackgroundWorker();
                this.updateTenWorker.DoWork       += this.updateTen_DoWork;
                this.updateGiftCodeWorker          = new BackgroundWorker();
                this.updateGiftCodeWorker.DoWork  += this.updateGiftCode_DoWork;
                UnhandedException.ShowErrMsgBox    = false;
                GlobalServiceManager.initialize();
                GlobalServiceManager.startup();
                if (!this.MainDispatcherWorker.IsBusy)
                {
                    this.MainDispatcherWorker.RunWorkerAsync();
                }
                GameDBManager.GameConfigMgr.UpdateGameConfigItem("gamedb_version", Program.GetVersionDateTime());
                DBWriter.UpdateGameConfig(this._DBManger, "gamedb_version", Program.GetVersionDateTime());
                Console.WriteLine("系统启动完毕");
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: qiuhoude/mu_server
        public void InitServer()
        {
            Program.InitProgramExtName();
            Console.WriteLine("正在初始化语言文件");
            Global.LoadLangDict();
            XElement xml = null;

            Console.WriteLine("正在初始化系统配置文件");
            try
            {
                xml = XElement.Load("AppConfig.xml");
            }
            catch (Exception)
            {
                throw new Exception(string.Format("启动时加载xml文件: {0} 失败", "AppConfig.xml"));
            }
            LogManager.LogTypeToWrite = (LogTypes)Global.GetSafeAttributeLong(xml, "Server", "LogType");
            GameDBManager.SystemServerSQLEvents.EventLevel = (EventLevels)Global.GetSafeAttributeLong(xml, "Server", "EventLevel");
            int dbLog = Math.Max(0, (int)Global.GetSafeAttributeLong(xml, "DBLog", "DBLogEnable"));

            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");

            Console.WriteLine("服务器正在建立数据链接池个数: {0}", (int)Global.GetSafeAttributeLong(xml, "Database", "maxConns"));
            Console.WriteLine("数据库地址: {0}", Global.GetSafeAttributeStr(xml, "Database", "ip"));
            Console.WriteLine("数据库名称: {0}", Global.GetSafeAttributeStr(xml, "Database", "dname"));
            Console.WriteLine("数据库字符集: {0}", Global.GetSafeAttributeStr(xml, "Database", "names"));
            DBConnections.dbNames = Global.GetSafeAttributeStr(xml, "Database", "names");
            Console.WriteLine("正在初始化数据库链接");
            this._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"));
            string          strTableName = "t_log_" + DateTime.Now.ToString("yyyyMMdd");
            MySQLConnection conn         = this._DBManger.DBConns.PopDBConnection();

            DBItemLogWriter.getInstance().ConformTableColumns(conn, strTableName);
            this._DBManger.DBConns.PushDBConnection(conn);
            Console.WriteLine("正在初始化网络");
            this._TCPManager = TCPManager.getInstance();
            this._TCPManager.initialize((int)Global.GetSafeAttributeLong(xml, "Socket", "capacity"));
            this._TCPManager.DBMgr      = this._DBManger;
            this._TCPManager.RootWindow = this;
            this._TCPManager.Start(Global.GetSafeAttributeStr(xml, "Socket", "ip"), (int)Global.GetSafeAttributeLong(xml, "Socket", "port"));
            Console.WriteLine("正在配置后台线程");
            this.eventWorker                       = new BackgroundWorker();
            this.eventWorker.DoWork               += this.eventWorker_DoWork;
            this.ByDayCreateLogTableWorker         = new BackgroundWorker();
            this.ByDayCreateLogTableWorker.DoWork += new DoWorkEventHandler(this.ByDayCreateLogTableWorker_DoWork);
            this.MainDispatcherWorker              = new BackgroundWorker();
            this.MainDispatcherWorker.DoWork      += new DoWorkEventHandler(this.MainDispatcherWorker_DoWork);
            UnhandedException.ShowErrMsgBox        = false;
            GlobalServiceManager.initialize();
            GlobalServiceManager.startup();
            if (!this.MainDispatcherWorker.IsBusy)
            {
                this.MainDispatcherWorker.RunWorkerAsync();
            }
            if (!this.ByDayCreateLogTableWorker.IsBusy)
            {
                this.ByDayCreateLogTableWorker.RunWorkerAsync();
            }
            Console.WriteLine("系统启动完毕");
        }