using System; using System.Collections.Generic; using System.Text; namespace SharpChat.Packet { public class ChatMessageAddPacket( long msgId, DateTimeOffset created, long userId, string text, bool isAction, bool isPrivate ) : ServerPacket(msgId) { public string Text { get; } = text ?? throw new ArgumentNullException(nameof(text)); public override IEnumerable<string> Pack() { StringBuilder sb = new(); sb.Append('2'); sb.Append('\t'); sb.Append(created.ToUnixTimeSeconds()); sb.Append('\t'); sb.Append(userId); sb.Append('\t'); if(isAction) sb.Append("<i>"); sb.Append( Text.Replace("<", "<") .Replace(">", ">") .Replace("\n", " <br/> ") .Replace("\t", " ") ); if(isAction) sb.Append("</i>"); sb.Append('\t'); sb.Append(SequenceId); sb.AppendFormat( "\t1{0}0{1}{2}", isAction ? '1' : '0', isAction ? '0' : '1', isPrivate ? '1' : '0' ); yield return sb.ToString(); } } }