Exemplo n.º 1
0
        public static void HandlePacket(WorldClient client, CMSG msgID, BinReader data)
        {
            DebugLogger.ILog("Handling CMSG packet: " + msgID);

            bool handled = false;

            try {
                IWorldClientPacketHandler handler = (IWorldClientPacketHandler)worldClientHandlers[msgID];
                if (handler != null)
                {
                    handler.HandlePacket(client, msgID, data);
                    handled = true;
                }
                WorldClientPacketDelegate wcpd = (WorldClientPacketDelegate)worldClientDelegates[(int)msgID];
                if (wcpd != null)
                {
                    wcpd(client, msgID, data);
                    handled = true;
                }
            } catch (Exception exp) {
                DebugLogger.Logger.Log("", exp);
            }

            if (handled == false)
            {
                DebugLogger.ILog("Unhandled CMSG: " + msgID.ToString());
            }
        }
 void SearchForClientPacketDelegates(Type type)
 {
     try {
         MethodInfo[] methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
         foreach (MethodInfo method in methods)
         {
             WorldPacketDelegate[] attribs = (WorldPacketDelegate[])method.GetCustomAttributes(typeof(WorldPacketDelegate), true);
             if (attribs.Length == 0)
             {
                 continue;
             }
             if (method.IsStatic)
             {
                 foreach (WorldPacketDelegate attrib in attribs)
                 {
                     if (attrib.ClientMessage)
                     {
                         WorldClientPacketDelegate wcpd = (WorldClientPacketDelegate)Delegate.CreateDelegate(typeof(WorldClientPacketDelegate), method);
                         WorldPacketManager.RegisterPacketHandler((CMSG)attrib.MsgID, wcpd);
                         if (m_clientPacketDelegates.Contains(attrib.MsgID))
                         {
                             WorldClientPacketDelegate dele = (WorldClientPacketDelegate)m_clientPacketDelegates[attrib.MsgID];
                             m_clientPacketDelegates[attrib.MsgID] = dele + wcpd;
                         }
                         else
                         {
                             m_clientPacketDelegates[attrib.MsgID] = wcpd;
                         }
                     }
                 }
             }
             else
             {
                 object obj = GetHandlerObject(type);
                 foreach (WorldPacketDelegate attrib in attribs)
                 {
                     if (attrib.ClientMessage)
                     {
                         WorldClientPacketDelegate wcpd = (WorldClientPacketDelegate)Delegate.CreateDelegate(typeof(WorldClientPacketDelegate), obj, method.Name);
                         WorldPacketManager.RegisterPacketHandler((CMSG)attrib.MsgID, wcpd);
                         if (m_clientPacketDelegates.Contains(attrib.MsgID))
                         {
                             WorldClientPacketDelegate dele = (WorldClientPacketDelegate)m_clientPacketDelegates[attrib.MsgID];
                             m_clientPacketDelegates[attrib.MsgID] = dele + wcpd;
                         }
                         else
                         {
                             m_clientPacketDelegates[attrib.MsgID] = wcpd;
                         }
                     }
                 }
             }
         }
     } catch (Exception exp) {
         DebugLogger.Log("", exp);
     }
 }
Exemplo n.º 3
0
 public static void RegisterPacketHandler(CMSG msgID, WorldClientPacketDelegate wcpd)
 {
     if (worldClientDelegates[(int)msgID] != null)
     {
         WorldClientPacketDelegate dele = (WorldClientPacketDelegate)worldClientDelegates[(int)msgID];
         worldClientDelegates[(int)msgID] = dele + wcpd;
     }
     else
     {
         worldClientDelegates[(int)msgID] = wcpd;
     }
 }
Exemplo n.º 4
0
        public static void HandlePacket(WorldClient client, CMSG msgID, BinReader data)
        {
            IWorldClientPacketHandler handler = (IWorldClientPacketHandler)worldClientHandlers[msgID];

            if (handler != null)
            {
                handler.HandlePacket(client, msgID, data);
            }
            WorldClientPacketDelegate wcpd = (WorldClientPacketDelegate)worldClientDelegates[(int)msgID];

            if (wcpd != null)
            {
                wcpd(client, msgID, data);
            }
        }
 public static void HandlePacket(WorldClient client, CMSG msgID, BinReader data)
 {
     try {
         IWorldClientPacketHandler handler = (IWorldClientPacketHandler)worldClientHandlers[msgID];
         if (handler != null)
         {
             handler.HandlePacket(client, msgID, data);
         }
         WorldClientPacketDelegate wcpd = (WorldClientPacketDelegate)worldClientDelegates[(int)msgID];
         if (wcpd != null)
         {
             wcpd(client, msgID, data);
         }
     } catch (Exception exp) {
         DebugLogger.Log("", exp);
     }
 }
Exemplo n.º 6
0
 static void SearchForDelegates(Type type)
 {
     MethodInfo[] methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
     foreach (MethodInfo method in methods)
     {
         WorldPacketDelegate[] attribs = (WorldPacketDelegate[])method.GetCustomAttributes(typeof(WorldPacketDelegate), true);
         if (attribs.Length == 0)
         {
             continue;
         }
         if (method.IsStatic)
         {
             foreach (WorldPacketDelegate attrib in attribs)
             {
                 if (attrib.ClientMessage)
                 {
                     WorldClientPacketDelegate wcpd = (WorldClientPacketDelegate)Delegate.CreateDelegate(typeof(WorldClientPacketDelegate), method);
                     RegisterPacketHandler((CMSG)attrib.MsgID, wcpd);
                 }
                 else
                 {
                     WorldServerPacketDelegate wspd = (WorldServerPacketDelegate)Delegate.CreateDelegate(typeof(WorldServerPacketDelegate), method);
                     RegisterPacketHandler((WORLDMSG)attrib.MsgID, wspd);
                 }
             }
         }
         else
         {
             object obj = GetHandlerObject(type);
             foreach (WorldPacketDelegate attrib in attribs)
             {
                 if (attrib.ClientMessage)
                 {
                     WorldClientPacketDelegate wcpd = (WorldClientPacketDelegate)Delegate.CreateDelegate(typeof(WorldClientPacketDelegate), obj, method.Name);
                     RegisterPacketHandler((CMSG)attrib.MsgID, wcpd);
                 }
                 else
                 {
                     WorldServerPacketDelegate wspd = (WorldServerPacketDelegate)Delegate.CreateDelegate(typeof(WorldServerPacketDelegate), obj, method.Name);
                     RegisterPacketHandler((WORLDMSG)attrib.MsgID, wspd);
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
        public static void UnregisterPacketHandler(CMSG msgID, WorldClientPacketDelegate wcpd)
        {
            WorldClientPacketDelegate dele = (WorldClientPacketDelegate)worldClientDelegates[(int)msgID];

            worldClientDelegates[(int)msgID] = dele - wcpd;
        }