sharp-chat/SharpChat/Packet/AuthFailPacket.cs

54 lines
1.5 KiB
C#

using SharpChat.Misuzu;
using System;
using System.Text;
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() {
StringBuilder sb = new();
sb.Append('1');
sb.Append("\tn\t");
switch(Reason) {
case AuthFailReason.AuthInvalid:
default:
sb.Append("authfail");
break;
case AuthFailReason.MaxSessions:
sb.Append("sockfail");
break;
case AuthFailReason.Banned:
sb.Append("joinfail");
break;
}
if(Reason == AuthFailReason.Banned) {
sb.Append('\t');
if(BanInfo.IsPermanent)
sb.Append("-1");
else
sb.Append(BanInfo.ExpiresAt.ToUnixTimeSeconds());
}
return sb.ToString();
}
}
}