minor bugfixing and log severity adjustment
This commit is contained in:
@@ -70,6 +70,7 @@ public class CachedPlayer
|
||||
|
||||
if (characterData.GetHashCode() == _cachedData.GetHashCode()) return;
|
||||
|
||||
bool updateModdedPaths = false;
|
||||
List<ObjectKind> charaDataToUpdate = new List<ObjectKind>();
|
||||
foreach (var objectKind in Enum.GetValues<ObjectKind>())
|
||||
{
|
||||
@@ -88,6 +89,7 @@ public class CachedPlayer
|
||||
if (hasNewButNotOldFileReplacements || hasOldButNotNewFileReplacements || hasNewButNotOldGlamourerData || hasOldButNotNewGlamourerData)
|
||||
{
|
||||
Logger.Debug("Updating " + objectKind);
|
||||
updateModdedPaths = true;
|
||||
charaDataToUpdate.Add(objectKind);
|
||||
continue;
|
||||
}
|
||||
@@ -98,6 +100,7 @@ public class CachedPlayer
|
||||
if (!listsAreEqual)
|
||||
{
|
||||
Logger.Debug("Updating " + objectKind);
|
||||
updateModdedPaths = true;
|
||||
charaDataToUpdate.Add(objectKind);
|
||||
continue;
|
||||
}
|
||||
@@ -117,11 +120,16 @@ public class CachedPlayer
|
||||
|
||||
_cachedData = characterData;
|
||||
|
||||
DownloadAndApplyCharacter(charaDataToUpdate);
|
||||
DownloadAndApplyCharacter(charaDataToUpdate, updateModdedPaths);
|
||||
}
|
||||
|
||||
private void DownloadAndApplyCharacter(List<ObjectKind> objectKind)
|
||||
private void DownloadAndApplyCharacter(List<ObjectKind> objectKind, bool updateModdedPaths)
|
||||
{
|
||||
if (!objectKind.Any())
|
||||
{
|
||||
Logger.Debug("Nothing to update for " + this);
|
||||
}
|
||||
|
||||
_downloadCancellationTokenSource?.Cancel();
|
||||
_downloadCancellationTokenSource = new CancellationTokenSource();
|
||||
var downloadToken = _downloadCancellationTokenSource.Token;
|
||||
@@ -130,22 +138,27 @@ public class CachedPlayer
|
||||
{
|
||||
List<FileReplacementDto> toDownloadReplacements;
|
||||
|
||||
Dictionary<string, string> moddedPaths;
|
||||
int attempts = 0;
|
||||
while ((toDownloadReplacements = TryCalculateModdedDictionary(out moddedPaths)).Count > 0 && attempts++ <= 10)
|
||||
if (updateModdedPaths)
|
||||
{
|
||||
Logger.Debug("Downloading missing files for player " + PlayerName + ", kind: " + objectKind);
|
||||
await _apiController.DownloadFiles(downloadId, toDownloadReplacements, downloadToken);
|
||||
if (downloadToken.IsCancellationRequested)
|
||||
Dictionary<string, string> moddedPaths;
|
||||
int attempts = 0;
|
||||
while ((toDownloadReplacements = TryCalculateModdedDictionary(out moddedPaths)).Count > 0 && attempts++ <= 10)
|
||||
{
|
||||
Logger.Verbose("Detected cancellation");
|
||||
return;
|
||||
Logger.Debug("Downloading missing files for player " + PlayerName + ", kind: " + objectKind);
|
||||
await _apiController.DownloadFiles(downloadId, toDownloadReplacements, downloadToken);
|
||||
if (downloadToken.IsCancellationRequested)
|
||||
{
|
||||
Logger.Verbose("Detected cancellation");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((TryCalculateModdedDictionary(out moddedPaths)).All(c => _apiController.ForbiddenTransfers.Any(f => f.Hash == c.Hash)))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((TryCalculateModdedDictionary(out moddedPaths)).All(c => _apiController.ForbiddenTransfers.Any(f => f.Hash == c.Hash)))
|
||||
{
|
||||
break;
|
||||
}
|
||||
ApplyBaseData(moddedPaths);
|
||||
}
|
||||
|
||||
if (_dalamudUtil.IsInGpose)
|
||||
@@ -158,8 +171,6 @@ public class CachedPlayer
|
||||
}
|
||||
}
|
||||
|
||||
ApplyBaseData(moddedPaths);
|
||||
|
||||
foreach (var kind in objectKind)
|
||||
{
|
||||
ApplyCustomizationData(kind);
|
||||
@@ -311,15 +322,13 @@ public class CachedPlayer
|
||||
{
|
||||
if (_isDisposed) return;
|
||||
if (string.IsNullOrEmpty(PlayerName)) return;
|
||||
Logger.Verbose("Disposing " + PlayerName + " (" + PlayerNameHash + ")");
|
||||
Logger.Debug("Disposing " + PlayerName + " (" + PlayerNameHash + ")");
|
||||
_isDisposed = true;
|
||||
try
|
||||
{
|
||||
Logger.Verbose("Restoring state for " + PlayerName);
|
||||
_dalamudUtil.FrameworkUpdate -= DalamudUtilOnFrameworkUpdate;
|
||||
_ipcManager.PenumbraRedrawEvent -= IpcManagerOnPenumbraRedrawEvent;
|
||||
_downloadCancellationTokenSource?.Cancel();
|
||||
_downloadCancellationTokenSource?.Dispose();
|
||||
_ipcManager.PenumbraRemoveTemporaryCollection(PlayerName);
|
||||
if (PlayerCharacter != null && PlayerCharacter.IsValid())
|
||||
{
|
||||
@@ -328,6 +337,9 @@ public class CachedPlayer
|
||||
RevertCustomizationData(item.Key);
|
||||
}
|
||||
}
|
||||
|
||||
_downloadCancellationTokenSource?.Cancel();
|
||||
_downloadCancellationTokenSource?.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<Authors></Authors>
|
||||
<Company></Company>
|
||||
<Version>0.2.8.0</Version>
|
||||
<Version>0.2.9.0</Version>
|
||||
<Description></Description>
|
||||
<Copyright></Copyright>
|
||||
<PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl>
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace MareSynchronos.Models
|
||||
{
|
||||
if (HatState != null && !hasChanges && !HasUnprocessedUpdate)
|
||||
{
|
||||
Logger.Verbose("Not Sending Update, only Hat changed");
|
||||
Logger.Debug("Not Sending Update, only Hat changed");
|
||||
DoNotSendUpdate = true;
|
||||
}
|
||||
HatState = newHatState;
|
||||
@@ -117,7 +117,7 @@ namespace MareSynchronos.Models
|
||||
{
|
||||
if (VisorWeaponState != null && !hasChanges && !HasUnprocessedUpdate)
|
||||
{
|
||||
Logger.Verbose("Not Sending Update, only Visor/Weapon changed");
|
||||
Logger.Debug("Not Sending Update, only Visor/Weapon changed");
|
||||
DoNotSendUpdate = true;
|
||||
}
|
||||
VisorWeaponState = newWeaponOrVisorState;
|
||||
|
||||
@@ -6,6 +6,12 @@ namespace MareSynchronos.Utils
|
||||
{
|
||||
internal class Logger
|
||||
{
|
||||
public static void Info(string info)
|
||||
{
|
||||
var caller = new StackTrace().GetFrame(1)?.GetMethod()?.ReflectedType?.Name ?? "Unknown";
|
||||
PluginLog.Information($"[{caller}] {info}");
|
||||
}
|
||||
|
||||
public static void Debug(string debug, string stringToHighlight = "")
|
||||
{
|
||||
var caller = new StackTrace().GetFrame(1)?.GetMethod()?.ReflectedType?.Name ?? "Unknown";
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace MareSynchronos.WebAPI
|
||||
if (ct.IsCancellationRequested)
|
||||
{
|
||||
File.Delete(tempFile);
|
||||
Logger.Verbose("Detected cancellation, removing " + currentDownloadId);
|
||||
Logger.Debug("Detected cancellation, removing " + currentDownloadId);
|
||||
CurrentDownloads.Remove(currentDownloadId);
|
||||
break;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ namespace MareSynchronos.WebAPI
|
||||
await Task.Delay(250, ct);
|
||||
}
|
||||
|
||||
Logger.Verbose("Download complete, removing " + currentDownloadId);
|
||||
Logger.Debug("Download complete, removing " + currentDownloadId);
|
||||
CurrentDownloads.Remove(currentDownloadId);
|
||||
}
|
||||
|
||||
@@ -162,10 +162,10 @@ namespace MareSynchronos.WebAPI
|
||||
}
|
||||
|
||||
var totalSize = CurrentUploads.Sum(c => c.Total);
|
||||
Logger.Verbose("Compressing and uploading files");
|
||||
Logger.Debug("Compressing and uploading files");
|
||||
foreach (var file in CurrentUploads.Where(f => f.CanBeTransferred && !f.IsTransferred).ToList())
|
||||
{
|
||||
Logger.Verbose("Compressing and uploading " + file);
|
||||
Logger.Debug("Compressing and uploading " + file);
|
||||
var data = await GetCompressedFileData(file.Hash, uploadToken);
|
||||
CurrentUploads.Single(e => e.Hash == data.Item1).Total = data.Item2.Length;
|
||||
await UploadFile(data.Item2, file.Hash, uploadToken);
|
||||
@@ -181,21 +181,21 @@ namespace MareSynchronos.WebAPI
|
||||
Logger.Debug($"Compressed {totalSize} to {compressedSize} ({(compressedSize / (double)totalSize):P2})");
|
||||
}
|
||||
|
||||
Logger.Verbose("Upload tasks complete, waiting for server to confirm");
|
||||
Logger.Debug("Upload tasks complete, waiting for server to confirm");
|
||||
var anyUploadsOpen = await _mareHub!.InvokeAsync<bool>(Api.InvokeFileIsUploadFinished, uploadToken);
|
||||
Logger.Verbose("Uploads open: " + anyUploadsOpen);
|
||||
Logger.Debug("Uploads open: " + anyUploadsOpen);
|
||||
while (anyUploadsOpen && !uploadToken.IsCancellationRequested)
|
||||
{
|
||||
anyUploadsOpen = await _mareHub!.InvokeAsync<bool>(Api.InvokeFileIsUploadFinished, uploadToken);
|
||||
await Task.Delay(TimeSpan.FromSeconds(0.5), uploadToken);
|
||||
Logger.Verbose("Waiting for uploads to finish");
|
||||
Logger.Debug("Waiting for uploads to finish");
|
||||
}
|
||||
|
||||
CurrentUploads.Clear();
|
||||
|
||||
if (!uploadToken.IsCancellationRequested)
|
||||
{
|
||||
Logger.Verbose("=== Pushing character data ===");
|
||||
Logger.Info("Pushing character data for " + character.GetHashCode());
|
||||
await _mareHub!.InvokeAsync(Api.InvokeUserPushCharacterDataToVisibleClients, character, visibleCharacterIds, uploadToken);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -145,7 +145,7 @@ namespace MareSynchronos.WebAPI
|
||||
|
||||
public async Task CreateConnections()
|
||||
{
|
||||
Logger.Verbose("Recreating Connection");
|
||||
Logger.Info("Recreating Connection");
|
||||
|
||||
await StopConnection(_connectionCancellationTokenSource.Token);
|
||||
|
||||
@@ -230,7 +230,7 @@ namespace MareSynchronos.WebAPI
|
||||
{
|
||||
Logger.Warn(ex.Message);
|
||||
Logger.Warn(ex.StackTrace ?? string.Empty);
|
||||
Logger.Debug("Failed to establish connection, retrying");
|
||||
Logger.Info("Failed to establish connection, retrying");
|
||||
await StopConnection(token);
|
||||
await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 20)), token);
|
||||
}
|
||||
@@ -269,14 +269,14 @@ namespace MareSynchronos.WebAPI
|
||||
CurrentUploads.Clear();
|
||||
CurrentDownloads.Clear();
|
||||
_uploadCancellationTokenSource?.Cancel();
|
||||
Logger.Debug("Connection closed");
|
||||
Logger.Info("Connection closed");
|
||||
Disconnected?.Invoke();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task MareHubOnReconnected(string? arg)
|
||||
{
|
||||
Logger.Debug("Connection restored");
|
||||
Logger.Info("Connection restored");
|
||||
await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 10)));
|
||||
_connectionDto = await _mareHub!.InvokeAsync<ConnectionDto>(Api.InvokeHeartbeat, _dalamudUtil.PlayerNameHashed);
|
||||
Connected?.Invoke();
|
||||
@@ -287,14 +287,14 @@ namespace MareSynchronos.WebAPI
|
||||
CurrentUploads.Clear();
|
||||
CurrentDownloads.Clear();
|
||||
_uploadCancellationTokenSource?.Cancel();
|
||||
Logger.Debug("Connection closed... Reconnecting");
|
||||
Logger.Warn("Connection closed... Reconnecting");
|
||||
Disconnected?.Invoke();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task StopConnection(CancellationToken token)
|
||||
{
|
||||
Logger.Verbose("Stopping all connections");
|
||||
Logger.Info("Stopping all connections");
|
||||
if (_mareHub is not null)
|
||||
{
|
||||
await _mareHub.StopAsync(token);
|
||||
|
||||
Reference in New Issue
Block a user