sharp-chat/SharpChat.Protocol.SockChat/Packets/ForceDisconnectPacket.cs

37 lines
1 KiB
C#
Raw Permalink Normal View History

2022-08-30 15:05:29 +00:00
using SharpChat.Events;
using System;
using System.Text;
namespace SharpChat.Protocol.SockChat.Packets {
public class ForceDisconnectPacket : ServerPacket {
public DateTimeOffset? Expires { get; }
public bool IsPermanent { get; }
public ForceDisconnectPacket(UserBanCreatedEvent ubce) {
Expires = ubce.Duration < 1
? null
: DateTimeOffset.Now + TimeSpan.FromSeconds(ubce.Duration);
IsPermanent = ubce.IsPermanent;
}
protected override string DoPack() {
StringBuilder sb = new();
sb.Append((int)ServerPacketId.BAKA);
sb.Append(IServerPacket.SEPARATOR);
if(Expires.HasValue) {
sb.Append('1');
sb.Append(IServerPacket.SEPARATOR);
if(IsPermanent)
sb.Append(-1);
else
sb.Append(Expires.Value.ToUnixTimeSeconds());
} else
sb.Append('0');
return sb.ToString();
}
}
}