I'm just starting an AI bot for the game nethack
, and I can't bypass the 'human-check' that's in source. The section of code I'm talking about is nethack/sys/unix/unixunix.c
:
#ifdef TTY_GRAPHICS
/* idea from rpick%ucqais@uccba.uc.edu
* prevent automated rerolling of characters
* test input (fd0) so that tee'ing output to get a screen dump still
* works
* also incidentally prevents development of any hack-o-matic programs
*/
/* added check for window-system type -dlc */
if (!strcmp(windowprocs.name, "tty"))
if (!isatty(0))
error("You must play from a terminal.");
#endif
I'm working in JavaScript, (more specifically Node.js), and due to the above, it won't let me play from the program, even though I'm spawning a bash shell child process and telling it to start nethack
. I need to figure out a way to bypass the above without recompiling the source.
The current code I'm using is:
"use strict";
var env = { TERM: 'tty' };
for (var k in process.env) {
env[k] = process.env[k];
}
var terminal = require('child_process').spawn('bash', [], {
env: env,
});
terminal.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
terminal.on('exit', function (code) {
console.log('child process exited with code ' + code);
});
setTimeout(function() {
terminal.stdin.write('nethack');
terminal.stdin.end();
}, 1000);
The output of the program is:
stdout: You must play from a terminal.
child process exited with code 1
What Node.js/JavaScript (and not any other language or framework, if possible) black magic could I use to solve this problem?