Esempio n. 1
0
        void InvokeHandler(PacketHandler packetHandler, byte[] buffer, int length)
        {
            if (packetHandler == null)
            {
                return;
            }
            PacketReader reader = PacketReader.CreateInstance(buffer, length, packetHandler.Length != -1);

            packetHandler.Invoke(reader);
        }
Esempio n. 2
0
        private void InvokeHandlers(List <PacketHandler> packetHandlers, byte[] buffer, int length)
        {
            if (packetHandlers == null)
            {
                return;
            }

            int count = packetHandlers.Count;

            for (int i = 0; i < count; i++)
            {
                PacketHandler      handler      = packetHandlers[i];
                TypedPacketHandler typedHandler = packetHandlers[i] as TypedPacketHandler;

                if (typedHandler != null)
                {
                    PacketReader reader = PacketReader.CreateInstance(buffer, length, typedHandler.Length != -1);

                    IRecvPacket recvPacket = typedHandler.CreatePacket(reader);

                    if (typedHandler.TypeHandler != null)
                    {
                        typedHandler.TypeHandler(recvPacket);
                    }
                    else
                    {
                        Tracer.Warn("ClientNetwork: Unknown packet received!");
                    }
                }
                else
                {
                    PacketReader reader = PacketReader.CreateInstance(buffer, length, packetHandlers[i].Length != -1);

                    if (handler.Handler != null)
                    {
                        handler.Handler(reader);
                    }
                }
            }
        }
Esempio n. 3
0
        private void InvokeHandler(PacketHandler packetHandler, byte[] buffer, int length)
        {
            if (packetHandler == null)
            {
                return;
            }

            TypedPacketHandler typedHandler = packetHandler as TypedPacketHandler;

            if (typedHandler != null)
            {
                PacketReader reader = PacketReader.CreateInstance(buffer, length, typedHandler.Length != -1);

                IRecvPacket recvPacket = typedHandler.CreatePacket(reader);

                if (typedHandler.TypeHandler != null)
                {
                    typedHandler.TypeHandler(recvPacket);
                }
                else
                {
                    Tracer.Warn("NetworkClient: Unhandled packet received! [typedHandler != null]");
                }
            }
            else
            {
                PacketReader reader = PacketReader.CreateInstance(buffer, length, packetHandler.Length != -1);

                if (packetHandler.Handler != null)
                {
                    packetHandler.Handler(reader);
                }
                else
                {
                    Tracer.Warn("NetworkClient: Unhandled packet received! [typedHandler == null]");
                }
            }
        }