GDA Posted August 29, 2016 Report Posted August 29, 2016 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); } }); } }); }); Quote
Dr. McKay Posted August 29, 2016 Report Posted August 29, 2016 Why are you using SteamUser, but also logging in via SteamCommunity? Quote
GDA Posted August 29, 2016 Author Report Posted August 29, 2016 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? Quote
Dr. McKay Posted August 29, 2016 Report Posted August 29, 2016 If you need web sessions, SteamUser can do that all for you. If you need fresh cookies, call user.webLogOn(). Quote
GDA Posted August 30, 2016 Author Report Posted August 30, 2016 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? Quote
Dr. McKay Posted August 30, 2016 Report Posted August 30, 2016 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). Quote
GDA Posted August 30, 2016 Author Report Posted August 30, 2016 (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 August 30, 2016 by GDA Quote
Dr. McKay Posted August 30, 2016 Report Posted August 30, 2016 Looks good. You might want to rate-limit calls to webLogOn though, as sessionExpired could be emitted with any frequency. Quote
GDA Posted August 30, 2016 Author Report Posted August 30, 2016 (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 August 30, 2016 by GDA Quote
Dr. McKay Posted August 30, 2016 Report Posted August 30, 2016 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. Quote
GDA Posted August 31, 2016 Author Report Posted August 31, 2016 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:) Quote
GDA Posted September 11, 2016 Author Report Posted September 11, 2016 Sorry but I'm still having this issues. Full code here http://pastebin.com/t5jNbdUw Quote
Dr. McKay Posted September 12, 2016 Report Posted September 12, 2016 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. Quote
GDA Posted September 14, 2016 Author Report Posted September 14, 2016 (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 September 14, 2016 by GDA Quote
GDA Posted September 17, 2016 Author Report Posted September 17, 2016 Up theme, can someone help me? Quote
Recommended Posts
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.