2022-08-30 15:00:58 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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('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');
|
2023-02-07 22:28:06 +00:00
|
|
|
|
if(Expires.Year >= 2100)
|
|
|
|
|
sb.Append("-1");
|
|
|
|
|
else
|
|
|
|
|
sb.Append(Expires.ToUnixTimeSeconds());
|
2022-08-30 15:00:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yield return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|