Browse Source

Add initial ttyrec code

master
Matthew Faltys 5 years ago
parent
commit
b4b388d91d
  1. 17
      Makefile
  2. 11
      nethack-launcher.go

17
Makefile

@ -1,6 +1,8 @@
GOC=go build
GOFLAGS=-a -ldflags '-s'
CGOR=CGO_ENABLED=0
NETHACK_DIR=$(shell pwd)/savedata
IMAGE_NAME=nethack_launch
all: stat reclist
@ -20,5 +22,20 @@ reclist:
dependencies:
go get github.com/gorilla/mux
#build_docker:
# mkdir -p stage.tmp/
# cp -R deps/Dockerfile stage.tmp/
#
#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)
clean:
rm -rf bin/
rm -rf stage.tmp/

11
nethack-launcher.go

@ -25,7 +25,7 @@ type Config struct {
NethackVersion string
InProgressDir string
UserDir string
RecordLocation string
RecordFileLocation string
ReclistLocation string
BootstrapDelay time.Duration
}
@ -98,8 +98,8 @@ func initRedisConnection() (*redis.Client, error) {
func checkFiles() {
// make sure record file exists
if _, err := os.Stat(config.NethackLauncher.RecordLocation); os.IsNotExist(err) {
glogger.Info.Printf("record file not found in %s\n", config.NethackLauncher.RecordLocation)
if _, err := os.Stat(config.NethackLauncher.RecordFileLocation); os.IsNotExist(err) {
glogger.Info.Printf("record file not found in %s\n", config.NethackLauncher.RecordFileLocation)
fmt.Printf("%s\n", err)
os.Exit(1)
}
@ -195,11 +195,12 @@ func printUserScreen(redisClient *redis.Client, username string) string {
// restart display
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run()
clearScreen()
nh := exec.Command("nethack", "-u", username)
nh := exec.Command("ttyrec", "yeto.ttyrec", "-e", "nethack", "-u", username)
nh.Stdout = os.Stdout
nh.Stdin = os.Stdin
nh.Stderr = os.Stderr
nh.Run()
exec.Command("exit").Run()
printUserScreen(redisClient, username)
case "q":
clearScreen()
@ -433,7 +434,7 @@ func gethighscore(w http.ResponseWriter, r *http.Request) {
// run script
output, err := exec.Command(config.NethackLauncher.ReclistLocation,
"-f",
config.NethackLauncher.RecordLocation).CombinedOutput()
config.NethackLauncher.RecordFileLocation).CombinedOutput()
if err != nil {
fmt.Printf("%s\n", err)
}

Loading…
Cancel
Save