38 lines
1 KiB
C#
38 lines
1 KiB
C#
using System;
|
|
|
|
namespace SharpChat.PacketsS2C {
|
|
public class AuthFailS2CPacket : SockChatS2CPacket {
|
|
public enum FailReason {
|
|
AuthInvalid,
|
|
MaxSessions,
|
|
Banned,
|
|
Null,
|
|
}
|
|
|
|
private readonly FailReason Reason;
|
|
private readonly long Expires;
|
|
|
|
public AuthFailS2CPacket(FailReason reason) {
|
|
Reason = reason;
|
|
}
|
|
|
|
public AuthFailS2CPacket(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;
|
|
}
|
|
}
|
|
}
|