sharp-chat/SharpChat/Packet/MessageAddLogPacket.cs

81 lines
2.7 KiB
C#

using System;
namespace SharpChat.Packet {
public class MessageAddLogPacket : ServerPacket {
private readonly long Created;
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 MessageAddLogPacket(
long msgId,
DateTimeOffset created,
long userId,
string userName,
Colour userColour,
int userRank,
UserPermissions userPerms,
string body,
bool isAction,
bool isPrivate,
bool isBroadcast,
bool notify
) : base(msgId) {
Created = created.ToUnixTimeSeconds();
UserId = userId < 0 ? -1 : userId;
UserName = userName;
UserColour = userColour;
UserRank = userRank;
UserPerms = userPerms;
Body = body;
IsAction = isAction;
IsPrivate = isPrivate;
IsBroadcast = isBroadcast;
Notify = notify;
}
public override string Pack() {
string body = SockChatUtility.SanitiseMessageBody(Body);
if(IsAction)
body = string.Format("<i>{0}</i>", 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}",
Created,
UserId,
UserName,
UserColour,
userPerms,
body,
SequenceId,
Notify ? 1 : 0,
1,
IsAction ? 1 : 0,
0,
IsAction ? 0 : 1,
IsPrivate ? 1 : 0
);
}
}
}