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); }
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); }
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); }
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); }