private RPCConnectionMetering.RuntimeData GetRuntimedData(uint serviceID, uint methodID)
        {
            uint num = serviceID * 1000u + methodID;

            RPCConnectionMetering.RuntimeData runtimeData = this.m_data.GetRuntimeData(num);
            if (runtimeData == null)
            {
                runtimeData = new RPCConnectionMetering.RuntimeData();
                this.m_data.RuntimeData[num] = runtimeData;
                RPCConnectionMetering.StaticData staticData = null;
                foreach (KeyValuePair <string, RPCConnectionMetering.StaticData> keyValuePair in this.m_data.MethodDefaults)
                {
                    if (keyValuePair.Value.ServiceId == serviceID && keyValuePair.Value.MethodId == methodID)
                    {
                        staticData = keyValuePair.Value;
                        break;
                    }
                }
                if (staticData == null)
                {
                    foreach (KeyValuePair <string, RPCConnectionMetering.StaticData> keyValuePair2 in this.m_data.ServiceDefaults)
                    {
                        if (keyValuePair2.Value.ServiceId == serviceID)
                        {
                            staticData = keyValuePair2.Value;
                            break;
                        }
                    }
                }
                if (staticData == null && this.m_data.GlobalDefault != null)
                {
                    staticData = this.m_data.GlobalDefault;
                }
                if (staticData == null)
                {
                    this.m_log.LogDebug("Always allowing ServiceId={0} MethodId={1}", new object[]
                    {
                        serviceID,
                        methodID
                    });
                    runtimeData.AlwaysAllow = true;
                    return(runtimeData);
                }
                runtimeData.StaticData = staticData;
                if (staticData.RateLimitCount == 0u)
                {
                    runtimeData.AlwaysDeny = true;
                }
                else if (staticData.RateLimitSeconds == 0u)
                {
                    runtimeData.FiniteCallsLeft = staticData.RateLimitCount;
                }
                else
                {
                    runtimeData.Tracker = new RPCConnectionMetering.CallTracker(staticData.RateLimitCount, staticData.RateLimitSeconds);
                }
            }
            return(runtimeData);
        }
        public bool AllowRPCCall(uint serviceID, uint methodID)
        {
            if (this.m_data == null)
            {
                return(true);
            }
            RPCConnectionMetering.RuntimeData runtimedData = this.GetRuntimedData(serviceID, methodID);
            if (runtimedData == null)
            {
                return(true);
            }
            float realTimeSinceStartup = (float)BattleNet.GetRealTimeSinceStartup();

            if ((double)this.m_data.StartupPeriodEnd > 0 && realTimeSinceStartup < this.m_data.StartupPeriodEnd)
            {
                float startupPeriodEnd = this.m_data.StartupPeriodEnd - realTimeSinceStartup;
                this.m_log.LogDebug("Allow (STARTUP PERIOD {0}) {1} ({2}:{3})", new object[] { startupPeriodEnd, runtimedData.GetServiceAndMethodNames(), serviceID, methodID });
                return(true);
            }
            if (runtimedData.AlwaysAllow)
            {
                this.m_log.LogDebug("Allow (ALWAYS ALLOW) {0} ({1}:{2})", new object[] { runtimedData.GetServiceAndMethodNames(), serviceID, methodID });
                return(true);
            }
            if (runtimedData.AlwaysDeny)
            {
                this.m_log.LogDebug("Deny (ALWAYS DENY) {0} ({1}:{2})", new object[] { runtimedData.GetServiceAndMethodNames(), serviceID, methodID });
                return(false);
            }
            if (runtimedData.FiniteCallsLeft == -1)
            {
                bool flag = runtimedData.CanCall(realTimeSinceStartup);
                this.m_log.LogDebug("{0} (TRACKER) {1} ({2}:{3})", new object[] { (!flag ? "Deny" : "Allow"), runtimedData.GetServiceAndMethodNames(), serviceID, methodID });
                return(flag);
            }
            if (runtimedData.FiniteCallsLeft <= 0)
            {
                this.m_log.LogDebug("Deny (FINITE CALLS LEFT 0) {0} ({1}:{2})", new object[] { runtimedData.GetServiceAndMethodNames(), serviceID, methodID });
                return(false);
            }
            this.m_log.LogDebug("Allow (FINITE CALLS LEFT {0}) {1} ({2}:{3})", new object[] { runtimedData.FiniteCallsLeft, runtimedData.GetServiceAndMethodNames(), serviceID, methodID });
            RPCConnectionMetering.RuntimeData finiteCallsLeft = runtimedData;
            finiteCallsLeft.FiniteCallsLeft = finiteCallsLeft.FiniteCallsLeft - 1;
            return(true);
        }
        public bool AllowRPCCall(uint serviceID, uint methodID)
        {
            if (this.m_data == null)
            {
                return(true);
            }
            RPCConnectionMetering.RuntimeData runtimedData = this.GetRuntimedData(serviceID, methodID);
            if (runtimedData == null)
            {
                return(true);
            }
            float num = (float)BattleNet.GetRealTimeSinceStartup();

            if ((double)this.m_data.StartupPeriodEnd > 0.0 && num < this.m_data.StartupPeriodEnd)
            {
                float num2 = this.m_data.StartupPeriodEnd - num;
                this.m_log.LogDebug("Allow (STARTUP PERIOD {0}) {1} ({2}:{3})", new object[]
                {
                    num2,
                    runtimedData.GetServiceAndMethodNames(),
                    serviceID,
                    methodID
                });
                return(true);
            }
            if (runtimedData.AlwaysAllow)
            {
                this.m_log.LogDebug("Allow (ALWAYS ALLOW) {0} ({1}:{2})", new object[]
                {
                    runtimedData.GetServiceAndMethodNames(),
                    serviceID,
                    methodID
                });
                return(true);
            }
            if (runtimedData.AlwaysDeny)
            {
                this.m_log.LogDebug("Deny (ALWAYS DENY) {0} ({1}:{2})", new object[]
                {
                    runtimedData.GetServiceAndMethodNames(),
                    serviceID,
                    methodID
                });
                return(false);
            }
            if (runtimedData.FiniteCallsLeft == 4294967295u)
            {
                bool flag = runtimedData.CanCall(num);
                this.m_log.LogDebug("{0} (TRACKER) {1} ({2}:{3})", new object[]
                {
                    (!flag) ? "Deny" : "Allow",
                    runtimedData.GetServiceAndMethodNames(),
                    serviceID,
                    methodID
                });
                return(flag);
            }
            if (runtimedData.FiniteCallsLeft > 0u)
            {
                this.m_log.LogDebug("Allow (FINITE CALLS LEFT {0}) {1} ({2}:{3})", new object[]
                {
                    runtimedData.FiniteCallsLeft,
                    runtimedData.GetServiceAndMethodNames(),
                    serviceID,
                    methodID
                });
                runtimedData.FiniteCallsLeft -= 1u;
                return(true);
            }
            this.m_log.LogDebug("Deny (FINITE CALLS LEFT 0) {0} ({1}:{2})", new object[]
            {
                runtimedData.GetServiceAndMethodNames(),
                serviceID,
                methodID
            });
            return(false);
        }
