From 36c07821d3caf928f56e8e691f0302ec00a1fde3 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Mon, 29 Mar 2021 23:34:51 +0100 Subject: [PATCH] improve ransom seed management --- lgsm/functions/command_wipe.sh | 16 ++++++++++------ lgsm/functions/info_parms.sh | 6 ++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lgsm/functions/command_wipe.sh b/lgsm/functions/command_wipe.sh index 4d5c63dbb..c08a9d943 100755 --- a/lgsm/functions/command_wipe.sh +++ b/lgsm/functions/command_wipe.sh @@ -98,13 +98,17 @@ fn_full_wipe_warning(){ fn_print_warn_nl "Full wipe will reset the map and remove player data" } -# Will change the seed everytime the wipe command is run if the seed in config is not set. +# Will change the seed everytime the wipe is run, if the seed is not defined by the user. fn_wipe_random_seed(){ - echo -en "generating random seed..." - shuf -i 1-2147483647 -n 1 > "${datadir}/${selfname}-seed.txt" - seed=$(cat "${datadir}/${selfname}-seed.txt") - exitcode=0 - fn_wipe_exit_code + if [ -f "${datadir}/${selfname}-seed.txt" ]; then + echo -en "generating random seed..." + shuf -i 1-2147483647 -n 1 > "${datadir}/${selfname}-seed.txt" + seed=$(cat "${datadir}/${selfname}-seed.txt") + echo -e "${cyan}${seed}${default}" + fn_sleep_time + exitcode=0 + fn_wipe_exit_code + fi } fn_print_dots "" diff --git a/lgsm/functions/info_parms.sh b/lgsm/functions/info_parms.sh index f2496ce5d..51596a571 100755 --- a/lgsm/functions/info_parms.sh +++ b/lgsm/functions/info_parms.sh @@ -142,11 +142,17 @@ fn_info_parms_rust(){ saveinterval=${saveinterval:-"0"} tickrate=${tickrate:-"0"} # Part of random seed feature. + # If seed is not defined by user generate a seed file. if [ -z "${seed}" ]; then if [ ! -f "${datadir}/${selfname}-seed.txt" ]; then shuf -i 1-2147483647 -n 1 > "${datadir}/${selfname}-seed.txt" fi seed=$(cat "${datadir}/${selfname}-seed.txt") + # If the seed is defined by the user remove the seed file if it exists. + else + if [ -f "${datadir}/${selfname}-seed.txt" ]; then + rm -f "${datadir:?}/${selfname}-seed.txt" + fi fi }