46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System;
|
|
|
|
namespace SharpChat.Packet {
|
|
public enum UserDisconnectReason {
|
|
Leave,
|
|
TimeOut,
|
|
Kicked,
|
|
Flood,
|
|
}
|
|
|
|
public class UserDisconnectPacket : ServerPacket {
|
|
private readonly long Timestamp;
|
|
private readonly long UserId;
|
|
private readonly string UserName;
|
|
private readonly UserDisconnectReason Reason;
|
|
|
|
public UserDisconnectPacket(
|
|
DateTimeOffset timestamp,
|
|
long userId,
|
|
string userName,
|
|
UserDisconnectReason reason
|
|
) {
|
|
Timestamp = timestamp.ToUnixTimeSeconds();
|
|
UserId = userId;
|
|
UserName = userName ?? throw new ArgumentNullException(nameof(userName));
|
|
Reason = reason;
|
|
}
|
|
|
|
public override string Pack() {
|
|
return string.Format(
|
|
"3\t{0}\t{1}\t{2}\t{3}\t{4}",
|
|
UserId,
|
|
UserName,
|
|
Reason switch {
|
|
UserDisconnectReason.Leave => "leave",
|
|
UserDisconnectReason.TimeOut => "timeout",
|
|
UserDisconnectReason.Kicked => "kick",
|
|
UserDisconnectReason.Flood => "flood",
|
|
_ => "leave",
|
|
},
|
|
Timestamp,
|
|
SequenceId
|
|
);
|
|
}
|
|
}
|
|
}
|