sharp-chat/SharpChat.SockChat/PacketsS2C/ChannelsPopulateS2CPacket.cs

30 lines
858 B
C#
Raw Normal View History

2024-05-19 21:02:17 +00:00
using System.Text;
2022-08-30 15:00:58 +00:00
namespace SharpChat.SockChat.PacketsS2C {
public class ChannelsPopulateS2CPacket : SockChatS2CPacket {
public record ListEntry(string Name, bool HasPassword, bool IsTemporary);
2022-08-30 15:00:58 +00:00
private readonly ListEntry[] Entries;
public ChannelsPopulateS2CPacket(ListEntry[] entries) {
Entries = entries;
2022-08-30 15:00:58 +00:00
}
2024-05-10 15:24:43 +00:00
public override string Pack() {
2023-02-07 15:01:56 +00:00
StringBuilder sb = new();
2022-08-30 15:00:58 +00:00
sb.AppendFormat("7\t2\t{0}", Entries.Length);
2022-08-30 15:00:58 +00:00
foreach(ListEntry entry in Entries)
2024-05-10 17:28:52 +00:00
sb.AppendFormat(
"\t{0}\t{1}\t{2}",
2024-05-19 21:02:17 +00:00
SockChatUtility.SanitiseChannelName(entry.Name),
entry.HasPassword ? 1 : 0,
entry.IsTemporary ? 1 : 0
2024-05-10 17:28:52 +00:00
);
2022-08-30 15:00:58 +00:00
2024-05-10 15:24:43 +00:00
return sb.ToString();
2022-08-30 15:00:58 +00:00
}
}
}