diff --git a/Makefile b/Makefile index d829a6c..09951b4 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,8 @@ build_docker: cp deps/redis.conf stage.tmp/ cp deps/run.sh stage.tmp/ cp deps/nethackrc stage.tmp/ + cp deps/chowner.sh stage.tmp/ + cp deps/run_nethack.sh stage.tmp/ cd stage.tmp/ && \ $(OS_PERMS) docker build -t $(IMAGE_NAME) . diff --git a/deps/Dockerfile b/deps/Dockerfile index cb13b4f..e1432d3 100644 --- a/deps/Dockerfile +++ b/deps/Dockerfile @@ -14,6 +14,7 @@ RUN mkdir -p /redisbackup/ # update nethack bin location RUN mv /usr/games/nethack /bin/nethack +RUN chmod 777 /bin/nethack RUN mkdir /hack/ # update ssh config @@ -21,7 +22,7 @@ RUN echo "AllowUsers hack" >> /etc/ssh/sshd_config RUN echo "PermitEmptyPasswords yes" >> /etc/ssh/sshd_config # add hack user -RUN useradd hack -s /nethack-launcher +RUN useradd hack -d / -s /nethack-launcher RUN echo 'hack:U6aMy0wojraho' | chpasswd -e RUN chown -R hack /hack/ @@ -30,6 +31,8 @@ COPY config.gcfg / COPY nethack-launcher / COPY redis.conf / COPY run.sh / +COPY chowner.sh /bin/ COPY nethackrc /hack/.nethackrc +COPY run_nethack.sh / CMD ["/run.sh"] diff --git a/deps/chowner.sh b/deps/chowner.sh new file mode 100755 index 0000000..fdc3aec --- /dev/null +++ b/deps/chowner.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +while : +do + chown -R hack:hack /hack 2> /dev/null + sleep 2 +done diff --git a/deps/nethackrc b/deps/nethackrc index da7e942..7035ddc 100644 --- a/deps/nethackrc +++ b/deps/nethackrc @@ -2,5 +2,172 @@ # good luck escaping # jk, its vim -OPTIONS=showexp,showscore,time,color,!autopickup -OPTIONS=autodig,fruit:slime mold,boulder:0 +#OPTIONS=showexp,showscore,time,color,!autopickup +#OPTIONS=autodig,fruit:slime mold,boulder:0 + +OPTIONS=menucolors +OPTIONS=autodig +OPTIONS=autoopen +OPTIONS=autopickup,pickup_types:$!/="+? +OPTIONS=autoquiver +OPTIONS=bones +OPTIONS=boulder:0 +OPTIONS=checkpoint +OPTIONS=color +OPTIONS=confirm +OPTIONS=dark_room +OPTIONS=disclose:+iagcv +OPTIONS=fruit:berries +OPTIONS=hilite_pet +OPTIONS=hilite_pile +OPTIONS=lootabc +OPTIONS=msg_window:reverse,msghistory:1000 +OPTIONS=pickup_burden:B +OPTIONS=!prayconfirm +OPTIONS=lit_corridor + +OPTIONS=showrace +OPTIONS=showexp,time +OPTIONS=sortloot:full +OPTIONS=runmode:teleport,!rest_on_space + +## Change symbols +SYMBOLS=S_ghost:X +SYMBOLS=S_mimic_def:m +SYMBOLS=S_water:~ +SYMBOLS=S_lava:~ + +## Use status hilites +OPTIONS=statushilites +# HP +OPTIONS=hitpointbar +OPTIONS=hilite_status:hitpoints/100%/grey&normal +OPTIONS=hilite_status:hitpoints/<100%/green&normal +OPTIONS=hilite_status:hitpoints/<66%/yellow&normal +OPTIONS=hilite_status:hitpoints/<50%/orange&normal +OPTIONS=hilite_status:hitpoints/<33%/red&bold +OPTIONS=hilite_status:hitpoints/<15%/red&inverse +## Pw +OPTIONS=hilite_status:power/100%/grey&normal +OPTIONS=hilite_status:power/<100%/green&normal +OPTIONS=hilite_status:power/<66%/yellow&normal +OPTIONS=hilite_status:power/<50%/orange&normal +OPTIONS=hilite_status:power/<33%/red&bold +## Carry +OPTIONS=hilite_status:cap/burdened/yellow/stressed/orange/strained/red&bold/overtaxed/red&inverse/overloaded/red&inverse&blink +## Hunger +OPTIONS=hilite_status:hunger/satiated/yellow/hungry/orange/weak/red&bold/fainting/red&inverse/fainted/red&inverse&blink +## Mental +OPTIONS=hilite_status:condition/hallu/yellow +OPTIONS=hilite_status:condition/conf/orange +OPTIONS=hilite_status:condition/stun/red&bold +## Health +OPTIONS=hilite_status:condition/termill/red&inverse +OPTIONS=hilite_status:condition/foodpois/red&inverse +OPTIONS=hilite_status:condition/slime/red&inverse +# Str, Con, Dex, Int, Wis, Cha +OPTIONS=hilite_status:characteristics/up/green/down/red +# gold +OPTIONS=hilite_status: gold/up/yellow/down/brown + +# FORCE COLORS +MENUCOLOR="\{R\}"=red +MENUCOLOR="\{B\}"=blue +MENUCOLOR="\{C\}"=cyan +MENUCOLOR="\{G\}"=green +MENUCOLOR="\{Y\}"=yellow +MENUCOLOR="\{[MP]\}"=magenta +MENUCOLOR="\{O\}"=orange +MENUCOLOR="\{W\}"=white +MENUCOLOR="\{L\}"=black +MENUCOLOR="\{y\}"=gray +MENUCOLOR="\{g\}"=lightgreen +MENUCOLOR="\{b\}"=lightblue +MENUCOLOR="\{[mp]\}"=lightmagenta +MENUCOLOR="\{c\}"=lightcyan + +# GOODIES +MENUCOLOR=" bag .* holding"=magenta +MENUCOLOR=" luck(stone)?($| )"=magenta +MENUCOLOR=" wand .* wish(ing)?($| )"=magenta +MENUCOLOR=" wand .* tele(port(ation)?)?($| )"=magenta +MENUCOLOR=" wand .* polymorph"=magenta +MENUCOLOR=" wand .* death"=magenta +MENUCOLOR=" gain level"=magenta +MENUCOLOR=" full healing"=magenta +MENUCOLOR=" magic marker"=magenta +MENUCOLOR=" magic lamp|lamp .* magic"=magenta + +MENUCOLOR=" unicorn horn[^[]*$"=magenta +#this doesn't color the #enhance unicorn + +MENUCOLOR=" tinning kit"=magenta +MENUCOLOR=" ring .* regen(eration)?($| )"=magenta +MENUCOLOR=" ring .* conflict"=magenta +MENUCOLOR=" ring .* (FA|free action)($| )"=magenta +MENUCOLOR=" ring .* (TC|teleport control)($| )"=magenta +MENUCOLOR=" ring .* lev(itation)?($| )"=magenta +MENUCOLOR=" scrolls? .* genocide($| )"=magenta +MENUCOLOR=" scrolls? .* charging($| )"=magenta +MENUCOLOR=" scrolls? .* identify($| )"=magenta +MENUCOLOR=" amulet .* (life ?saving|LS)($| )"=magenta +MENUCOLOR=" amulet .* ref(lection)?($| )"=magenta +MENUCOLOR=" c(o|hi)ckatrice (corpse|egg)"=magenta +MENUCOLOR=" egg .* cockatrice"=magenta +MENUCOLOR=" stethoscope"=magenta + +#instruments +MENUCOLOR="tooled horn|fire horn|frost horn|horn .* (tooled|fire|frost)"=magenta +MENUCOLOR=" harp"=magenta +MENUCOLOR=" bugle"=magenta +MENUCOLOR=" flute"=magenta + +# unidentified magic armor +MENUCOLOR="piece of cloth|opera cloak|ornamental cope|tattered cape"=magenta +MENUCOLOR="plumed helmet|etched helmet|crested helmet|visored helmet"=magenta +MENUCOLOR="(old|padded|riding|fencing) gloves"=magenta +MENUCOLOR="(mud|buckled|riding|snow|hiking|combat|jungle) boots"=magenta + +# FOOD CONDUCTS +# vegan +MENUCOLOR="(food |cram |K-|C-)ration|gunyoki"=green&bold +MENUCOLOR="lembas wafer|melon|carrot|tins? .* spinach"=green&bold +MENUCOLOR=" oranges?( named.*)?$"=green&bold +# avoid coloring orange DSM +MENUCOLOR=" pears?( named.*)?$"=green&bold +# avoid coloring pearl rings +MENUCOLOR=" (apple|banana|kelp|eucalyptus|garlic|wolfsbane)"=green&bold +MENUCOLOR=" (slime mold|berries)"=green&bold +## YOUR FRUIT HERE +MENUCOLOR="(tins? of )?(gelatinous cube|acid blob|quivering blob)( corpse)?"=green&bold +MENUCOLOR="(tins? of )?(blue|spotted|ochre) jelly( corpse)?"=green&bold +MENUCOLOR="(tins? of )?lichen|shrieker|violet fungus|(brown|yellow|green|red) mold( corpse)?"=green&bold + +# vegetarian +MENUCOLOR="egg|pancake|fortune cookie|candy bar|royal jelly|cream pie|candle"=green +MENUCOLOR="(tin of )?brown pudding|gray ooze( corpse)?"=green + +# WATER SPORTS +MENUCOLOR=" holy water"=cyan&bold +MENUCOLOR=" blessed clear potion"=cyan&bold +MENUCOLOR=" blessed potions? called water"=cyan&bold +MENUCOLOR=" clear potions? named (holy|blessed|B)($| )"=cyan&bold +MENUCOLOR=" potions? of water named (holy|blessed|B)($| )"=cyan&bold +MENUCOLOR=" potions? called water named (holy|blessed|B)($| )"=cyan&bold +MENUCOLOR=" unholy water"=orange +MENUCOLOR=" cursed clear potion"=orange +MENUCOLOR=" cursed potions? called water"=orange +MENUCOLOR=" potions? called water named (unholy|cursed|C)($| )"=orange + +# B/U/C +#MENUCOLOR="^[a-zA-Z$] - "=white #may want to enable this if regularly playing priest.. (priests don't see the 'uncursed') +MENUCOLOR=" !C"=white +MENUCOLOR=" !B"=white +MENUCOLOR=" !UC"=white +MENUCOLOR=" uncursed| UC?($| )"=white +MENUCOLOR=" \([-0-9]+:[-0-9]+\)"=white +#nethack doesn't display "uncursed" if charges are known +MENUCOLOR=" [+-][0-9]"=white + +MENUCOLOR=" blessed| B($| )"=cyan +MENUCOLOR=" cursed| C($| )"=red diff --git a/deps/run.sh b/deps/run.sh index 253931d..163440a 100755 --- a/deps/run.sh +++ b/deps/run.sh @@ -1,5 +1,8 @@ #!/bin/bash +# start chown script +/bin/chowner.sh & + # start redis server redis-server /redis.conf | sed "s/^/[redis] /" diff --git a/deps/run_nethack.sh b/deps/run_nethack.sh new file mode 100755 index 0000000..3bb2058 --- /dev/null +++ b/deps/run_nethack.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +TTYRECPATH=$1 +HOMEDIR=$2 +HACKDIR=$3 +USER=$4 + +HOME=$HOMEDIR nethack -d $HACKDIR -u $USER +ttyrec $TTYRECPATH -e "HOME=$HOMEDIR nethack -d $HACKDIR -u $USER" diff --git a/nethack-launcher.go b/nethack-launcher.go index 296302b..fbfd122 100644 --- a/nethack-launcher.go +++ b/nethack-launcher.go @@ -225,7 +225,6 @@ func printUserScreen(redisClient *redis.Client, username string) string { go runGame(username, fulltime) watcher := startWatcher(username, fulltime, redisClient) wg.Wait() - fmt.Println("CLOSING") close(watcher) printUserScreen(redisClient, username) case "q": @@ -457,15 +456,17 @@ func printProgressScreen(redisClient *redis.Client, username string) { func runGame(username, timestamp string) { // put together users home dir homeDir := fmt.Sprintf("%s/user/%s/", config.NethackLauncher.HackDir, username) - nhCommand := fmt.Sprintf("HOME=%s nethack -d %s -u %s\n", homeDir, config.NethackLauncher.HackDir, username) ttyrecPath := fmt.Sprintf("%s/user/%s/ttyrec/%s.ttyrec", config.NethackLauncher.HackDir, username, timestamp) exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() clearScreen() - nh := exec.Command("ttyrec", ttyrecPath, "-e", nhCommand) + nh := exec.Command("/run_nethack.sh", ttyrecPath, homeDir, config.NethackLauncher.HackDir, username) nh.Stdout = os.Stdout nh.Stdin = os.Stdin nh.Stderr = os.Stderr - nh.Run() + err := nh.Run() + if err != nil { + fmt.Print(err) + } exec.Command("exit").Run() wg.Done() }