2014-06-30 22:16:26 -04:00
|
|
|
spawn = require('child_process').spawn
|
2014-05-18 23:06:38 -04:00
|
|
|
|
2014-06-30 22:16:26 -04:00
|
|
|
[sessionOne, sessionTwo] = [process.argv[2], process.argv[3]]
|
2014-05-19 13:40:20 -04:00
|
|
|
homeDirectory = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE
|
2014-05-18 23:06:38 -04:00
|
|
|
unless sessionOne and sessionTwo and sessionOne.length is 24 and sessionTwo.length is 24
|
2014-06-30 22:16:26 -04:00
|
|
|
console.log 'Not enough games to continue!'
|
2014-05-18 23:06:38 -04:00
|
|
|
process.exit(1)
|
|
|
|
run = (cb) ->
|
2014-06-30 22:16:26 -04:00
|
|
|
command = spawn('coffee', ['headless_client.coffee', 'one-game', sessionOne, sessionTwo], {cwd: homeDirectory + '/codecombat/'})
|
|
|
|
result = ''
|
2014-05-18 23:06:38 -04:00
|
|
|
command.stdout.on 'data', (data) ->
|
|
|
|
result += data.toString()
|
|
|
|
command.stdout.on 'close', ->
|
|
|
|
return cb(result)
|
|
|
|
run (result) ->
|
2014-05-19 13:11:20 -04:00
|
|
|
lines = result.split("\n")
|
|
|
|
for line in lines
|
2014-06-30 22:16:26 -04:00
|
|
|
if line.slice(0, 10) is 'GAMERESULT'
|
2014-05-19 13:11:20 -04:00
|
|
|
process.stdout.write line.slice(11)
|
|
|
|
process.exit(0)
|
2014-05-18 23:06:38 -04:00
|
|
|
process.exit(0)
|