Пример #1
0
 public void Update()
 {
     this.ProcessPendingOutboundPackets();
     if (this.outBoundPackets.Count > 0)
     {
         object obj = this.outBoundPackets;
         Queue <BattleNetPacket> queue;
         lock (obj)
         {
             queue = new Queue <BattleNetPacket>(this.outBoundPackets.ToArray());
             this.outBoundPackets.Clear();
         }
         while (queue.Count > 0)
         {
             BattleNetPacket packet = queue.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.Count > 0)
     {
         object obj2 = this.incomingPackets;
         Queue <BattleNetPacket> queue2;
         lock (obj2)
         {
             queue2 = new Queue <BattleNetPacket>(this.incomingPackets.ToArray());
             this.incomingPackets.Clear();
         }
         while (queue2.Count > 0)
         {
             BattleNetPacket battleNetPacket = queue2.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, out 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,
                         ")"
                     }));
                 }
             }
         }
     }
 }