using System; namespace SharpChat.SockChat.PacketsS2C { public class MessageAddLogS2CPacket : ISockChatS2CPacket { private readonly long MessageId; private readonly DateTimeOffset TimeStamp; private readonly long UserId; private readonly string UserName; private readonly Colour UserColour; private readonly int UserRank; private readonly UserPermissions UserPerms; private readonly string Body; private readonly bool IsAction; private readonly bool IsPrivate; private readonly bool IsBroadcast; // this should be MessageBroadcastLogPacket private readonly bool Notify; public MessageAddLogS2CPacket( long messageId, DateTimeOffset timeStamp, long userId, string userName, Colour userColour, int userRank, UserPermissions userPerms, string body, bool isAction, bool isPrivate, bool isBroadcast, bool notify ) { MessageId = messageId; TimeStamp = timeStamp; UserId = userId < 0 ? -1 : userId; UserName = userName; UserColour = userColour; UserRank = userRank; UserPerms = userPerms; Body = body; IsAction = isAction; IsPrivate = isPrivate; IsBroadcast = isBroadcast; Notify = notify; } public string Pack() { string body = SockChatUtility.SanitiseMessageBody(Body); if(IsAction) body = string.Format("{0}", body); if(IsBroadcast) body = "0\fsay\f" + body; string userPerms = UserId < 0 ? string.Empty : string.Format( "{0} {1} {2} {3} {4}", UserRank, UserPerms.HasFlag(UserPermissions.KickUser) == true ? 1 : 0, UserPerms.HasFlag(UserPermissions.ViewLogs) == true ? 1 : 0, UserPerms.HasFlag(UserPermissions.SetOwnNickname) == true ? 1 : 0, UserPerms.HasFlag(UserPermissions.CreateChannel) == true ? ( UserPerms.HasFlag(UserPermissions.SetChannelPermanent) == true ? 2 : 1 ) : 0 ); return string.Format( "7\t1\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}{9}{10}{11}{12}", TimeStamp.ToUnixTimeSeconds(), UserId, UserName, UserColour, userPerms, body, MessageId, Notify ? 1 : 0, 1, IsAction ? 1 : 0, 0, IsAction ? 0 : 1, IsPrivate ? 1 : 0 ); } } }