sharp-chat/SharpChat/Packet/ForceDisconnectPacket.cs

43 lines
1.2 KiB
C#
Raw Normal View History

2022-08-30 15:00:58 +00:00
using System;
using System.Text;
namespace SharpChat.Packet {
public enum ForceDisconnectReason {
Kicked = 0,
Banned = 1,
}
public class ForceDisconnectPacket : ServerPacket {
public ForceDisconnectReason Reason { get; private set; }
public DateTimeOffset Expires { get; private set; }
public ForceDisconnectPacket(ForceDisconnectReason reason, DateTimeOffset? expires = null) {
Reason = reason;
2023-02-07 15:01:56 +00:00
if(reason == ForceDisconnectReason.Banned) {
if(!expires.HasValue)
2022-08-30 15:00:58 +00:00
throw new ArgumentNullException(nameof(expires));
Expires = expires.Value;
}
}
2024-05-10 15:24:43 +00:00
public override 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('9');
2022-08-30 15:00:58 +00:00
sb.Append('\t');
sb.Append((int)Reason);
2023-02-07 15:01:56 +00:00
if(Reason == ForceDisconnectReason.Banned) {
2022-08-30 15:00:58 +00:00
sb.Append('\t');
if(Expires.Year >= 2100)
sb.Append("-1");
else
sb.Append(Expires.ToUnixTimeSeconds());
2022-08-30 15:00:58 +00:00
}
2024-05-10 15:24:43 +00:00
return sb.ToString();
2022-08-30 15:00:58 +00:00
}
}
}