From 766761b40a8b51012e38aaa90b8a49547398a028 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Sat, 20 Feb 2021 15:06:19 +0100 Subject: [PATCH] Add mapserver --- README | 24 +++++++---- scripts/common.sh | 105 ++++++++++++++++++++++++++------------------- scripts/console.sh | 20 +++++---- scripts/restart.sh | 25 ++++++++--- scripts/setup.sh | 6 +++ scripts/start.sh | 25 ++++++++--- scripts/stop.sh | 27 +++++++++--- 7 files changed, 156 insertions(+), 76 deletions(-) diff --git a/README b/README index 6ca1b5f..55ba288 100644 --- a/README +++ b/README @@ -9,20 +9,22 @@ The goal of Elidragon v2 is to provide a server similar to popular Minecraft ser Minetest does not support "server-hopping" natively; therefore the multiserver proxy written in Go by HimbeerserverDE is used. multiserver depends on mt rudp by anon55555. +For the creative map, minetest mapserver is used. + Elidragon v2 runs on top of the latest git version of MineClone2, and the lastest stable release of minetest. Quick guide for installation and running ---------------------------------------- -Elidragon v2 requires a GNU/Linux system to run. The setup and update scripts rely on apt and sudo. Go 1.15 or higher is required. +Elidragon v2 requires a GNU/Linux x86_64 system to run. The setup and update scripts rely on apt and sudo. Go 1.15 or higher is required. The ports 33000, 30030, 30031, 30032, 30033 and 8080 need to be open. 1. Create a new user using adduser and switch to it. The user should be able to use sudo. 2. git clone this repository into that user's home directory and rename it to .minetest 3. cd into .minetest -4. run scripts/setup.sh - this will automatically install minetest and screen. Also, it initialized the submodules - all external mods and MineClone2 are installed automatically. It will also install multiserver and its dependencies. -5. run scripts/start.sh - this will automatically start all worlds and multiserver. If one world or multiserver crashes / shuts down it will automatically restart. +4. run scripts/setup.sh - this will automatically install minetest and screen. Also, it initialized the submodules - all external mods and MineClone2 are installed automatically. It will also install mapserver, multiserver and its dependencies. +5. run scripts/start.sh --all - this will automatically start all worlds, multiserver and mapserver. If one world or multiserver / mapserver crashes or shuts down it will automatically restarted. -To update, run scripts/update.sh, to restart all worlds and multiserver run scripts/restart.sh and to stop all worlds and multiserver run scripts/stop.sh +To update, run scripts/update.sh, to restart all worlds run scripts/restart.sh --worlds and to stop all worlds and multiserver run scripts/stop.sh --all. Organisation structure ------------------- @@ -34,17 +36,17 @@ Scripts For many tasks it is recommended to use the scripts from the scripts/ directory. All scripts need to be run from the root path of this repository. -scripts/setup.sh: This will install minetest and screen using sudo apt. For minetest a apt repository is added that is up to date (the official repos are often one or two versions behind). It will use go to install multiserver, also it will init and update the submodules, which is very important because all external mods are added as submodules. +scripts/setup.sh: This will install minetest and screen using sudo apt. For minetest a apt repository is added that is up to date (the official repos are often one or two versions behind). It will use go to install multiserver and mapserver, also it will init and update the submodules, which is very important because all external mods are added as submodules. scripts/update.sh: This will pull the repository including all submodules. Also, it will update minetest, screen and multiserver. -scripts/start.sh: You can use this to start one or all worlds from the worlds folder. If you pass an argument to it, it will start the specified world, else it will start everything. You can use this script even if some worlds are already running. The worlds will be started in a hidden screen and restarted when killed, shut down using /shutdown or crash. Any started world will have a lock file in the /tmp directory that contains the PID of the current minetest process. When the world is stopped, the lock file is deleted. If --multiserver is used, multiserver is started instead of any worlds, and if all worlds are started, multiserver is started as well. +scripts/start.sh | multiserver | mapserver | --all | --worlds: You can use this to start one or all worlds from the worlds folder, or the mapserver / multiserver. When --all is used it will start everything, --worlds starts all worlds. You can use --all or --world even if some tasks that would be started by it are already running. All tasks will be started in a hidden screen and restarted when killed, shut down using /shutdown or they crash. Any started task will have a lock file in the /tmp directory that contains the PID of the current process. When the task is stopped, the lock file is deleted. -scripts/stop.sh: You can use this to stop one or all worlds from the worlds folder started using the start script. If you pass an argument to it, it will stop the specified world, else it will stop everything. You can use this script even if some worlds are not running. If --multiserver is used, multiserver is stopped instead of any worlds, and if all worlds are stopped, multiserver is stopped as well. +scripts/stop.sh | multiserver | mapserver | --all | --worlds: You can use this to stop one or all worlds from the worlds folder or the mapserver / multiserver started using the start script. When --all is used it will stop everything, --worlds stops all worlds. You can use --all or --world even if some tasks that would be stopped by it are not running. -scripts/restart.sh: You can use this to restart one or all running worlds. You can use this script even if some worlds are not running. It will only restart the running worlds. If --multiserver is used, multiserver is restarted instead of any worlds (in case it is running) and if all worlds are restarted, multiserver is restarted as well (in case it is running). +scripts/restart.sh | multiserver | mapserver | --all | --worlds: You can use this to restart one or all worlds from the worlds folder or the mapserver / multiserver started using the start script. When --all is used it will restart everything, --worlds restarts all worlds. You can use --all or --world even if some tasks that would be restarted by it are not running - only the running tasks will be restarted. -scripts/console.sh: You can used this to access the console of the world specified in the argument (minetest --terminal running in a screen). If --multiserver is used, the multiserver screen will be shown. +scripts/console.sh | multiserver | mapserver: You can used this to access the console of the world specified in the argument (minetest --terminal running in a screen). If multiserver / mapserver is used, the multiserver / mapserver output will be shown (in real-time). scripts/common.sh: This script should not be started, it contains common functions imported by other scripts. You can modify it to e.g. change the paths of lock files or screen names. @@ -72,3 +74,7 @@ Adding new worlds ----------------- If you want to add a new world, add a folder to the worlds/directory. Then, create .gitignore, world.mt and minetest.conf in that directory. .gitignore needs to contain * to ignore everything, and !minetest.conf and !world.mt to include these two. minetest.conf and world.mt need to be created and filled, world.mt needs to contain load_mod_xy = true / false for every added mod, see the Adding existing mods section for that. Also, world.mt needs to contain database settings for map, players and auth data and settings to enable / disable creative mode and damage. Each world also has it's own configuration file. The concept for worlds and mods is that some mods are for one world only e.g. the skyblock mod for the skyblock world, and some are shared. Make sure that each world has the mods enabled that the enabled mods depend on. Every world needs to have a port specified in the config file and needs to be added to the multiserver configuration. Only the lobby server is supposed to announce to the server list and should announce the port multiserver is running on. + +Ports +----- + diff --git a/scripts/common.sh b/scripts/common.sh index caa3dad..c870997 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -5,7 +5,11 @@ function world_lock { } function multiserver_lock { - echo "/tmp/ElidragonV2_Multiserver_lock" + echo "/tmp/ElidragonV2_multiserver_lock" +} + +function mapserver_lock { + echo "/tmp/ElidragonV2_mapserver_lock" } function world_screenname { @@ -16,6 +20,10 @@ function multiserver_screenname { echo "Elidragon v2 - Multiserver" } +function mapserver_screenname { + echo "Elidragon v2 - Mapserver" +} + function kill_world { kill `cat \`world_lock $1\`` } @@ -24,6 +32,10 @@ function kill_multiserver { kill -2 `cat \`multiserver_lock\`` } +function kill_mapserver { + kill `cat \`mapserver_lock\`` +} + function world_running { return $([ -f `world_lock $1` ]) } @@ -32,26 +44,8 @@ function multiserver_running { return $([ -f `multiserver_lock` ]) } -function assert_running { - if ! world_running $1; then - echo -e "\e[31mWorld $1 is not running\e[0m" - if [ -z $2 ]; then - exit 1 - else - return 1 - fi - fi -} - -function assert_not_running { - if world_running $1; then - echo -e "\e[31mWorld $1 is already running\e[0m" - if [ -z $2 ]; then - exit 1 - else - return 1 - fi - fi +function mapserver_running { + return $([ -f `mapserver_lock` ]) } function loop_worlds { @@ -61,20 +55,10 @@ function loop_worlds { done } -function run_one_or_all { - if [ -z $2 ]; then - loop_worlds $1 - return 0 - else - $1 $2 - return 1 - fi -} - function run_in_screen { screen -dmS $1 bash -c " touch $2 - while [ -f $2; ] do + while [ -f $2 ]; do bash -c \" echo \\$\\$ > $2 exec $3 @@ -83,13 +67,46 @@ function run_in_screen { " } +function start_mapserver { + echo -n "Starting Mapserver... " + if ! mapserver_running; then + cd worlds/creative + run_in_screen `mapserver_screenname` `mapserver_lock` "./mapserver-linux-x86_64" + cd ../.. + echo -e "\e[32mDone\e[0m" + else + echo -e "\e[31mMapserver is already running\e[0m" + fi +} + +function stop_mapserver { + echo -n "Stopping Mapserver... " + if mapserver_running; then + kill_mapserver + rm `mapserver_lock` + echo -e "\e[32mDone\e[0m" + else + echo -e "\e[31mMapserver is not running\e[0m" + fi +} + +function restart_mapserver { + echo -n "Restarting Mapserver..." + if mapserver_running; then + kill_mapserver + echo -e "\e[32mDone\e[0m" + else + echo -e "\e[31mMapserver is not running\e[0m" + fi +} + function start_multiserver { echo -n "Starting Multiserver... " - if multiserver_running; then - echo -e "\e[31mMultiserver is already running\e[0m" - else + if ! multiserver_running; then run_in_screen `multiserver_screenname` `multiserver_lock` "~/go/bin/multiserver" echo -e "\e[32mDone\e[0m" + else + echo -e "\e[31mMultiserver is already running\e[0m" fi } @@ -98,7 +115,6 @@ function stop_multiserver { if multiserver_running; then kill_multiserver rm `multiserver_lock` - echo -e "\e[32mDone\e[0m" else echo -e "\e[31mMultiserver is not running\e[0m" @@ -106,10 +122,9 @@ function stop_multiserver { } function restart_multiserver { - echo -n "Multiserver..." + echo -n "Restarting Multiserver..." if multiserver_running; then kill_multiserver - echo -e "\e[32mDone\e[0m" else echo -e "\e[31mMultiserver is not running\e[0m" @@ -118,27 +133,31 @@ function restart_multiserver { function start_world { echo -n "Starting $1... " - if assert_not_running $1 "true"; then + if ! world_running $1; then run_in_screen `world_screenname $1` `world_lock $1` "minetest --server --terminal --world worlds/$1 --config worlds/$1/minetest.conf --logfile worlds/$1/debug.txt" echo -e "\e[32mDone\e[0m" + else + echo -e "\e[31m$2 is already running\e[0m" fi } function stop_world { echo -n "Stopping $1..." - if assert_running $1 "true"; then + if world_running $1; then kill_world $1 rm `world_lock $1` - echo -e "\e[32mDone\e[0m" + else + echo -e "\e[31m$2 is already running\e[0m" fi } function restart_world { echo -n "Restarting $1..." - if assert_running $1 "true"; then + if world_running $1; then kill_world $1 - echo -e "\e[32mDone\e[0m" + else + echo -e "\e[31m$2 is not running\e[0m" fi } diff --git a/scripts/console.sh b/scripts/console.sh index ef1538c..03f3d8f 100755 --- a/scripts/console.sh +++ b/scripts/console.sh @@ -1,13 +1,17 @@ #! /bin/bash # Elidragon v2 console script -# Attach to the console of a world or multiserver -# Arguments: +# Attach to the screen of a world, multiserver or mapserver source scripts/common.sh -if [[ $1 == "--multiserver" ]]; then - screen -r `multiserver_sceenname` -else - assert_running $1 - screen -r `world_screenname $1` -fi +case $1 in + "mapserver") + screen -r `mapserver_screenname` + ;; + "multiserver") + screen -r `multiserver_sceenname` + ;; + *) + screen -r `world_screenname $1` + ;; +esac diff --git a/scripts/restart.sh b/scripts/restart.sh index 53a385f..13b612a 100755 --- a/scripts/restart.sh +++ b/scripts/restart.sh @@ -1,10 +1,25 @@ #! /bin/bash # Elidragon v2 restart script -# Restart one or all worlds, or if --multiserver is used, the multiserver. If all worlds are restarted, multiserver is restarted as well -# Arguments: [ | --multiserver] +# Restart worlds, multiserver and mapserver source source scripts/common.sh -if [[ $1 == "--multiserver" || run_one_or_all restart_world $1 ]]; then - restart_multiserver -fi +case $1 in + "--all") + restart_mapserver + restart_multiserver + loop_worlds restart_world + ;; + "--worlds") + loop_worlds restart_world + ;; + "mapserver") + restart_mapserver + ;; + "multiserver") + restart_multiserver + ;; + *) + restart_world $1 + ;; +esac diff --git a/scripts/setup.sh b/scripts/setup.sh index 37460ab..67f2448 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -14,3 +14,9 @@ sudo apt install minetest screen -y # Install multiserver and its dependencies go get github.com/HimbeerserverDE/multiserver + +# Download & install mapserver +cd worlds/creative/ +curl -s https://api.github.com/repos/minetest-mapserver/mapserver/releases/latest | grep "mapserver-linux-x86_64" | cut -d : -f 2,3 | tr -d \" | wget -qi - +chmod +x mapserver-linux-x86_64 +cd ../.. diff --git a/scripts/start.sh b/scripts/start.sh index 06a96e2..17a7053 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -1,10 +1,25 @@ #! /bin/bash # Elidragon v2 start script -# Start one or all worlds, or if --multiserver is used, the multiserver. If all worlds are started, multiserver is started as well -# Arguments: [] +# Start worlds, multiserver and mapserver source source scripts/common.sh -if [ $1 = "--multiserver" ] || run_one_or_all start_world $1; then - start_multiserver -fi +case $1 in + "--all" + start_mapserver + start_multiserver + loop_worlds start_world + ;; + "--worlds") + loop_worlds start_world + ;; + "mapserver") + start_mapserver + ;; + "multiserver") + start_multiserver + ;; + *) + start_world $1 + ;; +esac diff --git a/scripts/stop.sh b/scripts/stop.sh index 8297ddc..b4a48bf 100755 --- a/scripts/stop.sh +++ b/scripts/stop.sh @@ -1,10 +1,25 @@ #! /bin/bash # Elidragon v2 stop script -# Stop one or all worlds, or if --multiserver is used, the multiserver. If all worlds are stopped, multiserver is stopped as well -# Arguments: [] +# Stop worlds, multiserver and mapserver -source scripts/common.sh +source source scripts/common.sh -if [[ $1 == "--multiserver" || run_one_or_all stop_world $1 ]]; then - stop_multiserver -fi +case $1 in + "--all" + stop_mapserver + stop_multiserver + loop_worlds stop_world + ;; + "--worlds") + loop_worlds stop_world + ;; + "mapserver") + stop_mapserver + ;; + "multiserver") + stop_multiserver + ;; + *) + stop_world $1 + ;; +esac -- 2.44.0