Browse Source

Add initial commit

master
Matthew Faltys 5 years ago
commit
d31638d191
  1. 31
      Makefile
  2. 73
      deps/Dockerfile
  3. 8
      deps/chowner.sh
  4. 399
      deps/dgamelaunch.conf
  5. BIN
      deps/initial_savedata.tar.gz
  6. 4
      deps/run.sh
  7. 18
      deps/run_nethack_docker.sh

31
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/

73
deps/Dockerfile vendored

@ -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"]

8
deps/chowner.sh vendored

@ -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

399
deps/dgamelaunch.conf vendored

@ -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:
# [ "<display title>", "<sortname>", <Screen column>, "<printf format>" ]
#
# <sortname> 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 [ <time> ] = <command> ...
#
# <time> can be one of:
# dglstart = when someone telnets in
# login = when user has logged in
# register = right after a new user is registered
# gamestart = just before a game is started
# gameend = after a game ends (see also per-game "postcommand" define)
#
# <command> is:
# mkdir "foo" = create a directory "foo"
# chdir "foo" = change current work dir to "foo"
# cp "foo" "bar" = copy file "foo" to "bar", overwriting previous "bar"
# ifnxcp "foo" "bar" = copy file "foo" to "bar", if "bar" doesn't exist
# unlink "foo" = delete file "foo"
# setenv "foo" "bar" = set environment variable "foo" to "bar"
# exec "foo" "bar" = execute "foo" with "bar" as it's param
# rawprint "foo" = output string "foo"
# chpasswd = do the change password prompting, if logged in
# chmail = do the change email prompting, if logged in
# watch_menu = go to the watching menu
# quit = quit dgl
# ask_login = do the login prompting, if not logged in
# ask_register = do register new user prompting, if not logged in and
# registration of new nicks is allowed.
# play_game "foo" = start game which has the short name "foo"
# (user must be logged in)
# play_if_exist "foo" "file" = start game "foo", if file "file" exists.
# submenu "foo" = go to submenu "foo"
# return = return from submenu
#
# NOTE: edit_options-command was removed. use ifnxcp and exec to simulate it.
#
# The commands will be done inside the chroot and with the uid and gid
# defined above.
# Parameters to the commands are subject to variable substitution:
# %r = dglroot, as defined above
# %n = user nick, if user is logged in
# %N = first character of user name, if user is logged in
# %u = shed_uid, as defined above, but numeric
# %g = game name, if user has selected a game.
# %s = short game name, if user has selected a game.
# %t = ttyrec path & filename of the last game played.
#
# Also some escape codes:
# \\ = backslash
# \a = bell
# \b = backspace
# \e = escape character
# \f = form feed
# \n = newline
# \r = carriage return
# \t = tab
# \v = vertical tab
#
# eg. commands[login] = mkdir "foo", unlink "bar", setenv "Z" "foo"
#
# Change the terminal title: (assuming terminals support the escape code)
#commands[dglstart] = rawprint "\e]2;nethack.alt.org\a"
# create the user's dirs when they register
commands[register] = mkdir "%ruserdata/%N",
mkdir "%ruserdata/%N/%n",
mkdir "%ruserdata/%N/%n/dumplog",
mkdir "%ruserdata/%N/%n/ttyrec"
commands[login] = mkdir "%ruserdata/%N",
mkdir "%ruserdata/%N/%n",
mkdir "%ruserdata/%N/%n/dumplog",
mkdir "%ruserdata/%N/%n/ttyrec"
# file mode for when commands copy files.
# readable and writable by all. you could use eg. "0644" to be more secure.
filemode = "0666"
# Define the main menus.
# You _must_ define "mainmenu_anon" and "mainmenu_user".
# $VERSION and $SERVERID will be replaced, as per the bannerfile above.
# First, the menu shown to anonymous user:
menu["mainmenu_anon"] {
bannerfile = "dgl_menu_main_anon.txt"
cursor = (5,18)
commands["l"] = ask_login
commands["r"] = ask_register
commands["w"] = watch_menu
commands["q"] = quit
}
# Then the menu shown when the user has logged in:
# $USERNAME in here will be replaced with the user name.
menu["mainmenu_user"] {
# contents of this file are written to screen.
# the file must be inside the chroot.
# Some string subsitutions can be done in the file:
# $INCLUDE(filename) = includes the file to this file.
# String substitutions defined in bannervars-section above.
# $VERSION = dgamelaunch version
# $USERNAME = user name (or [Anonymous] if not logged in)
# $ATTR(params) = change text color and attributes.
# params can be either number (to set the text color),
# one, or any of "b" (bold), "s" (standout), "u" (underline),
# "r" (reverse) or "d" (dim),
# or both color number and attribute characters, separated by colon.
# Empty param resets color and attributes to default.
bannerfile = "dgl_menu_main_user.txt"
# after which cursor is moved to this location
# if cursor-definition is missing, the cursor is put
# to the end of the last line of the banner.
# cursor = (5,18)
# keys we accept. format is
# commands["string_of_keys"] = <commandlist>
# for example, you could use commands["qQ"] = quit
commands["c"] = chpasswd
commands["e"] = chmail
commands["w"] = watch_menu
commands["o"] = ifnxcp "/dgl-default-rcfile.nh343" "%ruserdata/%N/%n/%n.nh343rc",
exec "/bin/virus" "%ruserdata/%N/%n/%n.nh343rc"
commands["p"] = play_game "NH343"
commands["q"] = quit
}
# this menu is shown when user presses '?' in the watching menu
menu["watchmenu_help"] {
bannerfile = "dgl_menu_watchmenu_help.txt"
commands["qQ "] = return
}
# Next, we'll define one game's data:
#DEFINE {
# # From inside the jail, the location of the binary to be launched.
# game_path = "/bin/nethack.343-naostub"
#
# # Full name of the game
# game_name = "NetHack stub"
#
# # Short name, used in the watching menu
# short_name = "NHstb"
#
# # Game ID - should be unique. Defaults to game_name, if not defined.
# # Used to determine which game is which for "play_game" and "play_if_exists" commands
# game_id = "NHstb"
#
# # arguments for when we exec the binary
# game_args = "/bin/nethack.343-naostub",
# "foo",
# "user:%n",
# "shed_uid:%u",
# "bar"
#
# # From inside the jail, where dgamelaunch should put mail.
# spooldir = "/var/mail/"
#
# # From inside the jail, the default .nethackrc that is copied for new users.
# # rc_template = "/dgl-default-rcfile"
#
# # If player idles longer than max_idle_time seconds, the game will
# # receive a sighup. Default value is 0, which disables the idling timer.
# max_idle_time = 2000
#
# # Player-specific path to an extra information file written by the game
# # The game should write the extra information on one line in this format:
# # <numeric-weight>|extra-information
# # For example, the game might write: "100|Astral", "1|D:1", etc. to indicate
# # where the player is in the game world. The numeric weight is used when
# # a spectator sorts games by the extra information field: higher weights
# # will be sorted to appear before lower weights.
# #
# extra_info_file = "%rgamedir/%N/%n.extrainfo"
#
# # Make sure the inprogress dir actually exists. default is "inprogress/"
# # Each game you define here must have it's own.
# inprogressdir = "%rinprogress-nethackstub/"
#
# # We can also define per-game commands, that are executed
# # when the game starts:
# # commands = chdir "/dgldir", mkdir "foo_%u_%g"
#
# # We can also define per-game commands executed after the game ends,
# # but before commands[gameend]
# postcommands = chdir "/"
#
# # If the game uses an ancient encoding, you may specify "ibm" or "dec".
# # If set to "ask", the game will be run with --print-charset beforehand,
# # expected to return one of these values.
# encoding = "unicode"
#}
#
# the second game
#
#
DEFINE {
game_path = "/nh343/nethack.343-nao"
game_name = "NetHack 3.4.3"
short_name = "NH343"
game_args = "/nh343/nethack.343-nao", "-u", "%n"
spooldir = "/mail/"
rc_template = "/dgl-default-rcfile.nh343"
rc_fmt = "%ruserdata/%N/%n/%n.nh343rc"
inprogressdir = "%rinprogress-nh343/"
# The place where ttyrecs are stored for this game.
# If this is not defined, ttyrecs are not saved for this game.
# Leaving this undefined also means the games cannot be spectated.
ttyrecdir = "%ruserdata/%N/%n/ttyrec/"
# back up savefile
commands = cp "/nh343/var/save/%u%n.gz" "/nh343/var/save/%u%n.gz.bak",
# set NETHACKOPTIONS to point to the rcfile
setenv "NETHACKOPTIONS" "@%ruserdata/%N/%n/%n.nh343rc",
# set up nethack mail stuff, assuming it's compiled with it...
setenv "MAIL" "/mail/%N/%n",
setenv "SIMPLEMAIL" "1",
# don't let the mail file grow
unlink "/mail/%N/%n"
}
#
# third game
#
#
#DEFINE {
# game_path = "/bin/crawlss017"
# game_name = "Crawl Stone Soup 0.1.7"
# short_name = "Cr017"
#
# game_args = "/bin/crawlss017",
# "-name", "%n",
# "-dir", "/crawlss017/",
# "-rc", "%rrcfiles/%N/%n.crawlrc",
# "-morgue", "/crawlss017/morgues/",
# "-macro", "/crawlss017/macros/%N/%n.macro"
#
# rc_template = "/dgl-default-rcfile.crawl"
# rc_fmt = "%rrcfiles/%N/%n.crawlrc"
# inprogressdir = "%rinprogress-crawlss017/"
# encoding = ask
#}
#
# fourth game
#
#
#DEFINE {
# game_path = "/bin/crawlss020"
# game_name = "Crawl Stone Soup 0.2.0"
# short_name = "Cr020"
#
# game_args = "/bin/crawlss020",
# "-name", "%n",
# "-dir", "/crawlss020/",
# "-rc", "/crawlss020/plr/%N/%n/%n.crawlrc",
# "-morgue", "/crawlss020/plr/%N/%n/",
# "-macro", "/crawlss020/plr/%N/%n/"
#
# rc_template = "/dgl-default-rcfile.crawl"
# rc_fmt = "/crawlss020/plr/%N/%n/%n.crawlrc"
# inprogressdir = "%rinprogress-crawlss020/"
#}

BIN
deps/initial_savedata.tar.gz vendored

Binary file not shown.

4
deps/run.sh vendored

@ -0,0 +1,4 @@
#!/bin/bash
/chowner.sh &
xinetd -dontfork

18
deps/run_nethack_docker.sh vendored

@ -0,0 +1,18 @@
#!/bin/bash
NETHACK_DIR=/home/admin/nethack-server/savedata
sudo 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 \
nethack-server
#--user 5:60 \
#-v $NETHACK_DIR/var:/opt/nethack/nethack.alt.org/nh343/var:rw \
#-v $NETHACK_DIR/dgldir:/opt/nethack/nethack.alt.org/dgldir:rw \
#-v /tmp/nethack:/tmp/nethack:rw \
#--mount type=bind,source=$NETHACK_DIR/dgldir,target=/opt/nethack/nethack.alt.org/dgldir \
#--mount type=bind,source=$NETHACK_DIR/var,target=/opt/nethack/nethack.alt.org/nh343/var \
Loading…
Cancel
Save