From 3515f760fffc8a3c7135c3107473ceda7eafef81 Mon Sep 17 00:00:00 2001 From: chrisw-dev <68233262+chrisw-dev@users.noreply.github.com> Date: Thu, 2 Nov 2023 22:05:51 +0000 Subject: [PATCH] handle username and XUID for ALLOW_LIST_USERS --- README.md | 6 ++++-- bedrock-entry.sh | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8138484..b3be3f4 100644 --- a/README.md +++ b/README.md @@ -151,10 +151,12 @@ There are two ways to handle a whitelist: The first is to set the `ALLOW_LIST` environment variable to true and map in an [allowlist.json](https://minecraft.wiki/w/Whitelist.json) file (previously known as "whitelist.json") that is custom-crafted to the container. -The other is to set the `ALLOW_LIST_USERS` environment variable to a comma-separated list of gamer tag usernames that should be allowed. The server will look up the names and add in the XUID to match the player. +The other is to set the `ALLOW_LIST_USERS` environment variable to a comma-separated list of gamer tag usernames and their corresponding XUIDs. Each username should be followed by its XUID, separated by a colon. The server will use these details to match the player. + +There are various tools to look XUIDs up online and they are also printed to the log when a player joins the server. ```shell --e ALLOW_LIST_USERS="player1,player2,player3" +-e ALLOW_LIST_USERS="player1:1234567890,player2:0987654321" ``` ## Mods Addons diff --git a/bedrock-entry.sh b/bedrock-entry.sh index 5ce4c1d..da00206 100755 --- a/bedrock-entry.sh +++ b/bedrock-entry.sh @@ -163,11 +163,15 @@ if [[ -n "$OPS" || -n "$MEMBERS" || -n "$VISITORS" ]]; then fi if [[ -n "$ALLOW_LIST_USERS" || -n "$WHITE_LIST_USERS" ]]; then - allowListUsers=${ALLOW_LIST_USERS:-$WHITE_LIST_USERS} + allowListUsers=$(echo "${ALLOW_LIST_USERS:-$WHITE_LIST_USERS}" | tr -d '\n' | tr -d '\r') if [[ "$allowListUsers" ]]; then echo "Setting allow list" - jq -c -n --arg users "$allowListUsers" '$users | split(",") | map({"ignoresPlayerLimit":false,"name": .})' > "allowlist.json" + if [[ "$allowListUsers" != *":"* ]]; then + jq -c -n --arg users "$allowListUsers" '$users | split(",") | map({"ignoresPlayerLimit":false,"name": .})' > "allowlist.json" + else + jq -c -n --arg users "$allowListUsers" '$users | split(",") | map(split(":") | {"ignoresPlayerLimit":false,"name": .[0], "xuid": .[1]})' > "allowlist.json" + fi # activate server property to enable list usage ALLOW_LIST=true else