2022-08-30 15:00:58 +00:00
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
2024-05-10 17:28:52 +00:00
|
|
|
|
sb.AppendFormat("7\t2\t{0}", Channels.Count());
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
2024-05-10 17:28:52 +00:00
|
|
|
|
foreach(ChatChannel channel in Channels)
|
|
|
|
|
sb.AppendFormat(
|
|
|
|
|
"\t{0}\t{1}\t{2}",
|
|
|
|
|
channel.Name,
|
|
|
|
|
channel.HasPassword ? 1 : 0,
|
|
|
|
|
channel.IsTemporary ? 1 : 0
|
|
|
|
|
);
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|