我无法使用Node.js hltv scorebot(https://github.com/Nols1000/hltv-scorebot)解决问题,但是当我使用匹配ID连接到hltv服务器时,没有任何关于匹配的日志。它只会执行一些不值钱的日志,仅此而已,是否有人从hltv获取了匹配的实时数据,还有其他方法可以执行此操作,除了此api。
这是我的代码

var Scorebot = require('hltv-scorebot');
var io = require('socket.io').listen(8080);
var client = io.sockets;


client.on("connection", function(socket){
    console.log("connected");
    var match_id = socket.request._query['matchid'];
    console.log("match_id is " + match_id);
    var sb = new Scorebot();
    sb.connect('http://scorebot.hltv.org',10022,478323);

    sb.on('kill', function(killer, victim, weapon, headshot, assister) {
        console.log("kill event");
        console.log(killer, victim, weapon, headshot, assister);
        var killerName = killer.name;

        // Checking if assister exists
        if(assister)
            killerName = killer.name + " and " + assister.name;

        console.log(killer.name, 'killed', vicitim.name, 'with', weapon, headshot ? 'headshot' : '');
    });

    sb.on("time", function(time){
        /*console.log("time event fired");
        console.log(time);*/
        socket.emit("msg", {type:"time", args: arguments})
    });

    sb.on("player", function(playermanager){
        console.log("player");
        for (var i in playermanager){
            console.log(i);
            for (var j in playermanager[i]){
                console.log(j);
                console.log(playermanager[i]);
            }
        }
        socket.emit("msg", {type:"player", args: arguments})
    });

    sb.on("assist", function(assister, victim){
        /*console.log("assist");
        console.log(assister, victim);*/
        socket.emit("msg", {type:"assist", args: arguments})
    });

    sb.on("roundend", function(winner, tscore, ctscore){
        /*console.log("roundend");
        console.log(winner, tscore, ctscore);*/
        socket.emit("msg", {type:"roundend", args: arguments})
    });

    sb.on("playerjoin", function(player){
        /*console.log("playerjoin");
        console.log(player);*/
        socket.emit("msg", {type:"playerjoin", args: arguments})
    });

    socket.on("ttt", function(){process.exit(1)});

    sb.on("playerquit", function(player){
        /*console.log("playerquit");
        console.log(player);*/
        socket.emit("msg", {type:"playerquit", args: arguments})
    });


    sb.on('bombPlanted', function(bia) {
        /*console.log("bombPlanted");
        console.log(bia);*/
        socket.emit("msg", {type:"bombPlanted", args: arguments})
    });

    sb.on("roundstart", function(){
        /*console.log("Round started");*/
        socket.emit("msg", {type:"rountstart", args: arguments})
    });

    sb.on('score', function(score) {
        /*console.log("score");
        console.log(score);*/
        socket.emit("msg", {type:"score", args: arguments})
    });

    sb.on('mapchange', function(map) {
        socket.emit("msg", {type:"mapChange", args: arguments})
        /*console.log("map");
        console.log(map);*/
    });
});

最佳答案

hltv-scorebot模块的上一次更新以来,HLTV已对其计分机器人进行了许多更改。我创建了一个 fork (可从https://github.com/andrewda/hltv-livescore获得),该 fork 是HLTV的最新更改的最新信息。

您的代码看起来非常相似,因为hltv-scorebothltv-livescore的核心API几乎相同。这是您如何开始使用它的基本示例:

const Livescore = require('hltv-livescore');
const live = new Livescore({ listid: 478323 });

live.on('kill', (data) => {
    console.log('kill event');
    console.log(data.killer.name, 'killed', data.victim.name, 'with', data.weapon, data.headshot ? '(headshot)' : '');
});

09-25 16:19