sharp-chat/SharpChat/Packet/AuthFailPacket.cs

56 lines
1.5 KiB
C#
Raw Normal View History

using SharpChat.Misuzu;
using System;
2022-08-30 15:00:58 +00:00
using System.Collections.Generic;
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; }
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
}
public override IEnumerable<string> Pack() {
2023-02-07 15:01:56 +00:00
StringBuilder sb = new();
2022-08-30 15:00:58 +00:00
2023-02-07 14:34:31 +00:00
sb.Append('1');
2022-08-30 15:00:58 +00:00
sb.Append("\tn\t");
2023-02-07 15:01:56 +00:00
switch(Reason) {
2022-08-30 15:00:58 +00:00
case AuthFailReason.AuthInvalid:
default:
sb.Append("authfail");
2022-08-30 15:00:58 +00:00
break;
case AuthFailReason.MaxSessions:
sb.Append("sockfail");
2022-08-30 15:00:58 +00:00
break;
case AuthFailReason.Banned:
sb.Append("joinfail");
2022-08-30 15:00:58 +00:00
break;
}
2023-02-07 15:01:56 +00:00
if(Reason == AuthFailReason.Banned) {
2022-08-30 15:00:58 +00:00
sb.Append('\t');
if(BanInfo.IsPermanent)
sb.Append("-1");
2022-08-30 15:00:58 +00:00
else
sb.Append(BanInfo.ExpiresAt.ToUnixTimeSeconds());
2022-08-30 15:00:58 +00:00
}
yield return sb.ToString();
}
}
}