public int InitializeClient(KuaFuClientContext clientInfo)
        {
            int result;

            try
            {
                if (clientInfo.ServerId != 0)
                {
                    bool bFirstInit = false;
                    int  ret        = ClientAgentManager.Instance().InitializeClient(clientInfo, out bFirstInit);
                    if (ret > 0)
                    {
                        if (clientInfo.MapClientCountDict != null && clientInfo.MapClientCountDict.Count > 0)
                        {
                            KuaFuServerManager.UpdateKuaFuLineData(clientInfo.ServerId, clientInfo.MapClientCountDict);
                            ClientAgentManager.Instance().SetMainlinePayload(clientInfo.ServerId, clientInfo.MapClientCountDict.Values.ToList <int>().Sum());
                        }
                    }
                    result = ret;
                }
                else
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("InitializeClient时GameType错误,禁止连接.ServerId:{0},GameType:{1}", clientInfo.ServerId, clientInfo.GameType), null, true);
                    result = -4003;
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteExceptionUseCache(string.Format("InitializeClient服务器ID重复,禁止连接.ServerId:{0},ClientId:{1},info:{2}", clientInfo.ServerId, clientInfo.ClientId, clientInfo.Token));
                result = -11003;
            }
            return(result);
        }
Exemple #2
0
        private void RemoveGameFuBen(TianTiFuBenData tianTiFuBenData)
        {
            int             gameId = tianTiFuBenData.GameId;
            TianTiFuBenData tianTiFuBenDataTemp;

            if (this.TianTiFuBenDataDict.TryRemove(gameId, out tianTiFuBenDataTemp))
            {
                tianTiFuBenDataTemp.State = GameFuBenState.End;
            }
            ClientAgentManager.Instance().RemoveKfFuben(this.GameType, tianTiFuBenData.ServerId, (long)tianTiFuBenData.GameId);
            lock (tianTiFuBenData)
            {
                foreach (KuaFuFuBenRoleData fuBenRoleData in tianTiFuBenData.RoleDict.Values)
                {
                    KuaFuRoleData kuaFuRoleData;
                    if (this.RoleIdKuaFuRoleDataDict.TryGetValue(KuaFuRoleKey.Get(fuBenRoleData.ServerId, fuBenRoleData.RoleId), out kuaFuRoleData))
                    {
                        if (kuaFuRoleData.GameId == gameId)
                        {
                            kuaFuRoleData.State = KuaFuRoleStates.None;
                        }
                    }
                }
            }
        }
        private void RemoveGameFuBen(HuanYingSiYuanFuBenData fubenData)
        {
            int gameId = fubenData.GameId;
            HuanYingSiYuanFuBenData tmpFuben;

            this.ShotOfRolesFuBenDataDict.TryRemove(gameId, out tmpFuben);
            if (this.HuanYingSiYuanFuBenDataDict.TryRemove(gameId, out tmpFuben))
            {
                tmpFuben.State = GameFuBenState.End;
            }
            ClientAgentManager.Instance().RemoveKfFuben(this.GameType, tmpFuben.ServerId, (long)tmpFuben.GameId);
            lock (fubenData)
            {
                foreach (KuaFuFuBenRoleData fuBenRoleData in fubenData.RoleDict.Values)
                {
                    KuaFuRoleData kuaFuRoleData;
                    if (this.RoleIdKuaFuRoleDataDict.TryGetValue(KuaFuRoleKey.Get(fuBenRoleData.ServerId, fuBenRoleData.RoleId), out kuaFuRoleData))
                    {
                        if (kuaFuRoleData.GameId == gameId)
                        {
                            kuaFuRoleData.State = KuaFuRoleStates.None;
                        }
                    }
                }
            }
        }
        private void CheckRoleTimerProc(DateTime now, out int signUpCount, out int startCount)
        {
            signUpCount = 0;
            startCount  = 0;
            bool assgionGameFuBen   = true;
            long maxRemoveRoleTicks = now.AddHours(-2.0).Ticks;
            long waitTicks          = now.AddSeconds((double)(-(double)this.Persistence.SignUpWaitSecs1)).Ticks;
            long waitTicks2         = now.AddSeconds((double)(-(double)this.Persistence.SignUpWaitSecs2)).Ticks;

            foreach (KuaFuRoleData kuaFuRoleData in this.RoleIdKuaFuRoleDataDict.Values)
            {
                int oldGameId = 0;
                lock (kuaFuRoleData)
                {
                    if (kuaFuRoleData.State == KuaFuRoleStates.None || kuaFuRoleData.State > KuaFuRoleStates.StartGame)
                    {
                        if (kuaFuRoleData.StateEndTicks < maxRemoveRoleTicks)
                        {
                            KuaFuRoleData kuaFuRoleDataTemp;
                            this.RoleIdKuaFuRoleDataDict.TryRemove(KuaFuRoleKey.Get(kuaFuRoleData.ServerId, kuaFuRoleData.RoleId), out kuaFuRoleDataTemp);
                            continue;
                        }
                    }
                    else if (kuaFuRoleData.State == KuaFuRoleStates.NotifyEnterGame || kuaFuRoleData.State == KuaFuRoleStates.EnterGame)
                    {
                        if (kuaFuRoleData.StateEndTicks < now.Ticks)
                        {
                            kuaFuRoleData.Age++;
                            kuaFuRoleData.State = KuaFuRoleStates.None;
                            oldGameId           = kuaFuRoleData.GameId;
                        }
                    }
                }
                if (kuaFuRoleData.State == KuaFuRoleStates.SignUp)
                {
                    signUpCount++;
                    if (assgionGameFuBen)
                    {
                        assgionGameFuBen = this.AssignGameFuben(kuaFuRoleData, waitTicks, waitTicks2, now);
                    }
                }
                else if (kuaFuRoleData.State == KuaFuRoleStates.SignUpWaiting)
                {
                    signUpCount++;
                }
                else if (kuaFuRoleData.State == KuaFuRoleStates.StartGame)
                {
                    startCount++;
                }
                if (oldGameId > 0)
                {
                    this.RemoveRoleFromFuBen(oldGameId, kuaFuRoleData.RoleId);
                    AsyncDataItem evItem = new AsyncDataItem(KuaFuEventTypes.RoleStateChange, new object[]
                    {
                        kuaFuRoleData
                    });
                    ClientAgentManager.Instance().PostAsyncEvent(kuaFuRoleData.ServerId, this.GameType, evItem);
                }
            }
        }
