38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
using System;
|
|
using System.Text;
|
|
|
|
namespace SharpChat.Packet {
|
|
public class ContextUsersPacket : ServerPacket {
|
|
public record ListEntry(long Id, string Name, ChatColour Colour, int Rank, ChatUserPermissions Perms, bool Visible);
|
|
|
|
private readonly ListEntry[] Entries;
|
|
|
|
public ContextUsersPacket(ListEntry[] entries) {
|
|
Entries = entries ?? throw new ArgumentNullException(nameof(entries));
|
|
}
|
|
|
|
public override string Pack() {
|
|
StringBuilder sb = new();
|
|
|
|
sb.AppendFormat("7\t0\t{0}", Entries.Length);
|
|
|
|
foreach(ListEntry entry in Entries)
|
|
sb.AppendFormat(
|
|
"\t{0}\t{1}\t{2}\t{3} {4} {5} {6} {7}\t{8}",
|
|
entry.Id,
|
|
entry.Name,
|
|
entry.Colour,
|
|
entry.Rank,
|
|
entry.Perms.HasFlag(ChatUserPermissions.KickUser) ? 1 : 0,
|
|
entry.Perms.HasFlag(ChatUserPermissions.ViewLogs) ? 1 : 0,
|
|
entry.Perms.HasFlag(ChatUserPermissions.SetOwnNickname) ? 1 : 0,
|
|
entry.Perms.HasFlag(ChatUserPermissions.CreateChannel) ? (
|
|
entry.Perms.HasFlag(ChatUserPermissions.SetChannelPermanent) ? 2 : 1
|
|
) : 0,
|
|
entry.Visible ? 1 : 0
|
|
);
|
|
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
}
|