public bool GetUserIDInBeOperation(string userid, IPOperaType type) { lock (this.dictOperaUserID) { UserOperaData oldData = null; if (!this.dictOperaUserID.TryGetValue(userid, out oldData)) { return(false); } if (oldData.createTicks + (long)(oldData.OperaTime[(int)type] * 1000) > TimeUtil.NOW()) { if (this.CheckUserIdValue(userid, "ThisUserIDPass")) { return(false); } LogManager.WriteLog(LogTypes.UserIDStatistics, string.Format("Operation {0} ip={1}", type.ToString(), userid), null, true); return(true); } } return(false); }
public void TimerProcForUserID() { int currMinite = Global.GetOffsetMiniteNow(); if (currMinite != IPStatisticsManager.lastUserIDMinite) { IPStatisticsManager.lastUserIDMinite = currMinite; long currTicks = TimeUtil.NOW(); List <UserIDState> UserIDStateList = null; lock (this.dictUserStateData) { UserIDStateList = this.dictUserStateData.Values.ToList <UserIDState>(); this.dictUserStateData.Clear(); } if (IPStatisticsManager.bBeReload) { IPStatisticsManager.bBeReload = false; lock (this.dictOperaUserID) { foreach (KeyValuePair <string, UserOperaData> operaData in this.dictOperaUserID) { for (int i = 0; i < 4; i++) { operaData.Value.OperaTime[i] = 0; operaData.Value.OperaCount[i] = 0; } foreach (StatisticsControl config in IPStatisticsManager._UserIDControlList) { if (!this.checkUserID(operaData.Value.AllCount, config)) { if (config.OperaType >= 0) { operaData.Value.OperaTime[config.OperaType] = config.OperaParam; operaData.Value.OperaCount[config.OperaType] = operaData.Value.AllCount[config.ParamType]; } } } } } } foreach (UserIDState userIDState in UserIDStateList) { UserOperaData operaData2 = null; foreach (StatisticsControl config in IPStatisticsManager._UserIDControlList) { if (!this.checkUserID(userIDState.Count, config)) { lock (this.dictOperaUserID) { if (!this.dictOperaUserID.TryGetValue(userIDState.UserID, out operaData2)) { operaData2 = new UserOperaData(); operaData2.UserID = userIDState.UserID; this.dictOperaUserID.Add(userIDState.UserID, operaData2); } } operaData2.IPAsInt = userIDState.IPAsInt; if (config.OperaType >= 0) { if ((long)config.OperaParam + currTicks > operaData2.createTicks + (long)operaData2.OperaTime[config.OperaType]) { operaData2.createTicks = currTicks; operaData2.OperaTime[config.OperaType] = config.OperaParam; } if (userIDState.Count[config.ParamType] > operaData2.OperaCount[config.OperaType]) { operaData2.OperaCount[config.OperaType] = userIDState.Count[config.ParamType]; } for (int i = 0; i < 6; i++) { operaData2.AllCount[i] = userIDState.Count[i]; } } string logmsg = string.Format("cant pass userid={0}:{1} ruleid={2} paramValue={3}", new object[] { operaData2.IPAsInt, IpHelper.IntToIp(operaData2.IPAsInt), config.ID, userIDState.Count[config.ParamType] }); if (config.ComParamType >= 0) { logmsg += string.Format(" comParamValue={0}", userIDState.Count[config.ComParamType]); } LogManager.WriteLog(LogTypes.UserIDStatistics, logmsg, null, true); } } } List <string> needDelUserIDList = new List <string>(); lock (this.dictOperaUserID) { foreach (KeyValuePair <string, UserOperaData> userIDData in this.dictOperaUserID) { bool needDel = true; if (this.isCanPassUserID(userIDData.Key)) { needDel = true; } else { for (int i = 0; i < 4; i++) { if (userIDData.Value.createTicks + (long)(userIDData.Value.OperaTime[i] * 1000) > currTicks) { needDel = false; break; } } } if (needDel) { needDelUserIDList.Add(userIDData.Key); } } foreach (string ip in needDelUserIDList) { this.dictOperaUserID.Remove(ip); } } } }