Compare commits
No commits in common. 'acd35ba7342114430d1216346a148f31276320b3' and '80a45f4736fd89015fa4acfac1045dcb8d10ae87' have entirely different histories.
acd35ba734
...
80a45f4736
16 changed files with 19 additions and 351 deletions
@ -1,30 +0,0 @@ |
|||||||
#!/bin/bash |
|
||||||
HACKDIR=$1 |
|
||||||
USERDIR=$2 |
|
||||||
TTYRECCACHE=$3 |
|
||||||
SOTWDUMPCACHE=$4 |
|
||||||
|
|
||||||
### |
|
||||||
# clean old ttyrecs |
|
||||||
### |
|
||||||
cd /$HACKDIR/user/$USERDIR/ttyrec/ |
|
||||||
ls -1tr | head -n -$TTYRECCACHE | xargs -d '\n' rm -f -- |
|
||||||
|
|
||||||
|
|
||||||
### |
|
||||||
# clean sotw files |
|
||||||
### |
|
||||||
cd /$HACKDIR/user/$USERDIR/sotw/ |
|
||||||
|
|
||||||
# there are always 4 symlinked files |
|
||||||
# leave 5 of the latest dumps |
|
||||||
DUMPFILES=$(expr $SOTWDUMPCACHE + 4) |
|
||||||
|
|
||||||
FILES=$(ls -1tr *.txt | head -n -$DUMPFILES) |
|
||||||
|
|
||||||
for f in $FILES; do |
|
||||||
#test -h $f || echo "removing old file $f" |
|
||||||
if [ ! -h $f ]; then |
|
||||||
rm -rf $f |
|
||||||
fi |
|
||||||
done |
|
@ -1,25 +0,0 @@ |
|||||||
#!/bin/bash |
|
||||||
|
|
||||||
FILES=/sotw/* |
|
||||||
USERDIR=$1 |
|
||||||
HACKDIR=$2 |
|
||||||
|
|
||||||
# create initial dir if it does not exist |
|
||||||
mkdir -p $USERDIR/sotw/ |
|
||||||
|
|
||||||
# link all game files to user dir |
|
||||||
for f in $FILES |
|
||||||
do |
|
||||||
echo "linking $f" |
|
||||||
ln -s $f $USERDIR/sotw/ |
|
||||||
done |
|
||||||
|
|
||||||
# remove inital score file |
|
||||||
rm -rf $USERDIR/sotw/scores.dat |
|
||||||
# link in shared score file from hackdir |
|
||||||
ln -s $HACKDIR/scores.dat $USERDIR/sotw/ |
|
||||||
|
|
||||||
# remove initial config file |
|
||||||
rm -rf $USERDIR/sotw/swyrm.ini |
|
||||||
# copy in sotw config file |
|
||||||
cp $HACKDIR/swyrm.ini $USERDIR/sotw/ |
|
Binary file not shown.
@ -1,19 +0,0 @@ |
|||||||
package main |
|
||||||
|
|
||||||
import ( |
|
||||||
"fmt" |
|
||||||
"os/exec" |
|
||||||
) |
|
||||||
|
|
||||||
func runCleanup(username string) { |
|
||||||
// clean up ttyrecs in /<hackdir>/user/<username>/ttyrec/
|
|
||||||
// clean up sotw dumps, aka:
|
|
||||||
// non-symlinked .txt files in /<hackdir>/user/<username>/sotw/
|
|
||||||
|
|
||||||
// run cleanup file
|
|
||||||
out, err := exec.Command("/bin/clean.sh", config.NethackLauncher.HackDir, username, config.NethackLauncher.TTYRecCache, config.NethackLauncher.SotwDumpCache).Output() |
|
||||||
if err != nil { |
|
||||||
fmt.Println(err) |
|
||||||
} |
|
||||||
fmt.Printf("%s\n", out) |
|
||||||
} |
|
@ -1,144 +0,0 @@ |
|||||||
package main |
|
||||||
|
|
||||||
import ( |
|
||||||
"bufio" |
|
||||||
"fmt" |
|
||||||
"io/ioutil" |
|
||||||
"os" |
|
||||||
"os/exec" |
|
||||||
"strconv" |
|
||||||
"strings" |
|
||||||
|
|
||||||
"gopkg.in/redis.v5" |
|
||||||
) |
|
||||||
|
|
||||||
func printLibraryScreen(redisClient *redis.Client, username string) { |
|
||||||
// print header
|
|
||||||
fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) |
|
||||||
println("") |
|
||||||
|
|
||||||
println(" Choose a users library to view ('enter' without selection returns)") |
|
||||||
println("") |
|
||||||
|
|
||||||
us, err := ioutil.ReadDir(fmt.Sprintf("/%s/user", config.NethackLauncher.HackDir)) |
|
||||||
if err != nil { |
|
||||||
println(" No users exist ('enter' without selection returns)") |
|
||||||
panic(err) |
|
||||||
} |
|
||||||
|
|
||||||
users := make(map[int]string) |
|
||||||
usersTimer := 1 |
|
||||||
for _, u := range us { |
|
||||||
fmt.Printf(" %d) %s\n", usersTimer, u.Name()) |
|
||||||
|
|
||||||
// add user to line map
|
|
||||||
users[usersTimer] = fmt.Sprintf("%s", u.Name()) |
|
||||||
usersTimer++ |
|
||||||
} |
|
||||||
|
|
||||||
fmt.Println("") |
|
||||||
fmt.Printf(">> ") |
|
||||||
// start user input
|
|
||||||
|
|
||||||
// disable input buffering
|
|
||||||
exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run() |
|
||||||
// do not display entered characters on the screen
|
|
||||||
exec.Command("stty", "-F", "/dev/tty", "-echo").Run() |
|
||||||
|
|
||||||
var b []byte = make([]byte, 1) |
|
||||||
for { |
|
||||||
os.Stdin.Read(b) |
|
||||||
s, _ := strconv.Atoi(string(b)) |
|
||||||
|
|
||||||
// check if user is trying to navigate
|
|
||||||
if string(b) == "\n" { |
|
||||||
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() |
|
||||||
clearScreen() |
|
||||||
if username == "" { |
|
||||||
clearScreen() |
|
||||||
printWelcomeScreen(redisClient) |
|
||||||
} else { |
|
||||||
clearScreen() |
|
||||||
printUserScreen(redisClient, username) |
|
||||||
} |
|
||||||
} |
|
||||||
// check if selection is in out map
|
|
||||||
if users[s] != "" { |
|
||||||
user := strings.Split(users[s], ":") |
|
||||||
fmt.Printf("going to spectate '%s'\n", user[0]) |
|
||||||
clearScreen() |
|
||||||
printUserLibraryScreen(redisClient, username, user[0]) |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
func printUserLibraryScreen(redisClient *redis.Client, username, currentUser string) { |
|
||||||
// print header
|
|
||||||
fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) |
|
||||||
println("") |
|
||||||
|
|
||||||
println(" Choose a ttyrec to view ('enter' without selection returns)") |
|
||||||
println(" The following keybinds are available during playback:") |
|
||||||
println(" • + or f: double the speed of playback") |
|
||||||
println(" • - or s: halve the speed of playback") |
|
||||||
println(" • 0: set playback speed to 0, pausing playback") |
|
||||||
println(" • 1: set playback speed to 1 again") |
|
||||||
println("") |
|
||||||
|
|
||||||
t, err := ioutil.ReadDir(fmt.Sprintf("/%s/user/%s/ttyrec", config.NethackLauncher.HackDir, currentUser)) |
|
||||||
if err != nil { |
|
||||||
println(" No ttyrecs exist ('enter' without selection returns)") |
|
||||||
panic(err) |
|
||||||
} |
|
||||||
|
|
||||||
ttyrecs := make(map[int]string) |
|
||||||
ttyrecsTimer := 1 |
|
||||||
for _, ty := range t { |
|
||||||
fmt.Printf(" %d) %s\n", ttyrecsTimer, ty.Name()) |
|
||||||
|
|
||||||
// add user to line map
|
|
||||||
ttyrecs[ttyrecsTimer] = fmt.Sprintf("%s", ty.Name()) |
|
||||||
ttyrecsTimer++ |
|
||||||
} |
|
||||||
|
|
||||||
fmt.Println("") |
|
||||||
fmt.Printf(">> ") |
|
||||||
// start user input
|
|
||||||
|
|
||||||
// disable input buffering
|
|
||||||
exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run() |
|
||||||
// enable showing input on screen
|
|
||||||
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() |
|
||||||
|
|
||||||
scanner := bufio.NewScanner(os.Stdin) |
|
||||||
for scanner.Scan() { |
|
||||||
if scanner.Text() == "" { |
|
||||||
clearScreen() |
|
||||||
printLibraryScreen(redisClient, username) |
|
||||||
} |
|
||||||
// save input
|
|
||||||
s := scanner.Text() |
|
||||||
sel, err := strconv.Atoi(s) |
|
||||||
if err != nil { |
|
||||||
fmt.Printf(" There was a problem with your last entry.\n>> ") |
|
||||||
} |
|
||||||
// check if selection is in our map
|
|
||||||
if ttyrecs[sel] != "" { |
|
||||||
fmt.Printf("going to watch '%s'\n", ttyrecs[sel]) |
|
||||||
clearScreen() |
|
||||||
|
|
||||||
// set ttyrec path
|
|
||||||
ttyrecPath := fmt.Sprintf("%s/user/%s/ttyrec/%s", config.NethackLauncher.HackDir, username, ttyrecs[sel]) |
|
||||||
tp := exec.Command("ttyplay", ttyrecPath) |
|
||||||
tp.Stdout = os.Stdout |
|
||||||
tp.Stdin = os.Stdin |
|
||||||
tp.Stderr = os.Stderr |
|
||||||
err := tp.Run() |
|
||||||
if err != nil { |
|
||||||
fmt.Print(err) |
|
||||||
} |
|
||||||
} |
|
||||||
clearScreen() |
|
||||||
printUserLibraryScreen(redisClient, username, currentUser) |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue