Jump to content
McKay Development

Recommended Posts

Posted

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.

 

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...