Exemple #5
0
        //Cancel
        public int OperateCancel(int serverID, int unionID, int targetID, bool isDel = false)
        {
            lock (_Mutex)
            {
                KFAllyData targetData = GetUnionData(targetID);
                if (targetData == null) return (int)EAlly.ENoTargetUnion;

                if (!UnionIsRequest(unionID, targetID)) return (int)EAlly.EFail;
                if (!UnionIsAccept(targetID, unionID)) return (int)EAlly.EFail;

                bool isDelRasult = AllyPersistence.Instance.DBAllyRequestDel(unionID, targetID);
                if (!isDelRasult) return (int)EAlly.EFail;

                DateTime logTime = DateTime.Now;
                int logState = (int)EAlly.AllyCancelSucc;

                //my
                KFAllyData rData = GetRequestData(unionID, targetID);
                if (!isDel) _requestDic[unionID].Remove(rData);
                ClientAgentManager.Instance().PostAsyncEvent(serverID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyRequestRemove, unionID, targetID));

                //target
                if (_acceptDic.ContainsKey(targetID))
                {
                    KFAllyData aData = GetAcceptData(targetID, unionID);
                    _acceptDic[targetID].Remove(aData);
                }

                if (IsAgent(targetData.ServerID))
                    ClientAgentManager.Instance().PostAsyncEvent(targetData.ServerID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyAcceptRemove, targetID, unionID));

                return (int)EAlly.AllyCancelSucc;
            }
        }
Exemple #6
0
        private void CheckAllyLog(int serverID, int unionID)
        {
            List<AllyLogData> list = AllyPersistence.Instance.DBAllyLogList(unionID);
            if (list == null || list.Count <= 0) return;

            ClientAgentManager.Instance().PostAsyncEvent(serverID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyLog, unionID, list));
        }
