2

I'm building an MMO using Node.js, and I'd like some scripters from my team to create scripts (duh) for bosses and other scripted objects. My first thought was to have a folder on the server where people can upload javascript files and let node.js automatically read and parse every script in the directory, but I don't want them to be able to execute process.exit() for example, or other hazardous stuff.

Is there a solution that lets me control what functions the scripters are able to call?

4

2 に答える 2

4

You can control what functions are they unable to call with vm module.

For example,

vm.runInNewContext(userCode, {
    require: null,
    process: null,
    someFunc: function (x) { return x+1 },
    someData: { abc: 'def' }
});
于 2012-06-28T09:31:07.670 に答える
1

Will javascript work as scripting language. I guess it should.
so, I think vm.runInNewContext is might be all you need. Have a look at http://nodejs.org/docs/latest/api/vm.html

于 2012-06-28T09:59:40.943 に答える