From a0850d7595bd3ee8fcc8c1a18220aa509666ee8c Mon Sep 17 00:00:00 2001 From: Tristan Donkers Date: Sun, 23 Aug 2015 09:56:54 +1000 Subject: [PATCH 01/10] Add set_property() function to load properties from versioning files. --- init/msm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/init/msm b/init/msm index b27239d..c0d0ee3 100755 --- a/init/msm +++ b/init/msm @@ -4043,6 +4043,13 @@ console_command() { eval SERVER_CONSOLE_COMMAND_TIMEOUT_${command_name}[$VERSIONING_SERVER_ID]=\"$command_timeout\" } +# Defines a servers property variables, VERSIONING_SERVER_ID +# must be set before calling this function +# $1: The name of the property +# $2: The value of the property +set_property() { + server_set_property "$VERSIONING_SERVER_ID" "$1" "$2" +} From 4f85edb958e85713e891b19d4a4700e16632ad0e Mon Sep 17 00:00:00 2001 From: Tristan Donkers Date: Sun, 23 Aug 2015 10:00:51 +1000 Subject: [PATCH 02/10] Use the server_set_property() function to set property values in all cases. --- init/msm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init/msm b/init/msm index c0d0ee3..e482a65 100755 --- a/init/msm +++ b/init/msm @@ -1814,11 +1814,11 @@ server_property() { if [ ! -z "$from_conf" ]; then # If the value is found in the server conf file (server.properties) # then set that as value for the property - eval SERVER_$2[$1]=\"$from_conf\" + server_set_property "$1" "$2" "$from_conf" else # Otherwise use the default value manager_property "DEFAULT_$2" - eval SERVER_$2[$1]=\"\$SETTINGS_DEFAULT_$2\" + server_set_property "$1" "$2" "\$SETTINGS_DEFAULT_$2" fi ### Post-changes to variables after loading From 3e9e72e128c1e1bd781a5c9981f8c6db532ae2ee Mon Sep 17 00:00:00 2001 From: Tristan Donkers Date: Sun, 23 Aug 2015 10:06:14 +1000 Subject: [PATCH 03/10] Move the if block for making paths absolute into the server_set_property() function. --- init/msm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/init/msm b/init/msm index e482a65..09e841f 100755 --- a/init/msm +++ b/init/msm @@ -1714,7 +1714,13 @@ server_connected() { # $2: The name of the server property # $3: The value for the property server_set_property() { - eval SERVER_$2[$1]=\"$3\" + # If it is a path make that path absolute + if [[ "$2" =~ _PATH$ ]]; then + server_property "$1" PATH + eval SERVER_$2[$1]=\"${SERVER_PATH[$1]}/$3\" + else + eval SERVER_$2[$1]=\"$3\" + fi } # Get the value of a server property @@ -1823,12 +1829,6 @@ server_property() { ### Post-changes to variables after loading - # If it is a path make that path absolute - if [[ "$2" =~ _PATH$ ]]; then - server_property "$1" PATH - eval SERVER_$2[$1]=\"${SERVER_PATH[$1]}/\${SERVER_$2[$1]}\" - fi - # Replace any place holders in a property we just loaded case "$2" in SCREEN_NAME) From 9b60033c2433a2233a9c18c91bcda3218ace88b3 Mon Sep 17 00:00:00 2001 From: Tristan Donkers Date: Sun, 23 Aug 2015 10:07:31 +1000 Subject: [PATCH 04/10] Change if conditions so versioning files are read for *_PATH as well as CONSOLE_* variables. --- init/msm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init/msm b/init/msm index 09e841f..9f536ef 100755 --- a/init/msm +++ b/init/msm @@ -1789,8 +1789,8 @@ server_property() { ;; esac - # If its a command lookup, load from versioning files - if [[ "$2" =~ ^CONSOLE_ ]]; then + # If its a command lookup or server path, load from versioning files + if [[ "$2" =~ ^CONSOLE_ ]] || [[ "$2" =~ _PATH$ ]]; then server_property "$1" VERSION_CONF if [[ -f "${SERVER_VERSION_CONF[$1]}" ]]; then From 64e14e5b164fcf29ce71724dda87944252d6b48e Mon Sep 17 00:00:00 2001 From: Tristan Donkers Date: Sun, 23 Aug 2015 10:08:59 +1000 Subject: [PATCH 05/10] Only return 0 if this is a CONSOLE_ variable. --- init/msm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/init/msm b/init/msm index 9f536ef..9e7ad4d 100755 --- a/init/msm +++ b/init/msm @@ -1800,7 +1800,9 @@ server_property() { SERVER_VERSIONING_LOADED[$1]="true" fi - return 0 + if [[ "$2" =~ ^CONSOLE_ ]]; then + return 0 + fi fi # If not a non-overridable load from conf From 7f11ec62d51cb2170cbfeaafbea082ed23f4b545 Mon Sep 17 00:00:00 2001 From: Tristan Donkers Date: Sun, 23 Aug 2015 10:10:04 +1000 Subject: [PATCH 06/10] Add LOG_PATH to version files. --- versioning/minecraft/1.2.0.sh | 2 ++ versioning/minecraft/1.7.0.sh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/versioning/minecraft/1.2.0.sh b/versioning/minecraft/1.2.0.sh index 5b811a4..e8a400e 100644 --- a/versioning/minecraft/1.2.0.sh +++ b/versioning/minecraft/1.2.0.sh @@ -1,5 +1,7 @@ # MSM version file for Minecraft 1.2.0 and above +set_property LOG_PATH "server.log" + console_event REGEX "^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} \[.*\]" console_event START:30 "Done" diff --git a/versioning/minecraft/1.7.0.sh b/versioning/minecraft/1.7.0.sh index e6f1f54..76e4d9a 100644 --- a/versioning/minecraft/1.7.0.sh +++ b/versioning/minecraft/1.7.0.sh @@ -2,4 +2,6 @@ extends "minecraft/1.3.0" +set_property LOG_PATH "logs/latest.log" + console_event REGEX "^\[[0-9]{2}:[0-9]{2}:[0-9]{2}\] \[.*\]:" From ef2a6c537c0fea57126f7af20a258f85fe7af959 Mon Sep 17 00:00:00 2001 From: Tristan Donkers Date: Sun, 23 Aug 2015 11:18:38 +1000 Subject: [PATCH 07/10] Code re-factoring: Move case statment applying post-changes to values to the server_set_property() function. --- init/msm | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/init/msm b/init/msm index 9e7ad4d..12b8bf5 100755 --- a/init/msm +++ b/init/msm @@ -1721,6 +1721,26 @@ server_set_property() { else eval SERVER_$2[$1]=\"$3\" fi + ### Changes to values before setting + case "$2" in + SCREEN_NAME) + eval SERVER_$2[$1]=\"${SERVER_SCREEN_NAME[$1]//\{SERVER_NAME\}/${SERVER_NAME[$1]}}\" + ;; + MESSAGE_STOP) + server_property "$1" STOP_DELAY + eval SERVER_$2[$1]=\"${SERVER_MESSAGE_STOP[$1]//\{DELAY\}/${SERVER_STOP_DELAY[$1]}}\" + ;; + MESSAGE_RESTART) + server_property "$1" RESTART_DELAY + eval SERVER_$2[$1]=\"${SERVER_MESSAGE_RESTART[$1]//\{DELAY\}/${SERVER_RESTART_DELAY[$1]}}\" + ;; + INVOCATION) + server_property "$1" RAM + server_property "$1" JAR_PATH + eval SERVER_$2[$1]=\"${SERVER_INVOCATION[$1]//\{RAM\}/${SERVER_RAM[$1]}}\" + eval SERVER_$2[$1]=\"${SERVER_INVOCATION[$1]//\{JAR\}/${SERVER_JAR_PATH[$1]}}\" + ;; + esac } # Get the value of a server property @@ -1828,29 +1848,6 @@ server_property() { manager_property "DEFAULT_$2" server_set_property "$1" "$2" "\$SETTINGS_DEFAULT_$2" fi - - ### Post-changes to variables after loading - - # Replace any place holders in a property we just loaded - case "$2" in - SCREEN_NAME) - server_set_property "$1" "$2" "${SERVER_SCREEN_NAME[$1]//\{SERVER_NAME\}/${SERVER_NAME[$1]}}" - ;; - MESSAGE_STOP) - server_property "$1" STOP_DELAY - server_set_property "$1" "$2" "${SERVER_MESSAGE_STOP[$1]//\{DELAY\}/${SERVER_STOP_DELAY[$1]}}" - ;; - MESSAGE_RESTART) - server_property "$1" RESTART_DELAY - server_set_property "$1" "$2" "${SERVER_MESSAGE_RESTART[$1]//\{DELAY\}/${SERVER_RESTART_DELAY[$1]}}" - ;; - INVOCATION) - server_property "$1" RAM - server_property "$1" JAR_PATH - server_set_property "$1" "$2" "${SERVER_INVOCATION[$1]//\{RAM\}/${SERVER_RAM[$1]}}" - server_set_property "$1" "$2" "${SERVER_INVOCATION[$1]//\{JAR\}/${SERVER_JAR_PATH[$1]}}" - ;; - esac fi } From f4d0c14aabf4af0887c2ca43d2268eb1c5002bd7 Mon Sep 17 00:00:00 2001 From: Tristan Donkers Date: Sun, 23 Aug 2015 11:26:30 +1000 Subject: [PATCH 08/10] Moved the server.properties checking to it's own function, read_server_conf(). --- init/msm | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/init/msm b/init/msm index 12b8bf5..4d6e049 100755 --- a/init/msm +++ b/init/msm @@ -1826,31 +1826,41 @@ server_property() { fi # If not a non-overridable load from conf - to_properties_name "$2" - local name="$RETURN" + read_server_conf "$1" "$2" - if [[ "$name" =~ ^properties\-(.*)$ ]]; then - name="${BASH_REMATCH[1]}" - else - name="msm-$name" - fi - - server_property "$1" CONF - - local from_conf="$(sed -rn "s/^$name=('|\"|)(.*)\1/\2/ip" "${SERVER_CONF[$1]}" | tail -n 1)" - - if [ ! -z "$from_conf" ]; then - # If the value is found in the server conf file (server.properties) - # then set that as value for the property - server_set_property "$1" "$2" "$from_conf" - else - # Otherwise use the default value + local target_varname=SERVER_$2[$1] + if [ -z ${!target_varname} ]; then + # if its still empty use the default value manager_property "DEFAULT_$2" server_set_property "$1" "$2" "\$SETTINGS_DEFAULT_$2" fi fi } +#Checks server config for overriding value +# $1: The ID of the server +# $2: The name of the server property +read_server_conf(){ + server_property "$1" CONF + + to_properties_name "$2" + local name="$RETURN" + + if [[ "$name" =~ ^properties\-(.*)$ ]]; then + name="${BASH_REMATCH[1]}" + else + name="msm-$name" + fi + + local from_conf="$(sed -rn "s/^$name=('|\"|)(.*)\1/\2/ip" "${SERVER_CONF[$1]}" | tail -n 1)" + + if [ ! -z "$from_conf" ]; then + # If the value is found in the server conf file (server.properties) + # then set that as value for the property + server_set_property "$1" "$2" "$from_conf" + fi +} + # $1: The server ID server_dirty_properties() { local index From 0a637b82b76e73897797d5f1875630c8afc5359a Mon Sep 17 00:00:00 2001 From: Tristan Donkers Date: Sun, 23 Aug 2015 11:32:02 +1000 Subject: [PATCH 09/10] Call read_server_conf() when reading set_property lines in versioning files. This allows overrides of version properties in the server.properties. --- init/msm | 1 + 1 file changed, 1 insertion(+) diff --git a/init/msm b/init/msm index 4d6e049..20ff1db 100755 --- a/init/msm +++ b/init/msm @@ -4058,6 +4058,7 @@ console_command() { # $2: The value of the property set_property() { server_set_property "$VERSIONING_SERVER_ID" "$1" "$2" + read_server_conf "$VERSIONING_SERVER_ID" "$1" } From af13191bb2d04a7e7b7007558c01b6aa7ee92c86 Mon Sep 17 00:00:00 2001 From: Tristan Donkers Date: Fri, 28 Aug 2015 23:25:28 +1000 Subject: [PATCH 10/10] refactor of server_set_property(), move content of if block into the case statement and check if path is already absolute. --- init/msm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/init/msm b/init/msm index 20ff1db..8a0fc62 100755 --- a/init/msm +++ b/init/msm @@ -1714,15 +1714,15 @@ server_connected() { # $2: The name of the server property # $3: The value for the property server_set_property() { - # If it is a path make that path absolute - if [[ "$2" =~ _PATH$ ]]; then - server_property "$1" PATH - eval SERVER_$2[$1]=\"${SERVER_PATH[$1]}/$3\" - else - eval SERVER_$2[$1]=\"$3\" - fi + eval SERVER_$2[$1]=\"$3\" ### Changes to values before setting case "$2" in + *_PATH) + server_property "$1" PATH + if [[ ! "$3" =~ ^${SERVER_PATH[$1]} ]]; then + eval SERVER_$2[$1]=\"${SERVER_PATH[$1]}/$3\" + fi + ;; SCREEN_NAME) eval SERVER_$2[$1]=\"${SERVER_SCREEN_NAME[$1]//\{SERVER_NAME\}/${SERVER_NAME[$1]}}\" ;;