Exemple #7
0
 private void NotifyFuBenRoleCount(TianTiFuBenData fuBenData)
 {
     try
     {
         lock (fuBenData)
         {
             int roleCount = fuBenData.RoleDict.Count;
             foreach (KuaFuFuBenRoleData role in fuBenData.RoleDict.Values)
             {
                 KuaFuRoleData kuaFuRoleData;
                 if (this.RoleIdKuaFuRoleDataDict.TryGetValue(KuaFuRoleKey.Get(role.ServerId, role.RoleId), out kuaFuRoleData))
                 {
                     AsyncDataItem evItem = new AsyncDataItem(KuaFuEventTypes.NotifyWaitingRoleCount, new object[]
                     {
                         kuaFuRoleData.RoleId,
                         roleCount
                     });
                     ClientAgentManager.Instance().PostAsyncEvent(kuaFuRoleData.ServerId, this.GameType, evItem);
                 }
             }
         }
     }
     catch
     {
     }
 }
 public void HandleChangeEraID(DateTime now, bool broadCast = false)
 {
     lock (this.Mutex)
     {
         int dayID = TimeUtil.GetOffsetDay(now);
         if (dayID != this.RuntimeData.EraUpdateDayID)
         {
             this.RuntimeData.EraUpdateDayID = dayID;
             int CurrentEraID = this.CalCurrentEraID(now);
             if (CurrentEraID != this.RuntimeData.CurrentEraID)
             {
                 this.EraDataDict.Clear();
                 this.EraRankList.V.Clear();
                 TimeUtil.AgeByNow(ref this.EraRankList.Age);
                 this.RuntimeData.CurrentEraID           = CurrentEraID;
                 this.RuntimeData.CurFastEraStage        = 1;
                 this.RuntimeData.CurFastEraStateProcess = 0;
                 if (broadCast)
                 {
                     AsyncDataItem evItem = new AsyncDataItem(KuaFuEventTypes.JunTuanEraChg, new object[]
                     {
                         CurrentEraID
                     });
                     ClientAgentManager.Instance().BroadCastAsyncEvent(GameTypes.JunTuan, evItem, 0);
                 }
             }
         }
     }
 }
Exemple #9
0
        public int InitializeClient(KuaFuClientContext clientInfo)
        {
            int result;

            try
            {
                if (clientInfo.ServerId != 0)
                {
                    bool bFirstInit = false;
                    int  ret        = ClientAgentManager.Instance().InitializeClient(clientInfo, out bFirstInit);
                    if (ret > 0)
                    {
                    }
                    result = ret;
                }
                else
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("InitializeClient时GameType错误,禁止连接.ServerId:{0},GameType:{1}", clientInfo.ServerId, clientInfo.GameType), null, true);
                    result = -4003;
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteExceptionUseCache(string.Format("InitializeClient服务器ID重复,禁止连接.ServerId:{0},ClientId:{1},info:{2}", clientInfo.ServerId, clientInfo.ClientId, clientInfo.Token));
                result = -11003;
            }
            return(result);
        }
Exemple #10
0
 public void ThreadProc(object state)
 {
     do
     {
         Thread.Sleep(1000);
     }while (!this.Persistence.Initialized);
     for (;;)
     {
         try
         {
             DateTime now = TimeUtil.NowDateTime();
             Global.UpdateNowTime(now);
             if (now > this.CheckRoleTimerProcTime)
             {
                 this.CheckRoleTimerProcTime = now.AddSeconds(1.428);
                 int signUpCnt;
                 int startCnt;
                 this.CheckRoleTimerProc(now, out signUpCnt, out startCnt);
                 ClientAgentManager.Instance().SetGameTypeLoad(this.GameType, signUpCnt, startCnt);
             }
             if (now > this.SaveServerStateProcTime)
             {
                 this.SaveServerStateProcTime = now.AddSeconds(30.0);
                 if (now.Hour >= 3 && now.Hour < 4)
                 {
                     this.ClearRolePairFightCount();
                     this.Persistence.UpdateTianTiRankData(now, false, false);
                 }
             }
             if (now > this.CheckGameFuBenTime)
             {
                 this.CheckGameFuBenTime = now.AddSeconds(1000.0);
                 this.CheckGameFuBenTimerProc(now);
             }
             AsyncDataItem[] asyncEvArray = ZhengBaManagerK.Instance().Update();
             ClientAgentManager.Instance().BroadCastAsyncEvent(this.GameType, asyncEvArray);
             this.Persistence.WriteRoleInfoDataProc();
             CoupleArenaService.getInstance().Update();
             CoupleWishService.getInstance().Update();
             zhengDuoService.Instance().Update(now);
             BangHuiMatchService.Instance().Update(now);
             CompService.Instance().Update(now);
             TianTi5v5Service.ThreadProc(null);
             Zork5v5Service.Instance().Update(now);
             int sleepMS = (int)(TimeUtil.NowDateTime() - now).TotalMilliseconds;
             this.Persistence.SaveCostTime(sleepMS);
             sleepMS = 1000 - sleepMS;
             if (sleepMS < 50)
             {
                 sleepMS = 50;
             }
             Thread.Sleep(sleepMS);
         }
         catch (Exception ex)
         {
             LogManager.WriteExceptionUseCache(ex.ToString());
         }
     }
 }
