Jump to content


Photo

sessionExpired after trade notification

node.js node-steamcommunity

  • Please log in to reply
8 replies to this topic

#1 neverhood

neverhood

    Advanced Member

  • Member
  • PipPipPip
  • 52 posts

Posted 01 February 2019 - 04:37 PM

Hello, I released some donation/trash bot and most of time everything is working fine, processing a lot of trades without any problems (only accepting gift trades), but lately I got weird problem, session expiring 1 second after new trade

 

my console logs:

 

[18:35:09] - Processing trade 3459285622
[18:35:10] Session expired - relogging
[21:56:28] - Processing trade 3459471951
[21:56:29] Session expired - relogging
 
how I handle it in my bot:
 
const community = new SteamCommunity();
const manager = new SteamTradeofferManager({
  steam: client,
  language: 'en',
  community
});


community.on('sessionExpired', () => {
  console.log(`[${new Date().toLocaleTimeString()}] Session expired - relogging`);
  client.webLogOn();
});

everything works good, but sometimes getting this error and my bot stuck (should I remove community from manager?)

 

edit: I noticed I wrongly used community in const manager


Edited by neverhood, 01 February 2019 - 06:18 PM.


#2 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 2,107 posts

Posted 01 February 2019 - 06:47 PM

edit: I noticed I wrongly used community in const manager

 

Does this mean it's fixed?



#3 neverhood

neverhood

    Advanced Member

  • Member
  • PipPipPip
  • 52 posts

Posted 01 February 2019 - 06:48 PM

I changed it to community: community, and I will test (need a few hours to test it)



#4 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 2,107 posts

Posted 01 February 2019 - 06:52 PM

The way you used community in your first post is correct. You can do just {community} which is interpreted as {community: community}.

 

I think probably what's happening is that your session is just expiring (which happens normally) and you aren't expecting it. It wouldn't hurt to add an automatic hourly webLogOn call to be more proactive about renewing your session rather than reactive.



#5 neverhood

neverhood

    Advanced Member

  • Member
  • PipPipPip
  • 52 posts

Posted 01 February 2019 - 07:00 PM

The way you used community in your first post is correct. You can do just {community} which is interpreted as {community: community}.

 

I think probably what's happening is that your session is just expiring (which happens normally) and you aren't expecting it. It wouldn't hurt to add an automatic hourly webLogOn call to be more proactive about renewing your session rather than reactive.

 

I have no idea why this is happening randomly (when someone send trade offer session getting expired 1 second after and my bot stuck), sometimes my bot works even 72 hours without this issue, I think maybe because bot is idling for longer time (not receving any trade offer) this is happening.



#6 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 2,107 posts

Posted 02 February 2019 - 01:24 AM

I have no idea why this is happening randomly (when someone send trade offer session getting expired 1 second after and my bot stuck)

 

I think you might be misunderstanding what's happening. Your session isn't expiring immediately after someone sends you a trade offer. The module can only know that your session expired if it attempts to make a cookie-authenticated request and it fails. The module knows that you got a new trade offer from the API (which doesn't expire), but when you try to act on it that takes place on steamcommunity.com so that's the earliest you can know that your session expired.

 

Exactly what causes a session to expire is known only to God Valve, and you'll just need to work around it by refreshing your session as needed.



#7 neverhood

neverhood

    Advanced Member

  • Member
  • PipPipPip
  • 52 posts

Posted 02 February 2019 - 05:00 AM

now I get it (I think so :D), thank you for explaining me
 
should I add setInterval in 'loggedOn' with 1 hour refresh? something like this:
 
setInterval(function(){ client.webLogOn(); }, 3600000);

my current code:

 

client.on('webSession', (sessionID, cookies) => {
  manager.setCookies(cookies);

  const f = Object.keys(client.myFriends);
  for (let i = f.length - 1; i >= 0; i--)
    if (client.myFriends[f[i]] === 2)
      client.addFriend(f[i]);
});


client.on('loggedOn', () => {
  client.gamesPlayed(configuration.gamesPlayed);
  client.setPersona(1);
  console.log(`[${new Date().toLocaleTimeString()}] - ONLINE - ${client.steamID.getSteamID64()}`);
});

am I setting properly manager cookies with every websession?

 



#8 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 2,107 posts

Posted 02 February 2019 - 05:09 AM

Yes, that would work.

 

For clarity's sake, you should use SteamUser.EPersonaState.Online instead of 1 and SteamUser.EFriendRelationship.RequestRecipient instead of 2 in that code.



#9 neverhood

neverhood

    Advanced Member

  • Member
  • PipPipPip
  • 52 posts

Posted 02 February 2019 - 05:14 AM

ok, thank you!







Also tagged with one or more of these keywords: node.js, node-steamcommunity

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users