minor bugfixing and log severity adjustment

This commit is contained in:
Stanley Dimant
2022-07-28 14:14:00 +02:00
parent 57c0a4b9b0
commit 34ed21472a
6 changed files with 54 additions and 36 deletions

View File

@@ -70,6 +70,7 @@ public class CachedPlayer
if (characterData.GetHashCode() == _cachedData.GetHashCode()) return; if (characterData.GetHashCode() == _cachedData.GetHashCode()) return;
bool updateModdedPaths = false;
List<ObjectKind> charaDataToUpdate = new List<ObjectKind>(); List<ObjectKind> charaDataToUpdate = new List<ObjectKind>();
foreach (var objectKind in Enum.GetValues<ObjectKind>()) foreach (var objectKind in Enum.GetValues<ObjectKind>())
{ {
@@ -88,6 +89,7 @@ public class CachedPlayer
if (hasNewButNotOldFileReplacements || hasOldButNotNewFileReplacements || hasNewButNotOldGlamourerData || hasOldButNotNewGlamourerData) if (hasNewButNotOldFileReplacements || hasOldButNotNewFileReplacements || hasNewButNotOldGlamourerData || hasOldButNotNewGlamourerData)
{ {
Logger.Debug("Updating " + objectKind); Logger.Debug("Updating " + objectKind);
updateModdedPaths = true;
charaDataToUpdate.Add(objectKind); charaDataToUpdate.Add(objectKind);
continue; continue;
} }
@@ -98,6 +100,7 @@ public class CachedPlayer
if (!listsAreEqual) if (!listsAreEqual)
{ {
Logger.Debug("Updating " + objectKind); Logger.Debug("Updating " + objectKind);
updateModdedPaths = true;
charaDataToUpdate.Add(objectKind); charaDataToUpdate.Add(objectKind);
continue; continue;
} }
@@ -117,11 +120,16 @@ public class CachedPlayer
_cachedData = characterData; _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?.Cancel();
_downloadCancellationTokenSource = new CancellationTokenSource(); _downloadCancellationTokenSource = new CancellationTokenSource();
var downloadToken = _downloadCancellationTokenSource.Token; var downloadToken = _downloadCancellationTokenSource.Token;
@@ -130,6 +138,8 @@ public class CachedPlayer
{ {
List<FileReplacementDto> toDownloadReplacements; List<FileReplacementDto> toDownloadReplacements;
if (updateModdedPaths)
{
Dictionary<string, string> moddedPaths; Dictionary<string, string> moddedPaths;
int attempts = 0; int attempts = 0;
while ((toDownloadReplacements = TryCalculateModdedDictionary(out moddedPaths)).Count > 0 && attempts++ <= 10) while ((toDownloadReplacements = TryCalculateModdedDictionary(out moddedPaths)).Count > 0 && attempts++ <= 10)
@@ -148,6 +158,9 @@ public class CachedPlayer
} }
} }
ApplyBaseData(moddedPaths);
}
if (_dalamudUtil.IsInGpose) if (_dalamudUtil.IsInGpose)
{ {
Logger.Verbose("Player is in GPose, waiting"); Logger.Verbose("Player is in GPose, waiting");
@@ -158,8 +171,6 @@ public class CachedPlayer
} }
} }
ApplyBaseData(moddedPaths);
foreach (var kind in objectKind) foreach (var kind in objectKind)
{ {
ApplyCustomizationData(kind); ApplyCustomizationData(kind);
@@ -311,15 +322,13 @@ public class CachedPlayer
{ {
if (_isDisposed) return; if (_isDisposed) return;
if (string.IsNullOrEmpty(PlayerName)) return; if (string.IsNullOrEmpty(PlayerName)) return;
Logger.Verbose("Disposing " + PlayerName + " (" + PlayerNameHash + ")"); Logger.Debug("Disposing " + PlayerName + " (" + PlayerNameHash + ")");
_isDisposed = true; _isDisposed = true;
try try
{ {
Logger.Verbose("Restoring state for " + PlayerName); Logger.Verbose("Restoring state for " + PlayerName);
_dalamudUtil.FrameworkUpdate -= DalamudUtilOnFrameworkUpdate; _dalamudUtil.FrameworkUpdate -= DalamudUtilOnFrameworkUpdate;
_ipcManager.PenumbraRedrawEvent -= IpcManagerOnPenumbraRedrawEvent; _ipcManager.PenumbraRedrawEvent -= IpcManagerOnPenumbraRedrawEvent;
_downloadCancellationTokenSource?.Cancel();
_downloadCancellationTokenSource?.Dispose();
_ipcManager.PenumbraRemoveTemporaryCollection(PlayerName); _ipcManager.PenumbraRemoveTemporaryCollection(PlayerName);
if (PlayerCharacter != null && PlayerCharacter.IsValid()) if (PlayerCharacter != null && PlayerCharacter.IsValid())
{ {
@@ -328,6 +337,9 @@ public class CachedPlayer
RevertCustomizationData(item.Key); RevertCustomizationData(item.Key);
} }
} }
_downloadCancellationTokenSource?.Cancel();
_downloadCancellationTokenSource?.Dispose();
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Authors></Authors> <Authors></Authors>
<Company></Company> <Company></Company>
<Version>0.2.8.0</Version> <Version>0.2.9.0</Version>
<Description></Description> <Description></Description>
<Copyright></Copyright> <Copyright></Copyright>
<PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl> <PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl>

View File

@@ -106,7 +106,7 @@ namespace MareSynchronos.Models
{ {
if (HatState != null && !hasChanges && !HasUnprocessedUpdate) if (HatState != null && !hasChanges && !HasUnprocessedUpdate)
{ {
Logger.Verbose("Not Sending Update, only Hat changed"); Logger.Debug("Not Sending Update, only Hat changed");
DoNotSendUpdate = true; DoNotSendUpdate = true;
} }
HatState = newHatState; HatState = newHatState;
@@ -117,7 +117,7 @@ namespace MareSynchronos.Models
{ {
if (VisorWeaponState != null && !hasChanges && !HasUnprocessedUpdate) 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; DoNotSendUpdate = true;
} }
VisorWeaponState = newWeaponOrVisorState; VisorWeaponState = newWeaponOrVisorState;

View File

@@ -6,6 +6,12 @@ namespace MareSynchronos.Utils
{ {
internal class Logger 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 = "") public static void Debug(string debug, string stringToHighlight = "")
{ {
var caller = new StackTrace().GetFrame(1)?.GetMethod()?.ReflectedType?.Name ?? "Unknown"; var caller = new StackTrace().GetFrame(1)?.GetMethod()?.ReflectedType?.Name ?? "Unknown";

View File

@@ -76,7 +76,7 @@ namespace MareSynchronos.WebAPI
if (ct.IsCancellationRequested) if (ct.IsCancellationRequested)
{ {
File.Delete(tempFile); File.Delete(tempFile);
Logger.Verbose("Detected cancellation, removing " + currentDownloadId); Logger.Debug("Detected cancellation, removing " + currentDownloadId);
CurrentDownloads.Remove(currentDownloadId); CurrentDownloads.Remove(currentDownloadId);
break; break;
} }
@@ -113,7 +113,7 @@ namespace MareSynchronos.WebAPI
await Task.Delay(250, ct); await Task.Delay(250, ct);
} }
Logger.Verbose("Download complete, removing " + currentDownloadId); Logger.Debug("Download complete, removing " + currentDownloadId);
CurrentDownloads.Remove(currentDownloadId); CurrentDownloads.Remove(currentDownloadId);
} }
@@ -162,10 +162,10 @@ namespace MareSynchronos.WebAPI
} }
var totalSize = CurrentUploads.Sum(c => c.Total); 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()) 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); var data = await GetCompressedFileData(file.Hash, uploadToken);
CurrentUploads.Single(e => e.Hash == data.Item1).Total = data.Item2.Length; CurrentUploads.Single(e => e.Hash == data.Item1).Total = data.Item2.Length;
await UploadFile(data.Item2, file.Hash, uploadToken); 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.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); var anyUploadsOpen = await _mareHub!.InvokeAsync<bool>(Api.InvokeFileIsUploadFinished, uploadToken);
Logger.Verbose("Uploads open: " + anyUploadsOpen); Logger.Debug("Uploads open: " + anyUploadsOpen);
while (anyUploadsOpen && !uploadToken.IsCancellationRequested) while (anyUploadsOpen && !uploadToken.IsCancellationRequested)
{ {
anyUploadsOpen = await _mareHub!.InvokeAsync<bool>(Api.InvokeFileIsUploadFinished, uploadToken); anyUploadsOpen = await _mareHub!.InvokeAsync<bool>(Api.InvokeFileIsUploadFinished, uploadToken);
await Task.Delay(TimeSpan.FromSeconds(0.5), 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(); CurrentUploads.Clear();
if (!uploadToken.IsCancellationRequested) if (!uploadToken.IsCancellationRequested)
{ {
Logger.Verbose("=== Pushing character data ==="); Logger.Info("Pushing character data for " + character.GetHashCode());
await _mareHub!.InvokeAsync(Api.InvokeUserPushCharacterDataToVisibleClients, character, visibleCharacterIds, uploadToken); await _mareHub!.InvokeAsync(Api.InvokeUserPushCharacterDataToVisibleClients, character, visibleCharacterIds, uploadToken);
} }
else else

View File

@@ -145,7 +145,7 @@ namespace MareSynchronos.WebAPI
public async Task CreateConnections() public async Task CreateConnections()
{ {
Logger.Verbose("Recreating Connection"); Logger.Info("Recreating Connection");
await StopConnection(_connectionCancellationTokenSource.Token); await StopConnection(_connectionCancellationTokenSource.Token);
@@ -230,7 +230,7 @@ namespace MareSynchronos.WebAPI
{ {
Logger.Warn(ex.Message); Logger.Warn(ex.Message);
Logger.Warn(ex.StackTrace ?? string.Empty); Logger.Warn(ex.StackTrace ?? string.Empty);
Logger.Debug("Failed to establish connection, retrying"); Logger.Info("Failed to establish connection, retrying");
await StopConnection(token); await StopConnection(token);
await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 20)), token); await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 20)), token);
} }
@@ -269,14 +269,14 @@ namespace MareSynchronos.WebAPI
CurrentUploads.Clear(); CurrentUploads.Clear();
CurrentDownloads.Clear(); CurrentDownloads.Clear();
_uploadCancellationTokenSource?.Cancel(); _uploadCancellationTokenSource?.Cancel();
Logger.Debug("Connection closed"); Logger.Info("Connection closed");
Disconnected?.Invoke(); Disconnected?.Invoke();
return Task.CompletedTask; return Task.CompletedTask;
} }
private async Task MareHubOnReconnected(string? arg) private async Task MareHubOnReconnected(string? arg)
{ {
Logger.Debug("Connection restored"); Logger.Info("Connection restored");
await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 10))); await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 10)));
_connectionDto = await _mareHub!.InvokeAsync<ConnectionDto>(Api.InvokeHeartbeat, _dalamudUtil.PlayerNameHashed); _connectionDto = await _mareHub!.InvokeAsync<ConnectionDto>(Api.InvokeHeartbeat, _dalamudUtil.PlayerNameHashed);
Connected?.Invoke(); Connected?.Invoke();
@@ -287,14 +287,14 @@ namespace MareSynchronos.WebAPI
CurrentUploads.Clear(); CurrentUploads.Clear();
CurrentDownloads.Clear(); CurrentDownloads.Clear();
_uploadCancellationTokenSource?.Cancel(); _uploadCancellationTokenSource?.Cancel();
Logger.Debug("Connection closed... Reconnecting"); Logger.Warn("Connection closed... Reconnecting");
Disconnected?.Invoke(); Disconnected?.Invoke();
return Task.CompletedTask; return Task.CompletedTask;
} }
private async Task StopConnection(CancellationToken token) private async Task StopConnection(CancellationToken token)
{ {
Logger.Verbose("Stopping all connections"); Logger.Info("Stopping all connections");
if (_mareHub is not null) if (_mareHub is not null)
{ {
await _mareHub.StopAsync(token); await _mareHub.StopAsync(token);