sharp-chat/SharpChat/PacketsS2C/WhoServerResponseS2CPacket.cs

37 lines
1.1 KiB
C#
Raw Normal View History

2024-05-14 22:17:25 +00:00
using System;
using System.Text;
namespace SharpChat.PacketsS2C {
public class WhoServerResponseS2CPacket : SockChatTimedS2CPacket {
2024-05-14 22:17:25 +00:00
private readonly string[] Users;
private readonly string SelfName;
public WhoServerResponseS2CPacket(string[] users, string selfName) {
2024-05-14 22:17:25 +00:00
Users = users;
SelfName = selfName;
}
public override string Pack() {
StringBuilder sb = new();
sb.AppendFormat("2\t{0}\t-1\t0\fwho\f", TimeStamp.ToUnixTimeSeconds());
2024-05-14 22:17:25 +00:00
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);
2024-05-14 22:17:25 +00:00
return sb.ToString();
}
}
}