Skip to content

Commit

Permalink
feat(wipe): resolve random seed and simplify wipe (#3420)
Browse files Browse the repository at this point in the history
merge


merge


merge


merge


merge


merge


MERGE


merge


merge


merge


merge


message about Rust+ data


merge


merge


merge


merge


merge


mertge


merge


merge


merge


merge


merge
  • Loading branch information
dgibbs64 committed Apr 6, 2021
1 parent 669e2c9 commit 70e6f9a
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 174 deletions.
8 changes: 5 additions & 3 deletions lgsm/config-default/config-lgsm/rustserver/_default.cfg
Expand Up @@ -16,16 +16,18 @@ appport=28082
rconpassword="CHANGE_ME"
rconweb="1" # Value is: 1 for the Facepunch web panel, Rustadmin desktop and Rustadmin Online; 0 for RCON tools like Rusty.
servername="Rust"
gamemode="vanilla" # values: vanilla, softcore ( Doc: https://wiki.facepunch.com/rust/server-gamemodes )
maxplayers="50"
gamemode="vanilla" # Values: vanilla, softcore ( Doc: https://wiki.facepunch.com/rust/server-gamemodes )
serverlevel="Procedural Map" # Values: Procedural Map, Barren, HapisIsland, SavasIsland
customlevelurl="" # Custom level url
seed="" # range: 1-2147483647, used to reproduce a procedural map.
salt="" # range: unknown, used to recover a known setting from an existing map.
maxplayers="50"
worldsize="3000" # default: 3000, range: 1000-6000, map size in meters.
saveinterval="300" # Auto-save in seconds.
tickrate="30" # default: 30, range: 15-100.

## Server Parameters | https://docs.linuxgsm.com/configuration/start-parameters#additional-parameters
startparameters="-batchmode +app.listenip ${ip} +app.port ${appport} +server.ip ${ip} +server.port ${port} +server.tickrate ${tickrate} +server.hostname \"${servername}\" +server.identity \"${selfname}\" +server.gamemode ${gamemode} +server.seed ${seed} +server.salt ${salt} +server.maxplayers ${maxplayers} +server.worldsize ${worldsize} +server.saveinterval ${saveinterval} +rcon.web ${rconweb} +rcon.ip ${ip} +rcon.port ${rconport} +rcon.password \"${rconpassword}\" -logfile"
startparameters="-batchmode +app.listenip ${ip} +app.port ${appport} +server.ip ${ip} +server.port ${port} +server.tickrate ${tickrate} +server.hostname \"${servername}\" +server.identity \"${selfname}\" +server.gamemode ${gamemode} +server.level \"${serverlevel}\" +server.seed ${seed} +server.salt ${salt} +server.levelurl ${customlevelurl} +server.maxplayers ${maxplayers} +server.worldsize ${worldsize} +server.saveinterval ${saveinterval} +rcon.web ${rconweb} +rcon.ip ${ip} +rcon.port ${rconport} +rcon.password \"${rconpassword}\" -logfile"

#### LinuxGSM Settings ####

Expand Down
Binary file added lgsm/data/bo_header.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lgsm/data/rust_header.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
267 changes: 109 additions & 158 deletions lgsm/functions/command_wipe.sh
Expand Up @@ -12,219 +12,170 @@ fn_firstcommand_set

# Provides an exit code upon error.
fn_wipe_exit_code(){
((exitcode=$?))
exitcode=$?
if [ "${exitcode}" != 0 ]; then
fn_script_log_fatal "${currentaction}"
fn_print_fail_eol_nl
core_exit.sh
else
fn_print_ok_eol_nl
fi
}

# Removes files to wipe server.
fn_wipe_server_files(){
fn_print_start_nl "Wiping server"
fn_script_log_info "Wiping server"
# Wipe procedural map.
if [ -n "$(find "${serveridentitydir}" -type f -name "proceduralmap.*.map")" ]; then
echo -en "removing procedural map proceduralmap.*.map file(s)..."
fn_sleep_time
fn_script_log_info "Removing procedural map file(s): ${serveridentitydir}/proceduralmap.*.map"
find "${serveridentitydir:?}" -type f -name "proceduralmap.*.map" -delete | tee -a "${lgsmlog}"
fn_wipe_exit_code
fn_sleep_time
else
echo -e "no procedural map file to remove"
fn_sleep_time
fn_script_log_pass "No procedural map file to remove"
fi
# Wipe Barren map.
if [ -n "$(find "${serveridentitydir}" -type f -name "barren*.map")" ]; then
echo -en "removing barren map barren*.map file(s)..."
fn_sleep_time
fn_script_log_info "Removing map file(s): ${serveridentitydir}/barren*.map"
find "${serveridentitydir:?}" -type f -name "barren*.map" -delete | tee -a "${lgsmlog}"
fn_wipe_exit_code
fn_sleep_time
else
echo -e "no barren map file to remove"
fn_sleep_time
fn_script_log_pass "No barren map file to remove"
fi
# Wipe custom map.
if [ -n "$(find "${serveridentitydir}" -type f -name "*.map")" ]; then
echo -en "removing custom map file(s)..."
fn_sleep_time
fn_script_log_info "Removing map file(s): ${serveridentitydir}/*.map"
find "${serveridentitydir:?}" -type f -name "*.map" -delete | tee -a "${lgsmlog}"
fn_wipe_exit_code
fn_sleep_time
else
echo -e "no map file to remove"
fn_sleep_time
fn_script_log_pass "No map file to remove"
fi
# Wipe custom map save.
if [ -n "$(find "${serveridentitydir}" -type f -name "*.sav*")" ]; then
echo -en "removing map save *.sav* file(s)..."
fn_sleep_time
fn_script_log_info "Removing map save(s): ${serveridentitydir}/*.sav*"
find "${serveridentitydir:?}" -type f -name "*.sav*" -delete | tee -a "${lgsmlog}"
fn_wipe_exit_code
fn_sleep_time
else
echo -e "no map save to remove"
fn_sleep_time
fn_script_log_pass "No map save to remove."
fi
# Wipe user dir, might be a legacy thing, maybe to be removed.
if [ -d "${serveridentitydir}/user" ]; then
echo -en "removing user directory..."
fn_sleep_time
fn_script_log_info "removing user directory: ${serveridentitydir}/user"
rm -rf "${serveridentitydir:?}/user"
fn_wipe_exit_code
fn_sleep_time
# We do not print additional information if there is nothing to remove since this might be obsolete.
fi
# Wipe storage dir, might be a legacy thing, maybe to be removed.
if [ -d "${serveridentitydir}/storage" ]; then
echo -en "removing storage directory..."
fn_sleep_time
fn_script_log_info "removing storage directory: ${serveridentitydir}/storage"
rm -rf "${serveridentitydir:?}/storage"
fn_wipe_exit_code
fn_sleep_time
# We do not print additional information if there is nothing to remove since this might be obsolete.
fi
# Wipe sv.files.
if [ -n "$(find "${serveridentitydir}" -type f -name "sv.files.*.db")" ]; then
echo -en "removing server misc srv.files*.db file(s)..."
fn_sleep_time
fn_script_log_info "Removing server misc files: ${serveridentitydir}/sv.files.*.db"
find "${serveridentitydir:?}" -type f -name "sv.files.*.db" -delete | tee -a "${lgsmlog}"
fn_wipe_exit_code
fn_sleep_time
# No further information if not found because it should I could not get this file showing up.
fi
# Wipe player death files.
if [ -n "$(find "${serveridentitydir}" -type f -name "player.deaths.*.db")" ]; then
echo -en "removing player deaths player.deaths.*.db file(s)..."
fn_sleep_time
fn_script_log_info "Removing player death files: ${serveridentitydir}/player.deaths.*.db"
find "${serveridentitydir:?}" -type f -name "player.deaths.*.db" -delete | tee -a "${lgsmlog}"
fn_wipe_exit_code
fn_sleep_time
else
echo -e "no player death to remove"
fn_sleep_time
fn_script_log_pass "No player death to remove"
fi
# Wipe player states files
if [ -n "$(find "${serveridentitydir}" -type f -name "player.states.*.db")" ]; then
echo -en "removing player states player.states.*.db file(s)..."
fn_sleep_time
fn_script_log_info "Removing player states: ${serveridentitydir}/player.states.*.db"
find "${serveridentitydir:?}" -type f -name "player.states.*.db" -delete | tee -a "${lgsmlog}"
fn_wipe_exit_code
fn_sleep_time
else
echo -e "no player states to remove"
fn_sleep_time
fn_script_log_pass "No player states to remove"
fi
# Wipe blueprints only if full-wipe command was used.
if [ "${fullwipe}" == "1" ]; then
if [ -n "$(find "${serveridentitydir}" -type f -name "player.blueprints.*.db")" ]; then
echo -en "removing blueprints player.blueprints.*.db file(s)..."
fn_wipe_files(){
fn_print_start_nl "${wipetype}"
fn_script_log_info "${wipetype}"

# Remove Map files
if [ -n "${serverwipe}" ]||[ -n "${mapwipe}" ]; then
if [ -n "$(find "${serveridentitydir}" -type f -name "*.map")" ]; then
echo -en "removing .map file(s)..."
fn_script_log_info "removing *.map file(s)"
fn_sleep_time
fn_script_log_info "Removing blueprint file(s): ${serveridentitydir}/player.blueprints.*.db"
find "${serveridentitydir:?}" -type f -name "player.blueprints.*.db" -delete | tee -a "${lgsmlog}"
find "${serveridentitydir:?}" -type f -name "*.map" -printf "%f\n" >> "${lgsmlog}"
find "${serveridentitydir:?}" -type f -name "*.map" -delete | tee -a "${lgsmlog}"
fn_wipe_exit_code
else
echo -e "no .map file(s) to remove"
fn_sleep_time
fn_script_log_pass "no .map file(s) to remove"
fi
fi
# Remove Save files.
if [ -n "${serverwipe}" ]||[ -n "${mapwipe}" ]; then
if [ -n "$(find "${serveridentitydir}" -type f -name "*.sav*")" ]; then
echo -en "removing .sav file(s)..."
fn_script_log_info "removing .sav file(s)"
fn_sleep_time
find "${serveridentitydir:?}" -type f -name "*.sav*" -printf "%f\n" >> "${lgsmlog}"
find "${serveridentitydir:?}" -type f -name "*.sav*" -delete
fn_wipe_exit_code
else
echo -e "no blueprint file to remove"
echo -e "no .sav file(s) to remove"
fn_script_log_pass "no .sav file(s) to remove"
fn_sleep_time
fn_script_log_pass "No blueprint file to remove"
fi
elif [ -n "$(find "${serveridentitydir}" -type f -name "player.blueprints.*.db")" ]; then
echo -e "keeping blueprints"
fn_sleep_time
fn_script_log_info "Keeping blueprints"
else
echo -e "no blueprints found"
fn_sleep_time
fn_script_log_pass "No blueprints found"
fi
# Wipe some logs that might be there.
if [ -n "$(find "${serveridentitydir}" -type f -name "Log.*.txt")" ]; then
echo -en "removing log files..."
fn_sleep_time
fn_script_log_info "Removing log files: ${serveridentitydir}/Log.*.txt"
find "${serveridentitydir:?}" -type f -name "Log.*.txt" -delete
fn_wipe_exit_code
fn_sleep_time
# We do not print additional information if there are no logs to remove.
# Remove db files for full wipe.
# Excluding player.tokens.db for Rust+.
if [ -n "${serverwipe}" ]; then
if [ -n "$(find "${serveridentitydir}" -type f ! -name 'player.tokens.db' -name "*.db")" ]; then
echo -en "removing .db file(s)..."
fn_script_log_info "removing .db file(s)"
fn_sleep_time
find "${serveridentitydir:?}" -type f ! -name 'player.tokens.db' -name "*.db" -printf "%f\n" >> "${lgsmlog}"
find "${serveridentitydir:?}" -type f ! -name 'player.tokens.db' -name "*.db" -delete
fn_wipe_exit_code
else
echo -e "no .db file(s) to remove"
fn_sleep_time
fn_script_log_pass "no .db file(s) to remove"
fi
fi
}

fn_stop_warning(){
fn_print_warn "this game server will be stopped during wipe"
fn_script_log_warn "this game server will be stopped during wipe"
fn_map_wipe_warning(){
fn_print_warn "Map wipe will reset the map data and keep blueprint data"
fn_script_log_warn "Map wipe will reset the map data and keep blueprint data"
totalseconds=3
for seconds in {3..1}; do
fn_print_warn "this game server will be stopped during wipe: ${totalseconds}"
fn_print_warn "Map wipe will reset the map data and keep blueprint data: ${totalseconds}"
totalseconds=$((totalseconds - 1))
sleep 1
if [ "${seconds}" == "0" ]; then
break
fi
done
fn_print_warn_nl "this game server will be stopped during wipe"
fn_print_warn_nl "Map wipe will reset the map data and keep blueprint data"
}

fn_wipe_warning(){
fn_print_warn "wipe is about to start"
fn_script_log_warn "wipe is about to start"
fn_full_wipe_warning(){
fn_print_warn "Server wipe will reset the map data and remove blueprint data"
fn_script_log_warn "Server wipe will reset the map data and remove blueprint data"
totalseconds=3
for seconds in {3..1}; do
fn_print_warn "wipe is about to start: ${totalseconds}"
fn_print_warn "Server wipe will reset the map data and remove blueprint data: ${totalseconds}"
totalseconds=$((totalseconds - 1))
sleep 1
if [ "${seconds}" == "0" ]; then
break
fi
done
fn_print_warn "wipe is about to start"
fn_print_warn_nl "Server wipe will reset the map data and remove blueprint 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(){
shuf -i 1-2147483647 -n 1 > "${datadir}/${selfname}-seed.txt"
if [ -f "${datadir}/${selfname}-seed.txt" ]&&[ -n "${randomseed}" ]; then
shuf -i 1-2147483647 -n 1 > "${datadir}/${selfname}-seed.txt"
seed=$(cat "${datadir}/${selfname}-seed.txt")
randomseed=1
echo -en "generating new random seed (${cyan}${seed}${default})..."
fn_script_log_pass "generating new random seed (${cyan}${seed}${default})"
fn_sleep_time
fn_print_ok_eol_nl
fi
}

# Summary of what wipe is going to do
fn_wipe_details(){
fn_print_information_nl "Wipe does not remove Rust+ data."
echo -en "* Wipe map data: "
if [ -n "${serverwipe}" ]||[ -n "${mapwipe}" ]; then
fn_print_yes_eol_nl
else
fn_print_no_eol_nl
fi

echo -en "* Wipe blueprint data: "
if [ -n "${serverwipe}" ]; then
fn_print_yes_eol_nl
else
fn_print_no_eol_nl
fi

echo -en "* Change Procedural Map seed: "
if [ -n "${randomseed}" ]; then
fn_print_yes_eol_nl
else
fn_print_no_eol_nl
fi
}

fn_print_dots ""
check.sh
fix_rust.sh

# Check if there is something to wipe.
if [ -d "${serveridentitydir}/storage" ]||[ -d "${serveridentitydir}/user" ]||[ -n "$(find "${serveridentitydir}" -type f -name "*.sav*")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "Log.*.txt")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "player.deaths.*.db")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "player.blueprints.*.db")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "sv.files.*.db")" ]; then
fn_wipe_warning
if [ -n "$(find "${serveridentitydir}" -type f -name "*.map")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "*.sav*")" ]&&[ -n "$(find "${serveridentitydir}" -type f ! -name 'player.tokens.db' -name "*.db")" ]; then
if [ -n "${serverwipe}" ]; then
wipetype="Full wipe"
fn_full_wipe_warning
fn_wipe_details
elif [ -n "${mapwipe}" ]; then
wipetype="Map wipe"
fn_map_wipe_warning
fn_wipe_details
fi
check_status.sh
if [ "${status}" != "0" ]; then
fn_stop_warning
fn_print_restart_warning
exitbypass=1
command_stop.sh
fn_firstcommand_reset
fn_wipe_server_files
fn_wipe_files
fn_wipe_random_seed
fn_print_complete_nl "${wipetype}"
fn_script_log_pass "${wipetype}"
exitbypass=1
command_start.sh
fn_firstcommand_reset
else
fn_wipe_server_files
fn_wipe_files
fn_wipe_random_seed
fn_print_complete_nl "${wipetype}"
fn_script_log_pass "${wipetype}"
fi
fn_print_complete_nl "Wiping ${selfname}"
fn_script_log_pass "Wiping ${selfname}"
fn_wipe_random_seed
else
fn_print_ok_nl "Wipe not required"
fn_script_log_pass "Wipe not required"
Expand Down
7 changes: 4 additions & 3 deletions lgsm/functions/core_getopt.sh
Expand Up @@ -40,8 +40,9 @@ cmd_mods_update=( "mu;mods-update" "command_mods_update.sh" "Update installed mo
# Server specific.
cmd_change_password=( "pw;change-password" "command_ts3_server_pass.sh" "Change TS3 serveradmin password." )
cmd_install_default_resources=( "ir;install-default-resources" "command_install_resources_mta.sh" "Install the MTA default resources." )
cmd_wipe=( "w;wipe;wi" "command_wipe.sh" "Map assets are wiped and blueprints are kept." )
cmd_full_wipe=( "fw;full-wipe;wa;wipeall" "fullwipe=1; command_wipe.sh" "Map assets and blueprints are wiped." )
cmd_serverwipe=( "fw;full-wipe;wa;wipeall" "serverwipe=1; command_wipe.sh" "Reset the map and remove blueprint data." )
cmd_mapwipe=( "mw;map-wipe;w;wipe;wi" "mapwipe=1; command_wipe.sh" "Reset the map and keep blueprint data." )

cmd_map_compressor_u99=( "mc;map-compressor" "compress_ut99_maps.sh" "Compresses all ${gamename} server maps." )
cmd_map_compressor_u2=( "mc;map-compressor" "compress_unreal2_maps.sh" "Compresses all ${gamename} server maps." )
cmd_install_cdkey=( "cd;server-cd-key" "install_ut2k4_key.sh" "Add your server cd key." )
Expand Down Expand Up @@ -105,7 +106,7 @@ fi

# Unreal exclusive.
if [ "${shortname}" == "rust" ]; then
currentopt+=( "${cmd_wipe[@]}" "${cmd_full_wipe[@]}" )
currentopt+=( "${cmd_serverwipe[@]}" "${cmd_mapwipe[@]}" )
fi
if [ "${engine}" == "unreal2" ]; then
if [ "${shortname}" == "ut2k4" ]; then
Expand Down

0 comments on commit 70e6f9a

Please sign in to comment.