Jump to content
McKay Development

Recommended Posts

Posted (edited)

Hey,  

my tradeBot (only sometimes) crashes right after receiving an offer. I tried to fix it with a friend who is more into coding SteamBots than me, but we weren't able to figure out what is going wrong here.  

 

I want to keep the script more or less private since someone made it for me and he doesn't want me to share the full code for it, but this should be enough. Will provide more if needed!

var config = require('./config.js');
var SteamUser = require('steam-user');
var client = new SteamUser();


var SteamCommunity = require("steamcommunity");
var community = new SteamCommunity();


var SteamTotp = require('steam-totp');
var mobilecode = SteamTotp.getAuthCode(config.sharedsecret);






var TradeOfferManager = require('steam-tradeoffer-manager');
var manager = new TradeOfferManager({
    "steam": client,
    "domain": "http://localhost",
    "language": "en",
    "cancelTime": "600000", // 10 minutes
    "pollInterval": "5000"
});






var login = {
    accountName: config.username,
    password: config.password,
    twoFactorCode: mobilecode
};




client.logOn(login);




client.on('loggedOn', function(details) {
    client.getPersonas([client.steamID], function(personas) {
        console.log("============ Logged in ===============================")
        console.log('== Name: ' + personas[client.steamID]["player_name"]);
        console.log('== ID64: ' + client.steamID);
        console.log("======================================================");
        console.log("");
    });
    console.log();
    client.setPersona(1); // Shows the status as online. 0 = offline (It will still work though!) 1 = online
    setInterval(function() { client.webLogOn(); }, 1000 * 60); // Refreshes session every 10 minutes
});






client.on('webSession', function(sessionID, cookies) {
    manager.setCookies(cookies, function(err) {
        if (err) { console.log("Couldn\'t set cookies! Error: " + err); }
    });
    community.setCookies(cookies);
    community.startConfirmationChecker(10000, config.identitysecret);
});






client.on('error', function(e) {
    console.log(e);
    process.exit(1);
});






community.on("sessionExpired", function(err) {
    console.log("## Session Expired, relogging.");
    client.webLogOn();
});






