コード例 #1
0
        public IEnumerator ServerGMCommand(Coroutine coroutine, RankService _this, ServerGMCommandInMessage msg)
        {
            var cmd   = msg.Request.Cmd;
            var param = msg.Request.Param;

            Logger.Info("Rank----------ServerGMCommand----------cmd={0}|param={1}", cmd, param);

            try
            {
                if ("ReloadTable" == cmd)
                {
                    Table.ReloadTable(param);
                }
                else if ("BackupRank" == cmd)
                {
                    ServerRankBackupManager.BackupAllRank(null, DateTime.Now);
                }
            }
            catch (Exception e)
            {
                Logger.Error("Rank----------ServerGMCommand----------error={0}", e.Message);
            }
            finally
            {
            }
            yield break;
        }
コード例 #2
0
        public IEnumerator BackupTotalRankCoroutine(Coroutine coroutine)
        {
            var timeStr = ServerRankBackupManager.FormatDateTimeToKey(DateTime.Now);
            var rankMgr = ServerRankManager.TotalRank;

            DBRankBackupServer db = new DBRankBackupServer();

            db.ServerId = rankMgr.ServerId;

            foreach (var rankMgrKV in rankMgr.rank)
            {
                DBRankList dbList = new DBRankList();
                dbList.Type = rankMgrKV.Key;

                var rank = rankMgrKV.Value;
                int i    = 0;
                foreach (var charId in rank.RankUUIDList)
                {
                    if (dbList.Items.Count >= ServerRankBackupManager.MAXMember)
                    {
                        break;
                    }
                    DBRank_One one = null;
                    if (!rank.DBRankCache.TryGetValue(charId, out one))
                    {
                        continue;
                    }

                    DBRankItem item = new DBRankItem();
                    item.CharacterId = one.Guid;
                    item.Name        = one.Name;
                    item.Value       = one.Value;
                    dbList.Items.Add(item);
                    i++;
                }
                db.List.Add(dbList);
            }

            var key = string.Format("{0}|{1}", timeStr, db.ServerId);

            Logger.Trace("BackupAllRankCoroutine-----begin[{0}]   key=[{1}]", DateTime.Now, key);

            var result = RankServer.Instance.DB.Set <DBRankBackupServer>(coroutine, DataCategory.RankBackup,
                                                                         key, db);

            yield return(result);

            if (DataStatus.Ok != result.Status)
            {
                Logger.Fatal("RankServer.Instance.DB.Set  DataStatus.Ok != result.Status [{0}]", key);
            }
            Logger.Trace("BackupTotalRankCoroutine-----end[{0}] key=[{1}]", DateTime.Now, key);
        }
コード例 #3
0
        public void Init()
        {
// #if DEBUG
//          var time = DateTime.Now.AddMinutes(1);
//          RankServerControl.Timer.CreateTrigger(time, ServerRankBackupManager.BackupAllRank, 1000 * 60);
// #else
            var time = DateTime.Now.Date + ServerRankBackupManager.Span;

            RankServerControl.Timer.CreateTrigger(time,
                                                  () => { ServerRankBackupManager.BackupAllRank(null, DateTime.Now.Date); }, //1月1号00:02分保存成1月1号的数据
                                                  ServerRankBackupManager.Interval);                                         //每24小时存储一次
//#endif
        }
コード例 #4
0
        public IEnumerator OnServerStart(Coroutine coroutine, RankService _this)
        {
            var rankServerControl = (RankServerControl)_this;

            //Thread.Sleep(GlobalVariable.WaitToConnectTimespan);
            RankServer.Instance.Start(rankServerControl);
            CoroutineFactory.NewCoroutine(ServerRankManager.Init).MoveNext();
            ServerRankBackupManager.Init();
            RankServer.Instance.IsReadyToEnter = true;
            _this.TickDuration = 1.0f;

            _this.Started = true;

            Console.WriteLine("RankServer startOver. [{0}]", RankServer.Instance.Id);
            return(null);
        }
コード例 #5
0
ファイル: GameMaster.cs プロジェクト: tuita520/mmorpgserver
        public IEnumerator GmCommand(Coroutine co, string commond, AsyncReturnValue <ErrorCodes> err)
        {
            err.Value = ErrorCodes.OK;

            var strs = commond.Split(',');

            if (strs.Length < 1)
            {
                err.Value = ErrorCodes.ParamError;
                yield break;
            }
            if (String.Compare(strs[0], "!!ReloadTable", StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (strs.Length < 2)
                {
                    err.Value = ErrorCodes.ParamError;
                    yield break;
                }
                GameMaster.ReloadTable(strs[1]);
                yield break;
            }
            var nIndex  = 0;
            var IntData = new List <int>();

            foreach (var s in strs)
            {
                if (nIndex != 0)
                {
                    int TempInt;
                    if (!Int32.TryParse(s, out TempInt))
                    {
                        err.Value = ErrorCodes.ParamError;
                        yield break;
                    }
                    IntData.Add(TempInt);
                }
                nIndex++;
            }
            if (String.Compare(strs[0], "!!LookRank", StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (IntData.Count == 0)
                {
                    GameMaster.LookRank();
                }
            }
            else if (String.Compare(strs[0], "!!BackupRank", StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (1 == strs.Length)
                {
                    ServerRankBackupManager.BackupAllRank(null, DateTime.Now);
                }
                else
                {
                    var serverList = new List <int>();
                    for (int i = 1; i < strs.Length; i++)
                    {
                        int ret = -1;
                        if (int.TryParse(strs[i], out ret))
                        {
                            serverList.Add(ret);
                        }
                    }
                    ServerRankBackupManager.BackupAllRank(serverList, DateTime.Now);
                }
            }
        }
コード例 #6
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;
        }