-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: christopher blodgett <christopher.blodgett@gmail.com>
- Loading branch information
Showing
8 changed files
with
197 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
version: '3' | ||
|
||
services: | ||
minecraft: | ||
image: ${IMAGE_TO_TEST:-itzg/minecraft-server} | ||
ports: | ||
- "25565:25565" | ||
volumes: | ||
- "mc:/data" | ||
environment: | ||
EULA: "TRUE" | ||
# YAML Heredoc, be sure to use '|-' this will remove the first newline and final new line. | ||
# This is versus '|' that will leaving with two empty strings at top and bottom. | ||
RCON_CMDS_STARTUP: |- | ||
/gamerule doFireTick false | ||
/team add New | ||
/team add Old | ||
RCON_CMDS_ON_CONNECT: |- | ||
/team join New @a[team=] | ||
/give @a[team=New] diamond_block | ||
/team join Old @a[team=New] | ||
restart: unless-stopped | ||
volumes: | ||
mc: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/bin/bash | ||
|
||
: "${RCON_CMDS_STARTUP:=}" | ||
: "${RCON_CMDS_ON_CONNECT:=}" | ||
: "${RCON_CMDS_ON_DISCONNECT:=}" | ||
: "${RCON_CMDS_PERIOD:=10}" | ||
|
||
# needed for the clients connected function residing in autopause | ||
# shellcheck source=/autopause/autopause-fcns.sh | ||
. /autopause/autopause-fcns.sh | ||
|
||
# shellcheck source=start-utils | ||
. ${SCRIPTS:-/}start-utils | ||
|
||
run_command(){ | ||
rcon_cmd="$1" | ||
logRcon "running - $rcon_cmd" | ||
output=$(rcon-cli "$rcon_cmd") | ||
logRcon "$output" | ||
} | ||
|
||
|
||
# wait for java process to be started | ||
while : | ||
do | ||
if java_process_exists ; then | ||
break | ||
fi | ||
sleep 0.1 | ||
done | ||
|
||
CLIENTCONNECTIONS=0 | ||
STATE=INIT | ||
|
||
while : | ||
do | ||
case X$STATE in | ||
XINIT) | ||
# Server startup | ||
if mc_server_listening ; then | ||
logRcon "MCServer is listening, running startup" | ||
if [[ "$RCON_CMDS_STARTUP" ]]; then | ||
while read -r cmd; do | ||
run_command "$cmd" | ||
done <<< "$RCON_CMDS_STARTUP" | ||
fi | ||
if [[ -z "$RCON_CMDS_ON_CONNECT" ]] && [[ -z "$RCON_CMDS_ON_DISCONNECT" ]]; then | ||
logRcon "No addition rcon commands are given, stopping rcon cmd service" | ||
exit 0 | ||
fi | ||
STATE=II | ||
fi | ||
;; | ||
XII) | ||
# Main Loop looking for connections | ||
CURR_CLIENTCONNECTIONS=$(java_clients_connections) | ||
if (( CURR_CLIENTCONNECTIONS > CLIENTCONNECTIONS )) && [[ "$RCON_CMDS_ON_CONNECT" ]]; then | ||
logRcon "Clients have Connected, running connect cmds" | ||
while read -r cmd; do | ||
run_command "$cmd" | ||
done <<< "$RCON_CMDS_ON_CONNECT" | ||
elif (( CURR_CLIENTCONNECTIONS < CLIENTCONNECTIONS )) && [[ "$RCON_CMDS_ON_DISCONNECT" ]]; then | ||
logRcon "Clients have Disconnected, running disconnect cmds" | ||
while read -r cmd; do | ||
run_command "$cmd" | ||
done <<< "$RCON_CMDS_ON_DISCONNECT" | ||
fi | ||
CLIENTCONNECTIONS=$CURR_CLIENTCONNECTIONS | ||
;; | ||
*) | ||
logRcon "Error: invalid state: $STATE" | ||
;; | ||
esac | ||
sleep "$RCON_CMDS_PERIOD" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
# shellcheck source=start-utils | ||
. "${SCRIPTS:-/}start-utils" | ||
|
||
: "${RCON_CMDS_STARTUP:=}" | ||
: "${RCON_CMDS_ON_CONNECT:=}" | ||
: "${RCON_CMDS_ON_DISCONNECT:=}" | ||
: "${RCON_CMDS_PERIOD:=10}" | ||
: "${SERVER_PORT:=25565}" | ||
export RCON_CMDS_STARTUP | ||
export RCON_CMDS_ON_CONNECT | ||
export RCON_CMDS_ON_DISCONNECT | ||
export RCON_CMDS_PERIOD | ||
export SERVER_PORT | ||
|
||
log "Rcon cmds functionality enabled" | ||
|
||
isDebugging && set -x | ||
|
||
if ! [[ $RCON_CMDS_PERIOD =~ ^[0-9]+$ ]]; then | ||
RCON_CMDS_PERIOD=10 | ||
export RCON_CMDS_PERIOD | ||
log "Warning: RCON_CMDS_PERIOD is not numeric, set to 10 (seconds)" | ||
fi | ||
if [ "$RCON_CMDS_PERIOD" -eq "0" ] ; then | ||
RCON_CMDS_PERIOD=10 | ||
export RCON_CMDS_PERIOD | ||
log "Warning: RCON_CMDS_PERIOD must not be 0, set to 10 (seconds)" | ||
fi | ||
|
||
/rconcmds/rcon-cmds-daemon.sh & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters