Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2024-02-22 #220

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

[Back to main](README.md#changelog)

## 2024-02-22

- Added RCON-Based player detection, for join and leave messages on console, rcon-broadcast and webhooks (#216)
- Important change: RCON is now on by default, was false in the Dockerfile before, not considered a breaking change

## 2024-02-21

- Fixed major CVEs and added re-compiled gosu-amd64 binary to the repository (#214 #215)
Expand Down
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ ENV DEBIAN_FRONTEND=noninteractive \
# Restart-settings
RESTART_ENABLED=false \
RESTART_CRON_EXPRESSION="0 18 * * *" \
# RCON-Playerdection - NEEDS RCON ENABLED!
RCON_PLAYER_DETECTION=true \
RCON_PLAYER_DETECTION_STARTUP_DELAY=60 \
RCON_PLAYER_DETECTION_CHECK_INTERVAL=15 \
# Webhook-settings
WEBHOOK_ENABLED=false \
WEBHOOK_DEBUG_ENABLED=false \
Expand Down Expand Up @@ -156,7 +160,7 @@ ENV DEBIAN_FRONTEND=noninteractive \
SERVER_PASSWORD=serverPasswordHere \
PUBLIC_PORT=8211 \
PUBLIC_IP= \
RCON_ENABLED=false \
RCON_ENABLED=true \
RCON_PORT=25575 \
REGION= \
USEAUTH=true \
Expand Down
4 changes: 4 additions & 0 deletions default.env
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ BACKUP_RETENTION_AMOUNT_TO_KEEP=72
# Restart-settings
RESTART_ENABLED=false
RESTART_CRON_EXPRESSION="0 18 * * *"
# RCON-Playerdection - NEEDS RCON ENABLED!
RCON_PLAYER_DETECTION=true
RCON_PLAYER_DETECTION_STARTUP_DELAY=60
RCON_PLAYER_DETECTION_CHECK_INTERVAL=15
# Webhook-settings
WEBHOOK_ENABLED=false
WEBHOOK_DEBUG_ENABLED=false
Expand Down
50 changes: 30 additions & 20 deletions docs/ENV_VARS.md

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions includes/playerdetection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# shellcheck disable=SC2148,SC1091

source /includes/colors.sh
source /includes/rcon.sh
source /includes/webhook.sh

player_detection_loop() {
sleep "$RCON_PLAYER_DETECTION_STARTUP_DELAY"
while true; do
compare_players
sleep "$RCON_PLAYER_DETECTION_CHECK_INTERVAL"
done
}

# Function to compare current and previous player lists
compare_players() {
local old_players=("${current_players[@]}")
readarray -t current_players < <(rcon showplayers | tail -n +2 | awk -F ',' '{print $1}')

for player in "${current_players[@]}"; do
local found=false
for old_player in "${old_players[@]}"; do
if [ "$old_player" = "$player" ]; then
found=true
break
fi
done
if ! $found; then
announce_join "$player"
fi
done
for player in "${old_players[@]}"; do
local found=false
for current_player in "${current_players[@]}"; do
if [ "$current_player" = "$player" ]; then
found=true
break
fi
done
if ! $found; then
announce_leave "$player"
fi
done
}

# Function to announce a player join
announce_join() {
time=$(date '+%H:%M:%S')
message="Player $1 has joined the server."
echo "${time}: $message"
if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then
send_player_join_notification "$message"
fi
if [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then
broadcast_player_join "$1"
fi
}

# Function to announce a player leave
announce_leave() {
time=$(date '+%H:%M:%S')
message="Player $1 has left the server."
echo "${time}: $message"
if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then
send_player_leave_notification "$message"
fi
if [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then
broadcast_player_leave "$1"
fi
}
10 changes: 10 additions & 0 deletions includes/rcon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,14 @@ function broadcast_backup_success() {

function broadcast_backup_failed() {
rconcli 'broadcast Backup-failed'
}

function broadcast_player_join() {
time=$(date '+%H:%M:%S')
rconcli "broadcast ${time}-Player-$1-has-joined-the-server"
}

function broadcast_player_leave() {
time=$(date '+%H:%M:%S')
rconcli "broadcast ${time}-Player-$1-has-left-the-server"
}
6 changes: 6 additions & 0 deletions includes/webhook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ send_stop_notification() {
send_update_notification() {
send_webhook_notification "$WEBHOOK_UPDATE_TITLE" "$WEBHOOK_UPDATE_DESCRIPTION" "$WEBHOOK_UPDATE_COLOR"
}
send_player_join_notification() {
send_webhook_notification "$WEBHOOK_INFO_TITLE" "$1" "$WEBHOOK_INFO_COLOR"
}
send_player_leave_notification() {
send_webhook_notification "$WEBHOOK_INFO_TITLE" "$1" "$WEBHOOK_INFO_COLOR"
}
5 changes: 5 additions & 0 deletions scripts/servermanager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set -e
source /includes/colors.sh
source /includes/config.sh
source /includes/cron.sh
source /includes/playerdetection.sh
source /includes/security.sh
source /includes/server.sh
source /includes/webhook.sh
Expand Down Expand Up @@ -43,6 +44,10 @@ do
e "> Started at: $current_date $current_time"
start_main &

if [[ -n $RCON_PLAYER_DETECTION ]] && [[ $RCON_PLAYER_DETECTION == "true" ]] && [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then
player_detection_loop &
fi

killpid="$!"
e "> Server main thread started with pid ${killpid}"
wait ${killpid}
Expand Down