Skip to content

Commit

Permalink
refactor: allow-deny lists refactor also allows for backwards compati…
Browse files Browse the repository at this point in the history
…bility

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.
  • Loading branch information
byhlel committed Sep 26, 2024
1 parent b3415d9 commit a0a4b91
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/Modding-API.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Check warning on line 40 in engine/src/main/java/org/terasology/engine/network/internal/ServerConnectListManager.java

View check run for this annotation

Terasology Jenkins.io / CheckStyle

RightCurlyCheck

ERROR: '}' at column 9 should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else, do/while or try/catch/finally).
Raw output
<p>Since Checkstyle 3.0</p><p> Checks the placement of right curly braces (<code>'}'</code>) for if-else, try-catch-finally blocks, while-loops, for-loops, method definitions, class definitions, constructor definitions, instance and static initialization blocks. The policy to verify is specified using the property <code> option</code>. For right curly brace of expression blocks please follow issue <a href="https://github.com/checkstyle/checkstyle/issues/5945">#5945</a>. </p>
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");
}

Check warning on line 47 in engine/src/main/java/org/terasology/engine/network/internal/ServerConnectListManager.java

View check run for this annotation

Terasology Jenkins.io / CheckStyle

RightCurlyCheck

ERROR: '}' at column 9 should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else, do/while or try/catch/finally).
Raw output
<p>Since Checkstyle 3.0</p><p> Checks the placement of right curly braces (<code>'}'</code>) for if-else, try-catch-finally blocks, while-loops, for-loops, method definitions, class definitions, constructor definitions, instance and static initialization blocks. The policy to verify is specified using the property <code> option</code>. For right curly brace of expression blocks please follow issue <a href="https://github.com/checkstyle/checkstyle/issues/5945">#5945</a>. </p>
else {
allowlistPath = PathManager.getInstance().getHomePath().resolve("whitelist.json");
}
this.context = context;
loadLists();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a0a4b91

Please sign in to comment.