Add /pal test-connection

rendering
Liza 2022-11-25 09:43:24 +01:00
parent a1a10e4b4a
commit 83b2823a9f
3 changed files with 56 additions and 21 deletions

View File

@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
<LangVersion>9.0</LangVersion> <LangVersion>9.0</LangVersion>
<Version>1.18.0.0</Version> <Version>1.19.0.0</Version>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
@ -13,6 +13,7 @@
<AssemblyName>Palace Pal</AssemblyName> <AssemblyName>Palace Pal</AssemblyName>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'"> <PropertyGroup Condition="'$(Configuration)' == 'Release'">

View File

@ -122,6 +122,16 @@ namespace Pal.Client
Task.Run(async () => await FetchFloorStatistics()); Task.Run(async () => await FetchFloorStatistics());
break; break;
case "test-connection":
case "tc":
var configWindow = Service.WindowSystem.GetWindow<ConfigWindow>();
if (configWindow == null)
return;
configWindow.IsOpen = true;
configWindow.TestConnection();
break;
#if DEBUG #if DEBUG
case "update-saves": case "update-saves":
LocalState.UpdateAll(); LocalState.UpdateAll();

View File

@ -10,6 +10,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -29,6 +31,7 @@ namespace Pal.Client.Windows
private bool _fillSilverCoffers; private bool _fillSilverCoffers;
private string? _connectionText; private string? _connectionText;
private bool _switchToCommunityTab;
public ConfigWindow() : base("Palace Pal###PalPalaceConfig") public ConfigWindow() : base("Palace Pal###PalPalaceConfig")
{ {
@ -109,8 +112,10 @@ namespace Pal.Client.Windows
ImGui.EndTabItem(); ImGui.EndTabItem();
} }
if (ImGui.BeginTabItem("Community")) if (BeginTabItemEx("Community", _switchToCommunityTab ? ImGuiTabItemFlags.SetSelected : ImGuiTabItemFlags.None))
{ {
_switchToCommunityTab = false;
ImGui.TextWrapped("Ideally, we want to discover every potential trap and chest location in the game, but doing this alone is very tedious. Floor 51-60 has over 100 trap locations and over 50 coffer locations, the last of which took over 50 runs to find - and we don't know if that map is complete. Higher floors naturally see fewer runs, making solo attempts to map the place much harder."); ImGui.TextWrapped("Ideally, we want to discover every potential trap and chest location in the game, but doing this alone is very tedious. Floor 51-60 has over 100 trap locations and over 50 coffer locations, the last of which took over 50 runs to find - and we don't know if that map is complete. Higher floors naturally see fewer runs, making solo attempts to map the place much harder.");
ImGui.TextWrapped("You can decide whether you want to share traps and chests you find with the community, which likewise also will let you see chests and coffers found by other players. This can be changed at any time. No data regarding your FFXIV character or account is ever sent to our server."); ImGui.TextWrapped("You can decide whether you want to share traps and chests you find with the community, which likewise also will let you see chests and coffers found by other players. This can be changed at any time. No data regarding your FFXIV character or account is ever sent to our server.");
@ -122,25 +127,7 @@ namespace Pal.Client.Windows
ImGui.BeginDisabled(Service.Configuration.Mode != Configuration.EMode.Online); ImGui.BeginDisabled(Service.Configuration.Mode != Configuration.EMode.Online);
if (ImGui.Button("Test Connection")) if (ImGui.Button("Test Connection"))
{ TestConnection();
Task.Run(async () =>
{
_connectionText = "Testing...";
CancellationTokenSource cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(60));
try
{
_connectionText = await Service.RemoteApi.VerifyConnection(cts.Token);
}
catch (Exception e)
{
PluginLog.Error(e, "Could not establish remote connection");
_connectionText = e.ToString();
}
});
}
if (_connectionText != null) if (_connectionText != null)
ImGui.Text(_connectionText); ImGui.Text(_connectionText);
@ -262,5 +249,42 @@ namespace Pal.Client.Windows
Service.Chat.PrintError("Could not draw markers, is Splatoon installed and enabled?"); Service.Chat.PrintError("Could not draw markers, is Splatoon installed and enabled?");
} }
} }
/// <summary>
/// None of the default BeginTabItem methods allow using flags without making the tab have a close button for some reason.
/// </summary>
private unsafe static bool BeginTabItemEx(string label, ImGuiTabItemFlags flags)
{
int labelLength = Encoding.UTF8.GetByteCount(label);
byte* labelPtr = stackalloc byte[labelLength + 1];
byte[] labelBytes = Encoding.UTF8.GetBytes(label);
Marshal.Copy(labelBytes, 0, (IntPtr)labelPtr, labelLength);
labelPtr[labelLength] = 0;
return ImGuiNative.igBeginTabItem(labelPtr, null, flags) != 0;
}
internal void TestConnection()
{
Task.Run(async () =>
{
_connectionText = "Testing...";
_switchToCommunityTab = true;
CancellationTokenSource cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(60));
try
{
_connectionText = await Service.RemoteApi.VerifyConnection(cts.Token);
}
catch (Exception e)
{
PluginLog.Error(e, "Could not establish remote connection");
_connectionText = e.ToString();
}
});
}
} }
} }