From e217ac503ecd5a2987061e2e1acc0229bcba01a9 Mon Sep 17 00:00:00 2001 From: Metalcape Date: Sun, 12 Mar 2023 19:40:35 +0100 Subject: [PATCH] Use modified knockd to set a cooldown on port 19132 (#2003) --- Dockerfile | 5 +++++ build/alpine/install-packages.sh | 4 ++-- build/ol/install-packages.sh | 2 +- build/ubuntu/install-packages.sh | 6 +++--- files/auto/autopause-daemon.sh | 2 +- files/auto/knockd-config.cfg | 1 + files/sudoers-mc | 2 +- scripts/start-autopause | 5 +++++ 8 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 275cf21..fae23a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,6 +52,11 @@ RUN curl -fsSL ${MC_HELPER_BASE_URL}/mc-image-helper-${MC_HELPER_VERSION}.tgz \ | tar -C /usr/share -zxf - \ && ln -s /usr/share/mc-image-helper-${MC_HELPER_VERSION}/bin/mc-image-helper /usr/bin +# Install modified knockd +ADD https://github.com/Metalcape/knock/releases/download/0.8.1/knock-0.8.1-${TARGETARCH}${TARGETVARIANT}.tar.gz /tmp/knock.tar.gz +RUN tar -xf /tmp/knock.tar.gz -C /usr/local/ && rm /tmp/knock.tar.gz +RUN find /usr/lib -name 'libpcap.so.0.8' -execdir cp '{}' libpcap.so.1 \; + VOLUME ["/data"] WORKDIR /data diff --git a/build/alpine/install-packages.sh b/build/alpine/install-packages.sh index fc2ffb8..4c11691 100755 --- a/build/alpine/install-packages.sh +++ b/build/alpine/install-packages.sh @@ -21,7 +21,7 @@ apk add --no-cache -U \ rsync \ nano \ sudo \ - knock \ tar \ zstd \ - nfs-utils \ No newline at end of file + nfs-utils \ + libpcap diff --git a/build/ol/install-packages.sh b/build/ol/install-packages.sh index e8eeadf..eab5e56 100755 --- a/build/ol/install-packages.sh +++ b/build/ol/install-packages.sh @@ -33,6 +33,6 @@ dnf install -y ImageMagick \ unzip \ zstd \ lbzip2 \ - knock + libpcap bash /build/ol/install-gosu.sh diff --git a/build/ubuntu/install-packages.sh b/build/ubuntu/install-packages.sh index f5ed4d0..d7b8822 100755 --- a/build/ubuntu/install-packages.sh +++ b/build/ubuntu/install-packages.sh @@ -23,7 +23,7 @@ apt-get install -y \ unzip \ zstd \ lbzip2 \ - knockd \ - nfs-common + nfs-common \ + libpcap0.8 -apt-get clean \ No newline at end of file +apt-get clean diff --git a/files/auto/autopause-daemon.sh b/files/auto/autopause-daemon.sh index 1cbfcdb..be88403 100644 --- a/files/auto/autopause-daemon.sh +++ b/files/auto/autopause-daemon.sh @@ -45,7 +45,7 @@ if isTrue "${DEBUG_AUTOPAUSE}"; then knockdArgs+=(-D) fi -sudo /usr/sbin/knockd "${knockdArgs[@]}" +sudo /usr/local/sbin/knockd "${knockdArgs[@]}" if [ $? -ne 0 ] ; then logAutopause "Failed to start knockd daemon." logAutopause "Probable cause: Unable to attach to interface \"$AUTOPAUSE_KNOCK_INTERFACE\"." diff --git a/files/auto/knockd-config.cfg b/files/auto/knockd-config.cfg index 0334ad0..1c54cc4 100644 --- a/files/auto/knockd-config.cfg +++ b/files/auto/knockd-config.cfg @@ -13,3 +13,4 @@ [unpauseMCServer-bedrock] sequence = 19132:udp command = /auto/resume.sh %IP% + seq_cooldown = 60 diff --git a/files/sudoers-mc b/files/sudoers-mc index 2869c23..bc0c19c 100644 --- a/files/sudoers-mc +++ b/files/sudoers-mc @@ -1,2 +1,2 @@ minecraft ALL=(ALL) NOPASSWD:/usr/bin/pkill -minecraft ALL=(ALL) NOPASSWD:/usr/sbin/knockd +minecraft ALL=(ALL) NOPASSWD:/usr/local/sbin/knockd diff --git a/scripts/start-autopause b/scripts/start-autopause index 66fbbe6..59d5c76 100755 --- a/scripts/start-autopause +++ b/scripts/start-autopause @@ -84,4 +84,9 @@ elif [[ -z "$MAX_TICK_TIME" ]] ; then export MAX_TICK_TIME fi +# seq_cooldown cannot be larger than AUTOPAUSE_TIMEOUT_KN, otherwise the server may +# become paused while knockd is still ignoring packets, preventing players from joining. +let COOLDOWN=$AUTOPAUSE_TIMEOUT_KN/2 +sed -i "s/\(seq_cooldown *= *\).*/\1$COOLDOWN/" /tmp/knockd-config.cfg + /auto/autopause-daemon.sh &