GetHandler() 공개 정적인 메소드

public static GetHandler ( int packetID ) : PacketHandler
packetID int
리턴 PacketHandler
예제 #1
0
파일: NetState.cs 프로젝트: Pumpk1ns/RunZHA
 public PacketHandler GetHandler(int packetID)
 {
     if (IsPost6017)
     {
         return(PacketHandlers.Get6017Handler(packetID));
     }
     else
     {
         return(PacketHandlers.GetHandler(packetID));
     }
 }
예제 #2
0
 public PacketHandler GetHandler(int packetID)
 {
     if (ContainerGridLines)
     {
         return(PacketHandlers.Get6017Handler(packetID));
     }
     else
     {
         return(PacketHandlers.GetHandler(packetID));
     }
 }
예제 #3
0
        public bool HandleReceive(NetState ns)
        {
            ByteQueue buffer = ns.Buffer;

            if (buffer == null || buffer.Length <= 0)
            {
                return(true);
            }

            lock ( buffer )
            {
                int length = buffer.Length;

                if (!ns.Seeded)
                {
                    if (buffer.Length >= 4)
                    {
                        buffer.Dequeue(m_Peek, 0, 4);

                        int seed = (m_Peek[0] << 24) | (m_Peek[1] << 16) | (m_Peek[2] << 8) | m_Peek[3];

                        if (seed == 0)
                        {
                            Console.WriteLine("Login: {0}: Invalid client detected, disconnecting", ns);
                            ns.Dispose();
                            return(false);
                        }

                        ns.m_Seed = seed;
                        ns.Seeded = true;

                        length = buffer.Length;
                    }
                    else
                    {
                        return(true);
                    }
                }

                while (length > 0 && ns.Running)
                {
                    int packetID = buffer.GetPacketID();

                    if (!ns.SentFirstPacket && packetID != 0xF1 && packetID != 0xCF && packetID != 0x80 && packetID != 0x91 && packetID != 0xA4)
                    {
                        Console.WriteLine("Client: {0}: Encrypted client detected, disconnecting", ns);
                        ns.Dispose();
                        break;
                    }

                    PacketHandler handler = PacketHandlers.GetHandler(packetID);

                    if (handler == null)
                    {
                        byte[] data = new byte[length];
                        length = buffer.Dequeue(data, 0, length);

                        new PacketReader(data, length, false).Trace(ns);

                        break;
                    }

                    int packetLength = handler.Length;

                    if (packetLength <= 0)
                    {
                        if (length >= 3)
                        {
                            packetLength = buffer.GetPacketLength();

                            if (packetLength < 3)
                            {
                                ns.Dispose();
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (length >= packetLength)
                    {
                        if (handler.Ingame && ns.Mobile == null)
                        {
                            Console.WriteLine("Client: {0}: Sent ingame packet (0x{1:X2}) before having been attached to a mobile", ns, packetID);
                            ns.Dispose();
                            break;
                        }
                        else if (handler.Ingame && ns.Mobile.Deleted)
                        {
                            ns.Dispose();
                            break;
                        }
                        else
                        {
                            ThrottlePacketCallback throttler = handler.ThrottleCallback;

                            if (throttler != null && !throttler(ns))
                            {
                                m_Throttled.Enqueue(ns);
                                return(false);
                            }

                            PacketProfile profile = PacketProfile.GetIncomingProfile(packetID);
                            DateTime      start   = (profile == null ? DateTime.MinValue : DateTime.Now);

                            byte[] packetBuffer;

                            if (BufferSize >= packetLength)
                            {
                                packetBuffer = m_Buffers.AcquireBuffer();
                            }
                            else
                            {
                                packetBuffer = new byte[packetLength];
                            }

                            packetLength = buffer.Dequeue(packetBuffer, 0, packetLength);

                            PacketReader r = new PacketReader(packetBuffer, packetLength, handler.Length != 0);

                            handler.OnReceive(ns, r);
                            length = buffer.Length;

                            if (BufferSize >= packetLength)
                            {
                                m_Buffers.ReleaseBuffer(packetBuffer);
                            }

                            if (profile != null)
                            {
                                profile.Record(packetLength, DateTime.Now - start);
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(true);
        }
예제 #4
0
        private void OnReceived(NetState state, ByteQueue buffer, out bool throttle)
        {
            throttle = false;
            GameClient client;

            if (!m_Clients.TryGetValue(state, out client))
            {
                Logger.Error("Inconsistent game server state: game client for {0} not found", state);
                return;
            }

            if (!client.Seeded)
            {
                if (buffer.GetPacketID() == 0xEF)
                {
                    client.Seeded = true;
                }
                else if (buffer.Length >= 4)
                {
                    byte[] peek = new byte[4];
                    buffer.Dequeue(peek, 0, 4);

                    int seed = (peek[0] << 24) | (peek[1] << 16) | (peek[2] << 8) | peek[3];

                    if (seed == 0)
                    {
                        Console.WriteLine("Login: {0}: Invalid client detected, disconnecting", client);
                        client.Dispose();

                        return;
                    }

                    client.m_Seed = seed;
                    client.Seeded = true;
                }
                else
                {
                    return;                     // Need at least 4 bytes for the seed
                }
            }

            int length = buffer.Length;

            while (length > 0 && buffer.Length > 0)
            {
                int packetID = buffer.GetPacketID();

                if (!client.SentFirstPacket && packetID != 0xF1 && packetID != 0xCF && packetID != 0x80 && packetID != 0x91 && packetID != 0xA4 && packetID != 0xEF)
                {
                    Console.WriteLine("Client: {0}: Encrypted client detected, disconnecting", client);
                    client.Dispose();
                    return;
                }

                PacketHandler handler = m_Handlers.GetHandler(packetID);

                if (handler == null)
                {
                    byte[] data = new byte[length];
                    length = buffer.Dequeue(data, 0, length);

                    if (Environment.Logging)
                    {
                        PacketReader reader = PacketReader.CreateInstance(data, length, false);
                        reader.Trace(client);
                        PacketReader.ReleaseInstance(reader);
                    }

                    return;
                }

                int packetLength = handler.Length;

                if (packetLength == 0)
                {
                    // Dynamic length packet. Need at leaset 3 bytes (1 packet cmd + 2 length)

                    if (length >= 3)
                    {
                        packetLength = buffer.GetPacketLength();

                        if (packetLength < 3)
                        {
                            client.Dispose();
                            return;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                if (length >= packetLength)
                {
                    if (handler.Ingame && client.Mobile == null)
                    {
                        Console.WriteLine("Client: {0}: Sent ingame packet (0x{1:X2}) before having been attached to a mobile", client, packetID);
                        client.Dispose();
                        return;
                    }
                    else if (handler.Ingame && client.Mobile.Deleted)
                    {
                        client.Dispose();
                        return;
                    }
                    else
                    {
                        ThrottlePacketCallback throttler = handler.ThrottleCallback;

                        if (throttler != null && !throttler(client))
                        {
                            throttle = true;
                            return;
                        }

                        PacketProfile profile = PacketProfile.GetIncomingProfile(packetID);
                        DateTime      start   = (profile == null ? DateTime.MinValue : DateTime.Now);

                        byte[] packetBuffer;

                        if (BufferSize >= packetLength)
                        {
                            packetBuffer = m_Buffers.AcquireBuffer();
                        }
                        else
                        {
                            packetBuffer = new byte[packetLength];
                        }

                        packetLength = buffer.Dequeue(packetBuffer, 0, packetLength);

                        PacketReader reader = PacketReader.CreateInstance(packetBuffer, packetLength, handler.Length != 0);

                        try
                        {
                            handler.OnReceive(client, reader);
                        }
                        catch (Exception e)
                        {
                            Logger.Error("Exception disarmed in HandleReceive from {0}: {1}", client.Address, e);
                        }

                        PacketReader.ReleaseInstance(reader);

                        length = buffer.Length;

                        if (BufferSize >= packetLength)
                        {
                            m_Buffers.ReleaseBuffer(packetBuffer);
                        }

                        if (profile != null)
                        {
                            profile.Record(packetLength, DateTime.Now - start);
                        }
                    }
                }
                else
                {
                    break;
                }
            }
        }
예제 #5
0
 public PacketHandler GetHandler(int packetID)
 {
     return(PacketHandlers.GetHandler(packetID));
 }
예제 #6
0
        public bool HandleReceive(NetState ns)
        {
            lock ( ns )
            {
                ByteQueue buffer = ns.Buffer;

                if (buffer == null)
                {
                    return(true);
                }

                int length = buffer.Length;

                if (!ns.Seeded)
                {
                    if (length >= 4)
                    {
                        buffer.Dequeue(m_Peek, 0, 4);

                        int seed = (m_Peek[0] << 24) | (m_Peek[1] << 16) | (m_Peek[2] << 8) | m_Peek[3];

                        //Console.WriteLine( "Login: {0}: Seed is 0x{1:X8}", ns, seed );

                        if (seed == 0)
                        {
                            log.Warn(String.Format("Login: {0}: Invalid client detected, disconnecting", ns));
                            ns.Dispose();
                            return(false);
                        }

                        ns.m_Seed = seed;
                        ns.Seeded = true;
                    }

                    return(true);
                }

                //Console.WriteLine( "{" );

                while (length > 0 && ns.Running)
                {
                    int packetID = buffer.GetPacketID();

                    if (!ns.SentFirstPacket && packetID != 0xF1 && packetID != 0xCF && packetID != 0x80 && packetID != 0x91 && packetID != 0xA4 && packetID != 0xBF)
                    {
                        log.Warn(String.Format("Client: {0}: Encrypted client detected, disconnecting", ns));
                        ns.Dispose();
                        break;
                    }

                    PacketHandler handler = PacketHandlers.GetHandler(packetID);

                    if (handler == null)
                    {
                        byte[] data = new byte[length];
                        length = buffer.Dequeue(data, 0, length);

                        new PacketReader(data, length, false).Trace(ns);

                        break;
                    }

                    int packetLength = handler.Length;

                    if (packetLength <= 0)
                    {
                        if (length >= 3)
                        {
                            packetLength = buffer.GetPacketLength();

                            if (packetLength < 3)
                            {
                                ns.Dispose();
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (length >= packetLength)
                    {
                        if (handler.Ingame && ns.Mobile == null)
                        {
                            log.Warn(String.Format("Client: {0}: Sent ingame packet (0x{1:X2}) before having been attached to a mobile", ns, packetID));
                            ns.Dispose();
                            break;
                        }
                        else if (handler.Ingame && ns.Mobile.Deleted)
                        {
                            ns.Dispose();
                            break;
                        }
                        else
                        {
                            ThrottlePacketCallback throttler = handler.ThrottleCallback;

                            if (throttler != null && !throttler(ns))
                            {
                                m_Throttled.Enqueue(ns);
                                //Console.WriteLine( "}" );
                                return(false);
                            }

                            //Console.WriteLine( handler.OnReceive.Method.Name );

                            PacketProfile profile = PacketProfile.GetIncomingProfile(packetID);
                            DateTime      start   = (profile == null ? DateTime.MinValue : DateTime.Now);

                            byte[] packetBuffer;

                            if (BufferSize >= packetLength)
                            {
                                packetBuffer = m_Buffers.AquireBuffer();
                            }
                            else
                            {
                                packetBuffer = new byte[packetLength];
                            }

                            packetLength = buffer.Dequeue(packetBuffer, 0, packetLength);

                            PacketReader r = new PacketReader(packetBuffer, packetLength, handler.Length != 0);

                            try {
                                handler.OnReceive(ns, r);
                            } catch (Exception e) {
                                log.Fatal(String.Format("Exception disarmed in HandleReceive from {0}",
                                                        ns.Address), e);
                            }

                            length = buffer.Length;

                            if (BufferSize >= packetLength)
                            {
                                m_Buffers.ReleaseBuffer(packetBuffer);
                            }

                            if (profile != null)
                            {
                                profile.Record(packetLength, DateTime.Now - start);
                            }

                            //Console.WriteLine( "Client: {0}: Unhandled packet 0x{1:X2}", ns, packetID );
                            //Utility.FormatBuffer( Console.Out, new System.IO.MemoryStream( r.Buffer ), r.Buffer.Length );
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                //Console.WriteLine( "}" );
            }

            return(true);
        }
예제 #7
0
        public bool HandleReceive(NetState ns)
        {
            ByteQueue     queue1;
            int           num1;
            int           num2;
            int           num3;
            PacketHandler handler1;

            byte[] buffer1;
            int    num4;
            ThrottlePacketCallback callback1;
            PacketProfile          profile1;
            DateTime     time1;
            PacketReader reader1;
            NetState     state1 = ns;

            lock (ns)
            {
                queue1 = ns.Buffer;
                if (queue1 == null)
                {
                    return(true);
                }
                num1 = queue1.Length;
                if (ns.Seeded)
                {
                    goto Label_0250;
                }
                if (num1 >= 4)
                {
                    queue1.Dequeue(this.m_Peek, 0, 4);
                    num2 = ((((this.m_Peek[0] << 24) | (this.m_Peek[1] << 16)) | (this.m_Peek[2] << 8)) | this.m_Peek[3]);
                    if (num2 == 0)
                    {
                        Console.WriteLine("Login: {0}: Invalid client detected, disconnecting", ns);
                        ns.Dispose();
                        return(false);
                    }
                    ns.m_Seed = num2;
                    ns.Seeded = true;
                }
                return(true);

Label_009D:
                queue1.Peek(this.m_Peek, 0, 1);
                num3 = this.m_Peek[0];
                if (((!ns.SentFirstPacket && (num3 != 241)) && ((num3 != 207) && (num3 != 128))) && ((num3 != 145) && (num3 != 164)))
                {
                    Console.WriteLine("Client: {0}: Encrypted client detected, disconnecting", ns);
                    ns.Dispose();
                    goto Label_0269;
                }
                handler1 = PacketHandlers.GetHandler(num3);
                if (handler1 == null)
                {
                    buffer1 = queue1.Dequeue(num1);
                    new PacketReader(buffer1, 0).Trace(ns);
                    goto Label_0269;
                }
                num4 = handler1.Length;
                if (num4 <= 0)
                {
                    if (num1 < 3)
                    {
                        goto Label_0269;
                    }
                    queue1.Peek(this.m_Peek, 0, 3);
                    num4 = ((this.m_Peek[1] << 8) | this.m_Peek[2]);
                    if (num4 < 3)
                    {
                        ns.Dispose();
                        goto Label_0269;
                    }
                }
                if (num1 < num4)
                {
                    goto Label_0269;
                }
                if (handler1.Ingame && (ns.Mobile == null))
                {
                    Console.WriteLine("Client: {0}: Sent ingame packet (0x{1:X2}) before having been attached to a mobile", ns, num3);
                    ns.Dispose();
                    goto Label_0269;
                }
                if (handler1.Ingame && ns.Mobile.Deleted)
                {
                    ns.Dispose();
                    goto Label_0269;
                }
                callback1 = handler1.ThrottleCallback;
                if ((callback1 != null) && !callback1.Invoke(ns))
                {
                    this.m_Throttled.Enqueue(ns);
                    return(false);
                }
                profile1 = PacketProfile.GetIncomingProfile(num3);
                time1    = ((profile1 == null) ? DateTime.MinValue : DateTime.Now);
                reader1  = new PacketReader(queue1.Dequeue(num4), (handler1.Length != 0));
                handler1.OnReceive(ns, reader1);
                num1 = queue1.Length;
                if (profile1 != null)
                {
                    profile1.Record(num4, ((TimeSpan)(DateTime.Now - time1)));
                }
Label_0250:
                if (num1 > 0)
                {
                    if (ns.Running)
                    {
                        goto Label_009D;
                    }
                }
            }
Label_0269:
            return(true);
        }