From bf1fc1833b752bc574f80d69fbf0ef6d886032c0 Mon Sep 17 00:00:00 2001
From: Christian <h3o66@users.noreply.github.com>
Date: Thu, 22 Sep 2022 22:26:19 +0200
Subject: [PATCH] feat(newserver): add Velocity Proxy (#3904)

---
 .../config-lgsm/vpmcserver/_default.cfg       | 179 ++++++++++++++++++
 lgsm/data/almalinux-8.csv                     |   1 +
 lgsm/data/centos-8.csv                        |   1 +
 lgsm/data/debian-10.csv                       |   1 +
 lgsm/data/debian-11.csv                       |   1 +
 lgsm/data/rhel-7.csv                          |   1 +
 lgsm/data/rhel-8.csv                          |   1 +
 lgsm/data/rocky-8.csv                         |   1 +
 lgsm/data/serverlist.csv                      |   1 +
 lgsm/data/ubuntu-18.04.csv                    |   1 +
 lgsm/data/ubuntu-20.04.csv                    |   1 +
 lgsm/data/ubuntu-21.04.csv                    |   1 +
 lgsm/data/ubuntu-21.10.csv                    |   1 +
 lgsm/data/ubuntu-22.04.csv                    |   1 +
 lgsm/functions/command_stop.sh                |   2 +
 lgsm/functions/command_update.sh              |   2 +-
 lgsm/functions/info_game.sh                   |  18 ++
 lgsm/functions/info_messages.sh               |  11 +-
 lgsm/functions/install_server_files.sh        |   2 +-
 lgsm/functions/update_papermc.sh              |   2 +
 20 files changed, 226 insertions(+), 3 deletions(-)
 create mode 100644 lgsm/config-default/config-lgsm/vpmcserver/_default.cfg

diff --git a/lgsm/config-default/config-lgsm/vpmcserver/_default.cfg b/lgsm/config-default/config-lgsm/vpmcserver/_default.cfg
new file mode 100644
index 000000000..6755e0e51
--- /dev/null
+++ b/lgsm/config-default/config-lgsm/vpmcserver/_default.cfg
@@ -0,0 +1,179 @@
+##################################
+######## Default Settings ########
+##################################
+# DO NOT EDIT, ANY CHANGES WILL BE OVERWRITTEN!
+# Copy settings from here and use them in either:
+# common.cfg - applies settings to every instance.
+# [instance].cfg - applies settings to a specific instance.
+
+#### Game Server Settings ####
+
+## Predefined Parameters | https://docs.linuxgsm.com/configuration/start-parameters
+javaram="1024" # -Xmx$1024M
+
+## Server Parameters | https://docs.linuxgsm.com/configuration/start-parameters#additional-parameters
+startparameters=""
+
+## Release Settings | https://docs.linuxgsm.com/game-servers/minecraft#release-settings
+# Version (latest|3.1.1)
+mcversion="latest"
+
+#### LinuxGSM Settings ####
+
+## LinuxGSM Stats
+# Send useful stats to LinuxGSM developers.
+# https://docs.linuxgsm.com/configuration/linuxgsm-stats
+# (on|off)
+stats="off"
+
+## Notification Alerts
+# (on|off)
+
+# Display IP | https://docs.linuxgsm.com/alerts#display-ip
+displayip=""
+
+# More info | https://docs.linuxgsm.com/alerts#more-info
+postalert="off"
+
+# Discord Alerts | https://docs.linuxgsm.com/alerts/discord
+discordalert="off"
+discordwebhook="webhook"
+
+# Email Alerts | https://docs.linuxgsm.com/alerts/email
+emailalert="off"
+email="email@example.com"
+emailfrom=""
+
+# Gotify Alerts | https://docs.linuxgsm.com/alerts/gotify
+gotifyalert="off"
+gotifytoken="token"
+gotifywebhook="webhook"
+
+# IFTTT Alerts | https://docs.linuxgsm.com/alerts/ifttt
+iftttalert="off"
+ifttttoken="accesstoken"
+iftttevent="linuxgsm_alert"
+
+# Mailgun Email Alerts | https://docs.linuxgsm.com/alerts/mailgun
+mailgunalert="off"
+mailgunapiregion="us"
+mailguntoken="accesstoken"
+mailgundomain="example.com"
+mailgunemailfrom="alert@example.com"
+mailgunemail="email@myemail.com"
+
+# Pushbullet Alerts | https://docs.linuxgsm.com/alerts/pushbullet
+pushbulletalert="off"
+pushbullettoken="accesstoken"
+channeltag=""
+
+# Pushover Alerts | https://docs.linuxgsm.com/alerts/pushover
+pushoveralert="off"
+pushovertoken="accesstoken"
+pushoveruserkey="userkey"
+
+# Rocket.Chat Alerts | https://docs.linuxgsm.com/alerts/rocket.chat
+rocketchatalert="off"
+rocketchatwebhook="webhook"
+rocketchattoken=""
+
+# Slack Alerts | https://docs.linuxgsm.com/alerts/slack
+slackalert="off"
+slackwebhook="webhook"
+
+# Telegram Alerts | https://docs.linuxgsm.com/alerts/telegram
+# You can add a custom cURL string eg proxy (useful in Russia) in "curlcustomstring".
+# For example "--socks5 ipaddr:port" for socks5 proxy see more in "curl --help".
+telegramapi="api.telegram.org"
+telegramalert="off"
+telegramtoken="accesstoken"
+telegramchatid=""
+curlcustomstring=""
+
+## Updating | https://docs.linuxgsm.com/commands/update
+updateonstart="off"
+
+## Backup | https://docs.linuxgsm.com/commands/backup
+maxbackups="4"
+maxbackupdays="30"
+stoponbackup="on"
+
+## Logging | https://docs.linuxgsm.com/features/logging
+consolelogging="on"
+logdays="7"
+
+## Monitor | https://docs.linuxgsm.com/commands/monitor
+# Query delay time
+querydelay="1"
+
+## ANSI Colors | https://docs.linuxgsm.com/features/ansi-colors
+ansi="on"
+
+#### Advanced Settings ####
+
+## Message Display Time | https://docs.linuxgsm.com/features/message-display-time
+sleeptime="0.5"
+
+## Stop Mode | https://docs.linuxgsm.com/features/stop-mode
+# 1: tmux kill
+# 2: CTRL+c
+# 3: quit
+# 4: quit 120s
+# 5: stop
+# 6: q
+# 7: exit
+# 8: 7 Days to Die
+# 9: GoldSrc
+# 10: Avorion
+# 11: end
+# 12: shutdown
+stopmode="12"
+
+## Query mode
+# 1: session only
+# 2: gamedig (gsquery fallback)
+# 3: gamedig
+# 4: gsquery
+# 5: tcp
+querymode="2"
+querytype="minecraft"
+
+## Console type
+consoleverbose="yes"
+consoleinteract="yes"
+
+## Game Server Details
+# Do not edit
+gamename="Velocity Proxy"
+engine="lwjgl2"
+glibc="null"
+
+#### Directories ####
+# Edit with care
+
+## Game Server Directories
+systemdir="${serverfiles}"
+executabledir="${serverfiles}"
+preexecutable="java -Xmx${javaram}M -XX:+UseG1GC -XX:G1HeapRegionSize=4M -XX:+UnlockExperimentalVMOptions -XX:+ParallelRefProcEnabled -XX:+AlwaysPreTouch -XX:MaxInlineLevel=15 -jar"
+executable="./velocity.jar"
+servercfgdir="${systemdir}"
+servercfg="velocity.toml"
+servercfgdefault="velocity.toml"
+servercfgfullpath="${servercfgdir}/${servercfg}"
+
+## Backup Directory
+backupdir="${lgsmdir}/backup"
+
+## Logging Directories
+logdir="${rootdir}/log"
+gamelogdir="${systemdir}/logs"
+lgsmlogdir="${logdir}/script"
+consolelogdir="${logdir}/console"
+lgsmlog="${lgsmlogdir}/${selfname}-script.log"
+consolelog="${consolelogdir}/${selfname}-console.log"
+alertlog="${lgsmlogdir}/${selfname}-alert.log"
+postdetailslog="${lgsmlogdir}/${selfname}-postdetails.log"
+
+## Logs Naming
+lgsmlogdate="${lgsmlogdir}/${selfname}-script-$(date '+%Y-%m-%d-%H:%M:%S').log"
+consolelogdate="${consolelogdir}/${selfname}-console-$(date '+%Y-%m-%d-%H:%M:%S').log"
diff --git a/lgsm/data/almalinux-8.csv b/lgsm/data/almalinux-8.csv
index 7c4eb59f5..9910acb8d 100644
--- a/lgsm/data/almalinux-8.csv
+++ b/lgsm/data/almalinux-8.csv
@@ -119,6 +119,7 @@ ut99
 vh,glibc-devel
 vs
 vints,mono-complete
+vpmc,java-11-openjdk
 wet
 wf
 wmc,java-11-openjdk
diff --git a/lgsm/data/centos-8.csv b/lgsm/data/centos-8.csv
index 8ece428a5..7d3095ba4 100644
--- a/lgsm/data/centos-8.csv
+++ b/lgsm/data/centos-8.csv
@@ -118,6 +118,7 @@ ut99
 vh,glibc-devel
 vs
 vints,mono-complete
+vpmc,java-11-openjdk
 wet
 wf
 wmc,java-11-openjdk
diff --git a/lgsm/data/debian-10.csv b/lgsm/data/debian-10.csv
index 30ca2df10..443c35cf0 100644
--- a/lgsm/data/debian-10.csv
+++ b/lgsm/data/debian-10.csv
@@ -119,6 +119,7 @@ ut99
 vh,libc6-dev
 vs
 vints,mono-complete
+vpmc,openjdk-11-jre
 wet
 wf
 wmc,openjdk-11-jre
diff --git a/lgsm/data/debian-11.csv b/lgsm/data/debian-11.csv
index f96d48862..58db53762 100644
--- a/lgsm/data/debian-11.csv
+++ b/lgsm/data/debian-11.csv
@@ -119,6 +119,7 @@ ut99
 vh,libc6-dev
 vs
 vints,mono-complete
+vpmc,openjdk-11-jre
 wet
 wf
 wmc,openjdk-17-jre
diff --git a/lgsm/data/rhel-7.csv b/lgsm/data/rhel-7.csv
index e9801a845..968c4dc98 100644
--- a/lgsm/data/rhel-7.csv
+++ b/lgsm/data/rhel-7.csv
@@ -119,6 +119,7 @@ ut99
 vh,glibc-devel
 vs
 vints,mono-complete
+vpmc,java-11-openjdk
 wet
 wf
 wmc,java-11-openjdk
diff --git a/lgsm/data/rhel-8.csv b/lgsm/data/rhel-8.csv
index 88b1babba..002db75fd 100644
--- a/lgsm/data/rhel-8.csv
+++ b/lgsm/data/rhel-8.csv
@@ -119,6 +119,7 @@ ut99
 vh,glibc-devel
 vs
 vints,mono-complete
+vpmc,java-11-openjdk
 wet
 wf
 wmc,java-11-openjdk
diff --git a/lgsm/data/rocky-8.csv b/lgsm/data/rocky-8.csv
index 7c4eb59f5..9910acb8d 100644
--- a/lgsm/data/rocky-8.csv
+++ b/lgsm/data/rocky-8.csv
@@ -119,6 +119,7 @@ ut99
 vh,glibc-devel
 vs
 vints,mono-complete
+vpmc,java-11-openjdk
 wet
 wf
 wmc,java-11-openjdk
diff --git a/lgsm/data/serverlist.csv b/lgsm/data/serverlist.csv
index f5463cd84..4c80f538a 100644
--- a/lgsm/data/serverlist.csv
+++ b/lgsm/data/serverlist.csv
@@ -117,6 +117,7 @@ ut3,ut3server,Unreal Tournament 3
 ut99,ut99server,Unreal Tournament 99
 vh,vhserver,Valheim
 vints,vintsserver,Vintage Story
+vpmc,vpmcserver,Velocity Proxy MC
 vs,vsserver,Vampire Slayer
 wet,wetserver,Wolfenstein: Enemy Territory
 wf,wfserver,Warfork
diff --git a/lgsm/data/ubuntu-18.04.csv b/lgsm/data/ubuntu-18.04.csv
index 30ca2df10..443c35cf0 100644
--- a/lgsm/data/ubuntu-18.04.csv
+++ b/lgsm/data/ubuntu-18.04.csv
@@ -119,6 +119,7 @@ ut99
 vh,libc6-dev
 vs
 vints,mono-complete
+vpmc,openjdk-11-jre
 wet
 wf
 wmc,openjdk-11-jre
diff --git a/lgsm/data/ubuntu-20.04.csv b/lgsm/data/ubuntu-20.04.csv
index 6f9bec4c0..49f64348d 100644
--- a/lgsm/data/ubuntu-20.04.csv
+++ b/lgsm/data/ubuntu-20.04.csv
@@ -119,6 +119,7 @@ ut99
 vh,libc6-dev
 vs
 vints,mono-complete
+vpmc,openjdk-11-jre
 wet
 wf
 wmc,openjdk-17-jre
diff --git a/lgsm/data/ubuntu-21.04.csv b/lgsm/data/ubuntu-21.04.csv
index 678c06f28..f1b28acd2 100644
--- a/lgsm/data/ubuntu-21.04.csv
+++ b/lgsm/data/ubuntu-21.04.csv
@@ -119,6 +119,7 @@ ut99
 vh,libc6-dev
 vs
 vints,mono-complete
+vpmc,openjdk-11-jre
 wet
 wf
 wmc,openjdk-17-jre
diff --git a/lgsm/data/ubuntu-21.10.csv b/lgsm/data/ubuntu-21.10.csv
index f99d2f46d..1ced64fc7 100644
--- a/lgsm/data/ubuntu-21.10.csv
+++ b/lgsm/data/ubuntu-21.10.csv
@@ -117,6 +117,7 @@ ut99
 vh,libc6-dev
 vs
 vints,mono-complete
+vpmc,openjdk-11-jre
 wet
 wf
 wmc,openjdk-17-jre
diff --git a/lgsm/data/ubuntu-22.04.csv b/lgsm/data/ubuntu-22.04.csv
index 18af1192f..dd567bf7b 100644
--- a/lgsm/data/ubuntu-22.04.csv
+++ b/lgsm/data/ubuntu-22.04.csv
@@ -117,6 +117,7 @@ ut99
 vh,libc6-dev
 vs
 vints,mono-complete
+vpmc,openjdk-11-jre
 wet
 wf
 wmc,openjdk-17-jre
diff --git a/lgsm/functions/command_stop.sh b/lgsm/functions/command_stop.sh
index b87185402..d18ef7c23 100644
--- a/lgsm/functions/command_stop.sh
+++ b/lgsm/functions/command_stop.sh
@@ -231,6 +231,8 @@ fn_stop_graceful_select() {
 		fn_stop_graceful_avorion
 	elif [ "${stopmode}" == "11" ]; then
 		fn_stop_graceful_cmd "end" 30
+	elif [ "${stopmode}" == "12" ]; then
+		fn_stop_graceful_cmd "shutdown" 30
 	fi
 }
 
diff --git a/lgsm/functions/command_update.sh b/lgsm/functions/command_update.sh
index 5b9858e84..07b65e5fa 100755
--- a/lgsm/functions/command_update.sh
+++ b/lgsm/functions/command_update.sh
@@ -21,7 +21,7 @@ elif [ "${shortname}" == "mc" ]; then
 	update_minecraft.sh
 elif [ "${shortname}" == "mcb" ]; then
 	update_minecraft_bedrock.sh
-elif [ "${shortname}" == "pmc" ] || [ "${shortname}" == "wmc" ]; then
+elif [ "${shortname}" == "pmc" ] || [ "${shortname}" == "vpmc" ] || [ "${shortname}" == "wmc" ]; then
 	update_papermc.sh
 elif [ "${shortname}" == "mumble" ]; then
 	update_mumble.sh
diff --git a/lgsm/functions/info_game.sh b/lgsm/functions/info_game.sh
index 7efc6008f..dcec74b31 100644
--- a/lgsm/functions/info_game.sh
+++ b/lgsm/functions/info_game.sh
@@ -2190,6 +2190,22 @@ fn_info_game_vints() {
 	configip=${configip:-"0.0.0.0"}
 }
 
+fn_info_game_vpmc() {
+	if [ ! -f "${servercfgfullpath}" ]; then
+		servername="${unavailable}"
+		configip="0.0.0.0"
+		port="25577"
+	else
+		servername=$(sed -nr 's/^motd\s*=\s*"(.*)"/\1/p' "${servercfgfullpath}")
+		bindaddress=$(sed -nr 's/^bind\s*=\s*"([0-9.:]+)"/\1/p' "${servercfgfullpath}")
+		configip=$(echo "${bindaddress}" | cut -d ':' -f 1)
+		port=$(echo "${bindaddress}" | cut -d ':' -f 2)
+
+		servername=${servername:-"NOT SET"}
+	fi
+	queryport=${port:-"25577"}
+}
+
 fn_info_game_wet() {
 	# Config
 	if [ ! -f "${servercfgfullpath}" ]; then
@@ -2456,6 +2472,8 @@ elif [ "${shortname}" == "vh" ]; then
 	fn_info_game_vh
 elif [ "${shortname}" == "vints" ]; then
 	fn_info_game_vints
+elif [ "${shortname}" == "vpmc" ]; then
+	fn_info_game_vpmc
 elif [ "${shortname}" == "wet" ]; then
 	fn_info_game_wet
 elif [ "${shortname}" == "wf" ]; then
diff --git a/lgsm/functions/info_messages.sh b/lgsm/functions/info_messages.sh
index cfad349ac..a216327c9 100755
--- a/lgsm/functions/info_messages.sh
+++ b/lgsm/functions/info_messages.sh
@@ -687,7 +687,7 @@ fn_info_message_ports() {
 		echo -e "ss -tuplwn | grep AvorionServer"
 	elif [ "${shortname}" == "bf1942" ]; then
 		echo -e "ss -tuplwn | grep bf1942_lnxded"
-	elif [ "${shortname}" == "mc" ] || [ "${shortname}" == "pmc" ] || [ "${shortname}" == "rw" ] || [ "${shortname}" == "wmc" ]; then
+	elif [ "${shortname}" == "mc" ] || [ "${shortname}" == "pmc" ] || [ "${shortname}" == "rw" ] || [ "${shortname}" == "vpmc" ] || [ "${shortname}" == "wmc" ]; then
 		echo -e "ss -tuplwn | grep java"
 	elif [ "${shortname}" == "terraria" ]; then
 		echo -e "ss -tuplwn | grep Main"
@@ -1610,6 +1610,13 @@ fn_info_message_vints() {
 	} | column -s $'\t' -t
 }
 
+fn_info_message_vpmc() {
+	{
+		fn_port "header"
+		fn_port "Game" port tcp
+	} | column -s $'\t' -t
+}
+
 fn_info_message_wet() {
 	{
 		fn_port "header"
@@ -1798,6 +1805,8 @@ fn_info_message_select_engine() {
 		fn_info_message_ut2k4
 	elif [ "${shortname}" == "ut3" ]; then
 		fn_info_message_ut3
+	elif [ "${shortname}" == "vpmc" ]; then
+		fn_info_message_vpmc
 	elif [ "${shortname}" == "wet" ]; then
 		fn_info_message_wet
 	elif [ "${shortname}" == "wf" ]; then
diff --git a/lgsm/functions/install_server_files.sh b/lgsm/functions/install_server_files.sh
index a81b75aea..c9faf643a 100755
--- a/lgsm/functions/install_server_files.sh
+++ b/lgsm/functions/install_server_files.sh
@@ -222,7 +222,7 @@ elif [ "${shortname}" == "mcb" ]; then
 elif [ "${shortname}" == "pmc" ]; then
 	install_eula.sh
 	update_papermc.sh
-elif [ "${shortname}" == "wmc" ]; then
+elif [ "${shortname}" == "wmc" ]||[ "${shortname}" == "vpmc" ]; then
 	update_papermc.sh
 elif [ "${shortname}" == "mumble" ]; then
 	update_mumble.sh
diff --git a/lgsm/functions/update_papermc.sh b/lgsm/functions/update_papermc.sh
index 881e912d3..1f334549c 100644
--- a/lgsm/functions/update_papermc.sh
+++ b/lgsm/functions/update_papermc.sh
@@ -122,6 +122,8 @@ remotelocation="papermc.io"
 
 if [ "${shortname}" == "pmc" ]; then
 	paperproject="paper"
+elif [ "${shortname}" == "vpmc" ]; then
+	paperproject="velocity"
 elif [ "${shortname}" == "wmc" ]; then
 	paperproject="waterfall"
 fi