Jump to content
McKay Development

Function Returns Undefined


Snow

Recommended Posts

I am using express.js and try to log all my bots in according to requests made from my python server. I can successfully make my bots logged into steam but can't get returned message (it just returns undefined) to send back to server. 

My code looks like this:

const accounts = []

function addAccount(username, password, twoFactorCode){

    const client = new SteamUser();
    const community = new SteamCommunity();
    const manager = new TradeOfferManager({
        steam: client,
        community: community,
        language: 'en',
        cancelTime: 300000,
        pendingCancelTime: 30000
    });

    const logOnOptions = {
        accountName: username,
        password: password,
        twoFactorCode: SteamTotp.generateAuthCode(twoFactorCode),
    };
    client.logOn(logOnOptions);
    client.on('loggedOn', ()=> {
        //console.log("success")
    })

    client.on('webSession', (sessionid, cookies) => {
        console.log(sessionid, cookies);
        manager.setCookies(cookies, function(err){
            if (err) {
                console.log(err);
                return err
            }else{
                console.log("Got API key: " + manager.apiKey);
                return "success";
            }
        });
        community.setCookies(cookies);
    });
    community.on('sessionExpired', () => {
        client.webLogOn();
    });

    accounts.push({"client":client, "community":community, "manager": manager})
}

app.post('/log', (req, res) => {
    if (accounts.length === 0){
        var json_data = req.body
        json_data.forEach(element => {
            var answer = addAccount(element["user_name"], element["password"], element["secret"])
        })
    }else{
    }
    res.json({ "answer": answer })
})

 

Edited by Snow
Link to comment
Share on other sites

On 8/26/2021 at 8:52 PM, Dr. McKay said:

accounts is always going to be empty when your /log listener executes, so no accounts will get added and nothing will be returned.

I am still using express js and can get accounts array without a problem. What would you suggest instead of adding them to array ?

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...