예제 #1
0
 public override void Read(PacketReader reader)
 {
     TimeStamp = reader.ReadLong();
     #if DEBUG
     Console.WriteLine(ToString());
     #endif
 }
예제 #2
0
 public override void Read(PacketReader reader)
 {
     Username = reader.ReadString16(4);
     #if DEBUG
     Console.WriteLine(ToString());
     #endif
 }
예제 #3
0
 public override void Read(PacketReader reader)
 {
     EntityId = reader.ReadInt();
     #if DEBUG
     Console.WriteLine(ToString());
     #endif
 }
예제 #4
0
 public override void Read(PacketReader reader)
 {
     Message = reader.ReadString8(1024);
     #if DEBUG
     Console.WriteLine(ToString());
     #endif
 }
예제 #5
0
 public override void Read(PacketReader reader)
 {
     PatternId = reader.ReadInt();
     TextureId = reader.ReadInt();
     X = reader.ReadFloat();
     Y = reader.ReadFloat();
 }
예제 #6
0
 public override void Read(PacketReader reader)
 {
     PlayerId = reader.ReadInt();
     X = reader.ReadFloat();
     Y = reader.ReadFloat();
     Z = reader.ReadFloat();
     #if DEBUG
     Console.WriteLine(ToString());
     #endif
 }
예제 #7
0
        public static void ReadEntitySpawn(Client client, PacketReader reader)
        {
            EntitySpawnPacket esp = new EntitySpawnPacket();
            esp.Read(reader);

            if (!reader.Failed)
            {
                client.HandleEntitySpawn(esp);
            }
        }
예제 #8
0
        public static void ReadHandshake(Client client, PacketReader reader)
        {
            HandshakePacket hp = new HandshakePacket();
            hp.Read(reader);

            if (!reader.Failed)
            {
                client.HandleHandshake(hp);
            }
        }
예제 #9
0
        public static void ReadKeepAlive(Client client, PacketReader reader)
        {
            KeepAlivePacket ap = new KeepAlivePacket();
            ap.Read(reader);

            if (!reader.Failed)
            {
                Client.HandleKeepAlive(client, ap);
            }
        }
예제 #10
0
        private static void ReadMovement(Client client, PacketReader reader)
        {
            MovePacket mp = new MovePacket();
            mp.Read(reader);

            if (!reader.Failed)
            {
                Client.HandleMovePacket(client, mp);
            }
        }
예제 #11
0
 public override void Read(PacketReader reader)
 {
     PlayerId = reader.ReadInt();
     Nickname = reader.ReadString16(9);
     Health = reader.ReadInt();
     Speed = reader.ReadFloat();
     #if DEBUG
     Console.WriteLine(ToString());
     #endif
 }
예제 #12
0
 public override void Read(PacketReader reader)
 {
     EntityId = reader.ReadInt();
     Nickname = reader.ReadString8(12);
     Health = reader.ReadInt();
     X = reader.ReadFloat();
     Y = reader.ReadFloat();
     #if DEBUG
     Console.WriteLine(ToString());
     #endif
 }
예제 #13
0
 public override void Read(PacketReader reader)
 {
     EntityId = reader.ReadInt();
     Position = new WorldPosition
     {
         X = reader.ReadFloat(),
         Y = reader.ReadFloat()
     };
     Direction = reader.ReadFloat();
     Speed = reader.ReadFloat();
     #if DEBUG
     Console.WriteLine(ToString());
     #endif
 }
예제 #14
0
        private void ProcessReadQueue()
        {
            while (_recv.WaitOne())
            {
                ByteQueue temp;
                lock (_queueLock)
                {
                    temp = _receiveBufferQueue;
                    _receiveBufferQueue = _readingBufferQueue;
                }

                _readingBufferQueue = temp;

                int length = _fragPackets.Size + _readingBufferQueue.Size;

                while (length > 0)
                {
                    byte packetType = _fragPackets.Size > 0
                                          ? _fragPackets.GetPacketId()
                                          : _readingBufferQueue.GetPacketId();

                    ClientPacketHandler handler = PacketHandlers.GetHandler((PacketType) packetType);

                    if (handler == null)
                    {
                        byte[] unhandled = GetBufferToBeRead(length);
                        Console.WriteLine("Received unknown packet! Id:{0}", packetType);
                        Console.WriteLine("Fehler {0}", BitConverter.ToString(unhandled));
                        length = 0;
                    }
                    else if (handler.Length == 0)
                    {
                        byte[] data = GetBufferToBeRead(length);
                        Console.WriteLine("Klappt {0}", BitConverter.ToString(data));

                        if (length >= handler.MinimumLength)
                        {
                            PacketReader reader = new PacketReader(data, length);

                            handler.OnReceive(this, reader);
                            if (reader.Failed)
                            {
                                EnqueueFragment(data);
                                length = 0;
                            }
                            else
                            {
                                _readingBufferQueue.Enqueue(data, reader.Index, data.Length - reader.Index);
                                length = _readingBufferQueue.Length;
                            }
                        }
                        else
                        {
                            EnqueueFragment(data);
                            length = 0;
                        }
                    }
                    else if (length >= handler.Length)
                    {
                        byte[] data = GetBufferToBeRead(handler.Length);
                        /*using (StreamWriter sw = new StreamWriter(String.Format("recv_packets{0}.log", _userName), true))
                        {
                            sw.WriteLine("Fixed length: {0}", BitConverter.ToString(data));
                        }*/
                        PacketReader reader = new PacketReader(data, handler.Length);

                        handler.OnReceive(this, reader);

                        // If we failed it's because the packet is wrong
                        if (reader.Failed)
                        {
                            Dispose();
                            length = 0;
                        }
                        else
                        {
                            if (_fragPackets.Length > 0)
                                throw new Exception("Fragpackets must be empy here!");
                            length = _readingBufferQueue.Length;
                        }
                    }
                    else
                    {
                        /*using (StreamWriter sw = new StreamWriter(String.Format("recv_packets{0}.log", _userName), true))
                        { */
                        byte[] data = GetBufferToBeRead(length);
                        //sw.WriteLine("Fragmented fixed: {0}", BitConverter.ToString(data));
                        EnqueueFragment(data);
                        length = 0;
                        //}
                    }
                }
            }
        }
