Jump to content
McKay Development

yellowish

Member
  • Posts

    4
  • Joined

  • Last visited

Reputation Activity

  1. Like
    yellowish reacted to Dr. McKay in Minimal code to stay logged in forever...   
    That all looks fine to me. sessionExpired is only emitted when a request you make fails because you aren't logged in. It doesn't check automatically, it only checks whenever the library makes a request somewhere.
     
    Starting a new confirmation checker without stopping the old one is just fine. It'll stop an old one if you call it while one is running.
     
    I recommend updating to v3.23.1 if you're going to use webchat.
  2. Like
    yellowish reacted to klonaway in Minimal code to stay logged in forever...   
    I have spent some time checking the node-steamcommunity GitHub wiki, and first of all : Dr. McKay, you are a hero for building up such an easy npm interface for the messy Steam API...
     
    I came up with some code to make sure I'm logged in almost 24/7 :
    // Modules are required and secret stuff is ready... function logOnSteam() { console.log("Logging in to Steam..."); steamCommunity.login(logOnOptions, function (e, sessionID, cookies, steamguard) { if (e) { console.log("There was an error logging in ! Error details : " + e.message); setTimeout(logOnSteam, 1000*60*4); // try to reconnect in 4 minutes return; } else { console.log("Successfully logged in as " + logOnOptions.accountName + " !"); steamCommunity.chatLogon(); // to appear online tradeOfferManager.setCookies(cookies, function (err) { if (err) { console.log(err); return; } }); } // automatic confirmation of EVERYTHING every "confirmationPeriod" ms steamCommunity.startConfirmationChecker(confirmationPeriod, identitySecret); }); } function checkSteamLogged() { steamCommunity.loggedIn( function (err, loggedIn, familyView) { if (err) { console.log(err); setTimeout(checkSteamLogged, 1000*60*4); // check again in 4 min } else if ( ! loggedIn ) { console.log("Steam login check : NOT LOGGED IN !"); logOnSteam(); } else { console.log("Steam login check : already logged in !"); } }); } steamCommunity.on('sessionExpired', function (err) { if (err) {console.log(err);} logOnSteam(); }); logOnSteam(); setInterval(checkSteamLogged, 1000*60*30); I guess this is enough to be safe... (unless I made some rookie mistake ?)
     
    This code is obviously the starting point for some TradeOfferManager handling, and I was wondering if I didn't go too far :
    if the 'sessionExpired' event is really triggered whenever we are not logged in, does it mean the 'checkSteamLogged()' function can be safely removed without harm ? '.startConfirmationChecker()' doesn't create a new instance each time it is called ? (I don't want to trigger 10 confirmations checkers leading to 10 times the intended check rate...) Thanks for any input !
×
×
  • Create New...