55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
using SharpChat.Flashii;
|
|
using System;
|
|
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 FlashiiBanInfo BanInfo { get; private set; }
|
|
|
|
public AuthFailPacket(AuthFailReason reason, FlashiiBanInfo fbi = null) {
|
|
Reason = reason;
|
|
|
|
if(reason == AuthFailReason.Banned)
|
|
BanInfo = fbi ?? throw new ArgumentNullException(nameof(fbi));
|
|
}
|
|
|
|
public override IEnumerable<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());
|
|
}
|
|
|
|
yield return sb.ToString();
|
|
}
|
|
}
|
|
}
|