Skip to content

Commit 62eb81d

Browse files
authored
Merge pull request #98 from ThePesta/main
Fix discord message server start not being sent
2 parents c7e8579 + d678094 commit 62eb81d

4 files changed

Lines changed: 68 additions & 9 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ ENV PUID=1000 \
120120
DISCORD_PLAYER_LEAVE_COLOR="11477760" \
121121
# Server Start
122122
DISCORD_SERVER_START_ENABLED=true \
123-
DISCORD_SERVER_START_MESSAGE='**World:** ${world_name}\n**GameID:** ${gameid}' \
123+
DISCORD_SERVER_START_MESSAGE="" \
124124
DISCORD_SERVER_START_TITLE="Server Started" \
125125
DISCORD_SERVER_START_COLOR="2013440" \
126126
# Server Stop

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ These are the arguments you can use to customize server behavior with default va
110110
| DISCORD_PLAYER_LEAVE_TITLE | "Player Left" | Embed title |
111111
| DISCORD_PLAYER_LEAVE_COLOR | "11477760" | Embed color |
112112
| DISCORD_SERVER_START_ENABLED | true | Enable/Disable message on server start |
113-
| DISCORD_SERVER_START_MESSAGE | `"**World:** $${world_name}\n**GameID:** $${gameid}"` | Embed message |
113+
| DISCORD_SERVER_START_MESSAGE | `"**World:** $${world_name}\n**GameID:** $${gameid}"` | Embed message. Available variables are `world_name`, `gameid`, (the following only in direct connection mode) `allowed_platforms`, `public_ip`, `port`, `password`, `join_string`|
114114
| DISCORD_SERVER_START_TITLE | "Server Started" | Embed title |
115115
| DISCORD_SERVER_START_COLOR | "2013440" | Embed color |
116116
| DISCORD_SERVER_STOP_ENABLED | true | Enable/Disable message on server stop |

scripts/launch.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function kill_corekeeperserver {
2525
trap kill_corekeeperserver EXIT
2626

2727
if [ -f "GameID.txt" ]; then rm GameID.txt; fi
28+
if [ -f "GameInfo.txt" ]; then rm GameInfo.txt; fi
2829

2930
# Compile Parameters
3031
# Populates `params` array with parameters.

scripts/logfile-parser.sh

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,73 @@ LogParser() {
3737
SendDiscordMessage "$DISCORD_PLAYER_LEAVE_TITLE" "$message" "$DISCORD_PLAYER_LEAVE_COLOR"
3838
fi
3939

40-
if [[ "$line" == "Started session with Game ID "* ]]; then
40+
if [[ "$line" == "Started session with info: "* ]]; then
4141
[[ "${DISCORD_SERVER_START_ENABLED,,}" == false ]] && continue
4242

43-
# Extract Game ID
44-
gameid=$(echo "$line" | awk '{print $6}')
45-
46-
# Build message from vars and send message
47-
message=$(world_name="$WORLD_NAME" gameid="$gameid" envsubst <<<"$DISCORD_SERVER_START_MESSAGE")
48-
SendDiscordMessage "$DISCORD_SERVER_START_TITLE" "$message" "$DISCORD_SERVER_START_COLOR"
43+
sendServerStartMessage &
4944
fi
5045
done
5146
}
47+
48+
sendServerStartMessage() {
49+
game_info="${STEAMAPPDIR}/GameInfo.txt"
50+
game_info_timeout=5
51+
game_info_count=0
52+
53+
LogDebug "Detecting file $game_info (max $game_info_timeout seconds)..."
54+
55+
# GameInfo.txt creation can happen shortly after the log line appears
56+
until [[ -f "$game_info" ]] || [ "$game_info_count" -ge "$game_info_timeout" ]; do
57+
sleep 1
58+
((game_info_count++))
59+
done
60+
61+
if [[ ! -f "$game_info" ]]; then
62+
LogDebug "Failed to detect file $game_info after $game_info_timeout seconds"
63+
else
64+
65+
LogDebug "Detected file $game_info, sending discord server start message"
66+
67+
read -r gameid \
68+
allowed_platforms \
69+
public_ip \
70+
port \
71+
password < <(
72+
awk -F': ' '
73+
BEGIN { gameid=""; allowed_platforms=""; public_ip=""; port=""; password=""; }
74+
/^GameID:/ { gameid=$2 }
75+
/^Allowed platforms:/ { allowed_platforms=$2 }
76+
/^Public IP:/ { public_ip=$2 }
77+
/^Port:/ { port=$2 }
78+
/^Password:/ { password=$2 }
79+
END { print gameid, allowed_platforms, public_ip, port, password }
80+
' "$game_info"
81+
)
82+
83+
if [[ -n "$port" ]]; then # Port will be set in Direct Connection and is empty in Steam Datagram Relay
84+
join_string="${public_ip}:${port}::${password}"
85+
fi
86+
87+
if [[ -n "$DISCORD_SERVER_START_MESSAGE" ]]; then
88+
start_message_template="$DISCORD_SERVER_START_MESSAGE"
89+
elif [[ -n "$port" ]]; then
90+
start_message_template='**World:** ${world_name}\n**GameID:** ${gameid}\n**Allowed Platforms:** ${allowed_platforms}\n**Server IP:** ${public_ip}\n**Port:** ${port}\n**Password:** ${password}\n**Join String:** ${join_string}'
91+
else
92+
start_message_template='**World:** ${world_name}\n**GameID:** ${gameid}'
93+
fi
94+
95+
# Build message from vars and send message
96+
message=$(
97+
world_name="$WORLD_NAME" \
98+
gameid="$gameid" \
99+
allowed_platforms="$allowed_platforms" \
100+
public_ip="$public_ip" \
101+
port="$port" \
102+
password="$password" \
103+
join_string="$join_string" \
104+
envsubst <<<"$start_message_template"
105+
)
106+
107+
SendDiscordMessage "$DISCORD_SERVER_START_TITLE" "$message" "$DISCORD_SERVER_START_COLOR"
108+
fi
109+
}

0 commit comments

Comments
 (0)