games-simulation/openttd: add custom attach command

Adding a custom attach command, so you can attach yourself with 'dtach'
in the interactive console open OpenTTD, when running in server mode.

Signed-off-by: Conrad Kostecki <conikost@gentoo.org>
This commit is contained in:
Conrad Kostecki
2022-04-12 22:57:20 +02:00
parent 9ed8e3a9c6
commit 17d9e66641
5 changed files with 47 additions and 23 deletions

View File

@@ -1,5 +0,0 @@
# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# Options for your started OpenTTD server
openttd_opts=""

View File

@@ -0,0 +1,10 @@
# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# Dtach options, which will used, when the `attach` extra command is called.
# By default, CTRL+D is used, and no signal is send,
# when you want to detach from the attached console.
dtach_opts="-e '^D' -r none"
# Options for your started OpenTTD server
openttd_opts=""

View File

@@ -1,16 +0,0 @@
#!/sbin/openrc-run
# Copyright 1999-2022 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2 or later
description="OpenTTD dedicated game server"
pidfile="/run/${SVCNAME}.pid"
command="/usr/bin/openttd"
command_args="-D ${openttd_opts}"
command_background="true"
command_group="openttd"
command_user="openttd"
depend() {
need net
}

View File

@@ -0,0 +1,34 @@
#!/sbin/openrc-run
# Copyright 1999-2022 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2 or later
description="OpenTTD dedicated game server"
dtach_tmpfile="$(mktemp -u)"
name="OpenTTD dedicated game server"
openttd_command="/usr/bin/openttd"
pidfile="/run/${SVCNAME}.pid"
description_attach="Attaches to the session (interactive console) of the OpenTTD game server"
extra_started_commands="attach"
command="/usr/bin/dtach"
command_args="-N ${dtach_tmpfile} ${openttd_command} -D ${openttd_opts}"
command_background="true"
command_group="openttd"
command_user="openttd"
depend() {
need net
}
attach() {
pidnumber="$(cat ${pidfile})"
dtach_tmpfile="$(cat /proc/${pidnumber}/cmdline | tr '\0' ' ' | awk '{print $3}')"
if [ -S "${dtach_tmpfile}" ]; then
eval "${command}" -a "${dtach_tmpfile}" "${dtach_opts}"
else
eerror "The determined socket file for dtach could not be found!"
eerror "Did the process crash?"
fi
}

View File

@@ -22,6 +22,7 @@ RDEPEND="
dedicated? (
acct-group/openttd
acct-user/openttd
app-misc/dtach
)
!dedicated? (
allegro? ( media-libs/allegro:5 )
@@ -90,8 +91,8 @@ src_configure() {
src_install() {
cmake_src_install
if use dedicated ; then
newconfd "${FILESDIR}"/openttd.confd openttd
newinitd "${FILESDIR}"/openttd.initd-r2 openttd
newconfd "${FILESDIR}"/openttd.confd-r1 openttd
newinitd "${FILESDIR}"/openttd.initd-r3 openttd
fi
}