Jump to content
McKay Development

Recommended Posts

Posted

Hi there. Im developing steam trade-bot but i have one issue during mothes. I need to reboot my server manually because after 1-3 days i got "Error malformed response" or smth like this. I got my code sample, can u say me whats wrong? i'm tired of this
 
 

var client = new SteamUser;
var steam = new SteamCommunity();
var community = steam; // alias
var app = express();

app.listen(app_settings.port, function () {
   console.log('App is running on ' + app_settings.port);
});

var logOnOptions = credentials.getDefault();
client.logOn(logOnOptions);

client.on('webSession', function(sessionID, cookies) {
   community.setCookies(cookies);
   manager.setCookies(cookies);
   community.startConfirmationChecker('10000', app_settings.identity_secret);
});

client.on('disconnected', function(){
   setTimeout(function(){
      var logOnOptions = credentials.getDefault();
      client.webLogOn(logOnOptions);
   }, 10000);
});

community.on('sessionExpired', function(err) {
   var logOnOptions = credentials.getDefault();
   community.login(logOnOptions, function(err, sessionID, cookies, steamguard){

      if (err) {
         console.log("There was an error logging in! Error details: " + err.message);
         process.exit(1); //terminates program
      } else {
         console.log("Successfully logged in as " + logOnOptions.accountName);
         steam.chatLogon();
         manager.setCookies(cookies, function(err) {
            if (err) {
               console.log(err);
               process.exit(1);
            }
         });
      }
   });
});
Posted

Why are you using SteamUser, but also logging in via SteamCommunity?

Because SteamCommunity starts confirmation checker, and client creates a trade offer. Am i missing something?

Posted

If you need web sessions, SteamUser can do that all for you. If you need fresh cookies, call user.webLogOn().

So what my steps?

 

I need only authenticate SteamUser then put cookies which i'll get from callback to other clients such as steamcommunity?

How can i check that my session/cookies expired?

Are they with the same lifetime? 

When i need to stop and start confirmation checker with this conditions? 

 

 

Posted

You're already using webSession to call setCookies. That's all you need to do to handle those cookies. Cookies from relogs will also arrive in that event.

 

The steamcommunity sessionExpired event will still work for determining that your cookies have gone bad. Cookies from a SteamUser session will last at most as long as your Steam connection, but Steam has a tendency to kill them whenever it pleases (as with all session cookies).

Posted (edited)

You're already using webSession to call setCookies. That's all you need to do to handle those cookies. Cookies from relogs will also arrive in that event.

 

The steamcommunity sessionExpired event will still work for determining that your cookies have gone bad. Cookies from a SteamUser session will last at most as long as your Steam connection, but Steam has a tendency to kill them whenever it pleases (as with all session cookies).

So my final code with solved issues would be looks like:

 

 

var client = new SteamUser;
var steam = new SteamCommunity();
var community = steam; // alias
var app = express();

app.listen(app_settings.port, function () {
   console.log('App is running on ' + app_settings.port);
});

var logOnOptions = credentials.getDefault();
client.logOn(logOnOptions);

client.on('webSession', function(sessionID, cookies) {
   community.setCookies(cookies);
   manager.setCookies(cookies);
   community.startConfirmationChecker('10000', app_settings.identity_secret);
});

client.on('disconnected', function(){
   setTimeout(function(){
      var logOnOptions = credentials.getDefault();
      client.logOn(logOnOptions);
   }, 10000);
});

community.on('sessionExpired', function(err) {
   community.stopConfirmationChecker();
   client.webLogOn();
});
am i right? Edited by GDA
Posted (edited)

Looks good. You might want to rate-limit calls to webLogOn though, as sessionExpired could be emitted with any frequency.

I dont get it. Why i should rate-limit call to webLogOn if i need to refresh session when it expires?

 

Also, do i need to stop confirmation checker in case when community gets sessionExpired? or it doesn't matter and i'll not lose any data or callbacks for confirmations?

Edited by GDA
Posted

If there are 3 requests in flight when your session expires and they all fail, then sessionExpired could be emitted 3 times, so you'd try to log on 3 times.

 

You don't need to explicitly stop it, no.

Thanks! I'll try it soon, and will write a result:)

  • 2 weeks later...
Posted

Don't reconnect as a result of disconnected. As per the documentation (please read it!), it will automatically reconnect as long as you haven't explicitly disabled that feature (and even then, if I remember correctly it should emit error instead of disconnected).

 

Why are you waiting 15 seconds to relog after your session expires? You can safely do it immediately.

 

As previously suggested, you should keep track of when you last tried to relog and throttle it to avoid spamming logins.

 

Checking isOurOffer inside of newOffer is unnecessary; it will only be emitted for new incoming offers.

Posted (edited)

Don't reconnect as a result of disconnected. As per the documentation (please read it!), it will automatically reconnect as long as you haven't explicitly disabled that feature (and even then, if I remember correctly it should emit error instead of disconnected).

 

Why are you waiting 15 seconds to relog after your session expires? You can safely do it immediately.

 

As previously suggested, you should keep track of when you last tried to relog and throttle it to avoid spamming logins.

 

Checking isOurOffer inside of newOffer is unnecessary; it will only be emitted for new incoming offers.

Sorry, i read docs. Thanks. Also i changed my code, you can see it http://pastebin.com/jG62XM8u here. Now i got limiter and still have this issue.

 

Upd. Maybe u need to know my bot is working under pm2 process manager.

Edited by GDA

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