sharp-chat/SharpChat/Packet/AuthFailPacket.cs

37 lines
1.1 KiB
C#
Raw Normal View History

using SharpChat.Misuzu;
using System;
2022-08-30 15:00:58 +00:00
namespace SharpChat.Packet {
public enum AuthFailReason {
AuthInvalid,
MaxSessions,
Banned,
}
public class AuthFailPacket : ServerPacket {
public AuthFailReason Reason { get; private set; }
public MisuzuBanInfo BanInfo { get; private set; }
2022-08-30 15:00:58 +00:00
public AuthFailPacket(AuthFailReason reason, MisuzuBanInfo fbi = null) {
2022-08-30 15:00:58 +00:00
Reason = reason;
if(reason == AuthFailReason.Banned)
BanInfo = fbi ?? throw new ArgumentNullException(nameof(fbi));
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}", BanInfo.IsPermanent ? -1 : BanInfo.ExpiresAt.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
}
}
}