Exemplo n.º 1
0
        public List <IPStatisticsData> getCurrDataList()
        {
            List <IPStatisticsData> result;

            lock (IPStatisticsManager.dictIPStatisticsData)
            {
                Dictionary <long, Tuple <int, int, int> > tmpDict = Global._TCPManager.MySocketListener.GetSocketCnt();
                foreach (KeyValuePair <long, Tuple <int, int, int> > item in tmpDict)
                {
                    IPStatisticsData IPData = null;
                    if (!IPStatisticsManager.dictIPStatisticsData.TryGetValue(item.Key, out IPData))
                    {
                        IPData = new IPStatisticsData
                        {
                            ipAsInt = item.Key
                        };
                        IPStatisticsManager.dictIPStatisticsData[item.Key] = IPData;
                    }
                    IPData.IPInfoParams[0] = item.Value.Item1;
                    IPData.IPInfoParams[1] = item.Value.Item2;
                    IPData.IPInfoParams[2] = item.Value.Item3;
                }
                List <IPStatisticsData> tempList = IPStatisticsManager.dictIPStatisticsData.Values.ToList <IPStatisticsData>();
                IPStatisticsManager.dictIPStatisticsData.Clear();
                result = tempList;
            }
            return(result);
        }
Exemplo n.º 2
0
 public void processEvent(EventObject eventObject)
 {
     if (!GameManager.IsKuaFuServer)
     {
         IpEventBase      e      = eventObject as IpEventBase;
         IPStatisticsData ipData = null;
         if (eventObject.getEventType() == 15)
         {
             PlayerInitGameAsyncEventObject e2 = eventObject as PlayerInitGameAsyncEventObject;
             if (null != e2)
             {
                 GameClient client = e2.getPlayer();
                 this.SetUserIdValue(client.strUserID, (int)client.ClientData.VipExp, Global.GetUnionLevel(client, false));
             }
         }
         lock (IPStatisticsManager.dictIPStatisticsData)
         {
             if (e.getIpAsInt() > 0L)
             {
                 if (!IPStatisticsManager.dictIPStatisticsData.TryGetValue(e.getIpAsInt(), out ipData))
                 {
                     ipData = new IPStatisticsData
                     {
                         ipAsInt = e.getIpAsInt()
                     };
                     IPStatisticsManager.dictIPStatisticsData.Add(e.getIpAsInt(), ipData);
                 }
                 if (null == ipData)
                 {
                     return;
                 }
                 IPInfoType ipInfoType = IPInfoType.Begin;
                 if (IPStatisticsManager.event2IPTypeDict.TryGetValue((EventTypes)eventObject.getEventType(), out ipInfoType))
                 {
                     ipData.IPInfoParams[(int)ipInfoType]++;
                 }
             }
         }
         UserParamType userInfoType = UserParamType.Begin;
         if (IPStatisticsManager.event2UserTypeDict.TryGetValue((EventTypes)eventObject.getEventType(), out userInfoType))
         {
             if (!string.IsNullOrEmpty(e.getUserID()))
             {
                 UserIDState userData = null;
                 lock (this.dictUserStateData)
                 {
                     if (!this.dictUserStateData.TryGetValue(e.getUserID(), out userData))
                     {
                         userData = new UserIDState();
                         this.dictUserStateData.Add(e.getUserID(), userData);
                     }
                     if (null != userData)
                     {
                         userData.Count[(int)userInfoType]++;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        private bool checkIP(IPStatisticsData IPData, StatisticsControl config)
        {
            bool bPass = true;

            if (config.ParamLimit > 0)
            {
                if (IPData.IPInfoParams[config.ParamType] >= config.ParamLimit)
                {
                    bPass = false;
                }
            }
            if (!bPass)
            {
                if (config.ComParamType >= 0)
                {
                    double coe = double.MaxValue;
                    if (IPData.IPInfoParams[config.ComParamType] > 0)
                    {
                        coe = (double)IPData.IPInfoParams[config.ParamType] * 1.0 / (double)IPData.IPInfoParams[config.ComParamType];
                    }
                    bPass = ((config.ComParamLimit > 0.0) ? (coe > config.ComParamLimit) : (coe < -config.ComParamLimit));
                }
            }
            return(bPass);
        }
Exemplo n.º 4
0
        private IPOperaData checkIP(IPStatisticsData ipData, bool local)
        {
            IPOperaData operaData = null;

            foreach (StatisticsControl config in IPStatisticsPersistence.Instance._IPControlList)
            {
                if (config.Local == local && !this.checkIP(ipData, config))
                {
                    if (!IPStatisticsPersistence.Instance.isCanPassIP(ipData.ipAsInt))
                    {
                        if (null == operaData)
                        {
                            operaData = new IPOperaData();
                        }
                        operaData.ipAsInt = ipData.ipAsInt;
                        if (config.OperaType >= 0)
                        {
                            if (config.OperaParam > operaData.OperaTime[config.OperaType])
                            {
                                operaData.OperaTime[config.OperaType] = config.OperaParam;
                            }
                            if (ipData.IPInfoParams[config.ParamType] > operaData.OperaParam[config.OperaType])
                            {
                                operaData.OperaParam[config.OperaType] = ipData.IPInfoParams[config.ParamType];
                            }
                        }
                        string logmsg = string.Format("cant pass ip={0}:{1} ruleid={2} paramValue={3}", new object[]
                        {
                            operaData.ipAsInt,
                            IpHelper.IntToIp(operaData.ipAsInt),
                            config.ID,
                            ipData.IPInfoParams[config.ParamType]
                        });
                        if (config.ComParamType >= 0)
                        {
                            logmsg += string.Format(" comParamValue={0}", ipData.IPInfoParams[config.ComParamType]);
                        }
                        LogManager.WriteLog(LogTypes.IPStatistics, logmsg, null, true);
                    }
                }
            }
            return(operaData);
        }
Exemplo n.º 5
0
        private void IPStatisticsProc()
        {
            Dictionary <int, List <IPStatisticsData> > lastData = new Dictionary <int, List <IPStatisticsData> >();

            lock (IPStatisticsService.dictCurrData)
            {
                foreach (KeyValuePair <int, List <IPStatisticsData> > item in IPStatisticsService.dictCurrData)
                {
                    lastData.Add(item.Key, item.Value);
                }
                IPStatisticsService.dictCurrData.Clear();
            }
            Dictionary <long, HashSet <int> >     ip2serveridDict = new Dictionary <long, HashSet <int> >();
            Dictionary <long, IPStatisticsData>   totalDataDict   = new Dictionary <long, IPStatisticsData>();
            Dictionary <int, List <IPOperaData> > IPOperaDataDict = new Dictionary <int, List <IPOperaData> >();

            foreach (KeyValuePair <int, List <IPStatisticsData> > ipDataList in lastData)
            {
                foreach (IPStatisticsData ipData in ipDataList.Value)
                {
                    try
                    {
                        IPOperaData operaData = this.checkIP(ipData, true);
                        if (null != operaData)
                        {
                            List <IPOperaData> opList;
                            if (!IPOperaDataDict.TryGetValue(ipDataList.Key, out opList))
                            {
                                opList = new List <IPOperaData>();
                                IPOperaDataDict[ipDataList.Key] = opList;
                            }
                            opList.Add(operaData);
                        }
                        if (ip2serveridDict.ContainsKey(ipData.ipAsInt))
                        {
                            ip2serveridDict[ipData.ipAsInt].Add(ipDataList.Key);
                        }
                        else
                        {
                            HashSet <int> hashServerID = new HashSet <int>();
                            hashServerID.Add(ipDataList.Key);
                            ip2serveridDict.Add(ipData.ipAsInt, hashServerID);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogManager.WriteLog(LogTypes.Error, "IPStatisticsProc", ex, false);
                    }
                    IPStatisticsData tmpIPData = null;
                    if (totalDataDict.TryGetValue(ipData.ipAsInt, out tmpIPData))
                    {
                        tmpIPData += ipData;
                    }
                    else
                    {
                        totalDataDict.Add(ipData.ipAsInt, ipData);
                    }
                }
            }
            List <IPOperaData> resultList = new List <IPOperaData>();

            foreach (KeyValuePair <long, IPStatisticsData> ipData2 in totalDataDict)
            {
                IPOperaData operaData = this.checkIP(ipData2.Value, false);
                if (null != operaData)
                {
                    resultList.Add(operaData);
                }
            }
            this.AddOpList(IPOperaDataDict, resultList, ip2serveridDict);
            lock (IPStatisticsService.dictIPOperaData)
            {
                IPStatisticsService.dictIPOperaData = IPOperaDataDict;
            }
        }