Exemple #11
0
        public bool IsAgent(int serverID)
        {
            bool isAgent = ClientAgentManager.Instance().ExistAgent(serverID);

            if (!isAgent)
            {
            }
            return(isAgent);
        }
 public int SetLingZhu(int roleId, int lingDiType, int junTuanId, string junTuanName, int zhiWu, byte[] roledata)
 {
     try
     {
         int        oldRid = 0;
         LingDiData data   = new LingDiData();
         lock (this.Mutex)
         {
             if (this.LingDiDataList.Count < 2 || this.LingDiDataList[0] == null || null == this.LingDiDataList[1])
             {
                 return(0);
             }
             oldRid = this.LingDiDataList[lingDiType].RoleId;
             this.LingDiDataList[lingDiType].RoleId    = roleId;
             this.LingDiDataList[lingDiType].OpenCount = 0;
             this.LingDiDataList[lingDiType].BeginTime = DateTime.MaxValue;
             this.LingDiDataList[lingDiType].EndTime   = DateTime.MinValue;
             foreach (LingDiShouWei item in this.LingDiDataList[lingDiType].ShouWeiList)
             {
                 item.State         = 0;
                 item.FreeBuShuTime = DateTime.MinValue;
             }
             this.LingDiDataList[lingDiType].JunTuanId   = junTuanId;
             this.LingDiDataList[lingDiType].RoleData    = roledata;
             this.LingDiDataList[lingDiType].JunTuanName = junTuanName;
             data = this.LingDiDataList[lingDiType];
         }
         string optTime = TimeUtil.NowDateTime().ToString();
         string sql     = string.Format("update t_lingditequan set lingzhu=0,opttime='{2}' where rid={0} and lingditype={1};", oldRid, lingDiType, optTime);
         sql += string.Format("replace into t_lingditequan(rid,lingditype,juntuanid,juntuanname,lingzhu,roledata,opttime) values ({0},{1},{2},'{3}',{4},@roledata,'{5}');", new object[]
         {
             roleId,
             lingDiType,
             junTuanId,
             junTuanName,
             zhiWu,
             optTime
         });
         int ret = DbHelperMySQL.ExecuteSqlInsertImg(sql, new List <Tuple <string, byte[]> >
         {
             new Tuple <string, byte[]>("roledata", roledata)
         });
         if (ret > 0)
         {
             ClientAgentManager.Instance().BroadCastAsyncEvent(GameTypes.JunTuan, new AsyncDataItem(KuaFuEventTypes.SyncLingDiData, new object[]
             {
                 data
             }), 0);
             return(1);
         }
         return(ret);
     }
     catch
     {
     }
     return(0);
 }
 public AsyncData GetClientCacheItems2(int serverId, long requestTicks)
 {
     return(new AsyncData
     {
         RequestTicks = requestTicks,
         ServerTicks = TimeUtil.NOW(),
         ItemList = ClientAgentManager.Instance().PickAsyncEvent(serverId, this.GameType)
     });
 }
Exemple #14
0
        public bool IsAgent(int serverID)
        {
            bool isAgent = ClientAgentManager.Instance().ExistAgent(serverID);
            if (!isAgent)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("UnionAlly时ServerId错误.ServerId:{0}", serverID));
            }

            return isAgent;
        }
Exemple #15
0
        public bool IsAgent(int serverID)
        {
            bool isAgent = ClientAgentManager.Instance().ExistAgent(serverID);

            if (!isAgent)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("SpreadSign时ServerId错误.ServerId:{0}", serverID), null, true);
            }
            return(isAgent);
        }
