void Tick(ServerFrame.DB.DBConnect dbConnect) { DBConnect.Tick(); if (mLoginQueue.Count > 0) { RoleEnterHolder atom = null; lock (this) { atom = mLoginQueue[0]; mLoginQueue.RemoveAt(0); } try { if (atom.RoleCreator != null) { Log.Log.Server.Info("atom.RoleCreator != null"); if (atom.RoleCreator.Exec != null) { atom.RoleCreator.Exec(); } } else { IDataServer.Instance.PlayerManager.Do_RoleLogin(atom); } } catch (System.Exception ex) { Log.Log.Login.Info("登陆失败{0}", atom.roleId); Log.Log.Common.Print(ex.ToString()); Log.Log.Common.Print(ex.StackTrace.ToString()); } } }
public void StartThread() { mDBConnect = new ServerFrame.DB.DBConnect(); mDBConnect.OpenConnect(); mRunning = true; mThread = new System.Threading.Thread(new System.Threading.ThreadStart(this.ThreadLoop)); mThread.Start(); }
public void Start(IDataServerParameter parameter) { Stop(); mParameter = parameter; mDBLoaderConnect = new ServerFrame.DB.DBConnect(); mDBLoaderConnect.OpenConnect(); //ServerFrame.Support.ClassInfoManager.Instance.Load(false); Log.FileLog.Instance.Begin("DataServer.log", false); Log.Log.Server.Print("DataServer Start!"); Log.FileLog.Instance.Flush(); IServer.LoadAllTemplateData(ServerCommon.ServerConfig.Instance.TemplatePath); CSCommon.CSLog.LogFun = Log.Log.Common.Warning; ServerCommon.TemplateTableLoader.LoadTable(ServerCommon.ServerConfig.Instance.TablePath); //加载数据库中的静态配置信息 CSCommon.Data.CDbConfig.LoadDbConfig(mDBLoaderConnect); //国战服务初始化 CountryWar.CCountryWarMgr.Instance.Start(mDBLoaderConnect); Thread.AccountLoginThread.Instance.StartThread(); Thread.PlayerEnterThread.Instance.StartThread(); Thread.DBConnectManager.Instance.StartThreadPool(2); AsyncExecuteThreadManager.Instance.InitManager(1); AsyncExecuteThreadManager.Instance.StartThread(); //mChargeManger = new Data.ChargeManager(); mPlanesMgr = new Data.PlanesMgr(this); Log.Log.Server.Print("DBConnect OK!"); mTcpSrv.ReceiveData += RPC.RPCNetworkMgr.Instance.ServerReceiveData; mTcpSrv.CloseConnect += this.ServerDisConnected; mRegisterConnect.ReceiveData += RPC.RPCNetworkMgr.Instance.ClientReceiveData; mRegisterConnect.NewConnect += this.OnRegisterConnected; mRegisterConnect.Connect(parameter.RegServerIP, parameter.RegServerPort); mLinkState = DataServerState.WaitRegServer; InitNamePool(); mPlayerManager.DownloadPlayerData(mDBLoaderConnect); /*int avgSize = 0; * Support.PerfCounter perf = new Support.PerfCounter(); * perf.Begin(); * for (int i = 0; i < 1000; i++) * { * RPC.DataWriter dw0 = new RPC.DataWriter(); * CSCommon.Data.ItemData item0 = new CSCommon.Data.ItemData(); * item0.ItemTemlateId = 2; * //item0.DangrousReInitData(); * RPC.DataWriter dw1 = new RPC.DataWriter(); * CSCommon.Data.ItemData item1 = new CSCommon.Data.ItemData(); * item1.ItemTemlateId = 2; * // item1.DangrousReInitData(); * dw0.Write(item0); * dw1.Write(item1); * * int compressSize = dw1.CompressWithTemplate(dw0); * dw1.UnCompressWithTemplate(dw0); * * avgSize += compressSize; * * RPC.DataWriter dw2 = new RPC.DataWriter(); * dw2.Write(item1); * bool isSame = dw1.IsSame(dw2); * } * Int64 time = perf.End(); * System.Diagnostics.Debug.WriteLine( "{0}:{1}" , avgSize / 1000, time);*/ //test /* * var start = ServerCommon.IServer.timeGetTime(); * * CSCommon.Data.RoleDetail rd = new CSCommon.Data.RoleDetail(); * CSCommon.Data.RoleDetail rd2 = new CSCommon.Data.RoleDetail(); * //var r = TestAutoCode(rd); * rd.BagSize = 155; * rd.BindRmb = 155; * rd.CreateTime = DateTime.Now; * rd.LocationX = 15211; * rd.LocationY = 15211; * rd.LocationZ = 15211; * rd.Rmb = 123; * rd.RoleExp = 333; * for (int i = 0; i < 10000; i++) * { * //var r = rd.GetSql(rd2); * var r = ServerFrame.DB.DBConnect.TestUpdateData("", rd, rd2); * } * var end = ServerCommon.IServer.timeGetTime() - start; * var t = end;*/ }
public void Tick(ServerFrame.DB.DBConnect dbConnect) { try {//这里之所以要try住,是因为存盘的过程中,如果发生了Clear,丢弃之前的存储指令,有可能触发迭代过程异常,但是这个异常不会影响到什么东西 if (mQueues.Count == 0) { lock (this) { mIsEmpty = true; } return; } ServerFrame.DB.DBOperator saver = mQueues.Dequeue(); if (saver == null) { Log.Log.Common.Print("见鬼了,居然还有null存盘" + mPlayerDataEx.RoleDetail.RoleName); return; } while (saver != null) { try { if (saver.Executer != null) { if (saver.Executer.Exec != null) { saver.Executer.Exec(); } } else if (saver.ExeType == SqlExeType.Update) { dbConnect._ExecuteUpdate(saver); } else if (saver.ExeType == SqlExeType.Insert) { dbConnect._ExecuteInsert(saver); } else if (saver.ExeType == SqlExeType.Delete) { dbConnect._ExecuteDelete(saver); } else if (saver.ExeType == SqlExeType.Destroy) { dbConnect._ExecuteDestroy(saver); } } catch (System.Exception ex) { Log.Log.Common.Print(ex.ToString()); System.Diagnostics.Debug.WriteLine(ex.ToString()); } if (mQueues.Count == 0) { lock (this) { mIsEmpty = true; } break;//减少异常的概率做的努力,虽然这个异常没啥,但是log压力也还是要考虑的 } saver = mQueues.Dequeue(); } } catch (System.Exception ex) { Log.Log.Common.Print(ex.ToString()); System.Diagnostics.Debug.WriteLine(ex.ToString()); } }