You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.6 KiB
42 lines
1.6 KiB
package main |
|
|
|
import ( |
|
"fmt" |
|
"os" |
|
"os/exec" |
|
) |
|
|
|
func createUserFiles(username string) { |
|
// create user directories |
|
userPath := fmt.Sprintf("%s/user/%s/ttyrec/", config.NethackLauncher.HackDir, username) |
|
exec.Command("mkdir", "-p", userPath).Run() |
|
|
|
// copy in rc file |
|
hackRCLoc := fmt.Sprintf("%s/.nethackrc", config.NethackLauncher.HackDir) |
|
hackRCDest := fmt.Sprintf("%s/user/%s/.nethackrc", config.NethackLauncher.HackDir, username) |
|
exec.Command("cp", hackRCLoc, hackRCDest).Run() |
|
|
|
// create necessary directories if they dont exist |
|
userpath := fmt.Sprintf("%s/user/%s", config.NethackLauncher.HackDir, username) |
|
|
|
if _, err := os.Stat(fmt.Sprintf("%s/dumps/", userpath)); os.IsNotExist(err) { |
|
os.Mkdir(fmt.Sprintf("%s/dumps/", userpath), os.ModeDir) |
|
} |
|
if _, err := os.Stat(fmt.Sprintf("%s/save/", userpath)); os.IsNotExist(err) { |
|
os.Mkdir(fmt.Sprintf("%s/save/", userpath), os.ModeDir) |
|
} |
|
|
|
// create necessary files if they dont exist |
|
os.OpenFile(fmt.Sprintf("%s/logfile", userpath), os.O_RDONLY|os.O_CREATE, 0666) |
|
os.OpenFile(fmt.Sprintf("%s/perm", userpath), os.O_RDONLY|os.O_CREATE, 0666) |
|
os.OpenFile(fmt.Sprintf("%s/xlogfile", userpath), os.O_RDONLY|os.O_CREATE, 0666) |
|
|
|
// create record symlink |
|
exec.Command("ln", "-s", fmt.Sprintf("%s/record", config.NethackLauncher.HackDir), fmt.Sprintf("%s/record", userpath)).Run() |
|
|
|
// create sysconf symlink |
|
exec.Command("ln", "-s", fmt.Sprintf("%s/sysconf", config.NethackLauncher.HackDir), fmt.Sprintf("%s/sysconf", userpath)).Run() |
|
|
|
// move in nhdat file if it does not exist |
|
exec.Command("cp", fmt.Sprintf("%s/nhdat", config.NethackLauncher.HackDir), userpath).Run() |
|
}
|
|
|