Exemple #16
0
        //Remove
        public int OperateRemove(int serverID, int unionID, int targetID, bool isDel = false)
        {
            lock (_Mutex)
            {
                KFAllyData targetData = GetUnionData(targetID);
                if (targetData == null) return (int)EAlly.ENoTargetUnion;

                if (!UnionIsAlly(unionID, targetData.UnionID)) return (int)EAlly.EFail;
                if (!UnionIsAlly(targetID, unionID)) return (int)EAlly.EFail;

                bool isDelResult = AllyPersistence.Instance.DBAllyDel(unionID, targetID);
                if (!isDelResult) return (int)EAlly.EFail;

                DateTime logTime = DateTime.Now;
                int logState = (int)EAlly.AllyRemoveSucc;

                //my
                if (!isDel) _allyDic[unionID].Remove(targetID);
                //ClientAgentManager.Instance().PostAsyncEvent(serverID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyRemove, unionID, targetID));

                AllyLogData logData = new AllyLogData();
                logData.UnionID = targetData.UnionID;
                logData.UnionZoneID = targetData.UnionZoneID;
                logData.UnionName = targetData.UnionName;
                logData.MyUnionID = unionID;
                logData.LogTime = logTime;
                logData.LogState = logState;
                ClientAgentManager.Instance().PostAsyncEvent(serverID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyLog, unionID, new List<AllyLogData>() { logData }));

                //target
                if (_allyDic.ContainsKey(targetData.UnionID)) _allyDic[targetData.UnionID].Remove(unionID);

                KFAllyData myData = GetUnionData(unionID);
                logData = new AllyLogData();
                logData.UnionID = myData.UnionID;
                logData.UnionZoneID = myData.UnionZoneID;
                logData.UnionName = myData.UnionName;
                logData.MyUnionID = targetID;
                logData.LogTime = logTime;
                logData.LogState = (int)EAlly.AllyRemoveSuccOther;

                if (IsAgent(targetData.ServerID))
                {
                    ClientAgentManager.Instance().PostAsyncEvent(targetData.ServerID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyRemove, targetID, unionID));
                    ClientAgentManager.Instance().PostAsyncEvent(targetData.ServerID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyLog, targetID, new List<AllyLogData>() { logData }));
                }
                else
                {
                    AllyPersistence.Instance.DBAllyLogAdd(logData);
                }

                ClientAgentManager.Instance().KFBroadCastAsyncEvent(_gameType, new AsyncDataItem(KuaFuEventTypes.KFAllyRemove, targetID, unionID));
                return (int)EAlly.AllyRemoveSucc;
            }
        }
Exemple #17
0
 private void NotifySpreadData(KFSpreadData data)
 {
     ClientAgentManager.Instance().PostAsyncEvent(data.ServerID, this.GameType, new AsyncDataItem(KuaFuEventTypes.SpreadCount, new object[]
     {
         data.ZoneID,
         data.RoleID,
         data.CountRole,
         data.CountVip,
         data.CountLevel
     }));
 }
Exemple #18
0
 private void RemoveFuBen(long gameId)
 {
     lock (this.Mutex)
     {
         CoupleArenaFuBenData fuben;
         if (this.GameFuBenDict.TryGetValue(gameId, out fuben))
         {
             ClientAgentManager.Instance().RemoveKfFuben(this.GameType, fuben.KfServerId, fuben.GameId);
             this.GameFuBenDict.Remove(fuben.GameId);
         }
     }
 }
 public void UpdateKuaFuMapClientCount(int serverId, Dictionary <int, int> mapClientCountDict)
 {
     if (mapClientCountDict != null && mapClientCountDict.Count > 0)
     {
         ClientAgent agent = ClientAgentManager.Instance().GetCurrentClientAgent(serverId);
         if (null != agent)
         {
             KuaFuServerManager.UpdateKuaFuLineData(agent.ClientInfo.ServerId, mapClientCountDict);
             ClientAgentManager.Instance().SetMainlinePayload(agent.ClientInfo.ServerId, mapClientCountDict.Values.ToList <int>().Sum());
         }
     }
 }
