using System; namespace SharpChat.SockChat.PacketsS2C { public class MessageAddS2CPacket : ISockChatS2CPacket { private readonly long MessageId; private readonly DateTimeOffset TimeStamp; private readonly long UserId; private readonly string Body; private readonly bool IsAction; private readonly bool IsPrivate; public MessageAddS2CPacket( long messageId, DateTimeOffset timeStamp, long userId, string body, bool isAction, bool isPrivate ) { MessageId = messageId; TimeStamp = timeStamp; UserId = userId < 0 ? -1 : userId; Body = body; IsAction = isAction; IsPrivate = isPrivate; } public string Pack() { string body = SockChatUtility.SanitiseMessageBody(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}", TimeStamp.ToUnixTimeSeconds(), UserId, body, MessageId, 1, IsAction ? 1 : 0, 0, IsAction ? 0 : 1, IsPrivate ? 1 : 0 ); } } }