public PoolByteWriter Encrypt(byte[] packet, int offset, int length) { PoolByteWriter result = WriteHeader(packet, offset, length); foreach (ICrypter crypter in encryptSeq) { crypter.Encrypt(result.Buffer, HEADER_SIZE, HEADER_SIZE + length); } return(result); }
public static byte[] SerializeDictionary <TK, TV>(this IDictionary <TK, TV> dictionary) where TK : struct where TV : struct { using var writer = new PoolByteWriter(); writer.WriteInt(dictionary.Count); foreach ((TK key, TV value) in dictionary) { writer.Write <TK>(key); writer.Write <TV>(value); } return(writer.ToArray()); }
public PoolByteWriter WriteHeader(byte[] packet, int offset, int length) { short encSeq = EncodeSeqBase(); var writer = new PoolByteWriter(length + HEADER_SIZE, ArrayProvider); writer.WriteShort(encSeq); writer.WriteInt(length); writer.WriteBytes(packet, offset, length); return(writer); }
private void SendInternal(byte[] packet, int length) { if (disposed) { return; } LogSend(packet, length); lock (sendCipher) { using PoolByteWriter encryptedPacket = sendCipher.Encrypt(packet, 0, length); SendRaw(encryptedPacket); } }
private void PerformHandshake() { var handshake = new ByteWriter(HANDSHAKE_SIZE); handshake.Write <ushort>(SendOp.REQUEST_VERSION); handshake.Write <uint>(VERSION); handshake.Write <uint>(riv); handshake.Write <uint>(siv); handshake.Write <uint>(BLOCK_IV); handshake.WriteByte((byte)Type); // No encryption for handshake using PoolByteWriter packet = sendCipher.WriteHeader(handshake.Buffer, 0, handshake.Length); logger.LogDebug("Handshake: {Packet}", packet); SendRaw(packet); }
private void Handle(InvocationContext ctx, string id, bool verbose, string[] packet) { try { using var pWriter = new PoolByteWriter(); foreach (string hexStr in packet) { // This currently does not fail even if string contains invalid hex chars. pWriter.WriteBytes(hexStr.ToByteArray()); } if (verbose) { ctx.Console.Out.WriteLine($"Sending packets to: {id}"); ctx.Console.Out.WriteLine(pWriter.ToString()); } Console.WriteLine("No game server to send packet"); ctx.ExitCode = 0; } catch (SystemException ex) { ctx.Console.Error.WriteLine(ex.Message); ctx.ExitCode = 1; } }
public static byte[] Serialize <T>(this T value) where T : IByteSerializable { using var writer = new PoolByteWriter(); writer.WriteClass <T>(value); return(writer.ToArray()); }
public static byte[] SerializeCollection <T>(this ICollection <T> collection) where T : struct { using var writer = new PoolByteWriter(); writer.WriteCollection(collection); return(writer.ToArray()); }