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 };
|
||||
|
||||
public int Version { get; set; } = 5;
|
||||
public int Version { get; set; } = 6;
|
||||
|
||||
#region Saved configuration values
|
||||
public bool FirstUse { get; set; } = true;
|
||||
@ -129,6 +129,14 @@ namespace Pal.Client
|
||||
Version = 5;
|
||||
Save();
|
||||
}
|
||||
|
||||
if (Version == 5)
|
||||
{
|
||||
LocalState.UpdateAll();
|
||||
|
||||
Version = 6;
|
||||
Save();
|
||||
}
|
||||
}
|
||||
#pragma warning restore CS0612 // Type or member is obsolete
|
||||
|
||||
|
@ -14,7 +14,7 @@ namespace Pal.Client
|
||||
internal class LocalState
|
||||
{
|
||||
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 ConcurrentBag<Marker> Markers { get; set; } = new();
|
||||
@ -69,6 +69,12 @@ namespace Pal.Client
|
||||
|
||||
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)
|
||||
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
|
||||
/// (where each server would assign you a different id).
|
||||
/// </summary>
|
||||
public List<Guid> RemoteSeenOn { get; set; } = new List<Guid>();
|
||||
public List<string> RemoteSeenOn { get; set; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 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),
|
||||
};
|
||||
PluginLog.Information($"TryConnect: Account created with id {PartialAccountId}");
|
||||
PluginLog.Information($"TryConnect: Account created with id {FormattedPartialAccountId}");
|
||||
|
||||
Service.Configuration.Save();
|
||||
}
|
||||
@ -76,11 +76,11 @@ namespace Pal.Client.Net
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
var account = Account;
|
||||
@ -141,6 +141,8 @@ namespace Pal.Client.Net
|
||||
PluginLog.Information("VerifyConnection: Connection established, trying to verify auth token");
|
||||
var accountClient = new AccountService.AccountServiceClient(_channel);
|
||||
await accountClient.VerifyAsync(new VerifyRequest(), headers: AuthorizedHeaders(), deadline: DateTime.UtcNow.AddSeconds(10), cancellationToken: cancellationToken);
|
||||
|
||||
PluginLog.Information("VerifyConnection: Verification returned no errors.");
|
||||
return "Connection successful.";
|
||||
}
|
||||
|
||||
|
@ -34,8 +34,9 @@ namespace Pal.Client.Net
|
||||
|
||||
public Guid? AccountId => Account?.Id;
|
||||
|
||||
private string PartialAccountId =>
|
||||
Account?.Id?.ToString()?.PadRight(14).Substring(0, 13) ?? "[no account id]";
|
||||
public string? PartialAccountId => Account?.Id?.ToString()?.PadRight(14).Substring(0, 13);
|
||||
|
||||
private string FormattedPartialAccountId => PartialAccountId ?? "[no account id]";
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<LangVersion>11.0</LangVersion>
|
||||
<Version>2.4</Version>
|
||||
<Version>2.5</Version>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@ -327,7 +327,7 @@ namespace Pal.Client
|
||||
var currentFloorMarkers = currentFloor.Markers;
|
||||
|
||||
bool updateSeenMarkers = false;
|
||||
var accountId = Service.RemoteApi.AccountId;
|
||||
var partialAccountId = Service.RemoteApi.PartialAccountId;
|
||||
foreach (var visibleMarker in visibleMarkers)
|
||||
{
|
||||
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,
|
||||
// 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;
|
||||
|
||||
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)
|
||||
marker.RemoteSeenRequested = true;
|
||||
Task.Run(async () => await SyncSeenMarkersForTerritory(LastTerritory, markersToUpdate));
|
||||
|
@ -45,14 +45,14 @@ namespace Pal.Client.Scheduled
|
||||
break;
|
||||
|
||||
case SyncType.MarkSeen:
|
||||
var accountId = Service.RemoteApi.AccountId;
|
||||
if (accountId == null)
|
||||
var partialAccountId = Service.RemoteApi.PartialAccountId;
|
||||
if (partialAccountId == null)
|
||||
break;
|
||||
foreach (var remoteMarker in remoteMarkers)
|
||||
{
|
||||
Marker? localMarker = currentFloor.Markers.SingleOrDefault(x => x == remoteMarker);
|
||||
if (localMarker != null)
|
||||
localMarker.RemoteSeenOn.Add(accountId.Value);
|
||||
localMarker.RemoteSeenOn.Add(partialAccountId);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user