sharp-chat/SharpChat/Packet/UserDisconnectPacket.cs

47 lines
1.4 KiB
C#
Raw Normal View History

2022-08-30 15:00:58 +00:00
using System;
namespace SharpChat.Packet {
public enum UserDisconnectReason {
Leave,
TimeOut,
Kicked,
Flood,
}
public class UserDisconnectPacket : ServerPacket {
private readonly DateTimeOffset Disconnected;
private readonly long UserId;
private readonly string UserName;
private readonly UserDisconnectReason Reason;
2022-08-30 15:00:58 +00:00
public UserDisconnectPacket(
DateTimeOffset disconnected,
long userId,
string userName,
UserDisconnectReason reason
) {
2022-08-30 15:00:58 +00:00
Disconnected = disconnected;
UserId = userId;
UserName = userName ?? throw new ArgumentNullException(nameof(userName));
2022-08-30 15:00:58 +00:00
Reason = reason;
}
2024-05-10 15:24:43 +00:00
public override string Pack() {
2024-05-10 17:28:52 +00:00
return string.Format(
"3\t{0}\t{1}\t{2}\t{3}\t{4}",
UserId,
UserName,
2024-05-10 17:28:52 +00:00
Reason switch {
UserDisconnectReason.Leave => "leave",
UserDisconnectReason.TimeOut => "timeout",
UserDisconnectReason.Kicked => "kick",
UserDisconnectReason.Flood => "flood",
_ => "leave",
},
Disconnected.ToUnixTimeSeconds(),
SequenceId
);
2022-08-30 15:00:58 +00:00
}
}
}