Exemple #20
0
        //Refuse
        public int OperateRefuse(int serverID, int unionID, int targetID, bool isDel = false)
        {
            lock (_Mutex)
            {
                KFAllyData targetData = GetUnionData(targetID);
                if (targetData == null) return (int)EAlly.ENoTargetUnion;

                if (!UnionIsAccept(unionID, targetID)) return (int)EAlly.EFail;
                if (!UnionIsRequest(targetID, unionID)) return (int)EAlly.EFail;

                bool isDelResult = AllyPersistence.Instance.DBAllyRequestDel(targetID, unionID);
                if (!isDelResult) return (int)EAlly.EFail;

                DateTime logTime = DateTime.Now;
                int logState = (int)EAlly.AllyRefuse;

                //my
                KFAllyData rData = GetAcceptData(unionID, targetID);
                if (!isDel) _acceptDic[unionID].Remove(rData);
                ClientAgentManager.Instance().PostAsyncEvent(serverID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyAcceptRemove, unionID, targetID));

                //target
                if (_requestDic.ContainsKey(targetID))
                {
                    KFAllyData aData = GetRequestData(targetID, unionID);
                    _requestDic[targetID].Remove(aData);
                }

                KFAllyData myData = GetUnionData(unionID);
                AllyLogData logData = new AllyLogData();
                logData.UnionID = myData.UnionID;
                logData.UnionZoneID = myData.UnionZoneID;
                logData.UnionName = myData.UnionName;
                logData.MyUnionID = targetID;
                logData.LogTime = logTime;
                logData.LogState = (int)EAlly.AllyRefuseOther;

                if (IsAgent(targetData.ServerID))
                {
                    ClientAgentManager.Instance().PostAsyncEvent(targetData.ServerID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyRequestRemove, targetID, unionID));
                    ClientAgentManager.Instance().PostAsyncEvent(targetData.ServerID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyLog, targetID, new List<AllyLogData>() { logData }));
                }
                else
                {
                    AllyPersistence.Instance.DBAllyLogAdd(logData);
                }

                return (int)EAlly.AllyRefuse;
            }
        }
Exemple #21
0
        private static void UpdateServerLoad()
        {
            lock (Mutex)
            {
                foreach (var srv in _ServerIdServerInfoDict.Values)
                {
                    int load = 0, state = 0;
                    ClientAgentManager.Instance().GetServerState(srv.ServerId, out state, out load);
                    if (load != srv.Load || state != srv.State)
                    {
                        try
                        {
                            DbHelperMySQL.ExecuteSql(string.Format("update ignore t_server_info set `load`={0},`state`={1} where `serverid`={2}", load, state, srv.ServerId));
                            srv.Load  = load;
                            srv.State = state;
                        }
                        catch (System.Exception ex)
                        {
                            LogManager.WriteExceptionUseCache(ex.ToString());
                        }
                    }
                }

                Dictionary <int, GameTypeStaticsData> statics = ClientAgentManager.Instance().GetGameTypeStatics();
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("DELETE FROM t_server_load;");
                if (statics != null)
                {
                    foreach (var kvp in statics)
                    {
                        sb.AppendFormat("INSERT INTO t_server_load(gametype, server_alived, fuben_alived, role_signup_count, role_start_game_count,tip) VALUES({0}, {1}, {2}, {3}, {4},'{5}');",
                                        (int)kvp.Key, kvp.Value.ServerAlived, kvp.Value.FuBenAlived, kvp.Value.SingUpRoleCount, kvp.Value.StartGameRoleCount, ((GameTypes)kvp.Key).ToString());
                        sb.AppendLine();
                    }
                }

                try
                {
                    DbHelperMySQL.ExecuteSql(sb.ToString());
                }
                catch (System.Exception ex)
                {
                    LogManager.WriteExceptionUseCache(ex.ToString());
                }
            }
        }
        public int SetDoubleOpenTime(int roleId, int lingDiType, DateTime openTime, int openSeconds)
        {
            LingDiData data = null;

            lock (this.Mutex)
            {
                if (this.LingDiDataList[lingDiType] == null)
                {
                    return(-8);
                }
                this.LingDiDataList[lingDiType].BeginTime = openTime;
                this.LingDiDataList[lingDiType].EndTime   = openTime.AddSeconds((double)openSeconds);
                this.LingDiDataList[lingDiType].OpenCount++;
                data = this.LingDiDataList[lingDiType];
            }
            int ret = 0;

            try
            {
                string upd = string.Format("update t_lingditequan set begintime='{0}',endtime='{1}',opencount={2},opttime='{5}' where rid={3} and lingditype={4}", new object[]
                {
                    data.BeginTime,
                    data.EndTime,
                    data.OpenCount,
                    roleId,
                    lingDiType,
                    TimeUtil.NowDateTime().ToString()
                });
                ret = DbHelperMySQL.ExecuteSql(upd);
                if (ret > 0)
                {
                    ClientAgentManager.Instance().BroadCastAsyncEvent(GameTypes.JunTuan, new AsyncDataItem(KuaFuEventTypes.SyncLingDiDoubleOpenData, new object[]
                    {
                        data
                    }), 0);
                    return(1);
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("初始化跨服地图{0}时出错!!!", "领地采集"), null, true);
                return(-7);
            }
            return(ret);
        }
        public void ThreadProc(object state)
        {
            Persistence.InitConfig();

            DateTime lastRunTime = TimeUtil.NowDateTime();

            do
            {
                try
                {
                    DateTime now = TimeUtil.NowDateTime();
                    Global.UpdateNowTime(now);

                    //处理游戏逻辑
                    if (now > CheckRoleTimerProcTime)
                    {
                        CheckRoleTimerProcTime = now.AddSeconds(CheckRoleTimerProcInterval);
                        int signUpCount, startCount;
                        CheckRoleTimerProc(now, out signUpCount, out startCount);
                        ClientAgentManager.Instance().SetGameTypeLoad(GameType, signUpCount, startCount);
                    }

                    if (now > CheckGameFuBenTime)
                    {
                        CheckGameFuBenTime = now.AddSeconds(CheckGameFuBenInterval);
                        CheckGameFuBenTimerProc(now);
                    }

                    int sleepMS = (int)((TimeUtil.NowDateTime() - now).TotalMilliseconds);
                    Persistence.SaveCostTime(sleepMS);
                    sleepMS = 1600 - sleepMS; //最大睡眠1600ms,最少睡眠50ms
                    if (sleepMS < 50)
                    {
                        sleepMS = 50;
                    }

                    Thread.Sleep(sleepMS);
                }
                catch (System.Exception ex)
                {
                    LogManager.WriteExceptionUseCache(ex.ToString());
                }
            } while (true);
        }
