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 *.swp
savedata/ hack/
stage.tmp/ stage.tmp/
bin/ bin/

7
Makefile

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

1
deps/Dockerfile vendored

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

1
deps/chowner.sh vendored

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

9
deps/nethackrc vendored

@ -8,7 +8,7 @@
OPTIONS=menucolors OPTIONS=menucolors
OPTIONS=autodig OPTIONS=autodig
OPTIONS=autoopen OPTIONS=autoopen
OPTIONS=autopickup,pickup_types:$!/="+? #OPTIONS=autopickup,pickup_types:$!/="+?
OPTIONS=autoquiver OPTIONS=autoquiver
OPTIONS=bones OPTIONS=bones
OPTIONS=boulder:0 OPTIONS=boulder:0
@ -16,20 +16,14 @@ OPTIONS=checkpoint
OPTIONS=color OPTIONS=color
OPTIONS=confirm OPTIONS=confirm
OPTIONS=dark_room OPTIONS=dark_room
OPTIONS=disclose:+iagcv
OPTIONS=fruit:berries
OPTIONS=hilite_pet OPTIONS=hilite_pet
OPTIONS=hilite_pile OPTIONS=hilite_pile
OPTIONS=lootabc
OPTIONS=msg_window:reverse,msghistory:1000 OPTIONS=msg_window:reverse,msghistory:1000
OPTIONS=pickup_burden:B
OPTIONS=!prayconfirm
OPTIONS=lit_corridor OPTIONS=lit_corridor
OPTIONS=showrace OPTIONS=showrace
OPTIONS=showexp,time OPTIONS=showexp,time
OPTIONS=sortloot:full OPTIONS=sortloot:full
OPTIONS=runmode:teleport,!rest_on_space
## Change symbols ## Change symbols
SYMBOLS=S_ghost:X SYMBOLS=S_ghost:X
@ -168,6 +162,5 @@ MENUCOLOR=" uncursed| UC?($| )"=white
MENUCOLOR=" \([-0-9]+:[-0-9]+\)"=white MENUCOLOR=" \([-0-9]+:[-0-9]+\)"=white
#nethack doesn't display "uncursed" if charges are known #nethack doesn't display "uncursed" if charges are known
MENUCOLOR=" [+-][0-9]"=white MENUCOLOR=" [+-][0-9]"=white
MENUCOLOR=" blessed| B($| )"=cyan MENUCOLOR=" blessed| B($| )"=cyan
MENUCOLOR=" cursed| C($| )"=red MENUCOLOR=" cursed| C($| )"=red

2
deps/redis.conf vendored

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

2
deps/run_nethack.sh vendored

@ -5,5 +5,5 @@ HOMEDIR=$2
HACKDIR=$3 HACKDIR=$3
USER=$4 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" ttyrec $TTYRECPATH -e "HOME=$HOMEDIR nethack -d $HACKDIR -u $USER"

23
nethack-launcher.go

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

Loading…
Cancel
Save