Closed sebneira closed 4 years ago
you can change the source, add this to the case under new-map or something...
start-scenario)
if [ -z $2 ]; then
echo -e "You must specify a scenario name example: scenario-name or base/freeplay or latest for the latest scenario added"
exit 1
fi
scenarioname="$2"
if [ "${scenarioname}" == "latest" ]; then
scenarioname="$(ls -t ${WRITE_DIR}/scenarios/ | head -1)"
echo -e "Using latest scenario: ${scenarioname}"
fi
# Check if user wants to use custom map gen settings
if [ $3 ]; then
if [ -e "${WRITE_DIR}/$3" ]; then
if [ $4 ]; then
if [ -e "${WRITE_DIR}/$4" ]; then
mapgen="--map-gen-settings=${WRITE_DIR}/$3 --map-settings=${WRITE_DIR}/$4"
else
echo -e "Specified map settings json does not exist"
exit 1
fi
fi
else
echo -e "Specified map gen settings json does not exist"
exit 1
fi
else
mapgen="--preset rail-world"
fi
# Stop Service
if is_running; then
send_cmd "Generating new save, please stand by"
if ! stop_service; then
echo -e "Failed to stop server, unable to create new save"
exit 1
fi
fi
if ! start_service_scenario "--start-server-load-scenario ${scenarioname}" "${mapgen}"; then
echo -e "Could not start $SERVICE_NAME"
exit 1
fi
;;
and add a function under start_service(), something like this...
start_service_scenario() {
if [ -z "$1" ]; then
echo -e "No scenario name passed to start_service_scenario()"
return 1
fi
scenario="$1"
if [ -z "$2" ]; then
echo -e "No map gen passed to start_service_scenario()"
return 1
fi
mapgen="$2"
if [ -e ${PIDFILE} ]; then
ps -p $(cat ${PIDFILE}) > /dev/null 2>&1
if [ "$?" -eq "0" ]; then
echo -e "${SERVICE_NAME} is already running!"
return 1
fi
debug "Found rogue pid file, server might have crashed"
rm ${PIDFILE} 2> /dev/null
fi
if ! check_permissions; then
echo -e "Error! Incorrect permissions, unable to write to ${WRITE_DIR}"
return 1
fi
if [ "${SAVELOG}" == "0" ]; then
debug "Erasing log ${CMDOUT}"
echo "" > ${CMDOUT}
fi
as_user "tail -f ${FIFO} |${INVOCATION} ${scenario} ${mapgen} >> ${CMDOUT} 2>&1 & echo \$! > ${PIDFILE}"
ps -p $(cat ${PIDFILE}) > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
echo -e "Unable to start ${SERVICE_NAME}"
return 1
else
echo -e "Started ${SERVICE_NAME} with pid: $(cat ${PIDFILE}), please see log for details"
fi
}
shouldn't be that hard
When I use the script after inserting the code I get --start-server-load-scenario can't be used together with --start-server-load-latest
Could you please take another look? I'm not well versed with code.
Should be possible :)
I was able to get this to work after making this change to the above code
if ! start_service_scenario ${scenarioname} "${mapgen}"; then
@Kilandor - feel free to submit a pull request of your changes if you have the time for it :)
I may be wrong here, but it seems like I can't start scenarios without having to call the binary directly.
The flag to start a scenario is
--start-server-load-scenario
.Thanks!