Example #1
0
        private int ComputeTotalNum(LinkedList <LimitAnalysisData> list, string key, LimitResultData CheckData)
        {
            int result = 0;
            int result2;

            if (list.Count == 0)
            {
                result2 = result;
            }
            else
            {
                this.DoHouseKeepingForAnalysisData(list);
                foreach (LimitAnalysisData data in list)
                {
                    int count = 0;
                    if (data.dict.TryGetValue(key, out count))
                    {
                        result += count;
                    }
                }
                if (list.Count != 0)
                {
                    CheckData.AnalysisDataTime = list.First.Value.Timestamp;
                }
                result2 = result;
            }
            return(result2);
        }
Example #2
0
        /// <summary>
        /// 计算到何时才可以再次尝试创建角色
        /// </summary>
        private int CaculateNextAvailableTime(LimitResultData CheckData)
        {
            if (CheckData.CanCreate)
            {
                return(0);
            }

            DateTime nextDayTime = CheckData.AnalysisDataTime.AddMinutes(CreateRoleLimitMinutes);
            DateTime Now         = TimeUtil.NowDateTime();

            return((int)(nextDayTime - Now).TotalSeconds);
        }
Example #3
0
        private int CaculateNextAvailableTime(LimitResultData CheckData)
        {
            int result;

            if (CheckData.CanCreate)
            {
                result = 0;
            }
            else
            {
                DateTime nextDayTime = CheckData.AnalysisDataTime.AddMinutes((double)this.CreateRoleLimitMinutes);
                DateTime Now         = TimeUtil.NowDateTime();
                result = (int)(nextDayTime - Now).TotalSeconds;
            }
            return(result);
        }
Example #4
0
        public bool IfCanCreateRole(string UserID, string UserName, string DeviceID, string IP, out int NotifyLeftTime)
        {
            NotifyLeftTime = 0;
            LimitResultData CheckData = new LimitResultData();

            if (!this._UserWhiteList.Contains(UserID.ToLower()))
            {
                this.CheckByDeviceID(UserID, UserName, DeviceID, CheckData);
                if (CheckData.CanCreate)
                {
                    this.CheckByIP(UserID, UserName, IP, CheckData);
                    if (!CheckData.CanCreate)
                    {
                    }
                }
            }
            if (!CheckData.CanCreate)
            {
                NotifyLeftTime = this.CaculateNextAvailableTime(CheckData);
            }
            return(CheckData.CanCreate);
        }
Example #5
0
        /// <summary>
        /// 根据IP检查
        /// </summary>
        private void CheckByIP(string UserID, string UserName, string IP, LimitResultData CheckData)
        {
            if (-1 == IPRestrictNum || string.IsNullOrEmpty(IP))
            {
                return;
            }

            if (IfIPInWhiteList(IP))
            {
                return;
            }

            lock (IPLimitData)
            {
                int CountNum = ComputeTotalNum(IPLimitData, IP, CheckData);
                if (CountNum >= IPRestrictNum)
                {
                    CheckData.CanCreate = false;
                    LogManager.WriteLog(LogTypes.Error, string.Format("玩家创建角色被限制, UserID={0}, UserName={1}, IP={2}, CountNum={3}", UserID, UserName, IP, CountNum));
                    return;
                }
            }
        }
Example #6
0
        /// <summary>
        /// 是否可以创建角色
        /// </summary>
        public bool IfCanCreateRole(string UserID, string UserName, string DeviceID, string IP, out int NotifyLeftTime)
        {
            NotifyLeftTime = 0;

            // 检查数据
            LimitResultData CheckData = new LimitResultData();

            do
            {
                //是否在帐号白名单
                if (_UserWhiteList.Contains(UserID.ToLower()))
                {
                    break;
                }

                // 根据设备号检查
                CheckByDeviceID(UserID, UserName, DeviceID, CheckData);
                if (!CheckData.CanCreate)
                {
                    break;
                }

                // 根据IP检查
                CheckByIP(UserID, UserName, IP, CheckData);
                if (!CheckData.CanCreate)
                {
                    break;
                }
            } while (false);

            // 提示时间
            if (!CheckData.CanCreate)
            {
                NotifyLeftTime = CaculateNextAvailableTime(CheckData);
            }
            return(CheckData.CanCreate);
        }
Example #7
0
 private void CheckByIP(string UserID, string UserName, string IP, LimitResultData CheckData)
 {
     if (-1 != this.IPRestrictNum && !string.IsNullOrEmpty(IP))
     {
         if (!this.IfIPInWhiteList(IP))
         {
             lock (this.IPLimitData)
             {
                 int CountNum = this.ComputeTotalNum(this.IPLimitData, IP, CheckData);
                 if (CountNum >= this.IPRestrictNum)
                 {
                     CheckData.CanCreate = false;
                     LogManager.WriteLog(LogTypes.Error, string.Format("玩家创建角色被限制, UserID={0}, UserName={1}, IP={2}, CountNum={3}", new object[]
                     {
                         UserID,
                         UserName,
                         IP,
                         CountNum
                     }), null, true);
                 }
             }
         }
     }
 }
Example #8
0
 private void CheckByDeviceID(string UserID, string UserName, string DeviceID, LimitResultData CheckData)
 {
     if (-1 != this.DeviceIDRestrictNum && !string.IsNullOrEmpty(DeviceID))
     {
         lock (this.DeviceIDLimitData)
         {
             int CountNum = this.ComputeTotalNum(this.DeviceIDLimitData, DeviceID, CheckData);
             if (CountNum >= this.DeviceIDRestrictNum)
             {
                 CheckData.CanCreate = false;
                 LogManager.WriteLog(LogTypes.Error, string.Format("玩家创建角色被限制, UserID={0}, UserName={1}, DeviceID={2}, CountNum={3}", new object[]
                 {
                     UserID,
                     UserName,
                     DeviceID,
                     CountNum
                 }), null, true);
             }
         }
     }
 }
Example #9
0
        /// <summary>
        /// 根据设备号检查
        /// </summary>
        private void CheckByDeviceID(string UserID, string UserName, string DeviceID, LimitResultData CheckData)
        {
            if (-1 == DeviceIDRestrictNum || string.IsNullOrEmpty(DeviceID))
            {
                return;
            }

            lock (DeviceIDLimitData)
            {
                int CountNum = ComputeTotalNum(DeviceIDLimitData, DeviceID, CheckData);
                if (CountNum >= DeviceIDRestrictNum)
                {
                    CheckData.CanCreate = false;
                    LogManager.WriteLog(LogTypes.Error, string.Format("玩家创建角色被限制, UserID={0}, UserName={1}, DeviceID={2}, CountNum={3}", UserID, UserName, DeviceID, CountNum));
                    return;
                }
            }
        }