Skip to content

Commit

Permalink
Merge pull request #52 from cubeworx/feature/refactor-updates
Browse files Browse the repository at this point in the history
Feature/refactor updates
  • Loading branch information
claflico authored Jan 5, 2025
2 parents 4d58363 + 5bdf449 commit e4570d7
Show file tree
Hide file tree
Showing 9 changed files with 511 additions and 364 deletions.
28 changes: 22 additions & 6 deletions .github/workflows/build-push-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,27 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: cubeworx/mcbe-server:${{ env.IMG_VER }},cubeworx/mcbe-server:latest

- uses: ethomson/send-tweet-action@v1.0.0
- name: Tweet Release
uses: nearform-actions/github-action-notify-twitter@master
if: github.event_name != 'pull_request'
with:
status: "New version of CubeWorx Minecraft Bedrock Edition Server Image released: https://hub.docker.com/r/cubeworx/mcbe-server/tags?page=1&ordering=last_updated&name=${{ env.IMG_VER }}"
consumer-key: ${{ secrets.TWITTER_CONSUMER_API_KEY }}
consumer-secret: ${{ secrets.TWITTER_CONSUMER_API_SECRET }}
access-token: ${{ secrets.TWITTER_ACCESS_TOKEN }}
access-token-secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
message: "New version of CubeWorx Minecraft Bedrock Edition Server Image released: https://hub.docker.com/r/cubeworx/mcbe-server/tags?page=1&ordering=last_updated&name=${{ env.IMG_VER }}"
twitter-app-key: ${{ secrets.TWITTER_CONSUMER_API_KEY }}
twitter-app-secret: ${{ secrets.TWITTER_CONSUMER_API_SECRET }}
twitter-access-token: ${{ secrets.TWITTER_ACCESS_TOKEN }}
twitter-access-token-secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}

- name: Create Tag
uses: mathieudutour/github-tag-action@v6.0
if: github.event_name != 'pull_request'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ env.IMG_VER }}

- name: Create Release
uses: softprops/action-gh-release@v2
if: github.event_name != 'pull_request'
with:
name: v${{ env.IMG_VER }}
generate_release_notes: true
tag_name: v${{ env.IMG_VER }}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM debian:10-slim
FROM debian:12-slim

ARG BUILD_DATE

Expand Down Expand Up @@ -26,7 +26,7 @@ RUN apt-get update && \
apt-get -y autoremove && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
curl -sL https://github.com/itzg/mc-monitor/releases/download/0.10.3/mc-monitor_0.10.3_linux_amd64.tar.gz -o mc-monitor.tar.gz && \
curl -sL https://github.com/itzg/mc-monitor/releases/download/0.15.0/mc-monitor_0.15.0_linux_amd64.tar.gz -o mc-monitor.tar.gz && \
mkdir /itzg-mc-monitor && \
tar -xzvf mc-monitor.tar.gz --directory=/itzg-mc-monitor && \
rm -rf mc-monitor.tar.gz && \
Expand Down
25 changes: 9 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ The image runs with default or recommended configurations but can be customized

| | |
|-------------------------------|---------------------------------------------------------------------------|
| `ALLOWLIST_ENABLE="false"` | Specify if connected players must be listed in ALLOWLIST_USERS variable |
| `ALLOWLIST_LOOKUP="true"` | Specify if player usernames get verified from online api or written as is |
| `ALLOWLIST_MODE="static"` | Specify if allowlist file gets overwritten every time container starts |
| `LEVEL_NAME="Bedrock-Level"` | Default level name of world. Customized to remove space in default name |
| `PERMISSIONS_LOOKUP="true"` | Specify if player xuids get verified from online api or written as is |
| `PERMISSIONS_MODE="static"` | Specify if permissions file gets overwritten every time container starts |
| `SERVER_NAME="CubeWorx-MCBE"` | Default server name that shows up under LAN Games in the Friends tab |
| `WHITELIST_ENABLE="false"` | Specify if connected players must be listed in WHITELIST_USERS variable |
| `WHITELIST_LOOKUP="true"` | Specify if player usernames get verified from online api or written as is |
| `WHITELIST_MODE="static"` | Specify if whitelist file gets overwritten every time container starts |

### Basic Server Properties Environment Variables