manager.on('newOffer', function(offer) { // When a new offer is received do the stuff below


    offer.getUserDetails(function(err, me, them) { // Get errors, an object containing the escrow days left and the inventory of the bot and the partner


        console.log("============ New Offer ===============================");
        console.log("== Partner:  " + them.personaName);                                       //This is where the error happened!
        console.log("============ My items ================================")

The error is happening in line 78. (The second-last starting with console.log("== Partner: ...))

 

TypeError: Cannot read property 'personaName' of undefined
    at C:\Users\Thomas\Desktop\Coding\Steam Trading\moneyBot\index.js:78:43
    at Object.exports.makeAnError (C:\Users\Thomas\Desktop\Coding\Steam Trading\moneyBot\node_modules\steam-tradeoffer-manager\lib\helpers.js:33:4)
    at C:\Users\Thomas\Desktop\Coding\Steam Trading\moneyBot\node_modules\steam-tradeoffer-manager\lib\classes\TradeOffer.js:818:12
    at SteamCommunity._checkTradeError (C:\Users\Thomas\Desktop\Coding\Steam Trading\moneyBot\node_modules\steamcommunity\components\http.js:145:3)
    at Request._callback (C:\Users\Thomas\Desktop\Coding\Steam Trading\moneyBot\node_modules\steamcommunity\components\http.js:52:80)
    at Request.self.callback (C:\Users\Thomas\Desktop\Coding\Steam Trading\moneyBot\node_modules\steamcommunity\node_modules\request\request.js:186:22)
    at emitTwo (events.js:87:13)
    at Request.emit (events.js:172:7)
    at Request.<anonymous> (C:\Users\Thomas\Desktop\Coding\Steam Trading\moneyBot\node_modules\steamcommunity\node_modules\request\request.js:1081:10)
    at emitOne (events.js:77:13)

 

 

 

I feel like this error is really weird. Why would personaName be undefined right after receiving the trade? It also handles a lot of trades without any problems, but then suddenly crashes.

 

steam-tradeoffer-manager is running on 2.5.0 and I also reinstalled all modules.  

 

Any help is appreciated! :)

Edited by MrInka
Posted (edited)

You should check if there is an error when you call getUserDetails.

If "err" is set, both "me" and "them" won't be.

 

Also you don't need to "refresh the session every 10 minutes". When the session expires, community emmits a sessionExpired event.

Edited by Van Kappa
Posted

Added a line to log "err" if something comes up. Sadly I can't reproduce the problem. Right now, it's running fine, no errors, handling trades how it should!

 

Thanks already!

Posted

Added a line to log "err" if something comes up. Sadly I can't reproduce the problem. Right now, it's running fine, no errors, handling trades how it should!

 

Thanks already!

 

As I said, it should only crash when err is set, as there won't be any data on me nor them. If you added a line to log err, the next time it crashes you should have an error object output just before the crash line

Posted (edited)

As I said, it should only crash when err is set, as there won't be any data on me nor them. If you added a line to log err, the next time it crashes you should have an error object output just before the crash line

 

It finally happened (this time while running on my raspberryPI.  

 

## Session Expired, relogging.

==> Couldn't get userInfo! Error: Error: Not Logged In

============ New Offer ===============================
/home/pi/Desktop/moneyBot/index.js:71
        console.log("== Partner:  " + them.personaName);

TypeError: Cannot read property 'personaName' of undefined
    at /home/pi/Desktop/moneyBot/index.js:71:43
    at Object.exports.makeAnError (/home/pi/Desktop/moneyBot/node_modules/steam-tradeoffer-manager/lib/helpers.js:33:4)
    at manager._community.httpRequestGet (/home/pi/Desktop/moneyBot/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:818:12)
    at SteamCommunity._checkCommunityError (/home/pi/Desktop/moneyBot/node_modules/steamcommunity/components/http.js:129:3)
    at Request._callback (/home/pi/Desktop/moneyBot/node_modules/steamcommunity/components/http.js:51:88)
    at Request.self.callback (/home/pi/Desktop/moneyBot/node_modules/steamcommunity/node_modules/request/request.js:186:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/home/pi/Desktop/moneyBot/node_modules/steamcommunity/node_modules/request/request.js:1081:10)
    at emitOne (events.js:96:13)

So ... "err" contains "Error: Not Logged In" - not quite sure what to do with that.

 

 

 

 

I am also getting these errors every now and then:  

 

 

#1

============ Logged in ===============================
== Name: ✘ Mr. Inka ✘ CS.MONEY
== ID64: 76561198046273125
======================================================


/home/pi/Desktop/moneyBot/node_modules/steam-user/components/web.js:9
throw new Error("Cannot log onto steamcommunity.com without first being connected to Steam network");
^


Error: Cannot log onto steamcommunity.com without first being connected to Steam network
    at SteamUser.webLogOn (/home/pi/Desktop/moneyBot/node_modules/steam-user/components/web.js:9:9)
    at Timeout._onTimeout (/home/pi/Desktop/moneyBot/index.js:47:37)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)
 
 

#2

## Session Expired, relogging.

/home/pi/Desktop/moneyBot/node_modules/steam-user/components/web.js:9
throw new Error("Cannot log onto steamcommunity.com without first being connected to Steam network");
^


Error: Cannot log onto steamcommunity.com without first being connected to Steam network
    at SteamUser.webLogOn (/home/pi/Desktop/moneyBot/node_modules/steam-user/components/web.js:9:9)
    at SteamCommunity.<anonymous> (/home/pi/Desktop/moneyBot/index.js:60:12)
    at emitOne (events.js:96:13)
    at SteamCommunity.emit (events.js:188:7)
    at SteamCommunity._notifySessionExpired (/home/pi/Desktop/moneyBot/node_modules/steamcommunity/components/http.js:85:7)
    at /home/pi/Desktop/moneyBot/node_modules/steamcommunity/components/confirmations.js:21:10
    at /home/pi/Desktop/moneyBot/node_modules/steamcommunity/components/confirmations.js:268:4
    at SteamCommunity._checkHttpError (/home/pi/Desktop/moneyBot/node_modules/steamcommunity/components/http.js:90:3)
    at Request._callback (/home/pi/Desktop/moneyBot/node_modules/steamcommunity/components/http.js:50:61)
    at self.callback (/home/pi/Desktop/moneyBot/node_modules/steamcommunity/node_modules/request/request.js:186:22)

Those two seem to pop up sometime after logging in or relogging when the session expired. It seems like those 3 errors have a connection.  

 

I find it a bit weird that it seems to happen "sometimes". Usually...

community.on("sessionExpired", function(err) {
    console.log("## Session Expired, relogging.");
    client.webLogOn();
});

...fires a new client.webLogOn(); and the bot keeps working. Why would this fail sometimes?

 

Any idea would help! :)

Edited by MrInka
Posted (edited)

You should check if loggedOn event's eresult is OK, otherwise there was an error logging in and therefore you can't proceed (request web session cookies).

Replace:

client.on('loggedOn', function(details) {
    client.getPersonas([client.steamID], function(personas) {
        console.log("============ Logged in ===============================")
        console.log('== Name: ' + personas[client.steamID]["player_name"]);
        console.log('== ID64: ' + client.steamID);
        console.log("======================================================");
        console.log("");
    });
    console.log();
    client.setPersona(1); // Shows the status as online. 0 = offline (It will still work though!) 1 = online
    setInterval(function() { client.webLogOn(); }, 1000 * 60); // Refreshes session every 10 minutes
});

with

client.on('loggedOn', function(details) {
	if(details.eresult == SteamUser.EResult.OK) {
		client.getPersonas([client.steamID], function(personas) {
			console.log("============ Logged in ===============================")
			console.log('== Name: ' + personas[client.steamID]["player_name"]);
			console.log('== ID64: ' + client.steamID);
			console.log("======================================================");
			console.log("");
		});
		console.log();
		client.setPersona(1); // Shows the status as online. 0 = offline (It will still work though!) 1 = online
		client.webLogOn();
	} else {
		console.log(details);
		//Do whatever u want to handle the error...
	}
});

Also, you should rate limit this:

community.on("sessionExpired", function(err) {
    console.log("## Session Expired, relogging.");
    client.webLogOn();
});

since it can be triggered too often and make steam temporary block your IP. You can do it like this:

var lastWebLoginAttempt = 0;

community.on("sessionExpired", function(err) {
    if(Date.now() - lastLoginAttempt >= 30000) {
        lastLoginAttempt = Date.now();
        console.log("## Session Expired, relogging.");
        client.webLogOn();
    } else {
        console.log("## Session Expired, waiting a while before attempting to relogin.");
    }
});
Edited by Van Kappa
Posted

I made the suggested changes. My dev is still wondering why these things are happening, but said that those changes could help.

 

Thanks a lot for the effort, my friend! Really hoping that it fixes my problems! :)

 

 

Another, probably really short thing:  

 

The bot sets my steam client (on my pc) to offline everytime it logs in. Is there any way to prevent this or shouldnt I be playing on the same account while the bot is running in general?

Posted

I don't know if you can actually be logged in an account in two clients at the same time.

Does it set your chat status to offline or it disconnects you from steam? If it just sets the chat to offline you can still play.

Posted

loggedOn will never be emitted for an eresult that isn't 1 (OK). disconnected or error will be emitted for failed logon attempts.

 

You can log into Steam with two clients at once ever since in-home streaming came out.

Posted (edited)

Sorry, I didn't fully understand what you meant with 

 

loggedOn will never be emitted for an eresult that isn't 1 (OK). disconnected or error will be emitted for failed logon attempts.

 

I used Van Kappas suggestion to check if it worked with 

if(details.eresult == SteamUser.EResult.OK)

 and added a

setTimeout(function() { client.logOn(login); }, 30000);

to the ELSE to handle any upcoming errors. Would this be the right way?  

 

 

 

You can log into Steam with two clients at once ever since in-home streaming came out.

 

And yes, Playing works fine and reconnecting to the steam chat doesn't seem to affect the bot, I would just like to keep it from setting my steamchat to offline everytime it logs in. Any chance here?

 

 

Thanks for the replies! :)

Edited by MrInka
Posted
throw new Error("Cannot log onto steamcommunity.com without first being connected to Steam network");

This clearly means you tried to webLogOn before loggedOn was successfull. Since it doesn't trigger for EResults that differ from OK, you should handle the logon error on disconnected or error events as McKay said.

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