using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SharpChat.Packet { public class ContextChannelsPacket : ServerPacket { public IEnumerable Channels { get; private set; } public ContextChannelsPacket(IEnumerable channels) { Channels = channels?.Where(c => c != null) ?? throw new ArgumentNullException(nameof(channels)); } public override string Pack() { StringBuilder sb = new(); sb.AppendFormat("7\t2\t{0}", Channels.Count()); foreach(ChatChannel channel in Channels) sb.AppendFormat( "\t{0}\t{1}\t{2}", channel.Name, channel.HasPassword ? 1 : 0, channel.IsTemporary ? 1 : 0 ); return sb.ToString(); } } }