From d31638d19193b15033151e582355183713a9a208 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Sat, 2 Nov 2019 21:21:49 -0500 Subject: [PATCH] Add initial commit --- Makefile | 31 +++ deps/Dockerfile | 73 +++++++ deps/chowner.sh | 8 + deps/dgamelaunch.conf | 399 +++++++++++++++++++++++++++++++++++ deps/initial_savedata.tar.gz | Bin 0 -> 526 bytes deps/run.sh | 4 + deps/run_nethack_docker.sh | 18 ++ 7 files changed, 533 insertions(+) create mode 100644 Makefile create mode 100644 deps/Dockerfile create mode 100755 deps/chowner.sh create mode 100644 deps/dgamelaunch.conf create mode 100644 deps/initial_savedata.tar.gz create mode 100755 deps/run.sh create mode 100755 deps/run_nethack_docker.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..636f28e --- /dev/null +++ b/Makefile @@ -0,0 +1,31 @@ +OS_PERMS=sudo +IMAGE_NAME=nethack-server +NETHACK_DIR=$(shell pwd)/savedata + +all: run + +run: savedata + $(OS_PERMS) docker run \ + -d \ + -p 23:23 \ + -v $(NETHACK_DIR)/var:/opt/nethack/nethack.alt.org/nh343/var:rw \ + -v $(NETHACK_DIR)/dgldir:/opt/nethack/nethack.alt.org/dgldir:rw \ + --name=nethack \ + --restart always \ + $(IMAGE_NAME) + + +build: + mkdir -p stage.tmp/ + cp deps/chowner.sh stage.tmp/ + cp deps/dgamelaunch.conf stage.tmp/ + cp deps/Dockerfile stage.tmp/ + cp deps/run.sh stage.tmp/ + cd stage.tmp/ && \ + $(OS_PERMS) docker build -t $(IMAGE_NAME) . + +savedata: + tar -xzf deps/initial_savedata.tar.gz + +clean: + rm -rf stage.tmp/ diff --git a/deps/Dockerfile b/deps/Dockerfile new file mode 100644 index 0000000..49a911b --- /dev/null +++ b/deps/Dockerfile @@ -0,0 +1,73 @@ +FROM debian + +RUN \ + apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y autoconf bison \ + bsdmainutils flex gcc git groff libncursesw5-dev libsqlite3-dev make \ + ncurses-dev sqlite3 tar telnetd xinetd locales && \ + apt-get clean + +RUN locale-gen en_US.UTF-8 + +RUN git clone git://github.com/paxed/dgamelaunch.git && \ + cd dgamelaunch && \ + sed -i \ + -e "s/-lrt/-lrt -pthread/" \ + configure.ac && \ + sed -i \ + -e "/^maxnicklen/s/=.*/= 20/" \ + -e "/game_\(path\|args\)/s/nethack/nethack.343-nao/" \ + -e "/^commands\[\(register\|login\)\]/s/=\(.*\)/= mkdir \"%ruserdata\/%N\",\n\1/" \ + -e "s:/%n:/%N/%n:" \ + examples/dgamelaunch.conf && \ + ./autogen.sh \ + --enable-sqlite \ + --enable-shmem \ + --with-config-file=/opt/nethack/nethack.alt.org/etc/dgamelaunch.conf && \ + make && \ + ./dgl-create-chroot && \ + cd .. && \ + rm -rf dgamelaunch + +RUN git clone http://alt.org/nethack/nh343-nao.git && \ + cd nh343-nao && \ + sed -i \ + -e "/^CFLAGS/s/-O/-O2 -fomit-frame-pointer/" \ + sys/unix/Makefile.src && \ + sed -i \ + -e "/rmdir \.\/-p/d" \ + sys/unix/Makefile.top && \ + sed -i \ + -e "/^CFLAGS/s/-O/-O2 -fomit-frame-pointer/" \ + sys/unix/Makefile.utl && \ + make all && \ + make install && \ + cd .. && \ + rm -rf nh343-nao + +RUN tar cf - \ + /lib/x86_64-linux-gnu/libncurses* \ + | tar xf - -C /opt/nethack/nethack.alt.org/ + +RUN ( \ + echo "service telnet" && \ + echo "{" && \ + echo " socket_type = stream" && \ + echo " protocol = tcp" && \ + echo " user = root" && \ + echo " wait = no" && \ + echo " server = /usr/sbin/in.telnetd" && \ + echo " server_args = -L /opt/nethack/nethack.alt.org/dgamelaunch" && \ + echo " rlimit_cpu = 120" && \ + echo "}" \ +) > /etc/xinetd.d/dgl + +#VOLUME ["/opt/nethack/nethack.alt.org/nh343/var", "/opt/nethack/nethack.alt.org/dgldir"] +COPY dgamelaunch.conf /opt/nethack/nethack.alt.org/etc/dgamelaunch.conf +COPY chowner.sh / +COPY run.sh / + +EXPOSE 23 + +#CMD ["xinetd", "-dontfork"] +CMD ["/run.sh"] diff --git a/deps/chowner.sh b/deps/chowner.sh new file mode 100755 index 0000000..9620445 --- /dev/null +++ b/deps/chowner.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +while : +do + chown -R games:games /opt/nethack/nethack.alt.org/nh343/var 2> /dev/null + chown -R games:games /opt/nethack/nethack.alt.org/dgldir 2> /dev/null + sleep 3 +done diff --git a/deps/dgamelaunch.conf b/deps/dgamelaunch.conf new file mode 100644 index 0000000..944e331 --- /dev/null +++ b/deps/dgamelaunch.conf @@ -0,0 +1,399 @@ +# This is a sample dgamelaunch configuration file. Only bash-style comments +# are allowed, such as this. Each configuration option will be explained +# along with its default value. + + + +# Global config variables: + + +# Max amount of registered users to allow. Has no effect if dgl was +# compiled with SQLite +maxusers = 64000 + +# Allow registration of new nicks? (yes or no) +allow_new_nicks = yes + +# Max length for newly registered nicks. Must be less than 20. +# By default, NetHack only stores the first 10 chars of a name into +# the record/logfile. +maxnicklen = 20 + +# Set the default watching-screen sorting mode. Can be one of +# "username", "game", "windowsize", "starttime" or "idletime". +# "username" is the default. +#sortmode = "username" + +# Set the columns displayed in the watching-screen. Each column definition +# must have four elements as: +# [ "", "", , "" ] +# +# may be "unsorted", "username", "game", "windowsize", "starttime", +# "duration", "idletime", or (if shmem is enabled) "watchers". +# +# watch_columns = [ ["", "", 1, "%s)"], +# ["User", "username", 4, "%-15s"], +# ["Game", "game", 21, "%-11s"], +# ["Term", "windowsize", 34, "%s"], +# ["Idle", "idletime", 43, "%-10s"], +# ["Watchers", "watchers", 55, "%5s"], +# ["Started", "starttime", 65, "%s"] +# ] + +# Path to a prepared chroot jail. +chroot_path = "/opt/nethack/nethack.alt.org/" + +# From inside the jail, dgamelaunch's working directory for rcfiles/ttyrec/etc +dglroot = "/dgldir/" + +# Strings to be replaced in every banner +# you can have either direct string replacements, like +# "$FOO" = "BAR", or you can get the server time with +# "$FOO" = timeformat("%F %T") +# for the timeformat parameter string format, see man strftime +bannervars = [ "$MOTDTIME" = "2011.10.08", + "$SERVERID" = "$ATTR(14)unixvoid.com - underground nethack server$ATTR()", + "$DATETIME" = timeformat("%F %T") + ] +#bannervars = [ "$MOTDTIME" = "2011.10.08", +# "$SERVERID" = "$ATTR(14)nethack.alt.org - http://nethack.alt.org/$ATTR()", +# "$DATETIME" = timeformat("%F %T") +# ] + +# From inside the jail, location of a banner file, which is +# shown in submenus that cannot be defined separately. +# Some string substitution is done for every banner file contents: +# - bannervars from above +# - $VERSION replaced with "dgamelaunch v" + dgl version number. +# - $USERNAME replaced with logged-in user's name, or with "[Anonymous]" +# - $INCLUDE(filename) the named file will be inserted here. +banner = "/dgl-banner" + +# The following two options are fairly insecure. They will force us to +# load the password/group database into memory while still having root +# privileges. Replace them with shed_uid/shed_gid entries as soon as +# possible if you decide to use them. dgamelaunch will inform you of +# the uids/gids corresponding to your choices when it loads. +# +# Note that shed_uid and shed_gid will always take precedence over +# shed_user and shed_group if they are specified. + +# shed_user: username to shed privileges to +#shed_user = "games" +# shed_group: group name to shed privileges to +#shed_group = "games" + +# Preferably, you may use the respective gids/uids. This is for Debian: +shed_uid = 5 +shed_gid = 60 + +# Locale. Leaving this out, dgamelaunch will not explicitly set locale. +locale = "en_US.UTF-8" + +# Default TERM, used if the user's $TERM is unknown. +# If undefined, dgamelaunch will just terminate in that case. +default_term = "xterm" + +# Should dgl send select-UTF8-charset escape code? (that is: ESC % G) +# default is no. +#utf8esc = yes + +# Should dgl allow XON/XOFF? Default is "yes", meaning "don't touch it". +# "no" disables XON/XOFF +#flowcontrol = no + +# Maximum time in seconds user can idle in the dgamelaunch menus +# before dgl exits. Default value is 0, which disables the idling timer. +# Does not apply to external programs or config editors. +# For setting game idle time, use max_idle_time in the game DEFINE. +# menu_max_idle_time = 1024 + +# Passwd refers to the file that stores the user database. +# The default passwd file is "/dgl-login" for flat-text database, and for +# sqlite, whatever value was defined for the sqlite database at compile time. +# This is also used for the shared memory key, if shmem is enabled at compile +# time. +#passwd = "/dgl-login" + +# Lockfile is used only when dgl was compiled without sqlite. +#lockfile = "/dgl-lock" + +# +# define some commands that are run when something happens. format is +# commands [