Skip to content
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
59 changes: 50 additions & 9 deletions TarkovMonitor/Blazor/Pages/Settings/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,26 @@
<MudItem xs="12">
<MudPaper Class="app-surface pa-2 ma-2 mx-4" Elevation="3">
<MudText Typo="Typo.h6" Class="d-flex align-center"><MudIcon Icon="@trackerIcon" Class="mr-2"/>@LocalizationService.GetString("TarkovTracker")</MudText>
<MudButton @onclick="OpenTrackerSettings" Variant="Variant.Text" Color="Color.Info">@LocalizationService.GetString("GetAToken")</MudButton>
<MudButton @onclick="TestToken" @bind-Disabled="@TestTokenButtonDisabled" Variant="Variant.Text" Color="Color.Info">@LocalizationService.GetString("TestToken")</MudButton>
@LocalizationService.GetString("CurrentProfile"):
<MudLink Href="@($"https://tarkov.dev/players/{GameWatcher.CurrentProfile.Type.ToString().ToLower()}/{GameWatcher.CurrentProfile.AccountId}")">@TarkovDev.GetPlayerName(GameWatcher.CurrentProfile) (@GameWatcher.CurrentProfile.Type)</MudLink>
<MudTextField @bind-Value="@TarkovTrackerToken" Immediate="true" Label="@LocalizationService.GetString("APIToken")" InputType="@PasswordInput" Variant="Variant.Outlined" Margin="Margin.Dense" Adornment="Adornment.End" AdornmentIcon="@PasswordInputIcon" OnAdornmentClick="TokenShowClick"></MudTextField>
<MudSelect @bind-Value="@TarkovTrackerDomain" T="string" Label="@LocalizationService.GetString("TarkovTrackerService")" ShrinkLabel="true" HelperText="@LocalizationService.GetString("TarkovTrackerServiceHelperText")" AnchorOrigin="Origin.BottomCenter" xs="3">
@foreach (var pair in TarkovTracker.Domains)
{
<MudSelectItem T="string" Value="@pair.Key">@pair.Value</MudSelectItem>
}
</MudSelect>
@if (IsRetiredTrackerService)
{
<MudAlert Severity="Severity.Warning" Dense="true" Class="mt-2">
Support for TarkovTracker.io has been retired. Switch to <MudLink Href="https://tarkovtracker.org/settings/" Target="_blank">TarkovTracker.org</MudLink> for continued support.
</MudAlert>
}
@if (!IsRetiredTrackerService)
{
<MudButton @onclick="OpenTrackerSettings" Variant="Variant.Text" Color="Color.Info">@LocalizationService.GetString("GetAToken")</MudButton>
<MudButton @onclick="TestToken" Disabled="@TestTokenButtonDisabled" Variant="Variant.Text" Color="Color.Info">@LocalizationService.GetString("TestToken")</MudButton>
<span>@LocalizationService.GetString("CurrentProfile"):</span>
<MudLink Href="@CurrentProfileUrl">@TarkovDev.GetPlayerName(GameWatcher.CurrentProfile) (@GameWatcher.CurrentProfile.Type)</MudLink>
<MudTextField @bind-Value="@TarkovTrackerToken" Immediate="true" Label="@LocalizationService.GetString("APIToken")" InputType="@PasswordInput" Variant="Variant.Outlined" Margin="Margin.Dense" Adornment="Adornment.End" AdornmentIcon="@PasswordInputIcon" OnAdornmentClick="TokenShowClick"></MudTextField>
}
</MudPaper>
</MudItem>

Expand Down Expand Up @@ -486,7 +495,7 @@
{
get
{
return TarkovTracker.GetToken(GameWatcher.CurrentProfile.Id).Length != 22;
return TarkovTracker.IsLegacyService || TarkovTracker.GetToken(GameWatcher.CurrentProfile.Id).Length != 22;
}
set
{
Expand Down Expand Up @@ -534,11 +543,14 @@
{
get
{
return TarkovTracker.GetToken(GameWatcher.CurrentProfile.Id);
return TarkovTracker.IsLegacyService ? "" : TarkovTracker.GetToken(GameWatcher.CurrentProfile.Id);
}
set
{
TarkovTracker.SetToken(GameWatcher.CurrentProfile.Id, value);
if (!TarkovTracker.IsLegacyService)
{
TarkovTracker.SetToken(GameWatcher.CurrentProfile.Id, value);
}
}
}
public string TarkovTrackerDomain
Expand All @@ -554,12 +566,41 @@
return;
}
Properties.Settings.Default.tarkovTrackerDomain = value;
TarkovTrackerToken = "";
TarkovTracker.ResetActiveState();
TarkovTracker.InitAPI();
Properties.Settings.Default.Save();
if (!TarkovTracker.IsLegacyService)
{
_ = RevalidateTrackerProfile();
}
}
}

