Browse Source

Termrec research

master
Matthew Faltys 5 years ago
parent
commit
d3cd8274a6
  1. 2
      .gitignore
  2. 7
      Makefile
  3. 1
      deps/Dockerfile
  4. 1
      deps/chowner.sh
  5. 9
      deps/nethackrc
  6. 2
      deps/redis.conf
  7. 2
      deps/run_nethack.sh
  8. 23
      nethack-launcher.go

2
.gitignore vendored

@ -1,4 +1,4 @@
*.swp
savedata/
hack/
stage.tmp/
bin/

7
Makefile

@ -2,7 +2,7 @@ GOC=go build
GOFLAGS=-a -ldflags '-s'
CGOR=CGO_ENABLED=0
OS_PERMS=sudo
NETHACK_DIR=$(shell pwd)/savedata
NETHACK_DIR=$(shell pwd)/hack
IMAGE_NAME=nethack_launch
@ -35,13 +35,12 @@ build_docker:
run_docker:
$(OS_PERMS) docker run \
-d \
-p 2222:22 \
--name=nethack \
-v $(NETHACK_DIR):/hack:rw \
--restart always \
$(IMAGE_NAME)
#-v $(NETHACK_DIR)/var:/opt/nethack/nethack.alt.org/nh343/var:rw \
#-v $(NETHACK_DIR)/dgldir:/opt/nethack/nethack.alt.org/dgldir:rw \
clean:
rm -rf bin/
rm -rf stage.tmp/

1
deps/Dockerfile vendored

@ -4,6 +4,7 @@ FROM debian
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
ttyrec \
termrec \
nethack-console \
redis-server \
openssh-server \

1
deps/chowner.sh vendored

@ -3,5 +3,6 @@
while :
do
chown -R hack:hack /hack 2> /dev/null
chmod -R 744 /hack 2> /dev/null
sleep 2
done

9
deps/nethackrc vendored

@ -8,7 +8,7 @@
OPTIONS=menucolors
OPTIONS=autodig
OPTIONS=autoopen
OPTIONS=autopickup,pickup_types:$!/="+?
#OPTIONS=autopickup,pickup_types:$!/="+?
OPTIONS=autoquiver
OPTIONS=bones
OPTIONS=boulder:0
@ -16,20 +16,14 @@ 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
@ -168,6 +162,5 @@ 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

2
deps/redis.conf vendored

@ -1,4 +1,4 @@
daemonize yes
dbfilename dump.rdb
dir /redisbackup/
dir /hack/
save 30 1

2
deps/run_nethack.sh vendored

@ -5,5 +5,5 @@ HOMEDIR=$2
HACKDIR=$3
USER=$4
HOME=$HOMEDIR nethack -d $HACKDIR -u $USER
#HOME=$HOMEDIR nethack -d $HACKDIR -u $USER
ttyrec $TTYRECPATH -e "HOME=$HOMEDIR nethack -d $HACKDIR -u $USER"

23
nethack-launcher.go

@ -1,5 +1,8 @@
package main
// TODO make poll time faster
// TODO password redo field
import (
"bufio"
"fmt"
@ -47,15 +50,15 @@ func main() {
// init redis connection
redisClient, redisErr := initRedisConnection()
if redisErr != nil {
glogger.Debug.Printf("redis connection cannot be made, trying again in %s second(s)\n", config.NethackLauncher.BootstrapDelay*time.Second)
//glogger.Debug.Printf("redis connection cannot be made, trying again in %s second(s)\n", config.NethackLauncher.BootstrapDelay*time.Second)
time.Sleep(config.NethackLauncher.BootstrapDelay * time.Second)
redisClient, redisErr = initRedisConnection()
if redisErr != nil {
glogger.Error.Println("redis connection cannot be made, exiting.")
//glogger.Error.Println("redis connection cannot be made, exiting.")
panic(redisErr)
}
} else {
glogger.Debug.Println("connection to redis succeeded.")
//glogger.Debug.Println("connection to redis succeeded.")
}
// create initial files needed by nethack
@ -438,7 +441,8 @@ func printProgressScreen(redisClient *redis.Client, username string) {
// restart display
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run()
clearScreen()
nh := exec.Command("ttyplay", "-p", ttyrecPath)
//nh := exec.Command("ttyplay", "-p", ttyrecPath)
nh := exec.Command("termplay", "-f", "live", ttyrecPath)
nh.Stdout = os.Stdout
nh.Stdin = os.Stdin
nh.Stderr = os.Stderr
@ -459,7 +463,13 @@ func runGame(username, timestamp string) {
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("/run_nethack.sh", ttyrecPath, homeDir, config.NethackLauncher.HackDir, username)
//nh := exec.Command("ttyrec", ttyrecPath, "-e", "nethack")
nh := exec.Command("termrec", ttyrecPath, "-e", "nethack")
//nh := exec.Command("termrec", ttyrecPath, "-e", "nethack")
nh.Env = os.Environ()
nh.Env = append(nh.Env, fmt.Sprintf("HOME=%s", homeDir))
nh.Env = append(nh.Env, fmt.Sprintf("USER=%s", username))
nh.Env = append(nh.Env, fmt.Sprintf("NETHACKDIR=%s", config.NethackLauncher.HackDir))
nh.Stdout = os.Stdout
nh.Stdin = os.Stdin
nh.Stderr = os.Stderr
@ -467,6 +477,9 @@ func runGame(username, timestamp string) {
if err != nil {
fmt.Print(err)
}
fmt.Printf("%v\n", nh.Stdout)
fmt.Printf("%v\n", nh.Stdin)
fmt.Printf("%v\n", nh.Stderr)
exec.Command("exit").Run()
wg.Done()
}

Loading…
Cancel
Save