2024-05-10 18:29:48 +00:00
|
|
|
|
using System;
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
|
|
|
|
namespace SharpChat.Packet {
|
|
|
|
|
public enum AuthFailReason {
|
|
|
|
|
AuthInvalid,
|
|
|
|
|
MaxSessions,
|
|
|
|
|
Banned,
|
2024-05-10 19:18:55 +00:00
|
|
|
|
Null,
|
2022-08-30 15:00:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class AuthFailPacket : ServerPacket {
|
2024-05-10 18:29:48 +00:00
|
|
|
|
private readonly AuthFailReason Reason;
|
|
|
|
|
private readonly DateTimeOffset Expires;
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
2024-05-10 18:29:48 +00:00
|
|
|
|
public AuthFailPacket(AuthFailReason reason) {
|
2022-08-30 15:00:58 +00:00
|
|
|
|
Reason = reason;
|
2024-05-10 18:29:48 +00:00
|
|
|
|
}
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
2024-05-10 18:29:48 +00:00
|
|
|
|
public AuthFailPacket(DateTimeOffset expires) {
|
|
|
|
|
Reason = AuthFailReason.Banned;
|
|
|
|
|
Expires = expires;
|
2022-08-30 15:00:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-10 15:24:43 +00:00
|
|
|
|
public override string Pack() {
|
2024-05-10 17:28:52 +00:00
|
|
|
|
string packet = string.Format("1\tn\t{0}fail", Reason switch {
|
|
|
|
|
AuthFailReason.AuthInvalid => "auth",
|
|
|
|
|
AuthFailReason.MaxSessions => "sock",
|
|
|
|
|
AuthFailReason.Banned => "join",
|
|
|
|
|
_ => "user",
|
|
|
|
|
});
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
2024-05-10 17:28:52 +00:00
|
|
|
|
if(Reason == AuthFailReason.Banned)
|
2024-05-10 18:29:48 +00:00
|
|
|
|
packet += string.Format("\t{0}", Expires.Year >= 2100 ? -1 : Expires.ToUnixTimeSeconds());
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
2024-05-10 17:28:52 +00:00
|
|
|
|
return packet;
|
2022-08-30 15:00:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|