sharp-chat/SharpChat/Packet/BanListPacket.cs

39 lines
1.2 KiB
C#
Raw Normal View History

using SharpChat.Misuzu;
using System;
2022-08-30 15:00:58 +00:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SharpChat.Packet {
public class BanListPacket : ServerPacket {
public IEnumerable<MisuzuBanInfo> Bans { get; private set; }
2022-08-30 15:00:58 +00:00
public BanListPacket(IEnumerable<MisuzuBanInfo> bans) {
2022-08-30 15:00:58 +00:00
Bans = bans ?? throw new ArgumentNullException(nameof(bans));
}
public override IEnumerable<string> Pack() {
2023-02-07 15:01:56 +00:00
StringBuilder sb = new();
2022-08-30 15:00:58 +00:00
2023-02-07 14:34:31 +00:00
sb.Append('2');
2022-08-30 15:00:58 +00:00
sb.Append('\t');
sb.Append(DateTimeOffset.Now.ToUnixTimeSeconds());
sb.Append("\t-1\t0\fbanlist\f");
foreach(MisuzuBanInfo ban in Bans) {
string banStr = string.IsNullOrEmpty(ban.UserName) ? ban.RemoteAddress : ban.UserName;
sb.AppendFormat(@"<a href=""javascript:void(0);"" onclick=""Chat.SendMessageWrapper('/unban '+ this.innerHTML);"">{0}</a>, ", banStr);
}
2022-08-30 15:00:58 +00:00
2023-02-07 15:01:56 +00:00
if(Bans.Any())
2022-08-30 15:00:58 +00:00
sb.Length -= 2;
sb.Append('\t');
sb.Append(SequenceId);
sb.Append("\t10010");
return new[] { sb.ToString() };
}
}
}