129 lines
3.0 KiB
Bash
Executable File
129 lines
3.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# port of the server in standalone mode, aka the open port
|
|
STANDALONE_PORT=25565
|
|
# port of the server in proxy mode, aka the internal port
|
|
PROXY_PORT=25566
|
|
|
|
function main {
|
|
|
|
# parse arguments
|
|
velocity=false
|
|
bungeecord=false
|
|
standalone=false
|
|
fetch=false
|
|
help=false
|
|
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
"velocity")
|
|
velocity=true
|
|
if $bungeecord || $standalone; then
|
|
echo "argument velocity can't be used together with bungeecord or standalone"
|
|
exit 1
|
|
fi
|
|
;;
|
|
"bungeecord")
|
|
bungeecord=true
|
|
if $velocity || $standalone; then
|
|
echo "argument bungeecord can't be used together with velocity or standalone"
|
|
exit 1
|
|
fi
|
|
;;
|
|
"standalone")
|
|
standalone=true
|
|
if $bungeecord || $velocity; then
|
|
echo "argument standalone can't be used together with bungeecord or velocity"
|
|
exit 1
|
|
fi
|
|
;;
|
|
"--fetch")
|
|
fetch=true
|
|
;;
|
|
"--help")
|
|
help=true
|
|
;;
|
|
*)
|
|
echo "Unknown argument: $arg"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if $help; then
|
|
echo "Configure the server to be used with BungeeCord, Velcity or in standalone mode."
|
|
echo ""
|
|
echo "Usage: $0 [OPTIONS] <mode>"
|
|
echo ""
|
|
echo "mode:"
|
|
echo " velocity"
|
|
echo " bungeecord"
|
|
echo " standalone"
|
|
echo ""
|
|
echo "OPTIONS:"
|
|
echo " --fetch - print the current mode before reconfiguring the server. Nothing else will be printed."
|
|
echo " --help - show this message"
|
|
exit 0
|
|
fi
|
|
|
|
# fetch current configuration
|
|
if $fetch; then
|
|
if [ "$(yq '.proxies.velocity.enabled // false' config/paper-global.yml)" = "true" ]; then
|
|
echo "velocity"
|
|
elif [ "$(yq '.settings.bungeecord // false' spigot.yml)" = "true" ]; then
|
|
echo "bungeecord"
|
|
else
|
|
echo "standalone"
|
|
fi
|
|
fi
|
|
|
|
# Do the actual configuration
|
|
if $velocity; then
|
|
enable_online_mode false
|
|
set_port "$PROXY_PORT"
|
|
enable_velocity true
|
|
enable_bungeecord false
|
|
elif $bungeecord; then
|
|
enable_online_mode false
|
|
set_port "$PROXY_PORT"
|
|
enable_velocity false
|
|
enable_bungeecord true
|
|
elif $standalone; then
|
|
enable_online_mode true
|
|
set_port "$STANDALONE_PORT"
|
|
enable_velocity false
|
|
enable_bungeecord false
|
|
fi
|
|
}
|
|
|
|
# Enables or disables online mode
|
|
#
|
|
# Usage: enable_online_mode <true|false>
|
|
function enable_online_mode {
|
|
sed -ie "/online-mode/c\online-mode=$1" server.properties
|
|
}
|
|
|
|
# Set the port of the server
|
|
#
|
|
# Usage: set_port <port>
|
|
function set_port {
|
|
sed -ie "/server-port/c\server-port=$1" server.properties
|
|
}
|
|
|
|
# Enables or disables velocity in the paper config.
|
|
# Does NOT configure the forwarding secret!
|
|
#
|
|
# Usage: enable_velocity <true|false>
|
|
function enable_velocity {
|
|
yq -iy ".proxies.velocity.enabled = $1" config/paper-global.yml
|
|
}
|
|
|
|
# Enables or disables bungeecord in spigot.yml.
|
|
#
|
|
# Usage: enable_bungeecord <true|false>
|
|
function enable_bungeecord {
|
|
yq -iy ".settings.bungeecord = $1" spigot.yml
|
|
}
|
|
|
|
main "$@"
|