#!/sbin/openrc-run
# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

command="/usr/bin/python"
command_args="/usr/bin/syncplay-server"
name="syncplay server"
pidfile="/run/syncplay-server.pid"

description="Syncplay Server to synchronize media playback"

start() {
	ebegin "Starting ${name}"

	args=""

	if [ -n "${port}" ]; then
		args="${args} --port=${port}"
	fi

	if [ "${isolate}" = True ]; then
		args="${args} --isolate-rooms"
	fi

	if [ -n "${password}" ]; then
		args="${args} --password=${password}"
	fi

	if [ -n "${salt}" ]; then
		args="${args} --salt=${salt}"
	fi

	if [ -n "${motd}" ]; then
		args="${args} --motd-file=${motd}"
	fi

	if [ "${noReady}" = True ]; then
		args="${args} --disable-ready"
	fi

	if [ "${noChat}" = True ]; then
		args="${args} --disable-chat"
	fi

	if [ -n "${maxChatLength}" ]; then
		args="${args} --max-chat-message-length=${maxChatLength}"
	fi

	if [ -n "${usernameLength}" ]; then
		args="${args} --max-username-length=${usernameLength}"
	fi

	if [ -n "${statsFile}" ]; then
		args="${args} --stats-db-file=${statsFile}"
	fi

	if [ -n "${tls}" ]; then
		args="${args} --tls=${tls}"
	fi

	start-stop-daemon --start --background --make-pid --pidfile="${pidfile}" \
		--exec "${command}" -- "${command_args}" ${args}

	eend $?
}
