Minecraft-Console-Client/MinecraftClient/Protocol/Message/ChatMessage.cs

76 lines
2.4 KiB
C#
Raw Normal View History

using System;
2022-08-27 02:10:44 +08:00
namespace MinecraftClient.Protocol.Message
{
public class ChatMessage
{
/// <summary>
/// In 1.19 and above, isSignedChat = true
/// </summary>
public bool isSignedChat;
public string content;
public bool isJson, isSenderJson;
/// <summary>
/// 0: chat (chat box), 1: system message (chat box), 2: game info (above hotbar), 3: say command,
/// 4: msg command, 5: team msg command, 6: emote command, 7: tellraw command
/// </summary>
public int chatTypeId;
public Guid senderUUID;
public bool isSystemChat;
public string? unsignedContent;
public string? displayName;
public string? teamName;
public DateTime? timestamp;
public byte[]? signature;
2022-08-27 02:10:44 +08:00
public bool? isSignatureLegal;
2023-01-14 02:41:03 +08:00
public ChatMessage(string content, bool isJson, int chatType, Guid senderUUID, string? unsignedContent, string displayName, string? teamName, long timestamp, byte[]? signature, bool isSignatureLegal)
{
2022-08-27 02:10:44 +08:00
isSignedChat = true;
isSystemChat = false;
this.content = content;
this.isJson = isJson;
chatTypeId = chatType;
this.senderUUID = senderUUID;
this.unsignedContent = unsignedContent;
this.displayName = displayName;
this.teamName = teamName;
2022-08-27 02:10:44 +08:00
this.timestamp = DateTimeOffset.FromUnixTimeMilliseconds(timestamp).DateTime;
this.signature = signature;
this.isSignatureLegal = isSignatureLegal;
}
public ChatMessage(string content, string? displayName, bool isJson, int chatType, Guid senderUUID, bool isSystemChat = false)
{
2022-08-27 02:10:44 +08:00
isSignedChat = isSystemChat;
this.isSystemChat = isSystemChat;
this.content = content;
this.displayName = displayName;
this.isJson = isJson;
chatTypeId = chatType;
this.senderUUID = senderUUID;
}
2022-08-27 02:10:44 +08:00
2023-01-13 16:12:10 +08:00
public LastSeenMessageList.AcknowledgedMessage? ToLastSeenMessageEntry()
2022-08-27 02:10:44 +08:00
{
2023-01-13 16:12:10 +08:00
return signature != null ? new LastSeenMessageList.AcknowledgedMessage(senderUUID, signature, true) : null;
2022-08-27 02:10:44 +08:00
}
public bool LacksSender()
2022-08-27 02:10:44 +08:00
{
return senderUUID == Guid.Empty;
2022-08-27 02:10:44 +08:00
}
}
}