Browse Source

Add initial ttyrec code

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

17
Makefile

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

25
nethack-launcher.go

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

Loading…
Cancel
Save