joshuaferrara / node-csgo

A node-steam plugin for Counter-Strike: Global Offensive.
MIT License
460 stars 82 forks source link

Matches array is always empty when using requestGame() #47

Closed lenovouser closed 7 years ago

lenovouser commented 7 years ago

I am using this snippet for testing:

steamFriends.setPersonaState(steam.EPersonaState.Busy);

const counterstrike = new csgo.CSGOClient(steamUser, steamCoordinator, false);

counterstrike.launch();

const decode = new csgo.SharecodeDecoder(sharecode);

counterstrike.on('ready', () => {
    counterstrike.requestGame(decode.matchId, decode.outcomeId, decode.tokenId);
});

counterstrike.on('matchList', (matchResponse) => {
    console.log(JSON.stringify(matchResponse));
});

which always returns

{
  "msgrequestid": 0000,
  "accountid": 000000000,
  "servertime": 0000000000,
  "matches": [],
  "streams": [],
  "tournamentinfo": null
}

Am I doing something wrong? The matches are always very recent (A few hours ago) - so they should definitely be returned? Or am I missing something?

joshuaferrara commented 7 years ago

Are you receiving the zeros for msgrequestid, accountid & servertime or were those added for privacy when posting the issue? If you're getting zeros, that's definitely a new one for me.

Furthermore, is that the whole program you're running, or are there definitions above steamFriends.setPersonaState(steam.EPersonaState.Busy); for steamUser, steamCoordinator, etc...

lenovouser commented 7 years ago

The zeros were added for privacy reasons.

A more complete part of the code:

const steamClient      = new steam.SteamClient();
const steamUser        = new steam.SteamUser(steamClient);
const steamCoordinator = new steam.SteamGameCoordinator(steamClient, 730);
const steamFriends     = new steam.SteamFriends(steamClient);

const sharecode = this.sharecode;
const account   = this.account;

const login = {
    account_name: account.id,
    password: account.password,
};

fs.access(`${__dirname}/sentry/${account.id}.sentry`, fs.F_OK, (err) => {
    if (!err) {
        login.sha_sentryfile = fs.readFileSync(`${__dirname}/sentry/${account.id}.sentry`);
    }
});

steamClient.connect();
steamClient.on('connected', () => {
    steamUser.logOn(login);
});

steamClient.on('logOnResponse', (response) => {
    if (response.eresult === steam.EResult.OK) {
        steamFriends.setPersonaState(steam.EPersonaState.Busy);

        const counterstrike = new csgo.CSGOClient(steamUser, steamCoordinator, false);
        counterstrike.launch();

        const decode = new csgo.SharecodeDecoder(sharecode);

        counterstrike.on('ready', () => {
            counterstrike.requestGame(decode.matchId, decode.outcomeId, decode.tokenId);
        });

        counterstrike.on('matchList', (matchResponse) => {
            console.log(JSON.stringify(matchResponse));
            counterstrike.exit();
            steamClient.disconnect();
        });
    } else if (response.eresult === steam.EResult.AccountLoginDeniedNeedTwoFactor) {
        logger.error(`Account needs Mobile Auth Code: ${login.account_name}: ${JSON.stringify(response)}`);
        utils.account.disable(login.account_name);
    } else if (response.eresult === steam.EResult.AccountLogonDenied) {
        logger.error(`Account needs Steam Guard Code or the Credentials are wrong: ${login.account_name}: ${JSON.stringify(response)}`);
        utils.account.disable(login.account_name);
    } else if (response.eresult === steam.EResult.RateLimitExceeded) {
        logger.error(`Rate limit was exceeded using ${login.account_name}: ${JSON.stringify(response)}`);
        utils.account.disable(login.account_name);
    } else {
        logger.error(`Login unsuccessful using ${login.account_name}: ${JSON.stringify(response)}`);
        utils.account.disable(login.account_name);
    }
});
joshuaferrara commented 7 years ago

Could you provide the sharecode you are using with this script? We've had issues in the past with the SharecodeDecoder providing weird values, and the implementation could have possibly changed in the engine since the JS port was written.

If you'd prefer to keep the sharecode private, send me an email at csgo@ferrara.space

lenovouser commented 7 years ago

It doesn't seem to work with any sharecode. Dumb question, must the account getting the match info have been in that game too? AFAIK no, because you can also watch other demos in CSGO if your friend gives you the sharecode.

Example Sharecode:

CSGO-qdZYs-pEcib-CqwiO-kU3KG-CKxbE

joshuaferrara commented 7 years ago

I'm able to poll the match results from my account. Please try this: counterstrike.requestGame(decode.matchId, decode.outcomeId, parseInt(decode.tokenId));

Usually you'll get a protobuf error when you try and pass tokenId as a string when it should be an int.

Here's more or less what I did within example.js:

        CSGOCli.on("ready", function() {
            util.log("node-csgo ready.");

            CSGOCli.matchmakingStatsRequest();
            CSGOCli.on("matchmakingStatsData", function(matchmakingStatsResponse) {
                util.log("Avg. Wait Time: " + matchmakingStatsResponse.global_stats.search_time_avg);
                util.log("Players Online: " + matchmakingStatsResponse.global_stats.players_online);
                util.log("Players Searching: " + matchmakingStatsResponse.global_stats.players_searching);
                util.log("Servers Online: " + matchmakingStatsResponse.global_stats.servers_online);
                util.log("Servers Available: " + matchmakingStatsResponse.global_stats.servers_available);
                util.log("Matches in Progress: " + matchmakingStatsResponse.global_stats.ongoing_matches);
                console.log(JSON.stringify(matchmakingStatsResponse, null, 4));

                CSGOCli.on("matchList", function(list) {
                   console.log("Match List");
                   if (list.matches && list.matches.length > 0) {
                        console.log(list.matches[0]);
                   }
                });
                var scDecoder = new csgo.SharecodeDecoder("CSGO-qdZYs-pEcib-CqwiO-kU3KG-CKxbE");
                const decoded = scDecoder.decode();
                setTimeout(function() {
                    console.log("Requesting game");
                    CSGOCli.requestGame(decoded.matchId, decoded.outcomeId, parseInt(decoded.tokenId));
                }, 2500);
            });
        });
lenovouser commented 7 years ago

@joshuaferrara yep, with the parseInt() it worked, thanks!

dennyb commented 2 years ago

Sorry to reopen this, but does anything changed? Right now, I've got the same problem like lenovouser on the first time. Also parseInt() does not work.

Just getting

27 Jan 00:40:33 - CS:GO fromGC: 9139 27 Jan 00:40:33 - Received match list Match List { msgrequestid: 9147, accountid: 1277797466, servertime: 1643240433, matches: [], streams: [], tournamentinfo: null }