Expand Down Expand Up @@ -100,28 +100,21 @@ docker run -d -it -p 19132:19132/udp -v mcbe-data:/mcbe/data -e EULA=true cubewo
If your server will not be exposed to the internet and players will only be connecting from tablets, consoles, etc. on the local network then you may want to set `ONLINE_MODE=false` so that players connecting to your server won't have to authticate. This is especially useful if you have younger children playing on tablets that don't have their own Microsoft accounts.


## CubeWorx API
## Allowlist

The CubeWorx API is being developed to help with automatically looking up information such as: versions, gamertags, xuids, etc. This API is currently **exerimental** and not guaranteed. If you experience issues with the API returning the correct information you can:

- Try setting `XBL_LOOKUP_URL=https://xbl-api.prouser123.me/profile/settings`
- Set `PERMISSIONS_LOOKUP="false"` and `WHITELIST_LOOKUP="false"`

## Whitelist

The whitelist is the list of player usernames that are allowed to connect to your server when `WHITELIST_ENABLE="true"` which should be set if your server is going to be publicly accessible. By default the whitelist file gets overwritten whenever the container starts/restarts to ensure that the usernames match what is in the config.
Setting `WHITELIST_MODE="dynamic"` will allow whitelist changes made in the game from supported clients to be retained upon start/restart of the container. Since usernames are case-sensitive, they are verified against an xbox live API to make sure there aren't any mistakes. This lookup can be disabled by setting `WHITELIST_LOOKUP="false"`.
The whitelist file is generated from the names included in the `WHITELIST_USERS`, `OPERATORS`, `MEMBERS`, & `VISITORS`. It is not necessary to enter a username in more than one environment variable. The following example will result in five names being added to the whitelist.
The allowlist is the list of player usernames that are allowed to connect to your server when `ALLOWLIST_ENABLE="true"` which should be set if your server is going to be publicly accessible. By default the allowlist file gets overwritten whenever the container starts/restarts to ensure that the usernames match what is in the config.
Setting `ALLOWLIST_MODE="dynamic"` will allow allowlist changes made in the game from supported clients to be retained upon start/restart of the container. Since usernames are case-sensitive, they are verified against an xbox live API to make sure there aren't any mistakes. This lookup can be disabled by setting `ALLOWLIST_LOOKUP="false"`.
The allowlist file is generated from the names included in the `ALLOWLIST_USERS`, `OPERATORS`, `MEMBERS`, & `VISITORS`. It is not necessary to enter a username in more than one environment variable. The following example will result in five names being added to the allowlist.

```
-e WHITELIST_USERS=player1,player2,player3 -e OPERATORS=operator1 -e MEMBERS=member1
-e ALLOWLIST_USERS=player1,player2,player3 -e OPERATORS=operator1 -e MEMBERS=member1
```

## Permissions

Permissions variables can be a list of usernames or XUIDs since the values are verified against an xbox live API when the container first starts. This lookup can be disabled by setting `PERMISSIONS_LOOKUP="false"` but then will require exact XUIDs to be entered for each user.
By default the permissions file gets overwritten whenever the container starts/restarts to ensure that the username permissions match what is in the config. Setting `PERMISSIONS_MODE="dynamic"` will allow permission changes made in the game from supported clients to be retained upon start/restart of the container.
If `WHITELIST_ENABLE="true"` then players in the `OPERATORS`, `MEMBERS`, or `VISITORS` will automatically be added to the server whitelist.
If `ALLOWLIST_ENABLE="true"` then players in the `OPERATORS`, `MEMBERS`, or `VISITORS` will automatically be added to the server allowlist.

