From a0a4b91356c5b61e0ddea4d707e96be86b22b944 Mon Sep 17 00:00:00 2001 From: Bilal <39002942+byhlel@users.noreply.github.com> Date: Thu, 26 Sep 2024 04:51:08 +0000 Subject: [PATCH] refactor: allow-deny lists refactor also allows for backwards compatibility Code strucutre is different in SelectGameScreen and ServerConnectListManager due to compiling error otherwise. We check if path exist then we set the value if it does, otherwise it applies "previous" behaviour (meaning in case if even blacklist or whitelist) do not exist it sets the file to null. So no different behaviour is to be expected. --- .gitignore | 4 +++- docs/Modding-API.md | 2 +- .../internal/ServerConnectListManager.java | 16 ++++++++++++++-- .../nui/layers/mainMenu/SelectGameScreen.java | 7 +++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 5b6891b3326..eb905b576f0 100644 --- a/.gitignore +++ b/.gitignore @@ -94,9 +94,11 @@ config/metrics/ API_file.txt New_API_file.txt -# Ignore Allowlist and Denylist files +# Ignore Allowlist and Denylist files (Whitelist and Blacklist are old filenames) allowlist.json denylist.json +whitelist.json +blacklist.json # Profiling related terasology.jfr diff --git a/docs/Modding-API.md b/docs/Modding-API.md index ed5065fe078..d2e81b2c284 100644 --- a/docs/Modding-API.md +++ b/docs/Modding-API.md @@ -1,7 +1,7 @@ Modding API ================= -Terasology's engine uses allowlisting approach to expose an API for modules using two primary methods and a rarely needed third one: +Terasology's engine uses an allowlisting approach to expose an API for modules using two primary methods and a rarely needed third one: * Classes or packages marked with the `@API` annotation * Classes or packages in the basic allowlist defined in `ExternalApiAllowlist.java` diff --git a/engine/src/main/java/org/terasology/engine/network/internal/ServerConnectListManager.java b/engine/src/main/java/org/terasology/engine/network/internal/ServerConnectListManager.java index 1c91de0fd88..c2189f19abd 100644 --- a/engine/src/main/java/org/terasology/engine/network/internal/ServerConnectListManager.java +++ b/engine/src/main/java/org/terasology/engine/network/internal/ServerConnectListManager.java @@ -34,8 +34,20 @@ public class ServerConnectListManager { private final Path allowlistPath; public ServerConnectListManager(Context context) { - denylistPath = PathManager.getInstance().getHomePath().resolve("denylist.json"); - allowlistPath = PathManager.getInstance().getHomePath().resolve("allowlist.json"); + // although this seems redundant, compiler wouldn't accept assigning then checking + if (Files.exists(PathManager.getInstance().getHomePath().resolve("denylist.json"))) { + denylistPath = PathManager.getInstance().getHomePath().resolve("denylist.json"); + } + else { + denylistPath = PathManager.getInstance().getHomePath().resolve("blacklist.json"); + } + // although this seems redundant, compiler wouldn't accept assigning then checking + if (Files.exists(PathManager.getInstance().getHomePath().resolve("allowlist.json"))) { + allowlistPath = PathManager.getInstance().getHomePath().resolve("allowlist.json"); + } + else { + allowlistPath = PathManager.getInstance().getHomePath().resolve("whitelist.json"); + } this.context = context; loadLists(); } diff --git a/engine/src/main/java/org/terasology/engine/rendering/nui/layers/mainMenu/SelectGameScreen.java b/engine/src/main/java/org/terasology/engine/rendering/nui/layers/mainMenu/SelectGameScreen.java index 293a07ed19f..af6e05371a6 100644 --- a/engine/src/main/java/org/terasology/engine/rendering/nui/layers/mainMenu/SelectGameScreen.java +++ b/engine/src/main/java/org/terasology/engine/rendering/nui/layers/mainMenu/SelectGameScreen.java @@ -151,6 +151,13 @@ private void loadGame(GameInfo item) { if (isLoadingAsServer()) { Path denylistPath = PathManager.getInstance().getHomePath().resolve("denylist.json"); Path allowlistPath = PathManager.getInstance().getHomePath().resolve("allowlist.json"); + if (!Files.exists(denylistPath)) { + denylistPath = PathManager.getInstance().getHomePath().resolve("blacklist.json"); + } + + if (!Files.exists(allowlistPath)) { + allowlistPath = PathManager.getInstance().getHomePath().resolve("whitelist.json"); + } if (!Files.exists(denylistPath)) { try { Files.createFile(denylistPath);