public static RPCMeterConfig ParseConfig(string str) { string str2; RPCMeterConfig config = new RPCMeterConfig(); Tokenizer tokenizer = new Tokenizer(str); Label_000D: str2 = tokenizer.NextString(); if (str2 == null) { return(config); } string key = str2; if (key != null) { int num; if (< > f__switch$map2A == null) { Dictionary <string, int> dictionary = new Dictionary <string, int>(5); dictionary.Add("method", 0); dictionary.Add("income_per_second:", 1); dictionary.Add("initial_balance:", 2); dictionary.Add("cap_balance:", 3); dictionary.Add("startup_period:", 4);
private bool UpdateConfigStats(RPCMeterConfig config) { int methodCount = config.MethodCount; for (int i = 0; i < methodCount; i++) { this.UpdateMethodStats(config.Method[i]); } RPCConnectionMetering.Stats stats = this.m_data.Stats; this.m_log.LogDebug("Config Stats:"); this.m_log.LogDebug(" MethodCount={0}", new object[] { stats.MethodCount }); this.m_log.LogDebug(" ServiceNameCount={0}", new object[] { stats.ServiceNameCount }); this.m_log.LogDebug(" MethodNameCount={0}", new object[] { stats.MethodNameCount }); this.m_log.LogDebug(" FixedCalledCostCount={0}", new object[] { stats.FixedCalledCostCount }); this.m_log.LogDebug(" FixedPacketSizeCount={0}", new object[] { stats.FixedPacketSizeCount }); this.m_log.LogDebug(" VariableMultiplierCount={0}", new object[] { stats.VariableMultiplierCount }); this.m_log.LogDebug(" MultiplierCount={0}", new object[] { stats.MultiplierCount }); this.m_log.LogDebug(" RateLimitCountCount={0}", new object[] { stats.RateLimitCountCount }); this.m_log.LogDebug(" RateLimitSecondsCount={0}", new object[] { stats.RateLimitSecondsCount }); this.m_log.LogDebug(" MaxPacketSizeCount={0}", new object[] { stats.MaxPacketSizeCount }); this.m_log.LogDebug(" MaxEncodedSizeCount={0}", new object[] { stats.MaxEncodedSizeCount }); this.m_log.LogDebug(" TimeoutCount={0}", new object[] { stats.TimeoutCount }); this.m_log.LogDebug(" AggregatedRateLimitCountCount={0}", new object[] { stats.AggregatedRateLimitCountCount }); return(true); }
public static RPCMeterConfig ParseConfig(string str) { RPCMeterConfig rpcmeterConfig = new RPCMeterConfig(); Tokenizer tokenizer = new Tokenizer(str); for (;;) { string text = tokenizer.NextString(); if (text == null) { break; } if (text == null) { goto IL_CF; } if (!(text == "method")) { if (!(text == "income_per_second:")) { if (!(text == "initial_balance:")) { if (!(text == "cap_balance:")) { if (!(text == "startup_period:")) { goto IL_CF; } rpcmeterConfig.StartupPeriod = tokenizer.NextFloat(); } else { rpcmeterConfig.CapBalance = tokenizer.NextUInt32(); } } else { rpcmeterConfig.InitialBalance = tokenizer.NextUInt32(); } } else { rpcmeterConfig.IncomePerSecond = tokenizer.NextUInt32(); } } else { rpcmeterConfig.AddMethod(RPCMeterConfigParser.ParseMethod(tokenizer)); } continue; IL_CF: tokenizer.SkipUnknownToken(); } return(rpcmeterConfig); }
public static RPCMeterConfig ParseConfig(string str) { RPCMeterConfig rPCMeterConfig = new RPCMeterConfig(); Tokenizer tokenizer = new Tokenizer(str); while (true) { Label2: string str1 = tokenizer.NextString(); if (str1 == null) { break; } if (str1 == null) { goto Label0; } else if (str1 == "method") { rPCMeterConfig.AddMethod(RPCMeterConfigParser.ParseMethod(tokenizer)); } else if (str1 == "income_per_second:") { rPCMeterConfig.IncomePerSecond = tokenizer.NextUInt32(); } else if (str1 == "initial_balance:") { rPCMeterConfig.InitialBalance = tokenizer.NextUInt32(); } else if (str1 == "cap_balance:") { rPCMeterConfig.CapBalance = tokenizer.NextUInt32(); } else { if (str1 != "startup_period:") { goto Label0; } rPCMeterConfig.StartupPeriod = tokenizer.NextFloat(); } } return(rPCMeterConfig); Label0: tokenizer.SkipUnknownToken(); goto Label2; }
public void SetConnectionMeteringData(byte[] data, ServiceCollectionHelper serviceHelper) { this.m_data = new RPCConnectionMetering.MeteringData(); if (data == null || data.Length == 0 || serviceHelper == null) { this.m_log.LogError("Unable to retrieve Connection Metering data"); return; } try { RPCMeterConfig rpcmeterConfig = RPCMeterConfigParser.ParseConfig(Encoding.ASCII.GetString(data)); if (rpcmeterConfig == null || !rpcmeterConfig.IsInitialized) { this.m_data = null; throw new Exception("Unable to parse metering config protocol buffer."); } this.UpdateConfigStats(rpcmeterConfig); if (rpcmeterConfig.HasStartupPeriod) { this.m_data.StartupPeriodDuration = rpcmeterConfig.StartupPeriod; this.m_data.StartupPeriodEnd = (float)BattleNet.GetRealTimeSinceStartup() + rpcmeterConfig.StartupPeriod; this.m_log.LogDebug("StartupPeriod={0}", new object[] { rpcmeterConfig.StartupPeriod }); this.m_log.LogDebug("StartupPeriodEnd={0}", new object[] { this.m_data.StartupPeriodEnd }); } this.InitializeInternalState(rpcmeterConfig, serviceHelper); } catch (Exception ex) { this.m_data = null; this.m_log.LogError("EXCEPTION = {0} {1}", new object[] { ex.Message, ex.StackTrace }); } if (this.m_data == null) { this.m_log.LogError("Unable to parse Connection Metering data"); } }
public void SetConnectionMeteringData(byte[] data, ServiceCollectionHelper serviceHelper) { this.m_data = new MeteringData(); if (((data == null) || (data.Length == 0)) || (serviceHelper == null)) { this.m_log.LogError("Unable to retrieve Connection Metering data"); } else { try { RPCMeterConfig config = RPCMeterConfigParser.ParseConfig(Encoding.ASCII.GetString(data)); if ((config == null) || !config.IsInitialized) { this.m_data = null; throw new Exception("Unable to parse metering config protocol buffer."); } this.UpdateConfigStats(config); if (config.HasStartupPeriod) { this.m_data.StartupPeriodDuration = config.StartupPeriod; this.m_data.StartupPeriodEnd = UnityEngine.Time.realtimeSinceStartup + config.StartupPeriod; object[] args = new object[] { config.StartupPeriod }; this.m_log.LogDebug("StartupPeriod={0}", args); object[] objArray2 = new object[] { this.m_data.StartupPeriodEnd }; this.m_log.LogDebug("StartupPeriodEnd={0}", objArray2); } this.InitializeInternalState(config, serviceHelper); } catch (Exception exception) { this.m_data = null; object[] objArray3 = new object[] { exception.Message, exception.StackTrace }; this.m_log.LogError("EXCEPTION = {0} {1}", objArray3); } if (this.m_data == null) { this.m_log.LogError("Unable to parse Connection Metering data"); } } }
private bool UpdateConfigStats(RPCMeterConfig config) { int methodCount = config.MethodCount; for (int i = 0; i < methodCount; i++) { RPCMethodConfig method = config.Method[i]; this.UpdateMethodStats(method); } Stats stats = this.m_data.Stats; this.m_log.LogDebug("Config Stats:"); object[] args = new object[] { stats.MethodCount }; this.m_log.LogDebug(" MethodCount={0}", args); object[] objArray2 = new object[] { stats.ServiceNameCount }; this.m_log.LogDebug(" ServiceNameCount={0}", objArray2); object[] objArray3 = new object[] { stats.MethodNameCount }; this.m_log.LogDebug(" MethodNameCount={0}", objArray3); object[] objArray4 = new object[] { stats.FixedCalledCostCount }; this.m_log.LogDebug(" FixedCalledCostCount={0}", objArray4); object[] objArray5 = new object[] { stats.FixedPacketSizeCount }; this.m_log.LogDebug(" FixedPacketSizeCount={0}", objArray5); object[] objArray6 = new object[] { stats.VariableMultiplierCount }; this.m_log.LogDebug(" VariableMultiplierCount={0}", objArray6); object[] objArray7 = new object[] { stats.MultiplierCount }; this.m_log.LogDebug(" MultiplierCount={0}", objArray7); object[] objArray8 = new object[] { stats.RateLimitCountCount }; this.m_log.LogDebug(" RateLimitCountCount={0}", objArray8); object[] objArray9 = new object[] { stats.RateLimitSecondsCount }; this.m_log.LogDebug(" RateLimitSecondsCount={0}", objArray9); object[] objArray10 = new object[] { stats.MaxPacketSizeCount }; this.m_log.LogDebug(" MaxPacketSizeCount={0}", objArray10); object[] objArray11 = new object[] { stats.MaxEncodedSizeCount }; this.m_log.LogDebug(" MaxEncodedSizeCount={0}", objArray11); object[] objArray12 = new object[] { stats.TimeoutCount }; this.m_log.LogDebug(" TimeoutCount={0}", objArray12); object[] objArray13 = new object[] { stats.AggregatedRateLimitCountCount }; this.m_log.LogDebug(" AggregatedRateLimitCountCount={0}", objArray13); return(true); }
private void InitializeInternalState(RPCMeterConfig config, ServiceCollectionHelper serviceHelper) { List <string> list = new List <string>(); List <string> list2 = new List <string>(); int methodCount = config.MethodCount; for (int i = 0; i < methodCount; i++) { RPCMethodConfig rpcmethodConfig = config.Method[i]; RPCConnectionMetering.StaticData staticData = new RPCConnectionMetering.StaticData(); staticData.FromProtocol(rpcmethodConfig); if (!rpcmethodConfig.HasServiceName) { if (this.m_data.GlobalDefault == null) { this.m_data.GlobalDefault = staticData; this.m_log.LogDebug("Adding global default {0}", new object[] { staticData }); } else { this.m_log.LogWarning("Static data has two defaults, ignoring additional ones."); } } else { string serviceName = rpcmethodConfig.ServiceName; ServiceDescriptor importedServiceByName = serviceHelper.GetImportedServiceByName(serviceName); if (importedServiceByName == null) { if (!list2.Contains(serviceName)) { this.m_log.LogDebug("Ignoring not imported service {0}", new object[] { serviceName }); list2.Add(serviceName); } } else { staticData.ServiceId = importedServiceByName.Id; if (rpcmethodConfig.HasMethodName) { string methodName = rpcmethodConfig.MethodName; string text = string.Format("{0}.{1}", serviceName, methodName); MethodDescriptor methodDescriptorByName = importedServiceByName.GetMethodDescriptorByName(text); if (methodDescriptorByName == null) { this.m_log.LogDebug("Configuration specifies an unused method {0}, ignoring.", new object[] { methodName }); goto IL_231; } if (this.m_data.MethodDefaults.ContainsKey(text)) { this.m_log.LogWarning("Default for method {0} already exists, ignoring extras.", new object[] { text }); goto IL_231; } staticData.MethodId = methodDescriptorByName.Id; this.m_data.MethodDefaults[text] = staticData; this.m_log.LogDebug("Adding Method default {0}", new object[] { staticData }); } else { if (this.m_data.ServiceDefaults.ContainsKey(serviceName)) { this.m_log.LogWarning("Default for service {0} already exists, ignoring extras.", new object[] { serviceName }); goto IL_231; } this.m_data.ServiceDefaults[serviceName] = staticData; this.m_log.LogDebug("Adding Service default {0}", new object[] { staticData }); } list.Add(serviceName); } } IL_231 :; } foreach (KeyValuePair <uint, ServiceDescriptor> keyValuePair in serviceHelper.ImportedServices) { if (!list.Contains(keyValuePair.Value.Name) && this.m_data.GlobalDefault == null) { this.m_log.LogDebug("Configuration for service {0} was not found and will not be metered.", new object[] { keyValuePair.Value.Name }); } } }
public static RPCMeterConfig ParseConfig(string str) { RPCMeterConfig rPCMeterConfig = new RPCMeterConfig(); Tokenizer tokenizer = new Tokenizer(str); while (true) { string text = tokenizer.NextString(); if (text == null) { break; } string text2 = text; if (text2 == null) { goto IL_108; } if (RPCMeterConfigParser.< > f__switch$mapD == null) { Dictionary <string, int> dictionary = new Dictionary <string, int>(5); dictionary.Add("method", 0); dictionary.Add("income_per_second:", 1); dictionary.Add("initial_balance:", 2); dictionary.Add("cap_balance:", 3); dictionary.Add("startup_period:", 4); RPCMeterConfigParser.< > f__switch$mapD = dictionary; } int num; if (!RPCMeterConfigParser.< > f__switch$mapD.TryGetValue(text2, ref num)) { goto IL_108; } switch (num) { case 0: rPCMeterConfig.AddMethod(RPCMeterConfigParser.ParseMethod(tokenizer)); break; case 1: rPCMeterConfig.IncomePerSecond = tokenizer.NextUInt32(); break; case 2: rPCMeterConfig.InitialBalance = tokenizer.NextUInt32(); break; case 3: rPCMeterConfig.CapBalance = tokenizer.NextUInt32(); break; case 4: rPCMeterConfig.StartupPeriod = tokenizer.NextFloat(); break; default: goto IL_108; } continue; IL_108: tokenizer.SkipUnknownToken(); } return(rPCMeterConfig); }
private void InitializeInternalState(RPCMeterConfig config, ServiceCollectionHelper serviceHelper) { string serviceName; string str; List <string> strs = new List <string>(); List <string> strs1 = new List <string>(); int methodCount = config.MethodCount; for (int i = 0; i < methodCount; i++) { RPCMethodConfig item = config.Method[i]; RPCConnectionMetering.StaticData staticDatum = new RPCConnectionMetering.StaticData(); staticDatum.FromProtocol(item); if (item.HasServiceName) { serviceName = item.ServiceName; ServiceDescriptor importedServiceByName = serviceHelper.GetImportedServiceByName(serviceName); if (importedServiceByName != null) { staticDatum.ServiceId = importedServiceByName.Id; if (!item.HasMethodName) { if (this.m_data.ServiceDefaults.ContainsKey(serviceName)) { goto Label1; } this.m_data.ServiceDefaults[serviceName] = staticDatum; this.m_log.LogDebug("Adding Service default {0}", new object[] { staticDatum }); } else { string methodName = item.MethodName; str = string.Format("{0}.{1}", serviceName, methodName); MethodDescriptor methodDescriptorByName = importedServiceByName.GetMethodDescriptorByName(str); if (methodDescriptorByName != null) { if (this.m_data.MethodDefaults.ContainsKey(str)) { goto Label2; } staticDatum.MethodId = methodDescriptorByName.Id; this.m_data.MethodDefaults[str] = staticDatum; this.m_log.LogDebug("Adding Method default {0}", new object[] { staticDatum }); } else { this.m_log.LogDebug("Configuration specifies an unused method {0}, ignoring.", new object[] { methodName }); goto Label0; } } strs.Add(serviceName); } else if (!strs1.Contains(serviceName)) { this.m_log.LogDebug("Ignoring not imported service {0}", new object[] { serviceName }); strs1.Add(serviceName); } } else if (this.m_data.GlobalDefault != null) { this.m_log.LogWarning("Static data has two defaults, ignoring additional ones."); } else { this.m_data.GlobalDefault = staticDatum; this.m_log.LogDebug("Adding global default {0}", new object[] { staticDatum }); } Label0: } foreach (KeyValuePair <uint, ServiceDescriptor> importedService in serviceHelper.ImportedServices) { if (strs.Contains(importedService.Value.Name) || this.m_data.GlobalDefault != null) { continue; } this.m_log.LogDebug("Configuration for service {0} was not found and will not be metered.", new object[] { importedService.Value.Name }); } return; Label1: BattleNetLogSource mLog = this.m_log; mLog.LogWarning("Default for service {0} already exists, ignoring extras.", new object[] { serviceName }); goto Label0; Label2: BattleNetLogSource battleNetLogSource = this.m_log; battleNetLogSource.LogWarning("Default for method {0} already exists, ignoring extras.", new object[] { str }); goto Label0; }
private void InitializeInternalState(RPCMeterConfig config, ServiceCollectionHelper serviceHelper) { List <string> list = new List <string>(); List <string> list2 = new List <string>(); int methodCount = config.MethodCount; for (int i = 0; i < methodCount; i++) { RPCMethodConfig method = config.Method[i]; StaticData data = new StaticData(); data.FromProtocol(method); if (!method.HasServiceName) { if (this.m_data.GlobalDefault == null) { this.m_data.GlobalDefault = data; object[] args = new object[] { data }; this.m_log.LogDebug("Adding global default {0}", args); } else { this.m_log.LogWarning("Static data has two defaults, ignoring additional ones."); } } else { string serviceName = method.ServiceName; ServiceDescriptor importedServiceByName = serviceHelper.GetImportedServiceByName(serviceName); if (importedServiceByName == null) { if (!list2.Contains(serviceName)) { object[] objArray2 = new object[] { serviceName }; this.m_log.LogDebug("Ignoring not imported service {0}", objArray2); list2.Add(serviceName); } } else { data.ServiceId = importedServiceByName.Id; if (method.HasMethodName) { string methodName = method.MethodName; string name = string.Format("{0}.{1}", serviceName, methodName); MethodDescriptor methodDescriptorByName = importedServiceByName.GetMethodDescriptorByName(name); if (methodDescriptorByName == null) { object[] objArray3 = new object[] { methodName }; this.m_log.LogDebug("Configuration specifies an unused method {0}, ignoring.", objArray3); goto Label_0231; } if (this.m_data.MethodDefaults.ContainsKey(name)) { object[] objArray4 = new object[] { name }; this.m_log.LogWarning("Default for method {0} already exists, ignoring extras.", objArray4); goto Label_0231; } data.MethodId = methodDescriptorByName.Id; this.m_data.MethodDefaults[name] = data; object[] objArray5 = new object[] { data }; this.m_log.LogDebug("Adding Method default {0}", objArray5); } else { if (this.m_data.ServiceDefaults.ContainsKey(serviceName)) { object[] objArray6 = new object[] { serviceName }; this.m_log.LogWarning("Default for service {0} already exists, ignoring extras.", objArray6); goto Label_0231; } this.m_data.ServiceDefaults[serviceName] = data; object[] objArray7 = new object[] { data }; this.m_log.LogDebug("Adding Service default {0}", objArray7); } list.Add(serviceName); Label_0231 :; } } } foreach (KeyValuePair <uint, ServiceDescriptor> pair in serviceHelper.ImportedServices) { if (!list.Contains(pair.Value.Name) && (this.m_data.GlobalDefault == null)) { object[] objArray8 = new object[] { pair.Value.Name }; this.m_log.LogDebug("Configuration for service {0} was not found and will not be metered.", objArray8); } } }