sharp-chat/SharpChat/Packet/UserDisconnectPacket.cs

39 lines
1.3 KiB
C#

using System;
namespace SharpChat.Packet {
public enum UserDisconnectReason {
Leave,
TimeOut,
Kicked,
Flood,
}
public class UserDisconnectPacket : ServerPacket {
public DateTimeOffset Disconnected { get; private set; }
public ChatUser User { get; private set; }
public UserDisconnectReason Reason { get; private set; }
public UserDisconnectPacket(DateTimeOffset disconnected, ChatUser user, UserDisconnectReason reason) {
Disconnected = disconnected;
User = user ?? throw new ArgumentNullException(nameof(user));
Reason = reason;
}
public override string Pack() {
return string.Format(
"3\t{0}\t{1}\t{2}\t{3}\t{4}",
User.UserId,
User.LegacyNameWithStatus,
Reason switch {
UserDisconnectReason.Leave => "leave",
UserDisconnectReason.TimeOut => "timeout",
UserDisconnectReason.Kicked => "kick",
UserDisconnectReason.Flood => "flood",
_ => "leave",
},
Disconnected.ToUnixTimeSeconds(),
SequenceId
);
}
}
}