sharp-chat/SharpChat/PacketsS2C/UsersPopulateS2CPacket.cs

37 lines
1.3 KiB
C#

using System.Text;
namespace SharpChat.PacketsS2C {
public class UsersPopulateS2CPacket : SockChatS2CPacket {
public record ListEntry(long Id, string Name, Colour Colour, int Rank, UserPermissions Perms, bool Visible);
private readonly ListEntry[] Entries;
public UsersPopulateS2CPacket(ListEntry[] entries) {
Entries = 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(UserPermissions.KickUser) ? 1 : 0,
entry.Perms.HasFlag(UserPermissions.ViewLogs) ? 1 : 0,
entry.Perms.HasFlag(UserPermissions.SetOwnNickname) ? 1 : 0,
entry.Perms.HasFlag(UserPermissions.CreateChannel) ? (
entry.Perms.HasFlag(UserPermissions.SetChannelPermanent) ? 2 : 1
) : 0,
entry.Visible ? 1 : 0
);
return sb.ToString();
}
}
}