```
-e OPERATORS=operator1,8675309124 -e MEMBERS=member1,1234567890,member2 -e VISITORS=visitor1
Expand Down
102 changes: 56 additions & 46 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,96 +2,103 @@

set -e

EULA=$EULA
EULA=${EULA:-""}
MCBE_HOME=${MCBE_HOME:-"/mcbe"}
ADDONS_PATH=${ADDONS_PATH:-"/mcbe/data/addons"}
ALLOWLIST_ENABLE=${ALLOWLIST_ENABLE:-"false"}
ALLOWLIST_FILE=${ALLOWLIST_FILE:-"/mcbe/data/allowlist.json"}
ALLOWLIST_LOOKUP=${ALLOWLIST_LOOKUP:-"true"}
ALLOWLIST_MODE=${ALLOWLIST_MODE:-"static"}
ARTIFACTS_PATH=${ARTIFACTS_PATH:-"/mcbe/data/artifacts"}
DATA_PATH=${DATA_PATH:-"/mcbe/data"}
DOWNLOAD_ENDPOINT=${DOWNLOAD_ENDPOINT:-"https://minecraft.azureedge.net/bin-linux"}
DOWNLOAD_ENDPOINT=${DOWNLOAD_ENDPOINT:-"https://www.minecraft.net/bedrockdedicatedserver/bin-linux"}
EXEC_NAME="cbwx-mcbe-${SERVER_NAME// /-}-server"
PERMISSIONS_FILE=${PERMISSIONS_FILE:-"/mcbe/data/permissions.json"}
PERMISSIONS_LOOKUP=${PERMISSIONS_LOOKUP:-"true"}
PERMISSIONS_MODE=${PERMISSIONS_MODE:-"static"}
PLAYERDB_LOOKUP_URL=${PLAYERDB_LOOKUP_URL:-"https://playerdb.co/api/player/xbox"}
SEEDS_FILE=${SEEDS_FILE:-"/mcbe/seeds.txt"}
SERVER_PATH=${SERVER_PATH:-"/mcbe/server"}
SERVER_PROPERTIES=${SERVER_PROPERTIES:-"/mcbe/server/server.properties"}
VERSION=${VERSION:-"LATEST"}
VERSIONS_FILE=${VERSIONS_FILE:-"/mcbe/versions.txt"}
WHITELIST_ENABLE=${WHITELIST_ENABLE:-"false"}
WHITELIST_FILE=${WHITELIST_FILE:-"/mcbe/data/whitelist.json"}
WHITELIST_LOOKUP=${WHITELIST_LOOKUP:-"true"}
WHITELIST_MODE=${WHITELIST_MODE:-"static"}
XBL_LOOKUP_URL=${XBL_LOOKUP_URL:-"https://api.cubeworx.io/mcbe/lookup"}

check_data_dir() {
DIR_NAME=$1
if [ ! -d "${DATA_PATH}/${DIR_NAME}" ]; then
echo "Creating directory: ${DATA_PATH}/${DIR_NAME}"
mkdir -p $DATA_PATH/$DIR_NAME
mkdir -p "${DATA_PATH}/${DIR_NAME}"
fi
}

get_latest_version() {
WEBSITE_DATA=$(curl -Ss -A "cubeworx/mcbe-server" -H "accept-language:*" https://www.minecraft.net/en-us/download/server/bedrock)
WEBSITE_DATA=$(curl -Ss -A "cubeworx/mcbe-server" -H "accept-language:*" "https://www.minecraft.net/en-us/download/server/bedrock")
#Check if website curl worked, if not default to latest from versions.txt
if [[ $(echo $WEBSITE_DATA | grep $DOWNLOAD_ENDPOINT | wc -l) -ne 0 ]]; then
LATEST_URL=$(echo $WEBSITE_DATA | grep -o 'https://minecraft.azureedge.net/bin-linux/[^"]*')
VERSION=$(echo $LATEST_URL | awk -F '-linux/' '{print $2}' | awk -F 'server-' '{print $2}' | awk -F '.zip' '{print $1}')
# shellcheck disable=SC2126
if [[ $(echo "${WEBSITE_DATA}" | grep "${DOWNLOAD_ENDPOINT}" | wc -l) -ne 0 ]]; then
LATEST_URL=$(echo "${WEBSITE_DATA}" | grep -o 'https://www.minecraft.net/bedrockdedicatedserver/bin-linux/[^"]*')
VERSION=$(echo "${LATEST_URL}" | awk -F '-linux/' '{print $2}' | awk -F 'server-' '{print $2}' | awk -F '.zip' '{print $1}')
echo "Latest version available is: ${VERSION}"
else
echo "ERROR: Unable to determine latest version, defaulting to latest in ${VERSIONS_FILE}"
VERSION=$(head -n 1 $VERSIONS_FILE)
VERSION=$(head -n 1 "${VERSIONS_FILE}")
fi
if [ ! -f "${ARTIFACTS_PATH}/bedrock-server-${VERSION}.zip" ]; then
download_file $DOWNLOAD_ENDPOINT/bedrock-server-$VERSION.zip $ARTIFACTS_PATH/bedrock-server-$VERSION.zip
download_file "${DOWNLOAD_ENDPOINT}/bedrock-server-${VERSION}.zip" "${ARTIFACTS_PATH}/bedrock-server-${VERSION}.zip"
fi
}

download_file(){
DOWNLOAD_URL=$1
DOWNLOAD_FILE=$2
echo "Downloading ${DOWNLOAD_URL} to ${DOWNLOAD_FILE}"
curl -Ss $DOWNLOAD_URL -o $DOWNLOAD_FILE
if [ ! -f $DOWNLOAD_FILE ]; then
curl -Ss -A "cubeworx/mcbe-server" --http1.1 "${DOWNLOAD_URL}" -o "${DOWNLOAD_FILE}"
if [ ! -f "${DOWNLOAD_FILE}" ]; then
echo "ERROR: File failed to download!"
exit 1
fi
}

extract_server_zip() {
if [ ! -d "${SERVER_PATH}" ]; then
mkdir -p $SERVER_PATH
mkdir -p "${SERVER_PATH}"
fi
echo "Unzipping ${ARTIFACTS_PATH}/bedrock-server-${VERSION}.zip to ${SERVER_PATH}"
unzip -q $ARTIFACTS_PATH/bedrock-server-$VERSION.zip -d $SERVER_PATH
unzip -q "${ARTIFACTS_PATH}/bedrock-server-${VERSION}.zip" -d "${SERVER_PATH}"
#If permissions.json in server directory exists, delete and create symlink to file in data dir
if [ -f "${SERVER_PATH}/permissions.json" ] && [ ! -L "${SERVER_PATH}/permissions.json" ]; then
rm -rf $SERVER_PATH/permissions.json
rm -rf "${SERVER_PATH}/permissions.json"
echo "Creating symlink ${SERVER_PATH}/permissions.json to ${PERMISSIONS_FILE}"
ln -s $PERMISSIONS_FILE $SERVER_PATH/permissions.json
ln -s "${PERMISSIONS_FILE}" "${SERVER_PATH}/permissions.json"
fi
#If allowlist.json in server directory exists, delete and create symlink to file in data dir
if [ -f "${SERVER_PATH}/allowlist.json" ] && [ ! -L "${SERVER_PATH}/allowlist.json" ]; then
rm -rf "${SERVER_PATH}/allowlist.json"
echo "Creating symlink ${SERVER_PATH}/allowlist.json to ${ALLOWLIST_FILE}"
ln -s "${ALLOWLIST_FILE}" "${SERVER_PATH}/allowlist.json"
fi
#If whitelist.json in server directory exists, delete and create symlink to file in data dir
if [ -f "${SERVER_PATH}/whitelist.json" ] && [ ! -L "${SERVER_PATH}/whitelist.json" ]; then
rm -rf $SERVER_PATH/whitelist.json
echo "Creating symlink ${SERVER_PATH}/whitelist.json to ${WHITELIST_FILE}"
ln -s $WHITELIST_FILE $SERVER_PATH/whitelist.json
rm -rf "${SERVER_PATH}/whitelist.json"
echo "Creating symlink ${SERVER_PATH}/whitelist.json to ${ALLOWLIST_FILE}"
ln -s "${ALLOWLIST_FILE}" "${SERVER_PATH}/whitelist.json"
fi
compare_version
echo $VERSION > $DATA_PATH/version.txt
echo "${VERSION}" > "${DATA_PATH}/version.txt"
echo "Renaming bedrock_server to ${EXEC_NAME} for easier host process identification."
mv $SERVER_PATH/bedrock_server $SERVER_PATH/$EXEC_NAME
chmod +x $SERVER_PATH/$EXEC_NAME
mv "${SERVER_PATH}/bedrock_server" "${SERVER_PATH}/${EXEC_NAME}"
chmod +x "${SERVER_PATH}/${EXEC_NAME}"
}

compare_version() {
if [ -f "${DATA_PATH}/version.txt" ]; then
OLD_VER=$(cat $DATA_PATH/version.txt)
if [[ "x${OLD_VER}" != "x${VERSION}" ]]; then
OLD_VER=$(cat "${DATA_PATH}/version.txt")
if [[ "${OLD_VER}" != "${VERSION}" ]]; then
DATE_TIME=$(date +%Y%m%d%H%M%S)
echo "Previous version was ${OLD_VER}, current version is ${VERSION}"
echo "Creating backup of data before version change."
echo "Backup file: ${DATA_PATH}/backups/${DATE_TIME}_${LEVEL_NAME// /-}_${OLD_VER}_to_${VERSION}.mcworld"
zip -r $DATA_PATH/backups/${DATE_TIME}_${LEVEL_NAME// /-}_${OLD_VER}_to_${VERSION}.mcworld $DATA_PATH/worlds
zip -r "${DATA_PATH}/backups/${DATE_TIME}_${LEVEL_NAME// /-}_${OLD_VER}_to_${VERSION}.mcworld" "${DATA_PATH}/worlds"
fi
fi
}
Expand All @@ -100,12 +107,12 @@ check_symlinks() {
LINK_NAME=$1
if [ ! -L "${SERVER_PATH}/${LINK_NAME}" ]; then
echo "Creating symlink ${SERVER_PATH}/${LINK_NAME} to ${DATA_PATH}/${LINK_NAME}"
ln -s $DATA_PATH/$LINK_NAME $SERVER_PATH/$LINK_NAME
ln -s "${DATA_PATH}/${LINK_NAME}" "${SERVER_PATH}/${LINK_NAME}"
fi
}

#Check EULA
if [[ "x${EULA^^}" != "xTRUE" ]]; then
if [[ "${EULA^^}" != "TRUE" ]]; then
echo "ERROR: EULA variable must be TRUE!"
echo "See https://minecraft.net/terms"
exit 1
Expand All @@ -119,15 +126,15 @@ if [ ! -f "${SERVER_PATH}/${EXEC_NAME}" ]; then
SERVER_INITIALIZED="false"
echo "Initializing new container."
#Determine download version
if [[ "x${VERSION^^}" == "xLATEST" ]]; then
if [[ "${VERSION^^}" == "LATEST" ]]; then
echo "Checking https://www.minecraft.net for latest version number."
get_latest_version
else
if [ ! -f "${ARTIFACTS_PATH}/bedrock-server-${VERSION}.zip" ]; then
download_file $DOWNLOAD_ENDPOINT/bedrock-server-$VERSION.zip $ARTIFACTS_PATH/bedrock-server-$VERSION.zip
download_file "${LINK_NAME}/bedrock-server-${VERSION}.zip" "${ARTIFACTS_PATH}/bedrock-server-${VERSION}.zip"
fi
fi
#Unzip server artifact if $SERVER_PATH doesn't exist
#Unzip server artifact if ${SERVER_PATH} doesn't exist
if [ -f "${ARTIFACTS_PATH}/bedrock-server-${VERSION}.zip" ]; then
extract_server_zip
fi
Expand All @@ -136,22 +143,25 @@ else
SERVER_INITIALIZED="true"
echo "###########################################"
echo "Already initialized. Did container restart?"
VERSION=$(cat $DATA_PATH/version.txt)
VERSION=$(cat "${DATA_PATH}/version.txt")
fi
#Check necessary symlinks
for LINK_NAME in worlds Dedicated_Server.txt ; do
check_symlinks $LINK_NAME
done
#Update server.properties
source $MCBE_HOME/scripts/server-properties.sh
# shellcheck disable=SC1091
source "${MCBE_HOME}/scripts/server-properties.sh"
update_server_properties
#Check permissions & whitelist
source $MCBE_HOME/scripts/permissions-whitelist.sh
check_whitelist
#Check permissions & allowlist
# shellcheck disable=SC1091
source "${MCBE_HOME}/scripts/permissions-allowlist.sh"
check_allowlist
check_permissions
create_cache_files
#Check addons
source $MCBE_HOME/scripts/addons.sh
# shellcheck disable=SC1091
source "${MCBE_HOME}/scripts/addons.sh"
check_addons
#Check pack directories
for PACK_TYPE in behavior_packs resource_packs ; do
Expand All @@ -160,16 +170,16 @@ done

echo "Starting Minecraft Bedrock Server Version ${VERSION} with the following configuration:"
echo "########## SERVER PROPERTIES ##########"
cat $SERVER_PROPERTIES | grep "=" | grep -v "\#" | sort
grep "=" "${SERVER_PROPERTIES}" | grep -v "\#" | sort
echo "###############################"
echo ""
echo "########## PERMISSIONS ##########"
cat $PERMISSIONS_FILE
cat "${PERMISSIONS_FILE}"
echo "#################################"
echo ""
echo "########## WHITELIST ##########"
cat $WHITELIST_FILE
echo "########## ALLOWLIST ##########"
cat "${ALLOWLIST_FILE}"
echo "#################################"
cd $SERVER_PATH/
cd "${SERVER_PATH}"/
export LD_LIBRARY_PATH=.
exec ./$EXEC_NAME
exec ./"${EXEC_NAME}"
Loading

0 comments on commit e4570d7

Please sign in to comment.