Jump to content


Photo

Node Steam Trade Offer Looping on Express

node.js node-steam-tradeoffer-manager

  • Please log in to reply
No replies to this topic

#1 Franz Darelle

Franz Darelle

    Newbie

  • Member
  • Pip
  • 2 posts

Posted 26 May 2018 - 02:36 AM

Hello sir im using php to communicate with my express my problem is the first offer is doing fine but it loops and get an erro on the second one. here is my code.

app.post('/test',function(req,res){
    r = req.body;
    items = JSON.parse(r.items);
    const tradeurl = r.tradeurl;
    let client = new SteamUser();
    let manager = new TradeOfferManager({
        "steam": client, // Polling every 30 seconds is fine since we get notifications from Steam
        "domain": "example.com", // Our domain is example.com
        "language": "en",
        "cancelTime":180000
    });
    let community = new SteamCommunity();
 
    // Steam logon options
    let logOnOptions = {
        "accountName": config.username,
        "password": config.password,
        "twoFactorCode": SteamTotp.getAuthCode(config.sharedSecret)
    };
 
    if (FS.existsSync('polldata.json')) {
        manager.pollData = JSON.parse(FS.readFileSync('polldata.json').toString('utf8'));
    }
 
    client.logOn(logOnOptions);
 
    client.on('loggedOn', function() {
        console.log("Logged into Steam");
    });
 
    client.on('webSession', function(sessionID, cookies) {
        manager.setCookies(cookies, function(err) {
            if (err) {
                console.log(err);
                process.exit(1); // Fatal error since we couldn't get our API key
                return;
            }
 
            console.log("Got API key: " + manager.apiKey);
 
            // Get our inventory
            manager.getInventoryContents(570, 2, true, function(err, inventory) {
                if (err) {
                    console.log(err);
                    return;
                }
                // console.log(inventory);
                // throw "stop execution";
                if (inventory.length == 0) {
                    // Inventory empty
                    console.log("Dota 2 inventory is empty");
                    return;
                }
 
                console.log("Found " + inventory.length + " Dota 2 items");
 
                // Create and send the offer
                let offer = manager.createOffer(tradeurl);
                item = [
                    {
                        appid: 570,
                        contextid: '2',
                        classid: '645249158',
                        assetid: '13126112943',
                        instanceid: '260036609',
                        amount: 1
                    }
                ];
                offer.addTheirItems(items);
                offer.setMessage("Offer: #"+ offer.id);
                offer.send(function(err, status) {
                    if (err) {
                        console.log(err);
                        return;
                    }
 
                    if (status == 'pending') {
                        // We need to confirm it
                        console.log(`Offer #${offer.id} sent, but requires confirmation`);
                        community.acceptConfirmationForObject(config.identitySecret, offer.id, function(err) {
                            if (err) {
                                console.log(err);
                            } else {
                                console.log("Offer confirmed");
                            }
                        });
                    } else {
                        console.log(`Offer #${offer.id} sent successfully`);
                    }
                });
            });
        });
 
        community.setCookies(cookies);
    });
 
    manager.on('sentOfferChanged', function(offer, oldState) {
        console.log(`Offer #${offer.id} changed: ${TradeOfferManager.ETradeOfferState[oldState]} -> ${TradeOfferManager.ETradeOfferState[offer.state]}`);
        if (TradeOfferManager.ETradeOfferState[offer.state] == 'Accepted'){
            manager.shutdown();
            client.logOff();       
            //process.exit(1); // testing lang
            return;
        }
    });
 
    manager.on('pollData', function(pollData) {
        FS.writeFileSync('polldata.json', JSON.stringify(pollData));
    });
 
    manager.on('sentOfferCanceled',function(reason){
        console.log('offer cancelled franz');
        manager.shutdown();
        client.logOff();
        FS.unlink('polldata.json',function(err){
            console.log('poll data deleted');
            res.send();
        });
    });
 
   
     
});

the attach file is the result. thank you. hope you guys can help me.

 







Also tagged with one or more of these keywords: node.js, node-steam-tradeoffer-manager

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users