From 0198494d5d8e6683a397c5d6b88b9db1e4c03ee8 Mon Sep 17 00:00:00 2001 From: "joshua.software.dev" Date: Thu, 13 Jul 2023 19:07:07 -0700 Subject: [PATCH] Add fix for WebSocket bypass failing if plugin loaded before player login --- LMeter/src/Cactbot/IinactCactbotClient.cs | 15 +++++++++++++++ .../src/Cactbot/TotallyNotCefCactbotHttpSource.cs | 1 + Version/Version.csproj | 2 +- deps/txt/changelog.md | 4 ++++ repo.json | 12 ++++++------ 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/LMeter/src/Cactbot/IinactCactbotClient.cs b/LMeter/src/Cactbot/IinactCactbotClient.cs index 6c82a94..13b9c6e 100644 --- a/LMeter/src/Cactbot/IinactCactbotClient.cs +++ b/LMeter/src/Cactbot/IinactCactbotClient.cs @@ -1,3 +1,4 @@ +using Dalamud.Game.ClientState; using Dalamud.Logging; using Dalamud.Plugin; using Dalamud.Plugin.Ipc; @@ -19,6 +20,7 @@ namespace LMeter.Cactbot; public class IinactCactbotClient : IActClient { private readonly bool _bypassWebSocket; + private readonly ClientState _clientState; private readonly CancellationTokenSource _cancelTokenSource; private readonly DalamudPluginInterface _dpi; private readonly HttpClient _httpClient; @@ -66,6 +68,7 @@ public List PastEvents public IinactCactbotClient ( bool bypassWebSocket, + ClientState clientState, CancellationTokenSource cts, DalamudPluginInterface dpi, HttpClient httpClient, @@ -73,12 +76,15 @@ string totallyNotCefUrl ) { _bypassWebSocket = bypassWebSocket; + _clientState = clientState; _cancelTokenSource = cts; _dpi = dpi; _httpClient = httpClient; _status = SubscriptionStatus.NotConnected; _totallyNotCefUrl = totallyNotCefUrl; + _clientState.Login += HandleOnLogin; + try { subscriptionReceiver = _dpi.GetIpcProvider(LMeterCactbotSubscriptionIpcEndpoint); @@ -87,6 +93,14 @@ string totallyNotCefUrl catch { } } + private void HandleOnLogin(object? sender, EventArgs args) + { + if (_bypassWebSocket && !_fakeHandshakeComplete) + { + RetryConnection(); + } + } + private void SendHttpPostRequest(string message) { _httpClient @@ -326,6 +340,7 @@ public void RetryConnection() public void Dispose() { _fakeHandshakeComplete = false; + _clientState.Login -= HandleOnLogin; subscriptionReceiver?.UnregisterFunc(); this.Dispose(true); GC.SuppressFinalize(this); diff --git a/LMeter/src/Cactbot/TotallyNotCefCactbotHttpSource.cs b/LMeter/src/Cactbot/TotallyNotCefCactbotHttpSource.cs index bbe16ef..efbb8aa 100644 --- a/LMeter/src/Cactbot/TotallyNotCefCactbotHttpSource.cs +++ b/LMeter/src/Cactbot/TotallyNotCefCactbotHttpSource.cs @@ -79,6 +79,7 @@ bool enableAudio _iinactCactbotClient = new ( _bypassWebSocket, + PluginManager.Instance?.ClientState ?? throw new NullReferenceException(), _cancelTokenSource, PluginManager.Instance?.PluginInterface ?? throw new NullReferenceException(), _httpClient, diff --git a/Version/Version.csproj b/Version/Version.csproj index 2bb9720..5d69ce5 100644 --- a/Version/Version.csproj +++ b/Version/Version.csproj @@ -1,5 +1,5 @@ - 0.2.0.14 + 0.2.0.15 diff --git a/deps/txt/changelog.md b/deps/txt/changelog.md index 882a9c5..9d4f25d 100644 --- a/deps/txt/changelog.md +++ b/deps/txt/changelog.md @@ -1,3 +1,7 @@ +# Version 0.2.0.15 +- Add fix for Cactbot WebSocket bypass option potentially not starting + correctly if the plugin loaded before the player had finished logging in. + # Version 0.2.0.14 - Fix Cactbot URL potentially causing crashes on plugin load if the url was not valid. diff --git a/repo.json b/repo.json index a5237f8..3962be2 100644 --- a/repo.json +++ b/repo.json @@ -25,8 +25,8 @@ "Name": "LMeter", "Description": "Plugin to display ACT combat log data. Now with Cactbot integration!", "InternalName": "LMeter", - "AssemblyVersion": "0.2.0.14", - "TestingAssemblyVersion": "0.2.0.14", + "AssemblyVersion": "0.2.0.15", + "TestingAssemblyVersion": "0.2.0.15", "RepoUrl": "https://github.com/joshua-software-dev/LMeter", "ApplicableVersion": "any", "DalamudApiLevel": 8, @@ -35,10 +35,10 @@ "DownloadCount": 0, "LastUpdate": 0, "LoadPriority": 69420, - "DownloadLinkInstall": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.14/latest.zip", - "DownloadLinkTesting": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.14/latest.zip", - "DownloadLinkUpdate": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.14/latest.zip", + "DownloadLinkInstall": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.15/latest.zip", + "DownloadLinkTesting": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.15/latest.zip", + "DownloadLinkUpdate": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.15/latest.zip", "IconUrl": "https://raw.githubusercontent.com/joshua-software-dev/LMeter/master/deps/img/icon.png", - "Changelog": "# Version 0.2.0.14\n- Fix Cactbot URL potentially causing crashes on plugin load if the url was not\n valid." + "Changelog": "# Version 0.2.0.15\n- Add fix for Cactbot WebSocket bypass option potentially not starting\n correctly if the plugin loaded before the player had finished logging in." } ]