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 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));
|
|
|
|
|
}
|
|
|
|
|
|
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\t0\t{0}", Users.Count());
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
2024-05-10 17:28:52 +00:00
|
|
|
|
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
|
|
|
|
|
);
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|