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