sharp-chat/SharpChat/PacketsS2C/WhoChannelResponseS2CPacket.cs

42 lines
1.3 KiB
C#

using System;
using System.Text;
namespace SharpChat.PacketsS2C {
public class WhoChannelResponseS2CPacket : SockChatTimedS2CPacket {
private readonly string ChannelName;
private readonly string[] Users;
private readonly string SelfName;
public WhoChannelResponseS2CPacket(string channelName, string[] users, string selfName) {
ChannelName = channelName;
Users = users;
SelfName = selfName;
}
public override string Pack() {
StringBuilder sb = new();
sb.AppendFormat(
"2\t{0}\t-1\t0\fwhochan\f{1}\f",
TimeStamp.ToUnixTimeSeconds(),
SockChatUtility.SanitiseChannelName(ChannelName)
);
foreach(string userName in Users) {
sb.Append(@"<a href=""javascript:void(0);"" onclick=""UI.InsertChatText(this.innerHTML);""");
if(userName.Equals(SelfName, StringComparison.InvariantCultureIgnoreCase))
sb.Append(@" style=""font-weight: bold;""");
sb.AppendFormat(@">{0}</a>, ", userName);
}
if(Users.Length > 0)
sb.Length -= 2;
sb.AppendFormat("\t{0}\t10010", MessageId);
return sb.ToString();
}
}
}