2021-04-05 18:45:04 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2020-08-31 17:47:51 +00:00
|
|
|
|
using Newtonsoft.Json.Serialization;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-04-05 18:45:04 +00:00
|
|
|
|
using Dalamud.Game.Text;
|
|
|
|
|
using Dalamud.Game.Text.SeStringHandling;
|
2023-09-29 00:59:42 +00:00
|
|
|
|
using Dalamud.Plugin.Services;
|
2020-12-26 01:24:43 +00:00
|
|
|
|
using Lumina.Excel.GeneratedSheets;
|
2021-05-15 22:19:27 +00:00
|
|
|
|
using NoSoliciting.Ml;
|
|
|
|
|
|
2021-03-03 23:05:43 +00:00
|
|
|
|
#if DEBUG
|
|
|
|
|
using System.Text;
|
|
|
|
|
#endif
|
2020-08-31 17:47:51 +00:00
|
|
|
|
|
|
|
|
|
namespace NoSoliciting {
|
2021-04-28 00:16:07 +00:00
|
|
|
|
[Serializable]
|
2020-08-31 17:47:51 +00:00
|
|
|
|
public class Message {
|
2020-12-21 02:49:10 +00:00
|
|
|
|
public Guid Id { get; }
|
2021-05-15 22:19:27 +00:00
|
|
|
|
|
2021-04-28 00:16:07 +00:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public uint ActorId { get; }
|
2021-05-15 22:19:27 +00:00
|
|
|
|
|
|
|
|
|
public uint? ModelVersion { get; }
|
2020-12-21 02:49:10 +00:00
|
|
|
|
public DateTime Timestamp { get; }
|
|
|
|
|
public ChatType ChatType { get; }
|
|
|
|
|
public SeString Sender { get; }
|
|
|
|
|
public SeString Content { get; }
|
2020-09-04 19:25:36 +00:00
|
|
|
|
|
2021-05-16 00:31:22 +00:00
|
|
|
|
public IEnumerable<MessageCategory> EnabledSnapshot { get; }
|
|
|
|
|
|
2021-05-15 22:19:27 +00:00
|
|
|
|
public MessageCategory? Classification { get; }
|
|
|
|
|
|
|
|
|
|
public bool Custom { get; }
|
|
|
|
|
public bool ItemLevel { get; }
|
|
|
|
|
|
|
|
|
|
public bool Filtered => this.Custom || this.ItemLevel || this.Classification != null;
|
|
|
|
|
|
|
|
|
|
public string? FilterReason => this.Custom
|
|
|
|
|
? "custom"
|
|
|
|
|
: this.ItemLevel
|
|
|
|
|
? "ilvl"
|
|
|
|
|
: this.Classification?.Name();
|
|
|
|
|
|
2021-05-16 00:31:22 +00:00
|
|
|
|
internal Message(uint? defsVersion, ChatType type, uint actorId, SeString sender, SeString content, MessageCategory? classification, bool custom, bool ilvl, IEnumerable<MessageCategory> enabledSnapshot) {
|
2020-08-31 17:47:51 +00:00
|
|
|
|
this.Id = Guid.NewGuid();
|
2021-05-15 22:19:27 +00:00
|
|
|
|
this.ModelVersion = defsVersion;
|
2020-08-31 17:47:51 +00:00
|
|
|
|
this.Timestamp = DateTime.Now;
|
|
|
|
|
this.ChatType = type;
|
2021-04-28 00:16:07 +00:00
|
|
|
|
this.ActorId = actorId;
|
2020-08-31 17:47:51 +00:00
|
|
|
|
this.Sender = sender;
|
|
|
|
|
this.Content = content;
|
2021-05-15 22:19:27 +00:00
|
|
|
|
this.Classification = classification;
|
|
|
|
|
this.Custom = custom;
|
|
|
|
|
this.ItemLevel = ilvl;
|
2021-05-16 00:31:22 +00:00
|
|
|
|
this.EnabledSnapshot = enabledSnapshot;
|
2020-08-31 17:47:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
[JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
|
|
|
|
|
private class JsonMessage {
|
2021-05-15 22:19:27 +00:00
|
|
|
|
public uint ReportVersion { get; } = 2;
|
|
|
|
|
public uint ModelVersion { get; set; }
|
2020-08-31 17:47:51 +00:00
|
|
|
|
public DateTime Timestamp { get; set; }
|
2020-12-23 08:52:19 +00:00
|
|
|
|
|
2020-08-31 17:47:51 +00:00
|
|
|
|
public ushort Type { get; set; }
|
2020-12-23 08:52:19 +00:00
|
|
|
|
|
2020-08-31 17:47:51 +00:00
|
|
|
|
// note: cannot use byte[] because Newtonsoft thinks it's a good idea to always base64 byte[]
|
2021-05-15 22:19:27 +00:00
|
|
|
|
// and I don't want to write a custom converter to overwrite their stupidity
|
2020-08-31 17:47:51 +00:00
|
|
|
|
public List<byte> Sender { get; set; }
|
|
|
|
|
public List<byte> Content { get; set; }
|
2020-12-21 02:49:10 +00:00
|
|
|
|
public string? Reason { get; set; }
|
2021-05-15 22:19:27 +00:00
|
|
|
|
public string? SuggestedClassification { get; set; }
|
2020-08-31 17:47:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-15 22:19:27 +00:00
|
|
|
|
public string? ToJson(string suggested) {
|
|
|
|
|
if (this.ModelVersion == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-20 01:19:03 +00:00
|
|
|
|
var msg = new JsonMessage {
|
2021-05-15 22:19:27 +00:00
|
|
|
|
ModelVersion = this.ModelVersion.Value,
|
2020-08-31 17:47:51 +00:00
|
|
|
|
Timestamp = this.Timestamp,
|
2020-12-23 08:52:19 +00:00
|
|
|
|
Type = (ushort) this.ChatType,
|
2020-08-31 17:47:51 +00:00
|
|
|
|
Sender = this.Sender.Encode().ToList(),
|
|
|
|
|
Content = this.Content.Encode().ToList(),
|
2021-05-15 22:19:27 +00:00
|
|
|
|
Reason = this.Custom
|
|
|
|
|
? "custom"
|
|
|
|
|
: this.ItemLevel
|
|
|
|
|
? "ilvl"
|
2021-05-17 18:28:31 +00:00
|
|
|
|
: (this.Classification ?? MessageCategory.Normal).ToModelName(),
|
2021-05-15 22:19:27 +00:00
|
|
|
|
SuggestedClassification = suggested,
|
2020-08-31 17:47:51 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return JsonConvert.SerializeObject(msg, new JsonSerializerSettings {
|
|
|
|
|
TypeNameHandling = TypeNameHandling.None,
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-03-03 23:05:43 +00:00
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
public StringBuilder ToCsv(StringBuilder? builder = null) {
|
|
|
|
|
builder ??= new StringBuilder();
|
|
|
|
|
|
2021-05-15 22:19:27 +00:00
|
|
|
|
builder.Append(this.Classification?.ToModelName());
|
2021-03-03 23:05:43 +00:00
|
|
|
|
builder.Append(',');
|
|
|
|
|
builder.Append((int) this.ChatType);
|
|
|
|
|
builder.Append(",\"");
|
|
|
|
|
builder.Append(this.Content.TextValue
|
|
|
|
|
.Replace("\"", "\"\"")
|
|
|
|
|
.Replace("\r", " "));
|
|
|
|
|
builder.Append('"');
|
|
|
|
|
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2020-08-31 17:47:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1028:Enum Storage should be Int32")]
|
|
|
|
|
public enum ChatType : ushort {
|
|
|
|
|
None = 0,
|
|
|
|
|
Debug = 1,
|
|
|
|
|
Urgent = 2,
|
|
|
|
|
Notice = 3,
|
|
|
|
|
Say = 10,
|
|
|
|
|
Shout = 11,
|
|
|
|
|
TellOutgoing = 12,
|
|
|
|
|
TellIncoming = 13,
|
|
|
|
|
Party = 14,
|
|
|
|
|
Alliance = 15,
|
2020-09-24 03:07:30 +00:00
|
|
|
|
Linkshell1 = 16,
|
|
|
|
|
Linkshell2 = 17,
|
|
|
|
|
Linkshell3 = 18,
|
|
|
|
|
Linkshell4 = 19,
|
|
|
|
|
Linkshell5 = 20,
|
|
|
|
|
Linkshell6 = 21,
|
|
|
|
|
Linkshell7 = 22,
|
|
|
|
|
Linkshell8 = 23,
|
2020-08-31 17:47:51 +00:00
|
|
|
|
FreeCompany = 24,
|
|
|
|
|
NoviceNetwork = 27,
|
|
|
|
|
CustomEmote = 28,
|
|
|
|
|
StandardEmote = 29,
|
|
|
|
|
Yell = 30,
|
|
|
|
|
CrossParty = 32,
|
2020-09-24 03:07:30 +00:00
|
|
|
|
PvpTeam = 36,
|
|
|
|
|
CrossLinkshell1 = 37,
|
2020-09-14 22:03:42 +00:00
|
|
|
|
Damage = 41,
|
|
|
|
|
Miss = 42,
|
2020-09-24 03:07:30 +00:00
|
|
|
|
Action = 43,
|
2020-09-14 22:03:42 +00:00
|
|
|
|
Item = 44,
|
|
|
|
|
Healing = 45,
|
|
|
|
|
GainBuff = 46,
|
|
|
|
|
GainDebuff = 47,
|
|
|
|
|
LoseBuff = 48,
|
|
|
|
|
LoseDebuff = 49,
|
2020-09-24 03:07:30 +00:00
|
|
|
|
Alarm = 55,
|
|
|
|
|
Echo = 56,
|
2020-09-14 22:03:42 +00:00
|
|
|
|
System = 57,
|
2020-09-24 03:07:30 +00:00
|
|
|
|
BattleSystem = 58,
|
2020-09-14 22:03:42 +00:00
|
|
|
|
GatheringSystem = 59,
|
|
|
|
|
Error = 60,
|
2020-09-24 03:07:30 +00:00
|
|
|
|
NpcDialogue = 61,
|
|
|
|
|
LootNotice = 62,
|
|
|
|
|
Progress = 64,
|
|
|
|
|
LootRoll = 65,
|
|
|
|
|
Crafting = 66,
|
|
|
|
|
Gathering = 67,
|
|
|
|
|
NpcAnnouncement = 68,
|
|
|
|
|
FreeCompanyAnnouncement = 69,
|
|
|
|
|
FreeCompanyLoginLogout = 70,
|
|
|
|
|
RetainerSale = 71,
|
|
|
|
|
PeriodicRecruitmentNotification = 72,
|
|
|
|
|
Sign = 73,
|
|
|
|
|
RandomNumber = 74,
|
|
|
|
|
NoviceNetworkSystem = 75,
|
|
|
|
|
Orchestrion = 76,
|
|
|
|
|
PvpTeamAnnouncement = 77,
|
|
|
|
|
PvpTeamLoginLogout = 78,
|
|
|
|
|
MessageBook = 79,
|
|
|
|
|
GmTell = 80,
|
|
|
|
|
GmSay = 81,
|
|
|
|
|
GmShout = 82,
|
|
|
|
|
GmYell = 83,
|
|
|
|
|
GmParty = 84,
|
|
|
|
|
GmFreeComapny = 85,
|
|
|
|
|
GmLinkshell1 = 86,
|
|
|
|
|
GmLinkshell2 = 87,
|
|
|
|
|
GmLinkshell3 = 88,
|
|
|
|
|
GmLinkshell4 = 89,
|
|
|
|
|
GmLinkshell5 = 90,
|
|
|
|
|
GmLinkshell6 = 91,
|
|
|
|
|
GmLinkshell7 = 92,
|
|
|
|
|
GmLinkshell8 = 93,
|
|
|
|
|
GmNoviceNetwork = 94,
|
|
|
|
|
CrossLinkshell2 = 101,
|
|
|
|
|
CrossLinkshell3 = 102,
|
|
|
|
|
CrossLinkshell4 = 103,
|
|
|
|
|
CrossLinkshell5 = 104,
|
|
|
|
|
CrossLinkshell6 = 105,
|
|
|
|
|
CrossLinkshell7 = 106,
|
|
|
|
|
CrossLinkshell8 = 107,
|
2020-09-14 22:03:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-31 17:47:51 +00:00
|
|
|
|
public static class ChatTypeExt {
|
2020-12-20 01:19:03 +00:00
|
|
|
|
private const ushort Clear7 = ~(~0 << 7);
|
2020-09-14 22:03:42 +00:00
|
|
|
|
|
2020-12-23 08:52:19 +00:00
|
|
|
|
public static byte LogKind(this ChatType type) => type switch {
|
|
|
|
|
ChatType.TellIncoming => (byte) ChatType.TellOutgoing,
|
|
|
|
|
_ => (byte) type,
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-29 00:59:42 +00:00
|
|
|
|
public static string Name(this ChatType type, IDataManager data) {
|
2020-12-26 01:24:43 +00:00
|
|
|
|
switch (type) {
|
|
|
|
|
case ChatType.None:
|
|
|
|
|
return "Party Finder";
|
|
|
|
|
case ChatType.TellIncoming:
|
|
|
|
|
return "Tell (Incoming)";
|
|
|
|
|
case ChatType.TellOutgoing:
|
|
|
|
|
return "Tell (Outgoing)";
|
|
|
|
|
case ChatType.CrossParty:
|
|
|
|
|
return "Party (Cross-world)";
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-22 22:07:28 +00:00
|
|
|
|
var lf = data.GetExcelSheet<LogFilter>()!.FirstOrDefault(lf => lf.LogKind == type.LogKind());
|
2020-12-26 01:24:43 +00:00
|
|
|
|
return lf?.Name?.ToString() ?? type.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 03:07:30 +00:00
|
|
|
|
public static ChatType FromCode(ushort code) {
|
2020-12-23 08:52:19 +00:00
|
|
|
|
return (ChatType) (code & Clear7);
|
2020-09-14 22:03:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 03:07:30 +00:00
|
|
|
|
public static ChatType FromDalamud(XivChatType type) {
|
2020-12-23 08:52:19 +00:00
|
|
|
|
return FromCode((ushort) type);
|
2020-09-14 22:03:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 03:07:30 +00:00
|
|
|
|
public static bool IsBattle(this ChatType type) {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case ChatType.Damage:
|
|
|
|
|
case ChatType.Miss:
|
|
|
|
|
case ChatType.Action:
|
|
|
|
|
case ChatType.Item:
|
|
|
|
|
case ChatType.Healing:
|
|
|
|
|
case ChatType.GainBuff:
|
|
|
|
|
case ChatType.LoseBuff:
|
|
|
|
|
case ChatType.GainDebuff:
|
|
|
|
|
case ChatType.LoseDebuff:
|
|
|
|
|
case ChatType.BattleSystem:
|
2020-09-14 22:03:42 +00:00
|
|
|
|
return true;
|
|
|
|
|
default:
|
2020-08-31 17:47:51 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|