2022-08-30 15:00:58 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-10 15:24:43 +00:00
|
|
|
|
public override string Pack() {
|
2023-02-07 15:01:56 +00:00
|
|
|
|
StringBuilder sb = new();
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
2023-02-07 14:34:31 +00:00
|
|
|
|
sb.Append('3');
|
2022-08-30 15:00:58 +00:00
|
|
|
|
sb.Append('\t');
|
|
|
|
|
sb.Append(User.UserId);
|
|
|
|
|
sb.Append('\t');
|
2024-05-09 21:31:19 +00:00
|
|
|
|
sb.Append(User.LegacyNameWithStatus);
|
2022-08-30 15:00:58 +00:00
|
|
|
|
sb.Append('\t');
|
|
|
|
|
|
2023-02-07 15:01:56 +00:00
|
|
|
|
switch(Reason) {
|
2022-08-30 15:00:58 +00:00
|
|
|
|
case UserDisconnectReason.Leave:
|
|
|
|
|
default:
|
2023-02-08 03:17:07 +00:00
|
|
|
|
sb.Append("leave");
|
2022-08-30 15:00:58 +00:00
|
|
|
|
break;
|
|
|
|
|
case UserDisconnectReason.TimeOut:
|
2023-02-08 03:17:07 +00:00
|
|
|
|
sb.Append("timeout");
|
2022-08-30 15:00:58 +00:00
|
|
|
|
break;
|
|
|
|
|
case UserDisconnectReason.Kicked:
|
2023-02-08 03:17:07 +00:00
|
|
|
|
sb.Append("kick");
|
2022-08-30 15:00:58 +00:00
|
|
|
|
break;
|
|
|
|
|
case UserDisconnectReason.Flood:
|
2023-02-08 03:17:07 +00:00
|
|
|
|
sb.Append("flood");
|
2022-08-30 15:00:58 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sb.Append('\t');
|
|
|
|
|
sb.Append(Disconnected.ToUnixTimeSeconds());
|
|
|
|
|
sb.Append('\t');
|
|
|
|
|
sb.Append(SequenceId);
|
|
|
|
|
|
2024-05-10 15:24:43 +00:00
|
|
|
|
return sb.ToString();
|
2022-08-30 15:00:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|