sharp-chat/SharpChat/PacketsS2C/MessageAddS2CPacket.cs

43 lines
1.2 KiB
C#

using System;
namespace SharpChat.PacketsS2C {
public class MessageAddS2CPacket : SockChatTimedS2CPacket {
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
) : base(messageId, timeStamp) {
UserId = userId < 0 ? -1 : userId;
Body = body;
IsAction = isAction;
IsPrivate = isPrivate;
}
public override string Pack() {
string body = SockChatUtility.SanitiseMessageBody(Body);
if(IsAction)
body = string.Format("<i>{0}</i>", 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
);
}
}
}