-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad83f1f
commit 5ad985d
Showing
7 changed files
with
85 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package launcher | ||
|
||
const cliMod = ` | ||
const http = require('http') | ||
const express = require('express') | ||
const bodyParser = require('body-parser') | ||
const vm = require('vm') | ||
const util = require('util') | ||
module.exports = config => { | ||
if (config.cli) { | ||
const app = express() | ||
const server = http.createServer(app) | ||
config.cli.connectionListener = socket => { | ||
server.emit('connection', socket) | ||
} | ||
app.get('/greeting', (req, res) => { | ||
let build = ' ' | ||
try { | ||
build = 'v'+require('screeps').version | ||
}catch(err){} | ||
let text = config.cli.greeting.replace('{build}', build) | ||
res.write(text) | ||
res.end() | ||
}) | ||
app.post('/cli', bodyParser.text(), async (req, res) => { | ||
const cb = (data, isResult) => { | ||
res.write(data + "\n") | ||
if (isResult) { | ||
res.end() | ||
} | ||
} | ||
const command = req.body | ||
const ctx = vm.createContext(config.cli.createSandbox(cb)) | ||
try { | ||
const result = await vm.runInContext(command, ctx) | ||
if (typeof result != 'string') { | ||
cb(''+util.inspect(result), true) | ||
} else { | ||
cb(''+result, true) | ||
} | ||
} catch(err) { | ||
cb('Error: '+(err.stack || err), true) | ||
} | ||
}) | ||
} | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters