bool updateRealItemCnt(string s, ShareRealItemCnt sric)
        {
            memoryRealInfoDataModel.HappyData hd = GameConfigMgr.Instance().getHappyData(sric.itemID);
            if (hd != null)
            {
                int      MinuteForReflesh = hd.MinuteForReflesh;
                DateTime now = DateTime.Now;
                TimeSpan ts  = now - sric.preUpdateTime;
                if (ts.TotalMinutes > MinuteForReflesh)
                {
                    sric.ModifyLocked(() =>
                    {
                        sric.preUpdateTime = now;
                        sric.num           = hd.RefleshNum;
                    });
                }
            }
            else
            {
                ConsoleLog.showErrorInfo(0, "RealItemCntUpdate error." + sric.itemID);
                TraceLog.WriteError("RealItemCntUpdate error." + sric.itemID);
            }

            // todo
            return(true);
        }
Exemple #2
0
 public ServerInfo()
 {
     // read config
     serverType    = GameConfigMgr.Instance().getInt("serverType", 0x0010000);
     serverID      = getID();
     serverHostStr = ConfigUtils.GetSetting("Game.Http.Host", "0.0.0.0");
     serverHost    = utils.getIpUnit(serverHostStr);
     serverPort    = ConfigUtils.GetSetting("Game.Http.Port", 0);
 }
        public bool update_HappyModeData_enterNum(string s0, string s1, HappyModeData hmd)
        {
            int maxEnterNum = GameConfigMgr.Instance().getInt("happyPointMaxEnterNum", 3);

            hmd.ModifyLocked(() => {
                hmd.EnterNum = maxEnterNum;
            });
            return(true);
        }
 static int getDiamond(int index)
 {
     GameConfigRankingReward.rewardData rd = GameConfigMgr.Instance().getRankReward(index + 1);
     if (rd != null)
     {
         return(rd.Diamonds);
     }
     return(0);
 }
        public void doIt()
        {
            ConsoleLog.showNotifyInfo("RankingClear Begin:");
            RankingFactorNew.Singleton().Refresh <UserRanking>(typeof(RankingScore).ToString());
            RankingFactorNew.Singleton().Loop <UserRanking>(typeof(RankingScore).ToString(), addRankingReward);

            // get fake data.
            // getFake();

            // memoryData,clear lst and unload sharecache
            RankingFactorNew.Singleton().Clear <UserRanking>(typeof(RankingScore).ToString());

            // redis delete
            List <int> keysremove        = new List <int>();
            var        urcache           = new ShareCacheStruct <UserRanking>();
            float      percent           = GameConfigMgr.Instance().getInt("rankclear_perscent", 1) / 100.0f;
            int        reduceScore       = GameConfigMgr.Instance().getInt("rank_score_redice", 10000);
            float      reduceAfterScorre = GameConfigMgr.Instance().getfloat("rank_clear_after", 0.1f);

            urcache.Foreach((string str, UserRanking ur) =>
            {
                if (ur.Score > reduceScore)
                {
                    ur.ModifyLocked(() =>
                    {
                        ur.Score = (int)(reduceAfterScorre * ur.Score);
                    });
                }
                return(true);
            });

            //  ZyGames.Framework.Redis.RedisConnectionPool.Process(client =>
            //  {
            //      string delKey = "$" + typeof(UserRanking).ToString();
            //      for(int i=0; i<keysremove.Count; ++i)
            //      {
            //          byte[] byteKeys = Encoding.UTF8.GetBytes(keysremove[i].ToString());
            //           client.HDel(delKey, byteKeys);
            //      }
            //  });

            // mysql delete
            //  var dbProvider = DbConnectionProvider.CreateDbProvider("ConnData");
            //  var command = dbProvider.CreateCommandStruct("UserRanking", CommandMode.Delete);
            //  command.Parser();
            //  dbProvider.ExecuteQuery(System.Data.CommandType.Text, command.Sql, command.Parameters);

            // update UserRankingTotal
            RankingFactorNew.Singleton().Refresh <UserRankingTotal>(typeof(RankingTotal).ToString());

            // add fake data mybe this is has not data ....
            // setFake();

            RankingFactorNew.Singleton().Refresh <UserRanking>(typeof(RankingScore).ToString());
            ConsoleLog.showNotifyInfo("RankingClear End");
        }
 public static GameConfigMgr Instance()
 {
     if (null == _instance)
     {
         _instance         = new GameConfigMgr();
         _instance._rwLock = new ReaderWriterLockSlim();
         _instance.Init();
     }
     return(_instance);
 }
        void Init()
        {
            var        cache   = new ShareCacheStruct <ShareRealItemCnt>();
            List <int> itemIds = GameConfigMgr.Instance().getHappyDataKeys();

            memoryRealInfoDataModel.HappyData hd = null;
            for (int i = 0; i < itemIds.Count; ++i)
            {
                if (null == cache.FindKey(itemIds[i])) // first add
                {
                    ShareRealItemCnt sric = new ShareRealItemCnt();
                    hd          = GameConfigMgr.Instance().getHappyData(itemIds[i]);
                    sric.itemID = hd.itemID;
                    sric.num    = hd.RefleshNum;
                    cache.Add(sric);
                }
            }

            string timestr = GameConfigMgr.Instance().getString("timer_item_cnt", "600000,600000");

            string[] tt = timestr.Split(',');
            int      b0 = int.Parse(tt[0]);
            int      b1 = int.Parse(tt[1]);

            TimerMgr.Singleton().add(typeof(RealItemCntUpdate).ToString(), actionrealItemCnt, b0, b1);

            bool openDebug = GameConfigMgr.Instance().getInt("timer_open_debug", 0) == 1;

            if (openDebug)
            {
                timestr = GameConfigMgr.Instance().getString("time_hdm_cnt", "600000,600000");
                tt      = timestr.Split(',');
                b0      = int.Parse(tt[0]);
                b1      = int.Parse(tt[1]);
                TimerMgr.Singleton().add("HappyModeData_EnterNum", action_HappyModeData_enterNum, b0, b1);
            }
            else
            {
                //每天05点执行
                try
                {
                    timestr = GameConfigMgr.Instance().getString("time_hdm_cnt_timming", "05:15");
                }
                catch
                {
                    timestr = "05:15";
                }
                TimeListener.Append(PlanConfig.EveryDayPlan(DoEveryDayExecute, "EveryDayTask", timestr));
                ConsoleLog.showNotifyInfo("HappyModeData_EnterNum begin:" + timestr);
            }
        }
        void init()
        {
            bool openDebug = GameConfigMgr.Instance().getInt("timer_open_debug", 0) == 1;

            if (openDebug)
            {
                string   debugParm = GameConfigMgr.Instance().getString("timer_user_ranking_clear", "330000,330000");
                string[] words     = debugParm.Split(',');
                TimerMgr.Singleton().add("RankingClear", ccccc, int.Parse(words[0]), int.Parse(words[1]));
            }
            else
            {
                string theStr = GameConfigMgr.Instance().getString("timer_user_ranking_clear_timming", "05:00");
                //每天0点执行
                TimeListener.Append(PlanConfig.EveryDayPlan(DoEveryWeekExecute, "EveryDayTask", theStr));
                ConsoleLog.showNotifyInfo("timer_user_ranking_clear_timming begin:" + theStr);
            }
        }
        void getFake()
        {
            ConsoleLog.showNotifyInfo("get fake begin");
            fakeLst = new List <UserRanking>();
            int   num                = GameConfigMgr.Instance().getInt("rank_send_num", 10);
            float percent            = GameConfigMgr.Instance().getInt("rankclear_perscent", 1) / 100.0f;
            int   reduceScore        = GameConfigMgr.Instance().getInt("rank_score_redice", 1);
            List <UserRanking> urlst = RankingFactorNew.Singleton().get <UserRanking>(typeof(RankingScore).ToString());

            if (null == urlst)
            {
                TraceLog.WriteError("getFake()");
                ConsoleLog.showErrorInfo(0, "getFake()");
                return;
            }
            var rankCache = new ShareCacheStruct <UserRanking>();
            var userCache = new PersonalCacheStruct <GameUser>();

            for (int i = 0; i < urlst.Count; ++i)
            {
                if (i > num)
                {
                    break;
                }
                UserRanking ur = urlst[i];
                if (ur.Score > reduceScore)
                {
                    ur.Score = (int)((float)urlst[i].Score * percent);
                    UserRanking cacheUR = rankCache.FindKey(ur.UserID);
                    if (null != cacheUR)
                    {
                        cacheUR.ModifyLocked(() => { cacheUR.Score = ur.Score; });
                    }
                    GameUser cacheGU = userCache.FindKey(ur.UserID.ToString());
                    if (null != cacheGU)
                    {
                        cacheGU.ModifyLocked(() => { cacheGU.Score = ur.Score; });
                    }
                }
                fakeLst.Add(copy(ur));
            }
            ConsoleLog.showNotifyInfo("getFake:" + fakeLst.Count);
            ConsoleLog.showNotifyInfo("get fake end");
        }
