How do I interact with a newly created server, created with child_process.spawn

依然范特西╮ 提交于 2019-12-10 10:26:13

问题


I'm trying to make a front-end for my privately hosted Counter-Strike Global Offensive servers, on the front-end when I hit run server, everything works great and the server starts up and logs to console. But how can I view information like the server IP address, players in the server, and other things?

This is what I have so far for running the server:

router.post('/create', function(req, res) {
    console.log(req.body);
    var child = spawn('/home/steam/steamcmd/csgo/srcds_run -game csgo -console +game_type 0 +game_mode 0 +host_workshop_collection 249376192 -tickrate 128 +maxplayers 20')
    child.stderr.on('data', function(err) {
        console.log(err);
    });
    child.stdin.on('data', function(chunk) {
        console.log(chunk);
    });
    child.stdout.on('data', function(chunk) {

    });

});

Like for e.g. if I used a paid server host I would have a control panel where I could see server IP, restart / stop view players in game and other things. I hope this was clear enough and sorry if it was poorly written. I'm not sure how else to word this.


回答1:


Does the server accept input once it has started? If so you can write to it using

child.stdin.write('my command\n');

Otherwise you're going to have to query it using something like gamedig



来源:https://stackoverflow.com/questions/30071370/how-do-i-interact-with-a-newly-created-server-created-with-child-process-spawn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!