sharp-chat/SharpChat/Packet/AuthFailPacket.cs

36 lines
1.1 KiB
C#

using SharpChat.Misuzu;
using System;
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; }
public AuthFailPacket(AuthFailReason reason, MisuzuBanInfo fbi = null) {
Reason = reason;
if(reason == AuthFailReason.Banned)
BanInfo = fbi ?? throw new ArgumentNullException(nameof(fbi));
}
public override string Pack() {
string packet = string.Format("1\tn\t{0}fail", Reason switch {
AuthFailReason.AuthInvalid => "auth",
AuthFailReason.MaxSessions => "sock",
AuthFailReason.Banned => "join",
_ => "user",
});
if(Reason == AuthFailReason.Banned)
packet += string.Format("\t{0}", BanInfo.IsPermanent ? -1 : BanInfo.ExpiresAt.ToUnixTimeSeconds());
return packet;
}
}
}