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
|
|
|
|
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; }
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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:
|
2023-02-08 03:17:07 +00:00
|
|
|
|
sb.Append("authfail");
|
2022-08-30 15:00:58 +00:00
|
|
|
|
break;
|
|
|
|
|
case AuthFailReason.MaxSessions:
|
2023-02-08 03:17:07 +00:00
|
|
|
|
sb.Append("sockfail");
|
2022-08-30 15:00:58 +00:00
|
|
|
|
break;
|
|
|
|
|
case AuthFailReason.Banned:
|
2023-02-08 03:17:07 +00:00
|
|
|
|
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');
|
|
|
|
|
|
2023-02-07 22:28:06 +00:00
|
|
|
|
if(BanInfo.IsPermanent)
|
|
|
|
|
sb.Append("-1");
|
2022-08-30 15:00:58 +00:00
|
|
|
|
else
|
2023-02-07 22:28:06 +00:00
|
|
|
|
sb.Append(BanInfo.ExpiresAt.ToUnixTimeSeconds());
|
2022-08-30 15:00:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yield return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|