Esempio n. 4
0
        private RPCConnectionMetering.RuntimeData GetRuntimedData(uint serviceID, uint methodID)
        {
            uint num = serviceID * 1000u + methodID;

            RPCConnectionMetering.RuntimeData runtimeData = this.m_data.GetRuntimeData(num);
            if (runtimeData == null)
            {
                runtimeData = new RPCConnectionMetering.RuntimeData();
                this.m_data.RuntimeData.set_Item(num, runtimeData);
                RPCConnectionMetering.StaticData staticData = null;
                using (Dictionary <string, RPCConnectionMetering.StaticData> .Enumerator enumerator = this.m_data.MethodDefaults.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        KeyValuePair <string, RPCConnectionMetering.StaticData> current = enumerator.get_Current();
                        if (current.get_Value().ServiceId == serviceID && current.get_Value().MethodId == methodID)
                        {
                            staticData = current.get_Value();
                            break;
                        }
                    }
                }
                if (staticData == null)
                {
                    using (Dictionary <string, RPCConnectionMetering.StaticData> .Enumerator enumerator2 = this.m_data.ServiceDefaults.GetEnumerator())
                    {
                        while (enumerator2.MoveNext())
                        {
                            KeyValuePair <string, RPCConnectionMetering.StaticData> current2 = enumerator2.get_Current();
                            if (current2.get_Value().ServiceId == serviceID)
                            {
                                staticData = current2.get_Value();
                                break;
                            }
                        }
                    }
                }
                if (staticData == null && this.m_data.GlobalDefault != null)
                {
                    staticData = this.m_data.GlobalDefault;
                }
                if (staticData == null)
                {
                    this.m_log.LogDebug("Always allowing ServiceId={0} MethodId={1}", new object[]
                    {
                        serviceID,
                        methodID
                    });
                    runtimeData.AlwaysAllow = true;
                    return(runtimeData);
                }
                runtimeData.StaticData = staticData;
                if (staticData.RateLimitCount == 0u)
                {
                    runtimeData.AlwaysDeny = true;
                }
                else if (staticData.RateLimitSeconds == 0u)
                {
                    runtimeData.FiniteCallsLeft = staticData.RateLimitCount;
                }
                else
                {
                    runtimeData.Tracker = new RPCConnectionMetering.CallTracker(staticData.RateLimitCount, staticData.RateLimitSeconds);
                }
            }
            return(runtimeData);
        }