예제 #15
0
        public static void ReadPattern(Client client, PacketReader reader)
        {
            PatternPacket pp = new PatternPacket();
            pp.Read(reader);

            if (!reader.Failed)
            {
                Client.HandlePatternPacket(client, pp);
            }
        }
예제 #16
0
        public static void ReadPlayerInfo(Client client, PacketReader reader)
        {
            PlayerInfoPacket pip = new PlayerInfoPacket();
            Console.WriteLine("Player Info Packet size is {0}", reader.Size);
            pip.Read(reader);

            if (!reader.Failed)
            {
                client.HandlePlayerInfo(pip);
            }
        }
예제 #17
0
        public static void ReadPlayerPosition(Client client, PacketReader reader)
        {
            PlayerPositionPacket ppp = new PlayerPositionPacket();
            ppp.Read(reader);

            if (!reader.Failed)
            {
                client.HandlePlayerPosition(ppp);
            }
        }
예제 #18
0
        public static void ReadMovement(Client client, PacketReader reader)
        {
            MovePacket mp = new MovePacket();
            mp.Read(reader);

            if (!reader.Failed)
            {
                Console.WriteLine("Received Move Packet");
                client.Move(
                    mp.EntityId,
                    mp.Position,
                    mp.Direction,
                    mp.Speed);
            }
        }
예제 #19
0
 public abstract void Read(PacketReader reader);
예제 #20
0
        public static void ProcessReadQueue()
        {
            int count = RecvClientQueue.Count;

            Parallel.For(0, count, i =>
            {
                Client client;
                if (!RecvClientQueue.TryDequeue(out client))
                    return;

                if (!client.Running)
                    return;

                Interlocked.Exchange(ref client.TimesEnqueuedForRecv, 0);
                ByteQueue bufferToProcess = client.GetBufferToProcess();

                int length = client.FragPackets.Size + bufferToProcess.Size;
                while (length > 0)
                {
                    byte packetType = 0;

                    if (client.FragPackets.Size > 0)
                        packetType = client.FragPackets.GetPacketId();
                    else
                        packetType = bufferToProcess.GetPacketId();

                    PacketHandler handler = PacketHandlers.GetHandler((PacketType)packetType);

                    if (handler == null)
                    {
                        byte[] unhandledPacketData = GetBufferToBeRead(bufferToProcess, client, length);
                        Console.WriteLine("Unhandled packet arrived, id: {0}", unhandledPacketData[0]);
                        Console.WriteLine("Data:\r\n {0}", BitConverter.ToString(unhandledPacketData, 1));

                        length = 0;
                    }
                    else if (handler.Length == 0)
                    {
                        byte[] data = GetBufferToBeRead(bufferToProcess, client, length);

                        if (length >= handler.MinimumLength)
                        {
                            PacketReader reader = new PacketReader(data, length);

                            handler.OnReceive(client, reader);

                            // If we failed it's because the packet isn't complete
                            if (reader.Failed)
                            {
                                EnqueueFragment(client, data);
                                length = 0;
                            }
                            else
                            {
                                bufferToProcess.Enqueue(data, reader.Index, data.Length - reader.Index);
                                length = bufferToProcess.Length;
                            }
                        }
                        else
                        {
                            EnqueueFragment(client, data);
                            length = 0;
                        }

                    }
                    else if (length >= handler.Length)
                    {
                        byte[] data = GetBufferToBeRead(bufferToProcess, client, handler.Length);

                        PacketReader reader = new PacketReader(data, handler.Length);

                        handler.OnReceive(client, reader);

                        // If we failed it's because the packet is wrong
                        if (reader.Failed)
                        {
                            client.MarkToDispose();
                            length = 0;
                        }
                        else
                            length = bufferToProcess.Length;
                    }
                    else
                    {
                        byte[] data = GetBufferToBeRead(bufferToProcess, client, length);
                        EnqueueFragment(client, data);
                        length = 0;
                    }
                }
            });
        }