Exemple #10
0
        protected override void OnStartAffer()
        {
            new ShareCacheStruct <UserRanking>();
            new ShareCacheStruct <HistoryUserRanking>();
            new ShareCacheStruct <ExchangeCode>();
            new ShareCacheStruct <UserRankingTotal>();

            NewGameConfig.Singleton().CreateDBTable();
            happyMapInit();
            List <GameRanking.Pack.ConfigData> LST_d = new List <GameRanking.Pack.ConfigData>();

            NewGameConfig.Singleton().getActivityDate(LST_d, "1.08");

            GameConfigMgr.Instance().Start();

            RankingFactorNew.Singleton().add <UserRanking>(typeof(RankingScore).ToString(), new RankingScore());
            RankingFactorNew.Singleton().add <UserRankingTotal>(typeof(RankingTotal).ToString(), new RankingTotal());
            bool openDebug = GameConfigMgr.Instance().getInt("timer_open_debug", 0) == 1;

            if (openDebug)
            {
                string str = GameConfigMgr.Instance().getString("timer_user_ranking", "10000,20000");
                RankingFactorNew.Singleton().Start <UserRanking>(typeof(RankingScore).ToString(), sortMethod.sortType.Interval, str);
                RankingFactorNew.Singleton().Start <UserRankingTotal>(typeof(RankingTotal).ToString(), sortMethod.sortType.Interval, str);
            }
            else
            {
                string strTiming = GameConfigMgr.Instance().getString("timer_user_ranking_timming", "00:00");
                RankingFactorNew.Singleton().Start <UserRanking>(typeof(RankingScore).ToString(), sortMethod.sortType.Timing, strTiming);
                RankingFactorNew.Singleton().Start <UserRankingTotal>(typeof(RankingTotal).ToString(), sortMethod.sortType.Timing, strTiming);
                ConsoleLog.showNotifyInfo("timer_user_ranking_timming begin:" + strTiming);
            }

            RankingClear.Instance().Start();
            RealItemCntUpdate.Instance().Start();
        }