private async Task RevalidateTrackerProfile()
{
if (string.IsNullOrWhiteSpace(GameWatcher.CurrentProfile.Id))
{
return;
}

try
{
await TarkovTracker.SetProfile(GameWatcher.CurrentProfile.Id);
}
catch (Exception ex)
{
messageLog.AddMessage(ex.Message, "exception");
}
}

private bool IsRetiredTrackerService => string.Equals(
TarkovTrackerDomain,
"tarkovtracker.io",
StringComparison.OrdinalIgnoreCase);

private string CurrentProfileUrl =>
$"https://tarkov.dev/players/{GameWatcher.CurrentProfile.Type.ToString().ToLower()}/{GameWatcher.CurrentProfile.AccountId}";

void TokenShowClick()
{
if (tokenShow)
Expand Down
34 changes: 32 additions & 2 deletions TarkovMonitor/TarkovTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ internal interface ITarkovTrackerAPI

public static ProgressResponse Progress { get; private set; } = new();
public static bool ValidToken { get; private set; } = false;
public static bool IsLegacyService => string.Equals(
Properties.Settings.Default.tarkovTrackerDomain,
"tarkovtracker.io",
StringComparison.OrdinalIgnoreCase);
private static Dictionary<string, string> tokens = new();
private static string currentProfile = "";
public static string CurrentProfileId { get { return currentProfile; } }
Expand Down Expand Up @@ -65,6 +69,13 @@ public static ITarkovTrackerAPI InitAPI()
return api;
}

public static void ResetActiveState()
{
currentProfile = "";
ValidToken = false;
Progress = new();
}

public static string GetToken(string profileId)
{
if (!tokens.ContainsKey(profileId))
Expand All @@ -76,6 +87,10 @@ public static string GetToken(string profileId)

public static void SetToken(string profileId, string token)
{
if (IsLegacyService)
{
return;
}
if (profileId == "")
{
throw new Exception("No PVP or PVE profile initialized, please launch Escape from Tarkov first");
Expand All @@ -87,6 +102,11 @@ public static void SetToken(string profileId, string token)

public static async Task<ProgressResponse> SetProfile(string profileId)
{
if (IsLegacyService)
{
ResetActiveState();
return Progress;
}
if (profileId == "") {
throw new Exception("Can't set PVP or PVE profile, please launch Escape from Tarkov and then restart this application");
}
Expand Down Expand Up @@ -145,7 +165,7 @@ private static void SyncStoredStatus(string questId, TaskStatus status)

public static async Task<string> SetTaskStatus(string questId, TaskStatus status)
{
if (!ValidToken)
if (IsLegacyService || !ValidToken)
{
throw new Exception("Invalid token");
}
Expand Down Expand Up @@ -231,7 +251,7 @@ public static async Task<string> SetTaskStarted(string questId)

public static async Task<string> SetTaskStatuses(Dictionary<string, TaskStatus> statuses)
{
if (!ValidToken)
if (IsLegacyService || !ValidToken)
{
throw new Exception("Invalid token");
}
Expand Down Expand Up @@ -271,6 +291,11 @@ public static async Task<string> SetTaskStatuses(Dictionary<string, TaskStatus>

public static async Task<ProgressResponse> GetProgress()
{
if (IsLegacyService)
{
ResetActiveState();
return Progress;
}
if (!ValidToken)
{
throw new Exception("Invalid token");
Expand Down Expand Up @@ -301,6 +326,11 @@ public static async Task<ProgressResponse> GetProgress()

public static async Task<TokenResponse> TestToken(string apiToken)
{
if (IsLegacyService)
{
throw new InvalidOperationException(
"Support for TarkovTracker.io has been retired. Switch to TarkovTracker.org.");
}
try
{
var response = await api.TestToken(apiToken);
Expand Down
Loading