sharp-chat/SharpChat/Packet/AuthFailPacket.cs

38 lines
1 KiB
C#

using System;
namespace SharpChat.Packet {
public enum AuthFailReason {
AuthInvalid,
MaxSessions,
Banned,
Null,
}
public class AuthFailPacket : ServerPacket {
private readonly AuthFailReason Reason;
private readonly DateTimeOffset Expires;
public AuthFailPacket(AuthFailReason reason) {
Reason = reason;
}
public AuthFailPacket(DateTimeOffset expires) {
Reason = AuthFailReason.Banned;
Expires = expires;
}
public override string Pack() {
string packet = string.Format("1\tn\t{0}fail", Reason switch {
AuthFailReason.AuthInvalid => "auth",
AuthFailReason.MaxSessions => "sock",
AuthFailReason.Banned => "join",
_ => "user",
});
if(Reason == AuthFailReason.Banned)
packet += string.Format("\t{0}", Expires.Year >= 2100 ? -1 : Expires.ToUnixTimeSeconds());
return packet;
}
}
}