示例#1
0
        public static IPInfo ParseIP(string ip)
        {
            string country = null;
            string area    = null;
            IPInfo info    = null;

            if (IpLibrary.findIpAddrInfo(ip, out country, out area))
            {
                info            = new IPInfo();
                info.RegionName = country.Substring(0, Math.Min(20, country.Length));
                info.CityName   = area.Substring(0, Math.Min(20, area.Length));
            }
            return(info);
        }
示例#2
0
        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("系统启动完毕");
            }
        }