diff --git a/src/main/java/org/betterx/bclib/api/v2/dataexchange/DataExchangeAPI.java b/src/main/java/org/betterx/bclib/api/v2/dataexchange/DataExchangeAPI.java index 120267dd..7c87481f 100644 --- a/src/main/java/org/betterx/bclib/api/v2/dataexchange/DataExchangeAPI.java +++ b/src/main/java/org/betterx/bclib/api/v2/dataexchange/DataExchangeAPI.java @@ -5,6 +5,7 @@ import org.betterx.bclib.api.v2.dataexchange.handler.DataExchange; import org.betterx.bclib.api.v2.dataexchange.handler.autosync.AutoSync; import org.betterx.bclib.api.v2.dataexchange.handler.autosync.AutoSyncID; import org.betterx.bclib.config.Config; +import org.betterx.bclib.config.Configs; import org.betterx.worlds.together.util.ModUtil; import net.minecraft.network.FriendlyByteBuf; @@ -55,7 +56,8 @@ public class DataExchangeAPI extends DataExchange { if (ModUtil.getModInfo(modID, false) != null && !"0.0.0".equals(ModUtil.getModVersion(modID))) { registerMod(modID); } else { - BCLib.LOGGER.info("Mod Dependency '" + modID + "' not found. This is probably OK."); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info("Mod Dependency '" + modID + "' not found. This is probably OK."); } } diff --git a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/HelloClient.java b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/HelloClient.java index 31e883f6..ead95a39 100644 --- a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/HelloClient.java +++ b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/HelloClient.java @@ -129,8 +129,9 @@ public class HelloClient extends DataHandler.FromServer { modID)); buf.writeBoolean(canDownload); - BCLib.LOGGER.info(" - Listing Mod " + modID + " v" + ver + " (size: " + PathUtil.humanReadableFileSize( - size) + ", download=" + canDownload + ")"); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info(" - Listing Mod " + modID + " v" + ver + " (size: " + PathUtil.humanReadableFileSize( + size) + ", download=" + canDownload + ")"); } } else { BCLib.LOGGER.info("Server will not list Mods."); @@ -149,7 +150,8 @@ public class HelloClient extends DataHandler.FromServer { buf.writeInt(existingAutoSyncFiles.size()); for (AutoFileSyncEntry entry : existingAutoSyncFiles) { entry.serialize(buf); - BCLib.LOGGER.info(" - Offering " + (entry.isConfigFile() ? "Config " : "File ") + entry); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info(" - Offering " + (entry.isConfigFile() ? "Config " : "File ") + entry); } } else { BCLib.LOGGER.info("Server will neither offer Files nor Configs."); @@ -159,7 +161,8 @@ public class HelloClient extends DataHandler.FromServer { if (Configs.SERVER_CONFIG.isOfferingFiles()) { buf.writeInt(AutoSync.syncFolderDescriptions.size()); AutoSync.syncFolderDescriptions.forEach(desc -> { - BCLib.LOGGER.info(" - Offering Folder " + desc.localFolder + " (allowDelete=" + desc.removeAdditionalFiles + ")"); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info(" - Offering Folder " + desc.localFolder + " (allowDelete=" + desc.removeAdditionalFiles + ")"); desc.serialize(buf); }); } else { @@ -230,20 +233,23 @@ public class HelloClient extends DataHandler.FromServer { } if (autoSynFolders.size() > 0) { - BCLib.LOGGER.info("Folders offered by Server:"); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info("Folders offered by Server:"); } autoSynFolders.forEach(desc -> { //desc contains the fileCache sent from the server, load the local version to get hold of the actual file cache on the client SyncFolderDescriptor localDescriptor = AutoSync.getSyncFolderDescriptor(desc.folderID); if (localDescriptor != null) { - BCLib.LOGGER.info(" - " + desc.folderID + " (" + desc.localFolder + ", allowRemove=" + desc.removeAdditionalFiles + ")"); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info(" - " + desc.folderID + " (" + desc.localFolder + ", allowRemove=" + desc.removeAdditionalFiles + ")"); localDescriptor.invalidateCache(); desc.relativeFilesStream() .filter(desc::discardChildElements) .forEach(subFile -> { - BCLib.LOGGER.warning(" * " + subFile.relPath + " (REJECTED)"); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.warning(" * " + subFile.relPath + " (REJECTED)"); }); @@ -259,7 +265,8 @@ public class HelloClient extends DataHandler.FromServer { )) .collect(Collectors.toList()); - additionalFiles.forEach(aid -> BCLib.LOGGER.info(" * " + desc.localFolder.relativize(aid.relFile.toPath()) + " (missing on server)")); + if (Configs.MAIN_CONFIG.verboseLogging()) + additionalFiles.forEach(aid -> BCLib.LOGGER.info(" * " + desc.localFolder.relativize(aid.relFile.toPath()) + " (missing on server)")); filesToRemove.addAll(additionalFiles); } @@ -270,17 +277,20 @@ public class HelloClient extends DataHandler.FromServer { if (localSubFile != null) { //the file exists locally, check if the hashes match if (!localSubFile.hash.equals(subFile.hash)) { - BCLib.LOGGER.info(" * " + subFile.relPath + " (changed)"); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info(" * " + subFile.relPath + " (changed)"); filesToRequest.add(new AutoSyncID.ForDirectFileRequest( desc.folderID, new File(subFile.relPath) )); } else { - BCLib.LOGGER.info(" * " + subFile.relPath); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info(" * " + subFile.relPath); } } else { //the file is missing locally - BCLib.LOGGER.info(" * " + subFile.relPath + " (missing on client)"); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info(" * " + subFile.relPath + " (missing on client)"); filesToRequest.add(new AutoSyncID.ForDirectFileRequest( desc.folderID, new File(subFile.relPath) @@ -291,7 +301,8 @@ public class HelloClient extends DataHandler.FromServer { //free some memory localDescriptor.invalidateCache(); } else { - BCLib.LOGGER.info(" - " + desc.folderID + " (Failed to find)"); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info(" - " + desc.folderID + " (Failed to find)"); } }); } @@ -301,7 +312,8 @@ public class HelloClient extends DataHandler.FromServer { final boolean debugHashes = Configs.CLIENT_CONFIG.shouldPrintDebugHashes(); if (autoSyncedFiles.size() > 0) { - BCLib.LOGGER.info("Files offered by Server:"); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info("Files offered by Server:"); } //Handle single sync files @@ -328,12 +340,13 @@ public class HelloClient extends DataHandler.FromServer { )); } } - - BCLib.LOGGER.info(" - " + e + ": " + actionString); - if (debugHashes) { - BCLib.LOGGER.info(" * " + e.serverHash + " (Server)"); - BCLib.LOGGER.info(" * " + e.localMatch.getFileHash() + " (Client)"); - BCLib.LOGGER.info(" * local Content " + (contentWrapper.getRawContent() == null)); + if (Configs.MAIN_CONFIG.verboseLogging()) { + BCLib.LOGGER.info(" - " + e + ": " + actionString); + if (debugHashes) { + BCLib.LOGGER.info(" * " + e.serverHash + " (Server)"); + BCLib.LOGGER.info(" * " + e.localMatch.getFileHash() + " (Client)"); + BCLib.LOGGER.info(" * local Content " + (contentWrapper.getRawContent() == null)); + } } } } @@ -349,10 +362,11 @@ public class HelloClient extends DataHandler.FromServer { final boolean clientOnly = nfo != null && nfo.metadata.getEnvironment() == ModEnvironment.CLIENT; final boolean requestMod = !clientOnly && !serverInfo.version.equals(localVersion) && serverInfo.size > 0 && serverInfo.canDownload; - BCLib.LOGGER.info(" - " + e.getKey() + " (client=" + localVersion + ", server=" + serverInfo.version + ", size=" + PathUtil.humanReadableFileSize( - serverInfo.size) + (requestMod ? ", requesting" : "") + (serverInfo.canDownload - ? "" - : ", not offered") + (clientOnly ? ", client only" : "") + ")"); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info(" - " + e.getKey() + " (client=" + localVersion + ", server=" + serverInfo.version + ", size=" + PathUtil.humanReadableFileSize( + serverInfo.size) + (requestMod ? ", requesting" : "") + (serverInfo.canDownload + ? "" + : ", not offered") + (clientOnly ? ", client only" : "") + ")"); if (requestMod) { filesToRequest.add(new AutoSyncID.ForModFileRequest(e.getKey(), serverInfo.version)); } diff --git a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/RequestFiles.java b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/RequestFiles.java index 35c4ecbe..ec4da863 100644 --- a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/RequestFiles.java +++ b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/RequestFiles.java @@ -73,11 +73,13 @@ public class RequestFiles extends DataHandler.FromClient { int size = buf.readInt(); files = new ArrayList<>(size); - BCLib.LOGGER.info("Client requested " + size + " Files:"); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info("Client requested " + size + " Files:"); for (int i = 0; i < size; i++) { AutoSyncID asid = AutoSyncID.deserializeData(buf); files.add(asid); - BCLib.LOGGER.info(" - " + asid); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info(" - " + asid); } diff --git a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/SendFiles.java b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/SendFiles.java index 5d16a6f5..531a7cf2 100644 --- a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/SendFiles.java +++ b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/SendFiles.java @@ -81,10 +81,12 @@ public class SendFiles extends DataHandler.FromServer { writeString(buf, token); buf.writeInt(existingFiles.size()); - BCLib.LOGGER.info("Sending " + existingFiles.size() + " Files to Client:"); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info("Sending " + existingFiles.size() + " Files to Client:"); for (AutoFileSyncEntry entry : existingFiles) { int length = entry.serializeContent(buf); - BCLib.LOGGER.info(" - " + entry + " (" + PathUtil.humanReadableFileSize(length) + ")"); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info(" - " + entry + " (" + PathUtil.humanReadableFileSize(length) + ")"); } } @@ -105,7 +107,8 @@ public class SendFiles extends DataHandler.FromServer { int size = buf.readInt(); receivedFiles = new ArrayList<>(size); - BCLib.LOGGER.info("Server sent " + size + " Files:"); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info("Server sent " + size + " Files:"); for (int i = 0; i < size; i++) { Triple p = AutoFileSyncEntry.deserializeContent(buf); if (p.first != null) { @@ -122,9 +125,11 @@ public class SendFiles extends DataHandler.FromServer { } else { type = "Ignoring "; } - BCLib.LOGGER.info(" - " + type + p.first + " (" + PathUtil.humanReadableFileSize(p.second.length) + ")"); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.info(" - " + type + p.first + " (" + PathUtil.humanReadableFileSize(p.second.length) + ")"); } else { - BCLib.LOGGER.error(" - Failed to receive File " + p.third + ", possibly sent from a Mod that is not installed on the client."); + if (Configs.MAIN_CONFIG.verboseLogging()) + BCLib.LOGGER.error(" - Failed to receive File " + p.third + ", possibly sent from a Mod that is not installed on the client."); } } } diff --git a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/SyncFolderDescriptor.java b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/SyncFolderDescriptor.java index b214047b..bc4bd275 100644 --- a/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/SyncFolderDescriptor.java +++ b/src/main/java/org/betterx/bclib/api/v2/dataexchange/handler/autosync/SyncFolderDescriptor.java @@ -131,9 +131,11 @@ public class SyncFolderDescriptor { buf.writeBoolean(removeAdditionalFiles); buf.writeInt(fileCache.size()); fileCache.forEach(fl -> { - BCLib.LOGGER.info(" - " + fl.relPath); - if (debugHashes) { - BCLib.LOGGER.info(" " + fl.hash); + if (Configs.MAIN_CONFIG.verboseLogging()) { + BCLib.LOGGER.info(" - " + fl.relPath); + if (debugHashes) { + BCLib.LOGGER.info(" " + fl.hash); + } } fl.serialize(buf); });