sharp-chat/SharpChat/Packet/UserDisconnectPacket.cs

40 lines
1.2 KiB
C#
Raw Normal View History

2022-08-30 15:00:58 +00:00
using System;
namespace SharpChat.Packet {
public class UserDisconnectPacket : ServerPacket {
2024-05-14 22:17:25 +00:00
private readonly long Timestamp;
private readonly long UserId;
private readonly string UserName;
private readonly UserDisconnectReason Reason;
2022-08-30 15:00:58 +00:00
public UserDisconnectPacket(
2024-05-14 22:17:25 +00:00
DateTimeOffset timestamp,
long userId,
string userName,
UserDisconnectReason reason
) {
2024-05-14 22:17:25 +00:00
Timestamp = timestamp.ToUnixTimeSeconds();
UserId = userId;
UserName = 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",
2024-05-10 17:28:52 +00:00
_ => "leave",
},
2024-05-14 22:17:25 +00:00
Timestamp,
2024-05-10 17:28:52 +00:00
SequenceId
);
2022-08-30 15:00:58 +00:00
}
}
}