2024-05-10 15:25:34 +00:00
|
|
|
|
using System;
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
2024-05-20 23:40:34 +00:00
|
|
|
|
namespace SharpChat.SockChat.PacketsS2C {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
public class MessageAddS2CPacket : SockChatTimedS2CPacket {
|
2024-05-10 18:29:48 +00:00
|
|
|
|
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-20 23:00:47 +00:00
|
|
|
|
public MessageAddS2CPacket(
|
2024-05-20 02:16:38 +00:00
|
|
|
|
long messageId,
|
|
|
|
|
DateTimeOffset timeStamp,
|
2023-02-23 21:46:49 +00:00
|
|
|
|
long userId,
|
2024-05-10 18:29:48 +00:00
|
|
|
|
string body,
|
2023-02-23 21:46:49 +00:00
|
|
|
|
bool isAction,
|
|
|
|
|
bool isPrivate
|
2024-05-20 02:16:38 +00:00
|
|
|
|
) : base(messageId, timeStamp) {
|
2023-02-23 21:46:49 +00:00
|
|
|
|
UserId = userId < 0 ? -1 : userId;
|
2024-05-14 22:56:56 +00:00
|
|
|
|
Body = body;
|
2023-02-23 21:46:49 +00:00
|
|
|
|
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);
|
2023-02-23 21:46:49 +00:00
|
|
|
|
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-20 02:16:38 +00:00
|
|
|
|
TimeStamp.ToUnixTimeSeconds(),
|
2024-05-10 17:28:52 +00:00
|
|
|
|
UserId,
|
|
|
|
|
body,
|
2024-05-20 02:16:38 +00:00
|
|
|
|
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
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|