Ejemplo n.º 1
0
 public static void BeginReadPacket(Socket skt, ClientProcessor psr, Action <Packet> callback, Action failure)
 {
     byte[] n = new byte[5];
     skt.BeginReceive(n, 0, 5, 0, ar =>
     {
         try
         {
             byte[] x = (byte[])ar.AsyncState;
             int len  = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(x, 0));
             if (len == 0)
             {
                 failure();
                 return;
             }
             len           -= 5;
             byte id        = x[4];
             Packet packet  = Packets[(PacketID)id].CreateInstance();
             byte[] content = new byte[len];
             if (len > 0)
             {
                 skt.Receive(content);
             }
             packet.Read(psr, new NReader(new MemoryStream(packet.Crypt(psr, content))));
             callback(packet);
         }
         catch { failure(); }
     }, n);
 }
Ejemplo n.º 2
0
        public static Packet ReadPacket(NReader rdr, ClientProcessor psr)
        {
            int    len    = rdr.ReadInt32() - 5;
            byte   id     = rdr.ReadByte();
            Packet packet = Packets[(PacketID)id].CreateInstance();

            byte[] content = rdr.ReadBytes(len);
            packet.Read(psr, new NReader(new MemoryStream(packet.Crypt(psr, content))));
            return(packet);
        }
Ejemplo n.º 3
0
        public static void WritePacket(NWriter wtr, Packet pkt, ClientProcessor psr)
        {
            MemoryStream s = new MemoryStream();
            pkt.Write(psr, new NWriter(s));

            byte[] content = s.ToArray();
            content = pkt.Crypt(psr, content);
            wtr.Write(content.Length + 5);
            wtr.Write((byte)pkt.ID);
            wtr.Write(content);
        }
Ejemplo n.º 4
0
        public static void WritePacket(NWriter wtr, Packet pkt, ClientProcessor psr)
        {
            MemoryStream s = new MemoryStream();

            pkt.Write(psr, new NWriter(s));

            byte[] content = s.ToArray();
            content = pkt.Crypt(psr, content);
            wtr.Write(content.Length + 5);
            wtr.Write((byte)pkt.ID);
            wtr.Write(content);
        }