【发布时间】:2015-12-23 23:29:44
【问题描述】:
我一直在尝试以编程方式控制多个反恐精英:全球攻势专用服务器。一切正常,但我无法完全关闭它。当您打开服务器时,它会创建两个进程:srcds_run 和 srcds_linux。我可以很容易地做到child_process.kill(),它会关闭srcds_run 进程,但srcds_linux 进程会继续运行,即使服务器关闭也是如此。如果我试图杀死 所有 srcds_linux 进程,那么它将杀死 所有 CSGO 服务器,即使我试图只关闭一个。有没有办法选择对应的srcds_run和srcds_linux进程?
到目前为止,这是我的代码:
// Turns on the server if not already on
Server.prototype.start = function(callback) {
if(!this.online) {
// Turn server on
console.log('Starting server');
this.process = spawn(this.directory + '/srcds_run', ['-game csgo', '-console', '-usercon', '+game_type 0', '+game_mode 0', '+mapgroup mg_active', '+map de_dust2', '+sv_setsteamaccount ' + this.token], { cwd: this.directory});
this.process.stderr.on('data', function(err) {
console.log('Error: ' + err);
});
this.process.stdin.on('data', function(chunk) {
console.log('stdin: ' + chunk);
});
this.process.stdout.on('data', function(chunk) {
console.log('stdout: ' + chunk);
});
}
this.online = true;
callback();
}
// Turns off the server if not already off
Server.prototype.stop = function(callback) {
if(this.online) {
// Turn server off
console.log('Stopping server');
this.process.kill();
}
this.online = false;
callback();
}
我正在使用 Ubuntu 服务器并且在 node.js 上使用 child_process.spawn module
感谢您的帮助:)
【问题讨论】:
-
没想到会在这里看到与 CS:GO 相关的东西 xD
-
哈哈,是的。我可能看到了 one or two threads 关于这个,但没有太多
-
srcds_run生成srcds_linux也是如此吗?有没有可能它是srcds_linux的父进程,您可以使用pgrep或类似的东西获取它的进程ID?您应该能够使用child_process.pid() 在节点中获取原始生成进程的进程ID -
谢谢,dvlsg!这正是我所需要的。一旦我启动并运行它,我将在下面发布一个带有工作代码的答案。
-
嘿,这很酷。你还能用 Node js 和 CSGO 做什么?
标签: javascript node.js steam