sharp-chat/SharpChat/Packet/ContextChannelsPacket.cs

31 lines
861 B
C#

using System;
using System.Text;
namespace SharpChat.Packet {
public class ContextChannelsPacket : ServerPacket {
public record ListEntry(string Name, bool HasPassword, bool IsTemporary);
private readonly ListEntry[] Entries;
public ContextChannelsPacket(ListEntry[] entries) {
Entries = entries ?? throw new ArgumentNullException(nameof(entries));
}
public override string Pack() {
StringBuilder sb = new();
sb.AppendFormat("7\t2\t{0}", Entries.Length);
foreach(ListEntry entry in Entries)
sb.AppendFormat(
"\t{0}\t{1}\t{2}",
entry.Name,
entry.HasPassword ? 1 : 0,
entry.IsTemporary ? 1 : 0
);
return sb.ToString();
}
}
}