30 lines
909 B
C#
30 lines
909 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace SharpChat.Packet {
|
|
public class ContextChannelsPacket : ServerPacket {
|
|
public IEnumerable<ChatChannel> Channels { get; private set; }
|
|
|
|
public ContextChannelsPacket(IEnumerable<ChatChannel> 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();
|
|
}
|
|
}
|
|
}
|