sharp-chat/SharpChat/Packet/MessageAddPacket.cs

44 lines
1.2 KiB
C#
Raw Normal View History

using System;
2022-08-30 15:00:58 +00:00
namespace SharpChat.Packet {
public class MessageAddPacket : SockChatTimedS2CPacket {
private readonly long UserId;
private readonly string Body;
private readonly bool IsAction;
private readonly bool IsPrivate;
2022-08-30 15:00:58 +00:00
2024-05-14 22:17:25 +00:00
public MessageAddPacket(
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;
}
2024-05-10 15:24:43 +00:00
public override string Pack() {
2024-05-19 21:02:17 +00:00
string body = SockChatUtility.SanitiseMessageBody(Body);
if(IsAction)
2024-05-10 17:28:52 +00:00
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(),
2024-05-10 17:28:52 +00:00
UserId,
body,
MessageId,
2024-05-10 17:28:52 +00:00
1,
IsAction ? 1 : 0,
0,
IsAction ? 0 : 1,
IsPrivate ? 1 : 0
2022-08-30 15:00:58 +00:00
);
}
}
}