sharp-chat/SharpChat/Packet/ContextUsersPacket.cs

38 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SharpChat.Packet {
public class ContextUsersPacket : ServerPacket {
public IEnumerable<ChatUser> Users { get; private set; }
public ContextUsersPacket(IEnumerable<ChatUser> users) {
Users = users?.Where(u => u != null) ?? throw new ArgumentNullException(nameof(users));
}
public override string Pack() {
StringBuilder sb = new();
sb.AppendFormat("7\t0\t{0}", Users.Count());
foreach(ChatUser user in Users)
sb.AppendFormat(
"\t{0}\t{1}\t{2}\t{3} {4} {5} {6} {7}\t{8}",
user.UserId,
user.LegacyNameWithStatus,
user.Colour,
user.Rank,
user.Can(ChatUserPermissions.KickUser) ? 1 : 0,
user.Can(ChatUserPermissions.ViewLogs) ? 1 : 0,
user.Can(ChatUserPermissions.SetOwnNickname) ? 1 : 0,
user.Can(ChatUserPermissions.CreateChannel | ChatUserPermissions.SetChannelPermanent, true) ? 2 : (
user.Can(ChatUserPermissions.CreateChannel) ? 1 : 0
),
1 // visibility flag
);
return sb.ToString();
}
}
}