コード例 #1
0
 public void Update()
 {
     this.ProcessPendingOutboundPackets();
     if (this.outBoundPackets.get_Count() > 0)
     {
         Queue <BattleNetPacket> queue = this.outBoundPackets;
         Queue <BattleNetPacket> queue2;
         lock (queue)
         {
             queue2 = new Queue <BattleNetPacket>(this.outBoundPackets.ToArray());
             this.outBoundPackets.Clear();
         }
         while (queue2.get_Count() > 0)
         {
             BattleNetPacket packet = queue2.Dequeue();
             if (this.Connection != null)
             {
                 this.Connection.QueuePacket(packet);
             }
             else
             {
                 this.m_logSource.LogError("##Client Connection object does not exists!##");
             }
         }
     }
     if (this.Connection != null)
     {
         this.Connection.Update();
     }
     if (this.incomingPackets.get_Count() > 0)
     {
         Queue <BattleNetPacket> queue3 = this.incomingPackets;
         Queue <BattleNetPacket> queue4;
         lock (queue3)
         {
             queue4 = new Queue <BattleNetPacket>(this.incomingPackets.ToArray());
             this.incomingPackets.Clear();
         }
         while (queue4.get_Count() > 0)
         {
             BattleNetPacket battleNetPacket = queue4.Dequeue();
             Header          header          = battleNetPacket.GetHeader();
             this.PrintHeader(header);
             byte[] payload = (byte[])battleNetPacket.GetBody();
             if (header.ServiceId == 254u)
             {
                 RPCContext rPCContext;
                 if (this.waitingForResponse.TryGetValue(header.Token, ref rPCContext))
                 {
                     ServiceDescriptor            importedServiceById = this.serviceHelper.GetImportedServiceById(rPCContext.Header.ServiceId);
                     MethodDescriptor.ParseMethod parseMethod         = null;
                     if (importedServiceById != null)
                     {
                         parseMethod = importedServiceById.GetParser(rPCContext.Header.MethodId);
                     }
                     if (parseMethod == null)
                     {
                         if (importedServiceById != null)
                         {
                             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,
                                         "<null>"
                                     });
                                 }
                                 else
                                 {
                                     this.m_logSource.LogDebug("  Found method id={0} name={1}", new object[]
                                     {
                                         i,
                                         methodDescriptor.Name
                                     });
                                 }
                             }
                         }
                         else
                         {
                             this.m_logSource.LogWarning("Incoming Response: Unable to identify service id={0}", new object[]
                             {
                                 rPCContext.Header.ServiceId
                             });
                         }
                     }
                     rPCContext.Header           = header;
                     rPCContext.Payload          = payload;
                     rPCContext.ResponseReceived = true;
                     if (rPCContext.Callback != null)
                     {
                         rPCContext.Callback(rPCContext);
                     }
                     this.waitingForResponse.Remove(header.Token);
                 }
             }
             else
             {
                 ServiceDescriptor exportedServiceDescriptor = this.GetExportedServiceDescriptor(header.ServiceId);
                 if (exportedServiceDescriptor != null)
                 {
                     MethodDescriptor.ParseMethod parser = this.serviceHelper.GetExportedServiceById(header.ServiceId).GetParser(header.MethodId);
                     if (parser == null)
                     {
                         this.m_logSource.LogDebug("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))
                     {
                         exportedServiceDescriptor.NotifyMethodListener(new RPCContext
                         {
                             Header           = header,
                             Payload          = payload,
                             ResponseReceived = true
                         });
                     }
                     else
                     {
                         string text = (exportedServiceDescriptor == null || string.IsNullOrEmpty(exportedServiceDescriptor.Name)) ? "<null>" : exportedServiceDescriptor.Name;
                         this.m_logSource.LogError(string.Concat(new object[]
                         {
                             "[!]Unhandled Server Request Received (Service Name: ",
                             text,
                             " Service id:",
                             header.ServiceId,
                             " Method id:",
                             header.MethodId,
                             ")"
                         }));
                     }
                 }
                 else
                 {
                     this.m_logSource.LogError(string.Concat(new object[]
                     {
                         "[!]Server Requested an Unsupported (Service id:",
                         header.ServiceId,
                         " Method id:",
                         header.MethodId,
                         ")"
                     }));
                 }
             }
         }
     }
 }
コード例 #2
0
        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);
                    }
                }
            }
        }