public void processCmd(GameServerClient client, byte[] cmdParams, int count)
        {
            string cmdData = null;
            int    nID     = 20002;

            try
            {
                cmdData = new UTF8Encoding().GetString(cmdParams, 0, count);
            }
            catch (Exception)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}", (TCPGameServerCmds)nID));
                client.sendCmd(32767, "0");
                return;
            }
            string[] fields = cmdData.Split(new char[]
            {
                ':'
            });
            if (fields.Length != 24)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Recv={1}, CmdData={2}", (TCPGameServerCmds)nID, fields.Length, cmdData));
                client.sendCmd(32767, "0");
            }
            else
            {
                DBItemLogWriter.getInstance().insertTradeNumLog(DBManager.getInstance(), fields);
                string strcmd = string.Format("{0}", 1);
                client.sendCmd(nID, strcmd);
            }
        }
Ejemplo n.º 2
0
        private void ByDayCreateLogTableWorker_DoWork(object sender, EventArgs e)
        {
            int sleepMs = 3600000;

            for (; ;)
            {
                try
                {
                    DBItemLogWriter.getInstance().AddItemLogTable(DBManager.getInstance());
                    if (Program.NeedExitServer)
                    {
                        sleepMs = 200;
                        this.closingTimer_Tick(null, null);
                        if (this.MustCloseNow)
                        {
                            break;
                        }
                    }
                    Thread.Sleep(sleepMs);
                }
                catch (Exception ex)
                {
                    DataHelper.WriteFormatExceptionLog(ex, "ByDayCreateLogTableWorker_DoWork", false, false);
                }
            }
            Console.WriteLine("日志表处理线程退出,回车退出系统");
        }
Ejemplo n.º 3
0
        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("系统启动完毕");
        }