Skip to content

Commit

Permalink
Merge pull request thijsvanloef#487 from xHyperElectric/Discord-Playe…
Browse files Browse the repository at this point in the history
…r-Logging

Add Discord player logging to notify when players join and leave the server
  • Loading branch information
thijsvanloef authored Mar 5, 2024
2 parents e789b00 + 6116531 commit 38bbaf7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ ENV HOME=/home/steam \
DISCORD_PRE_START_MESSAGE="Server has been started!" \
DISCORD_PRE_SHUTDOWN_MESSAGE="Server is shutting down..." \
DISCORD_POST_SHUTDOWN_MESSAGE="Server has been stopped!" \
DISCORD_PLAYER_JOIN_MESSAGE="\${player_name} has joined Palworld!" \
DISCORD_PLAYER_LEAVE_MESSAGE="\${player_name} has left Palworld." \
ENABLE_PLAYER_LOGGING=true \
PLAYER_LOGGING_POLL_PERIOD=5 \
ARM_COMPATIBILITY_MODE=false \
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ It is highly recommended you set the following environment values before startin
| OLD_BACKUP_DAYS | How many days to keep backups | 30 | any positive integer |
| AUTO_UPDATE_CRON_EXPRESSION | Setting affects frequency of automatic updates. | 0 \* \* \* \* | Needs a Cron-Expression - See [Configuring Automatic Backups with Cron](#configuring-automatic-backups-with-cron) |
| AUTO_UPDATE_ENABLED | Enables automatic updates | false | true/false |
| AUTO_UPDATE_WARN_MINUTES | How long to wait to update the server, after the player were informed. (This will be ignored, if no Players are connected) | 30 | Integer |
| AUTO_UPDATE_WARN_MINUTES | How long to wait to update the server, after the player were informed. (This will be ignored, if no Players are connected) | 30 | Integer |
| AUTO_REBOOT_CRON_EXPRESSION | Setting affects frequency of automatic updates. | 0 0 \* \* \* | Needs a Cron-Expression - See [Configuring Automatic Backups with Cron](#configuring-automatic-reboots-with-cron) |
| AUTO_REBOOT_ENABLED | Enables automatic reboots | false | true/false |
| AUTO_REBOOT_WARN_MINUTES | How long to wait to reboot the server, after the player were informed. | 5 | Integer |
| AUTO_REBOOT_WARN_MINUTES | How long to wait to reboot the server, after the player were informed. | 5 | Integer |
| AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE | Restart the Server even if there are players online. | false | true/false |
| TARGET_MANIFEST_ID | Locks game version to corespond with Manifest ID from Steam Download Depot. | | See [Manifest ID Table](#locking-specific-game-version) |
| TARGET_MANIFEST_ID | Locks game version to corespond with Manifest ID from Steam Download Depot. | | See [Manifest ID Table](#locking-specific-game-version) |
| DISCORD_WEBHOOK_URL | Discord webhook url found after creating a webhook on a discord server | | `https://discord.com/api/webhooks/<webhook_id>` |
| DISCORD_CONNECT_TIMEOUT | Discord command initial connection timeout | 30 | !0 |
| DISCORD_MAX_TIMEOUT | Discord total hook timeout | 30 | !0 |
Expand All @@ -240,8 +240,10 @@ It is highly recommended you set the following environment values before startin
| DISCORD_PRE_START_MESSAGE | Discord message sent when server begins to start | Server is started! | "string" |
| DISCORD_PRE_SHUTDOWN_MESSAGE | Discord message sent when server begins to shutdown | Server is shutting down... | "string" |
| DISCORD_POST_SHUTDOWN_MESSAGE | Discord message sent when server has stopped | Server is stopped! | "string" |
| DISCORD_PLAYER_JOIN_MESSAGE | Discord message sent when player joins the server | \${player_name} has joined Palworld! | "string" |
| DISCORD_PLAYER_LEAVE_MESSAGE | Discord message sent when player leaves the server | \${player_name} has left Palworld. | "string" |
| DISABLE_GENERATE_SETTINGS | Whether to automatically generate the PalWorldSettings.ini | false | true/false |
| DISABLE_GENERATE_ENGINE | Whether to automatically generate the Engine.ini | true | true/false |
| DISABLE_GENERATE_ENGINE | Whether to automatically generate the Engine.ini | true | true/false |
| ENABLE_PLAYER_LOGGING | Enables Logging and announcing when players join and leave | true | true/false |
| PLAYER_LOGGING_POLL_PERIOD | Polling period (in seconds) to check for players who have joined or left | 5 | !0 |
| ARM_COMPATIBILITY_MODE | Switches the compatibility layer from Box86 to QEMU when executing steamcmd for server updates. This setting is only applicable for ARM64 hosts. | false | true/false |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ It is highly recommended you set the following environment values before startin
| DISCORD_PRE_START_MESSAGE | Discord message sent when server begins to start | Server is started! | "string" |
| DISCORD_PRE_SHUTDOWN_MESSAGE | Discord message sent when server begins to shutdown | Server is shutting down... | "string" |
| DISCORD_POST_SHUTDOWN_MESSAGE | Discord message sent when server has stopped | Server is stopped! | "string" |
| DISCORD_PLAYER_JOIN_MESSAGE | Discord message sent when player joins the server | \$\{player_name\} has joined Palworld! | "string" |
| DISCORD_PLAYER_LEAVE_MESSAGE | Discord message sent when player leaves the server | \$\{player_name\} has left Palworld. | "string" |
| DISABLE_GENERATE_SETTINGS | Whether to automatically generate the PalWorldSettings.ini | false | true/false |
| DISABLE_GENERATE_ENGINE | Whether to automatically generate the Engine.ini | true | true/false |
| ENABLE_PLAYER_LOGGING | Enables Logging and announcing when players join and leave | true | true/false |
Expand Down
10 changes: 8 additions & 2 deletions scripts/player_logging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,24 @@ while true; do
<(printf '%s\n' "${current_player_list[@]}") )
fi

# Log all players who have left
# Notify Discord and log all players who have left
for player in "${players_who_left_list[@]}"; do
player_name=$( get_playername "${player}" )
LogInfo "${player_name} has left"
broadcast_command "${player_name} has left"

# Replace ${player_name} with actual player's name
DiscordMessage "Player Left" "${DISCORD_PLAYER_LEAVE_MESSAGE//\$\{player_name\}/${player_name}}" "failure"
done

# Log all players who have joined
# Notify Discord and log all players who have joined
for player in "${players_who_joined_list[@]}"; do
player_name=$( get_playername "${player}" )
LogInfo "${player_name} has joined"
broadcast_command "${player_name} has joined"

# Replace ${player_name} with actual player's name
DiscordMessage "Player Joined" "${DISCORD_PLAYER_JOIN_MESSAGE//\$\{player_name\}/${player_name}}" "success"
done

old_player_list=("${current_player_list[@]}")
Expand Down

0 comments on commit 38bbaf7

Please sign in to comment.