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; }
public void Update() { Queue <BattleNetPacket> battleNetPackets; Queue <BattleNetPacket> battleNetPackets1; RPCContext rPCContext; this.ProcessPendingOutboundPackets(); if (this.outBoundPackets.Count > 0) { object obj = this.outBoundPackets; Monitor.Enter(obj); try { battleNetPackets = new Queue <BattleNetPacket>(this.outBoundPackets.ToArray()); this.outBoundPackets.Clear(); } finally { Monitor.Exit(obj); } while (battleNetPackets.Count > 0) { BattleNetPacket battleNetPacket = battleNetPackets.Dequeue(); if (this.Connection == null) { this.m_logSource.LogError("##Client Connection object does not exists!##"); } else { this.Connection.QueuePacket(battleNetPacket); } } } if (this.Connection != null) { this.Connection.Update(); } if (this.incomingPackets.Count > 0) { object obj1 = this.incomingPackets; Monitor.Enter(obj1); try { battleNetPackets1 = new Queue <BattleNetPacket>(this.incomingPackets.ToArray()); this.incomingPackets.Clear(); } finally { Monitor.Exit(obj1); } while (battleNetPackets1.Count > 0) { BattleNetPacket battleNetPacket1 = battleNetPackets1.Dequeue(); Header header = battleNetPacket1.GetHeader(); this.PrintHeader(header); byte[] body = (byte[])battleNetPacket1.GetBody(); if (header.ServiceId != 254) { ServiceDescriptor exportedServiceDescriptor = this.GetExportedServiceDescriptor(header.ServiceId); if (exportedServiceDescriptor == null) { this.m_logSource.LogError(string.Concat(new object[] { "[!]Server Requested an Unsupported (Service id:", header.ServiceId, " Method id:", header.MethodId, ")" })); } else { if (this.serviceHelper.GetExportedServiceById(header.ServiceId).GetParser(header.MethodId) == null) { this.m_logSource.LogDebug(string.Concat("Incoming Packet: NULL TYPE service=", this.serviceHelper.GetExportedServiceById(header.ServiceId).Name, ", method=", this.serviceHelper.GetExportedServiceById(header.ServiceId).GetMethodName(header.MethodId))); } if (!exportedServiceDescriptor.HasMethodListener(header.MethodId)) { string str = (exportedServiceDescriptor == null || string.IsNullOrEmpty(exportedServiceDescriptor.Name) ? "<null>" : exportedServiceDescriptor.Name); this.m_logSource.LogError(string.Concat(new object[] { "[!]Unhandled Server Request Received (Service Name: ", str, " Service id:", header.ServiceId, " Method id:", header.MethodId, ")" })); } else { RPCContext rPCContext1 = new RPCContext() { Header = header, Payload = body, ResponseReceived = true }; exportedServiceDescriptor.NotifyMethodListener(rPCContext1); } } } else if (this.waitingForResponse.TryGetValue(header.Token, out rPCContext)) { ServiceDescriptor importedServiceById = this.serviceHelper.GetImportedServiceById(rPCContext.Header.ServiceId); MethodDescriptor.ParseMethod parser = null; if (importedServiceById != null) { parser = importedServiceById.GetParser(rPCContext.Header.MethodId); } if (parser == null) { if (importedServiceById == null) { this.m_logSource.LogWarning("Incoming Response: Unable to identify service id={0}", new object[] { rPCContext.Header.ServiceId }); } else { this.m_logSource.LogWarning("Incoming Response: Unable to find method for serviceName={0} method id={1}", new object[] { importedServiceById.Name, rPCContext.Header.MethodId }); int methodCount = importedServiceById.GetMethodCount(); this.m_logSource.LogDebug(" Found {0} methods", new object[] { methodCount }); for (int i = 0; i < methodCount; i++) { MethodDescriptor methodDescriptor = importedServiceById.GetMethodDescriptor((uint)i); if (methodDescriptor != null || i == 0) { this.m_logSource.LogDebug(" Found method id={0} name={1}", new object[] { i, methodDescriptor.Name }); } else { this.m_logSource.LogDebug(" Found method id={0} name={1}", new object[] { i, "<null>" }); } } } } rPCContext.Header = header; rPCContext.Payload = body; rPCContext.ResponseReceived = true; if (rPCContext.Callback != null) { rPCContext.Callback(rPCContext); } this.waitingForResponse.Remove(header.Token); } } } }
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.get_Item(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.set_Item(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.set_Item(serviceName, staticData); this.m_log.LogDebug("Adding Service default {0}", new object[] { staticData }); } list.Add(serviceName); } } IL_231 :; } using (Dictionary <uint, ServiceDescriptor> .Enumerator enumerator = serviceHelper.ImportedServices.GetEnumerator()) { while (enumerator.MoveNext()) { KeyValuePair <uint, ServiceDescriptor> current = enumerator.get_Current(); if (!list.Contains(current.get_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[] { current.get_Value().Name }); } } } }