Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge from Develop #79

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 24 additions & 32 deletions LMeter/ACT/FFLogsClient.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Text.RegularExpressions;
using Microsoft.ClearScript.V8;
using Dalamud.Plugin.Services;
using LMeter.Helpers;
using Newtonsoft.Json;

namespace LMeter.Act
{
public partial class FFLogsClient : IPluginDisposable
public class FFLogsClient : IPluginDisposable
{
[GeneratedRegex(@"https://assets.rpglogs.com/js/log-parsers/parser-ff\.[a-f0-9]+\.js", RegexOptions.Compiled)]
private static partial Regex GeneratedRegex();
private static Regex ParserUrlRegex { get; } = GeneratedRegex();

private const string FFLOGS_URL = "https://www.fflogs.com/desktop-client/parser";
private static readonly string LMETER_USERAGENT = $"LMeter/{Plugin.Version} (+https://github.com/lichie567/LMeter)";
private const string PARSER_FILENAME = "parser-ff.c0affdeee3005b9d.js";
private readonly string PARSER_URL = $"https://assets.rpglogs.com/js/log-parsers/{PARSER_FILENAME}";
private static readonly string LMETER_USERAGENT = $"LMeter/{Plugin.Version}";

private V8ScriptEngine Engine { get; set; }
private string ParserScript { get; init; }
Expand All @@ -31,19 +28,28 @@ public FFLogsClient()

try
{
HttpClient httpClient = new();
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(LMETER_USERAGENT);
HttpResponseMessage response = httpClient.GetAsync(FFLOGS_URL).GetAwaiter().GetResult();
string result = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
Match match = ParserUrlRegex.Match(result);
if (match.Success)
string parserFile = Path.Join(Plugin.ConfigFileDir, PARSER_FILENAME);
bool parserCached = File.Exists(parserFile);
if (parserCached)
{
this.ParserScript = File.ReadAllText(parserFile);
}
else
{
string parser_url = match.Groups[0].ToString();
response = httpClient.GetAsync(parser_url).GetAwaiter().GetResult();
this.ParserScript = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
HttpClient httpClient = new();
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(LMETER_USERAGENT);
HttpResponseMessage response = httpClient.GetAsync(PARSER_URL).GetAwaiter().GetResult();
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
this.ParserScript = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
}
}

this.InitializeEngine();
if (!parserCached && this.Initialized == true)
{
File.WriteAllText(parserFile, this.ParserScript);
}
}
catch (Exception ex)
{
Expand All @@ -68,20 +74,6 @@ private void InitializeEngine()
}
}

// Debugging
// public void Run(string command)
// {
// try
// {
// var result = this.Engine.Evaluate(command);
// Singletons.Get<IPluginLog>().Info($"{result}");
// }
// catch(Exception ex)
// {
// Singletons.Get<IPluginLog>().Error(ex.ToString());
// }
// }

public void ParseLine(string logLine)
{
if (this.Initialized)
Expand Down
6 changes: 3 additions & 3 deletions LMeter/LMeter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<!-- Assembly Configuration -->
<PropertyGroup>
<AssemblyName>LMeter</AssemblyName>
<AssemblyVersion>0.4.1.1</AssemblyVersion>
<FileVersion>0.4.1.1</FileVersion>
<InformationalVersion>0.4.1.1</InformationalVersion>
<AssemblyVersion>0.4.1.2</AssemblyVersion>
<FileVersion>0.4.1.2</FileVersion>
<InformationalVersion>0.4.1.2</InformationalVersion>
</PropertyGroup>

<!-- Build Configuration -->
Expand Down
2 changes: 1 addition & 1 deletion LMeter/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Plugin : IDalamudPlugin
{
public const string ConfigFileName = "LMeter.json";

public static string Version { get; private set; } = "0.4.1.1";
public static string Version { get; private set; } = "0.4.1.2";
public static string ConfigFileDir { get; private set; } = "";
public static string ConfigFilePath { get; private set; } = "";
public static string AssemblyFileDir { get; private set; } = "";
Expand Down
11 changes: 0 additions & 11 deletions LMeter/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,6 @@ private void OnLogout()

private void PluginCommand(string command, string arguments)
{
// if (arguments.StartsWith("script"))
// {
// string[] split = arguments.Split(" ");
// FFLogsClient? client = Singletons.Get<LogClient>()._fflogsClient;
// if (client is not null && split.Length > 1)
// {
// client.Run(split[1]);
// }
// return;
// }

string[] argArray = arguments.Split(" ");
switch (argArray)
{
Expand Down
3 changes: 3 additions & 0 deletions LMeter/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Version 0.4.1.2
- Update FFLogs integration

# Version 0.4.1.1
- Fix bug with [dps] tag not working for some users

Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.4.1.1")]
[assembly: AssemblyFileVersion("0.4.1.1")]
[assembly: AssemblyVersion("0.4.1.2")]
[assembly: AssemblyFileVersion("0.4.1.2")]
Loading