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 enum AuthFailReason {
AuthInvalid,
MaxSessions,
Banned,
2024-05-10 19:18:55 +00:00
Null,
2022-08-30 15:00:58 +00:00
}
public class AuthFailPacket : ServerPacket {
private readonly AuthFailReason Reason;
private readonly DateTimeOffset Expires;
2022-08-30 15:00:58 +00:00
public AuthFailPacket(AuthFailReason reason) {
2022-08-30 15:00:58 +00:00
Reason = reason;
}
2022-08-30 15:00:58 +00:00
public AuthFailPacket(DateTimeOffset expires) {
Reason = AuthFailReason.Banned;
Expires = expires;
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 {
AuthFailReason.AuthInvalid => "auth",
AuthFailReason.MaxSessions => "sock",
AuthFailReason.Banned => "join",
_ => "user",
});
2022-08-30 15:00:58 +00:00
2024-05-10 17:28:52 +00:00
if(Reason == AuthFailReason.Banned)
packet += string.Format("\t{0}", Expires.Year >= 2100 ? -1 : Expires.ToUnixTimeSeconds());
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
}
}
}