Update RemoteSeenOn logic
This commit is contained in:
parent
c203f5bc95
commit
51d474099f
@ -17,7 +17,7 @@ namespace Pal.Client
|
|||||||
{
|
{
|
||||||
private static readonly byte[] _entropy = { 0x22, 0x4b, 0xe7, 0x21, 0x44, 0x83, 0x69, 0x55, 0x80, 0x38 };
|
private static readonly byte[] _entropy = { 0x22, 0x4b, 0xe7, 0x21, 0x44, 0x83, 0x69, 0x55, 0x80, 0x38 };
|
||||||
|
|
||||||
public int Version { get; set; } = 5;
|
public int Version { get; set; } = 6;
|
||||||
|
|
||||||
#region Saved configuration values
|
#region Saved configuration values
|
||||||
public bool FirstUse { get; set; } = true;
|
public bool FirstUse { get; set; } = true;
|
||||||
@ -129,6 +129,14 @@ namespace Pal.Client
|
|||||||
Version = 5;
|
Version = 5;
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Version == 5)
|
||||||
|
{
|
||||||
|
LocalState.UpdateAll();
|
||||||
|
|
||||||
|
Version = 6;
|
||||||
|
Save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#pragma warning restore CS0612 // Type or member is obsolete
|
#pragma warning restore CS0612 // Type or member is obsolete
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ namespace Pal.Client
|
|||||||
internal class LocalState
|
internal class LocalState
|
||||||
{
|
{
|
||||||
private static readonly JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions { IncludeFields = true };
|
private static readonly JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions { IncludeFields = true };
|
||||||
private static readonly int _currentVersion = 3;
|
private static readonly int _currentVersion = 4;
|
||||||
|
|
||||||
public uint TerritoryType { get; set; }
|
public uint TerritoryType { get; set; }
|
||||||
public ConcurrentBag<Marker> Markers { get; set; } = new();
|
public ConcurrentBag<Marker> Markers { get; set; } = new();
|
||||||
@ -69,6 +69,12 @@ namespace Pal.Client
|
|||||||
|
|
||||||
localState.ApplyFilters();
|
localState.ApplyFilters();
|
||||||
|
|
||||||
|
if (version <= 3)
|
||||||
|
{
|
||||||
|
foreach (var marker in localState.Markers)
|
||||||
|
marker.RemoteSeenOn = marker.RemoteSeenOn.Select(x => x.PadRight(14).Substring(0, 13)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
if (version < _currentVersion)
|
if (version < _currentVersion)
|
||||||
localState.Save();
|
localState.Save();
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ namespace Pal.Client
|
|||||||
/// Which account ids this marker was seen. This is a list merely to support different remote endpoints
|
/// Which account ids this marker was seen. This is a list merely to support different remote endpoints
|
||||||
/// (where each server would assign you a different id).
|
/// (where each server would assign you a different id).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<Guid> RemoteSeenOn { get; set; } = new List<Guid>();
|
public List<string> RemoteSeenOn { get; set; } = new List<string>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether this marker was requested to be seen, to avoid duplicate requests.
|
/// Whether this marker was requested to be seen, to avoid duplicate requests.
|
||||||
|
@ -52,7 +52,7 @@ namespace Pal.Client.Net
|
|||||||
{
|
{
|
||||||
Id = Guid.Parse(createAccountReply.AccountId),
|
Id = Guid.Parse(createAccountReply.AccountId),
|
||||||
};
|
};
|
||||||
PluginLog.Information($"TryConnect: Account created with id {PartialAccountId}");
|
PluginLog.Information($"TryConnect: Account created with id {FormattedPartialAccountId}");
|
||||||
|
|
||||||
Service.Configuration.Save();
|
Service.Configuration.Save();
|
||||||
}
|
}
|
||||||
@ -76,11 +76,11 @@ namespace Pal.Client.Net
|
|||||||
|
|
||||||
if (!_loginInfo.IsValid)
|
if (!_loginInfo.IsValid)
|
||||||
{
|
{
|
||||||
PluginLog.Information($"TryConnect: Logging in with account id {PartialAccountId}");
|
PluginLog.Information($"TryConnect: Logging in with account id {FormattedPartialAccountId}");
|
||||||
LoginReply loginReply = await accountClient.LoginAsync(new LoginRequest { AccountId = AccountId?.ToString() }, headers: UnauthorizedHeaders(), deadline: DateTime.UtcNow.AddSeconds(10), cancellationToken: cancellationToken);
|
LoginReply loginReply = await accountClient.LoginAsync(new LoginRequest { AccountId = AccountId?.ToString() }, headers: UnauthorizedHeaders(), deadline: DateTime.UtcNow.AddSeconds(10), cancellationToken: cancellationToken);
|
||||||
if (loginReply.Success)
|
if (loginReply.Success)
|
||||||
{
|
{
|
||||||
PluginLog.Information($"TryConnect: Login successful with account id: {PartialAccountId}");
|
PluginLog.Information($"TryConnect: Login successful with account id: {FormattedPartialAccountId}");
|
||||||
_loginInfo = new LoginInfo(loginReply.AuthToken);
|
_loginInfo = new LoginInfo(loginReply.AuthToken);
|
||||||
|
|
||||||
var account = Account;
|
var account = Account;
|
||||||
@ -141,6 +141,8 @@ namespace Pal.Client.Net
|
|||||||
PluginLog.Information("VerifyConnection: Connection established, trying to verify auth token");
|
PluginLog.Information("VerifyConnection: Connection established, trying to verify auth token");
|
||||||
var accountClient = new AccountService.AccountServiceClient(_channel);
|
var accountClient = new AccountService.AccountServiceClient(_channel);
|
||||||
await accountClient.VerifyAsync(new VerifyRequest(), headers: AuthorizedHeaders(), deadline: DateTime.UtcNow.AddSeconds(10), cancellationToken: cancellationToken);
|
await accountClient.VerifyAsync(new VerifyRequest(), headers: AuthorizedHeaders(), deadline: DateTime.UtcNow.AddSeconds(10), cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
PluginLog.Information("VerifyConnection: Verification returned no errors.");
|
||||||
return "Connection successful.";
|
return "Connection successful.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +34,9 @@ namespace Pal.Client.Net
|
|||||||
|
|
||||||
public Guid? AccountId => Account?.Id;
|
public Guid? AccountId => Account?.Id;
|
||||||
|
|
||||||
private string PartialAccountId =>
|
public string? PartialAccountId => Account?.Id?.ToString()?.PadRight(14).Substring(0, 13);
|
||||||
Account?.Id?.ToString()?.PadRight(14).Substring(0, 13) ?? "[no account id]";
|
|
||||||
|
private string FormattedPartialAccountId => PartialAccountId ?? "[no account id]";
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net7.0-windows</TargetFramework>
|
<TargetFramework>net7.0-windows</TargetFramework>
|
||||||
<LangVersion>11.0</LangVersion>
|
<LangVersion>11.0</LangVersion>
|
||||||
<Version>2.4</Version>
|
<Version>2.5</Version>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
@ -327,7 +327,7 @@ namespace Pal.Client
|
|||||||
var currentFloorMarkers = currentFloor.Markers;
|
var currentFloorMarkers = currentFloor.Markers;
|
||||||
|
|
||||||
bool updateSeenMarkers = false;
|
bool updateSeenMarkers = false;
|
||||||
var accountId = Service.RemoteApi.AccountId;
|
var partialAccountId = Service.RemoteApi.PartialAccountId;
|
||||||
foreach (var visibleMarker in visibleMarkers)
|
foreach (var visibleMarker in visibleMarkers)
|
||||||
{
|
{
|
||||||
Marker? knownMarker = currentFloorMarkers.SingleOrDefault(x => x == visibleMarker);
|
Marker? knownMarker = currentFloorMarkers.SingleOrDefault(x => x == visibleMarker);
|
||||||
@ -341,7 +341,7 @@ namespace Pal.Client
|
|||||||
|
|
||||||
// This requires you to have seen a trap/hoard marker once per floor to synchronize this for older local states,
|
// This requires you to have seen a trap/hoard marker once per floor to synchronize this for older local states,
|
||||||
// markers discovered afterwards are automatically marked seen.
|
// markers discovered afterwards are automatically marked seen.
|
||||||
if (accountId != null && knownMarker.NetworkId != null && !knownMarker.RemoteSeenRequested && !knownMarker.RemoteSeenOn.Contains(accountId.Value))
|
if (partialAccountId != null && knownMarker.NetworkId != null && !knownMarker.RemoteSeenRequested && !knownMarker.RemoteSeenOn.Contains(partialAccountId))
|
||||||
updateSeenMarkers = true;
|
updateSeenMarkers = true;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@ -377,9 +377,9 @@ namespace Pal.Client
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateSeenMarkers && accountId != null)
|
if (updateSeenMarkers && partialAccountId != null)
|
||||||
{
|
{
|
||||||
var markersToUpdate = currentFloorMarkers.Where(x => x.Seen && x.NetworkId != null && !x.RemoteSeenRequested && !x.RemoteSeenOn.Contains(accountId.Value)).ToList();
|
var markersToUpdate = currentFloorMarkers.Where(x => x.Seen && x.NetworkId != null && !x.RemoteSeenRequested && !x.RemoteSeenOn.Contains(partialAccountId)).ToList();
|
||||||
foreach (var marker in markersToUpdate)
|
foreach (var marker in markersToUpdate)
|
||||||
marker.RemoteSeenRequested = true;
|
marker.RemoteSeenRequested = true;
|
||||||
Task.Run(async () => await SyncSeenMarkersForTerritory(LastTerritory, markersToUpdate));
|
Task.Run(async () => await SyncSeenMarkersForTerritory(LastTerritory, markersToUpdate));
|
||||||
|
@ -45,14 +45,14 @@ namespace Pal.Client.Scheduled
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SyncType.MarkSeen:
|
case SyncType.MarkSeen:
|
||||||
var accountId = Service.RemoteApi.AccountId;
|
var partialAccountId = Service.RemoteApi.PartialAccountId;
|
||||||
if (accountId == null)
|
if (partialAccountId == null)
|
||||||
break;
|
break;
|
||||||
foreach (var remoteMarker in remoteMarkers)
|
foreach (var remoteMarker in remoteMarkers)
|
||||||
{
|
{
|
||||||
Marker? localMarker = currentFloor.Markers.SingleOrDefault(x => x == remoteMarker);
|
Marker? localMarker = currentFloor.Markers.SingleOrDefault(x => x == remoteMarker);
|
||||||
if (localMarker != null)
|
if (localMarker != null)
|
||||||
localMarker.RemoteSeenOn.Add(accountId.Value);
|
localMarker.RemoteSeenOn.Add(partialAccountId);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user