using System; namespace SharpChat.Packet { public class MessageAddPacket : ServerPacket { private readonly long Created; private readonly long UserId; private readonly string Body; private readonly bool IsAction; private readonly bool IsPrivate; public MessageAddPacket( long msgId, DateTimeOffset created, long userId, string body, bool isAction, bool isPrivate ) : base(msgId) { Created = created.ToUnixTimeSeconds(); UserId = userId < 0 ? -1 : userId; Body = body; IsAction = isAction; IsPrivate = isPrivate; } public override string Pack() { string body = SharpUtil.Sanitise(Body); if(IsAction) body = string.Format("{0}", body); return string.Format( "2\t{0}\t{1}\t{2}\t{3}\t{4}{5}{6}{7}{8}", Created, UserId, body, SequenceId, 1, IsAction ? 1 : 0, 0, IsAction ? 0 : 1, IsPrivate ? 1 : 0 ); } } }