sharp-chat/SharpChat/Packet/AuthFailPacket.cs

39 lines
1 KiB
C#
Raw Normal View History

using System;
2022-08-30 15:00:58 +00:00
namespace SharpChat.Packet {
public class AuthFailPacket : ServerPacket {
public enum FailReason {
AuthInvalid,
MaxSessions,
Banned,
Null,
}
private readonly FailReason Reason;
2024-05-14 22:17:25 +00:00
private readonly long Expires;
2022-08-30 15:00:58 +00:00
public AuthFailPacket(FailReason reason) {
2022-08-30 15:00:58 +00:00
Reason = reason;
}
2022-08-30 15:00:58 +00:00
public AuthFailPacket(DateTimeOffset expires) {
Reason = FailReason.Banned;
2024-05-14 22:17:25 +00:00
Expires = expires.Year >= 2100 ? -1 : expires.ToUnixTimeSeconds();
2022-08-30 15:00:58 +00:00
}
2024-05-10 15:24:43 +00:00
public override string Pack() {
2024-05-10 17:28:52 +00:00
string packet = string.Format("1\tn\t{0}fail", Reason switch {
FailReason.AuthInvalid => "auth",
FailReason.MaxSessions => "sock",
FailReason.Banned => "join",
2024-05-10 17:28:52 +00:00
_ => "user",
});
2022-08-30 15:00:58 +00:00
if(Reason == FailReason.Banned)
2024-05-14 22:17:25 +00:00
packet += string.Format("\t{0}", Expires);
2022-08-30 15:00:58 +00:00
2024-05-10 17:28:52 +00:00
return packet;
2022-08-30 15:00:58 +00:00
}
}
}