Exemple #24
0
        public int RoleChangeState(int serverId, int roleId, int state)
        {
            KuaFuRoleKey  key = KuaFuRoleKey.Get(serverId, roleId);
            KuaFuRoleData kuaFuRoleData;
            int           result;

            if (!this.RoleIdKuaFuRoleDataDict.TryGetValue(key, out kuaFuRoleData))
            {
                result = -11003;
            }
            else
            {
                int oldGameId = 0;
                lock (kuaFuRoleData)
                {
                    if (state == 0)
                    {
                        if (kuaFuRoleData.GameId > 0)
                        {
                            TianTiFuBenData fuBenData;
                            if (this.TianTiFuBenDataDict.TryGetValue(kuaFuRoleData.GameId, out fuBenData))
                            {
                                AsyncDataItem evItem = new AsyncDataItem(KuaFuEventTypes.CopyCanceled, new object[]
                                {
                                    kuaFuRoleData.GameId
                                });
                                ClientAgentManager.Instance().PostAsyncEvent(fuBenData.ServerId, this.GameType, evItem);
                            }
                        }
                        oldGameId            = kuaFuRoleData.GameId;
                        kuaFuRoleData.GameId = 0;
                    }
                    kuaFuRoleData.Age++;
                    kuaFuRoleData.State = (KuaFuRoleStates)state;
                }
                if (oldGameId > 0)
                {
                    this.RemoveRoleFromFuBen(oldGameId, roleId);
                }
                result = state;
            }
            return(result);
        }
        public void ThreadProc(object state)
        {
            do
            {
                Thread.Sleep(1000);
            }while (!this.Persistence.Initialized);
            DateTime lastRunTime = TimeUtil.NowDateTime();

            for (;;)
            {
                try
                {
                    DateTime now = TimeUtil.NowDateTime();
                    Global.UpdateNowTime(now);
                    if (now > this.CheckRoleTimerProcTime)
                    {
                        this.CheckRoleTimerProcTime = now.AddSeconds(1.428);
                        int signUpCount;
                        int startCount;
                        this.CheckRoleTimerProc(now, out signUpCount, out startCount);
                        ClientAgentManager.Instance().SetGameTypeLoad(this.GameType, signUpCount, startCount);
                    }
                    if (now > this.CheckGameFuBenTime)
                    {
                        this.CheckGameFuBenTime = now.AddSeconds(1000.0);
                        this.CheckGameFuBenTimerProc(now);
                    }
                    int sleepMS = (int)(TimeUtil.NowDateTime() - now).TotalMilliseconds;
                    this.Persistence.SaveCostTime(sleepMS);
                    sleepMS = 1600 - sleepMS;
                    if (sleepMS < 50)
                    {
                        sleepMS = 50;
                    }
                    Thread.Sleep(sleepMS);
                }
                catch (Exception ex)
                {
                    LogManager.WriteExceptionUseCache(ex.ToString());
                }
            }
        }
