Exemplo n.º 1
0
        public IEnumerator SSGetRankDataByServerId(Coroutine coroutine, RankService _this, SSGetRankDataByServerIdInMessage msg)
        {
            var serverList = msg.Request.ServerList;
            var time       = msg.Request.Time;
            var type       = msg.Request.Ranktype;

            //请求这个时间点的数据不存在,那就把当前的排行榜数据存成那个时间点,防止下次再取时,又会取下次的排行榜,但排行榜会变化
            var needSave = false;


            var timeStr = ServerRankBackupManager.FormatDateTimeToKey(DateTime.FromBinary(time));

            foreach (var sid in serverList.Items)
            {
                string             tempKey = timeStr + "|" + sid;
                DBRankBackupServer data    = null;
                if (!ServerRankBackupManager.DictRankDataCache.TryGetValue(tempKey, out data))
                {
                    var result = RankServer.Instance.DB.Get <DBRankBackupServer>(coroutine, DataCategory.RankBackup, tempKey);

                    yield return(result);

                    if (DataStatus.Ok == result.Status && null != result.Data)
                    {
                        data = result.Data;

                        if (ServerRankBackupManager.DictRankDataCache.ContainsKey(tempKey))
                        {
                            ServerRankBackupManager.DictRankDataCache[tempKey] = data;
                        }
                        else
                        {
                            ServerRankBackupManager.DictRankDataCache.Add(tempKey, data);
                        }
                    }
                    else
                    {
                        Logger.Fatal("RankServer.Instance.DB.Get  DataStatus.Ok != result.Status [{0}]", tempKey);
                    }
                }

                bool ok = false;
                if (null != data)
                {
                    foreach (var item in data.List)
                    {
                        if (item.Type != type)
                        {
                            continue;
                        }
                        MsgRankList msgList = new MsgRankList();
                        msgList.ServerId = sid;
                        msgList.Type     = type;

                        foreach (var rankItem in item.Items)
                        {
                            if (msgList.Items.Count >= ServerRankBackupManager.MAXMember)
                            {
                                break;
                            }
                            MsgRankItemData msgItem = new MsgRankItemData();
                            msgItem.CharacterId = rankItem.CharacterId;
                            msgItem.Name        = rankItem.Name;
                            msgItem.Value       = rankItem.Value;

                            msgList.Items.Add(msgItem);
                        }
                        msg.Response.Data.Add(msgList);

                        ok = true;
                        break;
                    }
                }

                if (!ok)
                {                //数据库没找到就取当前数据
                    needSave = true;

                    foreach (var rankMgrKV in ServerRankManager.Ranks)
                    {
                        if (rankMgrKV.Value.ServerId != sid)
                        {
                            continue;
                        }
                        foreach (var rank in rankMgrKV.Value.rank)
                        {
                            if (rank.Value.RankType != type)
                            {
                                continue;
                            }
                            ok = true;
                            MsgRankList msgList = new MsgRankList();
                            msgList.ServerId = sid;
                            msgList.Type     = type;
                            foreach (var charId in rank.Value.RankUUIDList)
                            {
                                if (msgList.Items.Count >= ServerRankBackupManager.MAXMember)
                                {
                                    break;
                                }

                                DBRank_One one = null;
                                if (!rank.Value.DBRankCache.TryGetValue(charId, out one))
                                {
                                    continue;
                                }

                                MsgRankItemData msgItem = new MsgRankItemData();
                                msgItem.CharacterId = one.Guid;
                                msgItem.Name        = one.Name;
                                msgItem.Value       = one.Value;

                                msgList.Items.Add(msgItem);
                            }
                            msg.Response.Data.Add(msgList);
                            break;
                        }

                        break;
                    }
                }

                if (!ok)
                {
                    Logger.Fatal("SSGetRankDataByServerId  [{0}]-[{1}]", timeStr, type);
                }
            }

            msg.Reply((int)ErrorCodes.OK);

            if (needSave)
            {    //需要保存数据库
                var passedTime = DateTime.FromBinary(time);
                var serverl    = new List <int>();
                foreach (var item in serverList.Items)
                {
                    serverl.Add(item);
                }
                var co = CoroutineFactory.NewSubroutine(ServerRankBackupManager.BackupAllRankCoroutine, coroutine, serverl, passedTime);
                if (co.MoveNext())
                {
                    yield return(co);
                }
            }

            yield break;
        }
Exemplo n.º 2
0
        public override void RefreshActivity(OperationActivity data)
        {
            base.RefreshActivity(data);
            var actRank = data as OperationActivityRank;

            if (eRechargeActivityOpenRule.NewServerAuto == data.OpenRule)
            {
                ScoreTime = DateTime.Parse(Table.GetServerName(Controller.serverId).OpenTime).AddHours(data.ScoreDelayHours).AddSeconds(30);
            }
            else if (eRechargeActivityOpenRule.LimitTime == data.OpenRule ||
                     eRechargeActivityOpenRule.Last == data.OpenRule)
            {
                ScoreTime = actRank.ScoreTime;
            }

            if (null == actRank)
            {
                return;
            }
            foreach (var actItem in Items)
            {
                actItem.Need           = 1;
                actItem.Desc           = "【" + Table.GetDictionary(100002286).Desc[0] + "】";
                actItem.mDBData.Status = 0;
            }

            if (RankType.Level == RankType)
            {
                OnRankDataChange(RankType.Level, (long)Controller.mBag.GetRes(eResourcesType.LevelRes));
            }
            else if (RankType.Money == RankType)
            {
                OnRankDataChange(RankType.Money,
                                 (long)Controller.mBag.GetRes(eResourcesType.GoldRes));
            }


            if (actRank.HasResult)
            {
                MsgRankList list = null;
                if (!actRank.DictRankData.TryGetValue(Controller.serverId, out list))
                {
                    return;
                }

                foreach (var actItem in Items)
                {
                    actItem.mDBData.Status = 0;

                    var needRankIdx = actItem.Params[0];
                    if (-1 == needRankIdx)
                    {
                        if (mDBData.Param >= actItem.Params[1] &&
                            -2 == Controller.CheckCondition(actItem.Condition))
                        {
                            actItem.mDBData.Status = 1;
                        }
                        else
                        {
                            actItem.mDBData.Status = 0;
                        }
                    }
                    else
                    {
                        if (needRankIdx >= 0 && needRankIdx < list.Items.Count)
                        {
                            var rankData = list.Items[needRankIdx];
                            actItem.Desc = string.Format("【{0}】", rankData.Name);

                            if (rankData.CharacterId == Controller.mGuid &&
                                rankData.Value >= actItem.Params[1] &&
                                -2 == Controller.CheckCondition(actItem.Condition))
                            {
                                actItem.mDBData.Status = 1;
                            }
                            else
                            {
                                actItem.mDBData.Status = 0;
                            }
                        }
                    }
                }
            }
        }