2023-02-08 23:53:42 +00:00
|
|
|
|
using SharpChat.Misuzu;
|
2023-02-07 22:28:06 +00:00
|
|
|
|
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; }
|
2023-02-08 23:53:42 +00:00
|
|
|
|
public MisuzuBanInfo BanInfo { get; private set; }
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
2023-02-08 23:53:42 +00:00
|
|
|
|
public AuthFailPacket(AuthFailReason reason, MisuzuBanInfo fbi = null) {
|
2022-08-30 15:00:58 +00:00
|
|
|
|
Reason = reason;
|
|
|
|
|
|
2023-02-07 22:28:06 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|