sharp-chat/SharpChat.Protocol.SockChat/Packets/ContextUsersPacket.cs

36 lines
1.1 KiB
C#
Raw Normal View History

2022-08-30 15:05:29 +00:00
using SharpChat.Protocol.SockChat.Users;
using SharpChat.Users;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SharpChat.Protocol.SockChat.Packets {
public class ContextUsersPacket : ServerPacket {
public IEnumerable<IUser> Users { get; private set; }
public ContextUsersPacket(IEnumerable<IUser> users) {
Users = users?.Where(u => u != null) ?? throw new ArgumentNullException(nameof(users));
}
protected override string DoPack() {
StringBuilder sb = new();
sb.Append((int)ServerPacketId.ContextPopulate);
sb.Append(IServerPacket.SEPARATOR);
sb.Append((int)ServerContextSubPacketId.Users);
sb.Append(IServerPacket.SEPARATOR);
sb.Append(Users.Count());
foreach(IUser user in Users) {
sb.Append(IServerPacket.SEPARATOR);
sb.Append(user.Pack());
sb.Append(IServerPacket.SEPARATOR);
sb.Append('1'); // visibility flag
}
return sb.ToString();
}
}
}