Exemple #11
0
 public static GameConfigMgr Instance()
 {
     if (null == _instance)
     {
         _instance = new GameConfigMgr();
         _instance._rwLock = new ReaderWriterLockSlim();
         _instance.Init();
     }
     return _instance;
 }
Exemple #12
0
        static bool addRankingReward(List <UserRanking> rankingList)
        {
            if (null == rankingList)
            {
                ConsoleLog.showErrorInfo(135, "addRankingReward:Error");
                TraceLog.WriteError("Error : addRankingReward");
                return(false);
            }
            int scoreNum = GameConfigMgr.Instance().getInt("rankclear_scoreNum", 20);
            int DemoNum  = GameConfigMgr.Instance().getInt("rankclear_dimondNum", 10000);

            int max = Math.Max(scoreNum, DemoNum);
            // get Score accounding to Ranking
            var totalCache  = new ShareCacheStruct <UserRankingTotal>();
            var personCache = new PersonalCacheStruct <GameUser>();

            for (int i = 0; i < rankingList.Count; ++i)
            {
                if (i < DemoNum)
                {
                    UserRanking      ur    = rankingList[i];
                    int              score = getScore(i);
                    UserRankingTotal urt   = totalCache.FindKey(ur.UserID);
                    if (null == urt)
                    {
                        UserRankingTotal newUrt = new UserRankingTotal();
                        newUrt.UserID = ur.UserID;
                        newUrt.Total  = score;
                        totalCache.Add(newUrt);
                    }
                    else
                    {
                        urt.ModifyLocked(() =>
                        {
                            urt.Total += score;
                        });
                    }
                }
                int      UserId = rankingList[i].UserID;
                GameUser gu     = personCache.FindKey(UserId.ToString());
                if (i < DemoNum)
                {
                    if (null != gu)
                    {
                        gu.ModifyLocked(() =>
                        {
                            gu.Diamond  += getDiamond(i);
                            gu.theTotal += getScore(i);
                        });
                    }
                }

                if (null != gu)
                {
                    gu.ModifyLocked(() =>
                    {
                        gu.preRanking = i + 1;
                    });
                }
            }

            return(true);
        }