Exemple #26
0
        private void ThreadProc(object state)
        {
            dbMgr.InitConfig();

            do
            {
                try
                {
                    long     nowMs = TimeUtil.NOW();
                    DateTime now   = DateTime.Now;
                    Global.UpdateNowTime(now);

                    // 每个30秒存储服务器状态
                    const int SaveServerStateIntervalMs = 30 * 1000;
                    if (nowMs >= LastSaveServerStateMs + SaveServerStateIntervalMs)
                    {
                        LastSaveServerStateMs = nowMs;
                        dbMgr.SaveCopyTeamAnalysisData(teamMgr.BuildAnalysisData());
                    }

                    // 队伍管理器(处理超时关闭)
                    teamMgr.Update();
                    AsyncDataItem[] evList = teamMgr.PopAsyncEvent();
                    ClientAgentManager.Instance().BroadCastAsyncEvent(GameType, evList);
                    dbMgr.CheckLogAsyncEvents(evList);

                    int sleepMS = (int)((DateTime.Now - now).TotalMilliseconds);
                    dbMgr.SaveCostTime(sleepMS);
                    sleepMS = 1600 - sleepMS; //最大睡眠1600ms,最少睡眠50ms
                    if (sleepMS < 50)
                    {
                        sleepMS = 50;
                    }

                    Thread.Sleep(sleepMS);
                }
                catch (System.Exception ex)
                {
                    LogManager.WriteExceptionUseCache(ex.ToString());
                }
            } while (true);
        }
 public void BroadcastGMCmdData(GMCmdData data, int serverFlag)
 {
     lock (this.Mutex)
     {
         if (serverFlag == 1)
         {
             ClientAgentManager.Instance().KFBroadCastAsyncEvent(GameTypes.HuanYingSiYuan, new AsyncDataItem(KuaFuEventTypes.GMCmd, new object[]
             {
                 data
             }));
         }
         else
         {
             ClientAgentManager.Instance().BroadCastAsyncEvent(GameTypes.HuanYingSiYuan, new AsyncDataItem(KuaFuEventTypes.GMCmd, new object[]
             {
                 data
             }), 0);
         }
     }
 }
Exemple #28
0
 /// <summary>
 /// 初始化跨服客户端回调对象
 /// </summary>
 public int InitializeClient(IKuaFuClient callback, KuaFuClientContext clientInfo)
 {
     try
     {
         if (clientInfo.GameType == (int)GameTypes.Spread && clientInfo.ServerId != 0)
         {
             return(ClientAgentManager.Instance().InitializeClient(callback, clientInfo));
         }
         else
         {
             LogManager.WriteLog(LogTypes.Warning, string.Format("InitializeClient时GameType错误,禁止连接.ServerId:{0},GameType:{1}", clientInfo.ServerId, clientInfo.GameType));
             return(StdErrorCode.Error_Invalid_GameType);
         }
     }
     catch (System.Exception ex)
     {
         LogManager.WriteExceptionUseCache(string.Format("InitializeClient服务器ID重复,禁止连接.ServerId:{0},ClientId:{1}", clientInfo.ServerId, clientInfo.ClientId));
         return(StdErrorCode.Error_Server_Internal_Error);
     }
 }
Exemple #29
0
		private void ClearZhengDuoFuBenData()
		{
			lock (this.Mutex)
			{
				if (this.SyncData.State == 0)
				{
					foreach (ZhengDuoFuBenData data in this.FuBenDict.Values)
					{
						try
						{
							ClientAgentManager.Instance().RemoveKfFuben(GameTypes.ZhengDuo, data.ServerId, data.GameId);
						}
						catch (Exception ex)
						{
							LogManager.WriteException(ex.ToString());
						}
					}
				}
			}
		}
 public bool GetClientCacheItems(int serverId)
 {
     lock (this.Mutex)
     {
         if (this.Initialized)
         {
             ClientAgent agent = ClientAgentManager.Instance().GetCurrentClientAgent(serverId);
             if (agent != null && agent.ClientInfo.ClientId > 0)
             {
                 int clientId;
                 if (!this.BroadcastServerIdHashSet.TryGetValue(serverId, out clientId) || clientId != agent.ClientInfo.ClientId)
                 {
                     this.BroadcastServerIdHashSet[serverId] = agent.ClientInfo.ClientId;
                     return(true);
                 }
             }
         }
     }
     return(false);
 }