sharp-chat/SharpChat/Packet/BanListPacket.cs

33 lines
1 KiB
C#

using SharpChat.Misuzu;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SharpChat.Packet {
public class BanListPacket : ServerPacket {
public IEnumerable<MisuzuBanInfo> Bans { get; private set; }
public BanListPacket(IEnumerable<MisuzuBanInfo> bans) {
Bans = bans ?? throw new ArgumentNullException(nameof(bans));
}
public override string Pack() {
StringBuilder sb = new();
sb.AppendFormat("2\t{0}\t-1\t0\fbanlist\f", DateTimeOffset.Now.ToUnixTimeSeconds());
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);
}
if(Bans.Any())
sb.Length -= 2;
sb.AppendFormat("\t{0}\t10010", SequenceId);
return sb.ToString();
}
}
}