Ejemplo n.º 1
0
        public void BroadCast(APacket packet, Client except = null)
        {
            foreach (Client c in Clients)
            {
                if (except == c)
                {
                    continue;
                }

                c.AddResponse(packet.Clone() as APacket);
            }
        }
Ejemplo n.º 2
0
        public void ReadPacket(Client client, byte[] buffer, int lengthRead)
        {
            try
            {
                ByteBuffer byteBuffer = new ByteBuffer();

                byteBuffer.Write(buffer, 0, lengthRead);
                byteBuffer.Position = 0;

                while (byteBuffer.Position < lengthRead)
                {
                    int len = byteBuffer.ReadVarInt();
                    int id  = byteBuffer.ReadVarInt();

                    object tmp = client.State.Peek()._ReceiptPackets[id];
                    if (tmp != null)
                    {
                        APacket packet = tmp as APacket;
                        packet = packet.Clone() as APacket;
                        if (packet == null)
                        {
                            throw new NullReferenceException("The server does not handle packet " + id);
                        }

                        packet.Read(client, byteBuffer);
                    }
                    else
                    {
                        Console.WriteLine("Unhandled packet - ID : " + id + " - Length : " + len);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR : " + e.Message);
            }
        }