sharp-chat/SharpChat/Packet/MessageAddPacket.cs

46 lines
1.3 KiB
C#
Raw Normal View History

using System;
2022-08-30 15:00:58 +00:00
namespace SharpChat.Packet {
2024-05-14 22:17:25 +00:00
public class MessageAddPacket : ServerPacket {
private readonly long Created;
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 msgId,
DateTimeOffset created,
long userId,
string body,
bool isAction,
bool isPrivate
) : base(msgId) {
2024-05-14 22:17:25 +00:00
Created = created.ToUnixTimeSeconds();
UserId = userId < 0 ? -1 : userId;
Body = body ?? throw new ArgumentNullException(nameof(body));
IsAction = isAction;
IsPrivate = isPrivate;
}
2024-05-10 15:24:43 +00:00
public override string Pack() {
string body = SharpUtil.Sanitise(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}",
2024-05-14 22:17:25 +00:00
Created,
2024-05-10 17:28:52 +00:00
UserId,
body,
SequenceId,
1,
IsAction ? 1 : 0,
0,
IsAction ? 0 : 1,
IsPrivate ? 1 : 0
2022-08-30 15:00:58 +00:00
);
}
}
}