Skip to content

Commit

Permalink
Added updated changelogs, refactored webhook.sh, fixed #226, fixed #227
Browse files Browse the repository at this point in the history
…, fixed #228 regarding player-detection edge-cases
  • Loading branch information
jammsen committed Feb 23, 2024
1 parent c3cc831 commit c7b4e7e
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 19 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@

- Added new SERVER_SETTINGS_MODE called "rcononly" this will only setup up RCON, everything else is still manually to set (#221)
- Added RESTART_DEBUG_OVERRIDE for local testing
- Fixed expansion-bug from #224 by @Dashboy1998
- Fixed expansion-bug from #224 & #225 by @Dashboy1998
- Refactoring of code-duplication in webhook.sh
- Extended fixing for edge-cases of playernames from #226, #227 & #228
- Default mechanic checks more steamid oriented, not comparing playernames directly
- Added mechanic for playername changes and temporary characters which are still in char-creation screen
- Also cut down on text in the announces on RCON, because messages can only be 40 chars long
- Stripped all special-chars from playername, using TR class [:alnum:] meaning only a-zA-z0-9 are valid

## 2024-02-22

Expand Down
149 changes: 137 additions & 12 deletions includes/playerdetection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,183 @@ player_detection_loop() {
sleep "$RCON_PLAYER_DETECTION_CHECK_INTERVAL"
done
}
#v1
# # 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}')

# Function to compare current and previous player lists
# 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
# }

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

# for player_info in "${current_players[@]}"; do
# # Extract player name, UID, and Steam ID from player info
# IFS=',' read -r name playeruid steamid <<< "$player_info"
# ew "$name"
# ew "$playeruid"
# ew "$steamid"

# local found=false
# for old_player_info in "${old_players[@]}"; do
# IFS=',' read -r old_name old_playeruid old_steamid <<< "$old_player_info"
# ew "$old_name"
# ew "$old_playeruid"
# ew "$old_steamid"
# if [[ "$old_steamid" == "$steamid" ]]; then
# found=true
# if [[ "$old_playeruid" == "00000000" && "$playeruid" != "00000000" ]]; then
# announce_name_change "$old_name" "$name"
# fi
# break
# fi
# done
# if ! $found; then
# announce_join "$name"
# fi
# done

# for old_player_info in "${old_players[@]}"; do
# IFS=',' read -r old_name old_playeruid old_steamid <<< "$old_player_info"
# local found=false
# for player_info in "${current_players[@]}"; do
# IFS=',' read -r name playeruid steamid <<< "$player_info"
# if [[ "$old_steamid" == "$steamid" ]]; then
# found=true
# break
# fi
# done
# if ! $found; then
# announce_leave "$old_name"
# fi
# done
# }

#v3
# 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}')
readarray -t current_players < <(rcon showplayers | tail -n +2)

for player_info in "${current_players[@]}"; do
# Extract player name, UID, and Steam ID from player info
IFS=',' read -r -a player_data <<< "$player_info"
local steamid="${player_data[-1]}"
local playeruid="${player_data[-2]}"
local name="${player_data[*]::${#player_data[@]}-2}"

# Strip special characters from the player name
name="$(echo "$name" | tr -cd '[:alnum:]')"

for player in "${current_players[@]}"; do
local found=false
for old_player in "${old_players[@]}"; do
if [ "$old_player" = "$player" ]; then
for old_player_info in "${old_players[@]}"; do
IFS=',' read -r -a old_player_data <<< "$old_player_info"
local old_steamid="${old_player_data[-1]}"
local old_playeruid="${old_player_data[-2]}"
local old_name="${old_player_data[*]::${#old_player_data[@]}-2}"

# Strip special characters from the old player name
old_name="$(echo "$old_name" | tr -cd '[:alnum:]')"

if [[ "$old_steamid" == "$steamid" ]]; then
found=true
if [[ "$old_playeruid" == "00000000" && "$playeruid" != "00000000" ]]; then
announce_name_change "$old_name" "$name"
fi
break
fi
done
if ! $found; then
announce_join "$player"
announce_join "$name"
fi
done
for player in "${old_players[@]}"; do

for old_player_info in "${old_players[@]}"; do
IFS=',' read -r -a old_player_data <<< "$old_player_info"
local old_steamid="${old_player_data[-1]}"
local old_playeruid="${old_player_data[-2]}"
local old_name="${old_player_data[*]::${#old_player_data[@]}-2}"

# Strip special characters from the old player name
old_name="$(echo "$old_name" | tr -cd '[:alnum:]')"

local found=false
for current_player in "${current_players[@]}"; do
if [ "$current_player" = "$player" ]; then
for player_info in "${current_players[@]}"; do
IFS=',' read -r -a player_data <<< "$player_info"
local steamid="${player_data[-1]}"
if [[ "$old_steamid" == "$steamid" ]]; then
found=true
break
fi
done
if ! $found; then
announce_leave "$player"
announce_leave "$old_name"
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"
send_info_notification "$message"
fi
if [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then
broadcast_player_join "${1// /\-}"
fi
}

# Function to announce a player join
announce_name_change() {
time=$(date '+%H:%M:%S')
message="Player $1 has changed their name to $2."
echo "${time}: $message"
if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then
send_info_notification "$message"
fi
if [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then
broadcast_player_name_change "${1// /\-}" "${2// /\-}"
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"
send_info_notification "$message"
fi
if [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then
broadcast_player_leave "${1// /\-}"
Expand Down
9 changes: 7 additions & 2 deletions includes/rcon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ function broadcast_backup_failed() {

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

function broadcast_player_name_change() {
time=$(date '+%H:%M:%S')
rconcli "broadcast ${time}-$1-renamed-to-$2"
}

function broadcast_player_leave() {
time=$(date '+%H:%M:%S')
rconcli "broadcast ${time}-Player-$1-has-left-the-server"
rconcli "broadcast ${time}-$1-left-the-server"
}
5 changes: 1 addition & 4 deletions includes/webhook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ 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_info_notification() {
send_webhook_notification "$WEBHOOK_INFO_TITLE" "$1" "$WEBHOOK_INFO_COLOR"
}

0 comments on commit c7b4e7e

Please sign in to comment.