sharp-chat/SharpChat/Packet/ChatMessageAddPacket.cs

46 lines
1.3 KiB
C#
Raw Normal View History

using System;
2022-08-30 15:00:58 +00:00
namespace SharpChat.Packet {
2022-08-30 15:00:58 +00:00
public class ChatMessageAddPacket : ServerPacket {
public DateTimeOffset Created { get; }
public long UserId { get; }
public string Text { get; }
public bool IsAction { get; }
public bool IsPrivate { get; }
2022-08-30 15:00:58 +00:00
public ChatMessageAddPacket(
long msgId,
DateTimeOffset created,
long userId,
string text,
bool isAction,
bool isPrivate
) : base(msgId) {
Created = created;
UserId = userId < 0 ? -1 : userId;
Text = text;
IsAction = isAction;
IsPrivate = isPrivate;
}
2024-05-10 15:24:43 +00:00
public override string Pack() {
2024-05-10 17:28:52 +00:00
string body = Text.Replace("<", "&lt;").Replace(">", "&gt;").Replace("\n", " <br/> ").Replace("\t", " ");
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}",
Created.ToUnixTimeSeconds(),
UserId,
body,
SequenceId,
1,
IsAction ? 1 : 0,
0,
IsAction ? 0 : 1,
IsPrivate ? 1 : 0
2022-08-30 15:00:58 +00:00
);
}
}
}