sharp-chat/SharpChat/Packet/BanListPacket.cs

38 lines
1.2 KiB
C#

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