using System; using System.Collections.Generic; using Lidgren.Network; namespace RageCoop.Core { internal partial class Packets { internal class ChatMessage : Packet { public override PacketType Type => PacketType.ChatMessage; private Func crypt; private Func decrypt; public ChatMessage(Func crypter) { crypt = crypter; } public ChatMessage(Func decrypter) { decrypt = decrypter; } public string Username { get; set; } public string Message { get; set; } public override byte[] Serialize() { List byteArray = new List(); // Write Username byteArray.AddString(Username); // Write Message byteArray.AddArray(crypt(Message)); return byteArray.ToArray(); } public override void Deserialize(byte[] array) { #region NetIncomingMessageToPacket BitReader reader = new BitReader(array); // Read username Username = reader.ReadString(); Message = decrypt(reader.ReadByteArray()).GetString(); #endregion } } } }