Frohser Posted September 23, 2017 Report Posted September 23, 2017 (edited) bot.js: manager.on('pollFailure', function (err) { if (err) { console.log(`Error polling for trade offers ${err.message}`); console.log(formatted); // time_and_date client.logOff(); sleep.sleep(10); client.logOn(logOnOptions); } }); bot-out-0.log Logged: my_name 2017-09-23 16:42:57 Error polling for trade offers socket hang up 2017-09-23 18:42:57 Logged: my_name 2017-09-23 18:43:27 bot-error-0.log Error: Already logged on, cannot log on again at SteamUser.logOn (/home/steam/node_modules/steam-user/components/logon.js:11:9) at TradeOfferManager.<anonymous> (/home/steam/bot.js:267:10) at emitOne (events.js:96:13) at TradeOfferManager.emit (events.js:188:7) at getOffers (/home/steam/node_modules/steam-tradeoffer-manager/lib/polling.js:54:9) at _apiCall (/home/steam/node_modules/steam-tradeoffer-manager/lib/index.js:453:4) at _community.httpRequest (/home/steam/node_modules/steam-tradeoffer-manager/lib/webapi.js:32:4) at SteamCommunity._checkHttpError (/home/steam/node_modules/steamcommunity/components/http.js:90:3) at Request._callback (/home/steam/node_modules/steamcommunity/components/http.js:50:61) at self.callback (/home/steam/node_modules/request/request.js:186:22) What is wrong with this code? Edited September 25, 2017 by Frohser Quote
Dr. McKay Posted September 23, 2017 Report Posted September 23, 2017 Sleeping won't work. You need to use setTimeout to delay asynchronously. Delaying synchronously breaks pretty much everything, always. Frohser 1 Quote
Frohser Posted September 25, 2017 Author Report Posted September 25, 2017 Sleeping won't work. You need to use setTimeout to delay asynchronously. Delaying synchronously breaks pretty much everything, always.Using this: const sleep = require('sleep'); // https://www.npmjs.com/package/sleepSet to 30 and sleeping working. This code is pretty good? manager.on('pollFailure', function (err) { if (err) { console.log("(" + dateTime() + " |" + dateTime(true) + ")" + ` Error polling: ${err.message}`); //console.log("(" + dateTime() + " |" + dateTime(true) + ")" + ' Log off...'); client.logOff(); setTimeout(function () { client.logOn(logOnOptions); }, 10000); // 10 seconds } }); Quote
Dr. McKay Posted September 25, 2017 Report Posted September 25, 2017 That should work, but for robustness you should listen for the disconnected event then re-login after that gets emitted (but make sure you only call logOn in response to disconnected if you manually initiated the logoff; disconnected can also be emitted if Steam goes down, in which case it will automatically reconnect). Frohser 1 Quote
Frohser Posted September 26, 2017 Author Report Posted September 26, 2017 (edited) That should work, but for robustness you should listen for the disconnected event then re-login after that gets emitted (but make sure you only call logOn in response to disconnected if you manually initiated the logoff; disconnected can also be emitted if Steam goes down, in which case it will automatically reconnect). I don't know if I good understand you but imo yes. Changed little bit my code: manager.on('pollFailure', function (err) { if (err) { console.log("Error polling"); client.logOff(); } }); client.on('disconnected', function () { console.log("(" + dateTime() + " |" + dateTime(true) + ")" + " Disconnected... Login in again!"); setTimeout(function () { client.logOn(logOptions); }, 10000); // 10 seconds }); Anyway I'm getting pollFailure - socket hang up always after 2 hours. I check my connection in VPS and also at my home connection and its not a caused by my connection.Why when I send a request to a remote server, and receive no timely response always after two hours? Edit: nope... not working.. he didn't logOn (26/09/2017 | 14:59:45) Logged in! (26/09/2017 | 17:00:01) Disconnected... Login in again! Also I changed code to client.relog, but after getting new offer I got error from accepting trade: "Can't accept offer: Not logged in" Fuck off with this logOn or Relog or whatever... I just put new crontab for restart bot.js every hour and I don't give a shit about this.. I can feel pain -.- Edited September 26, 2017 by Frohser Quote
Dr. McKay Posted September 26, 2017 Report Posted September 26, 2017 but make sure you only call logOn in response to disconnected if you manually initiated the logoff; disconnected can also be emitted if Steam goes down, in which case it will automatically reconnect Quote
Frohser Posted September 27, 2017 Author Report Posted September 27, 2017 (edited) but make sure you only call logOn in response to disconnected if you manually initiated the logoff; disconnected can also be emitted if Steam goes down, in which case it will automatically reconnect I'm not sure what to do that... I'm trying with many ways and all failed. This should work? You wrote about this? manager.on('pollFailure', function (err) { if (err) { console.log("(" + dateTime() + " |" + dateTime(true) + ")" + ` Error polling information: ${err.message}`); console.log("(" + dateTime() + " |" + dateTime(true) + ")" + ' Login off...'); client.logOff(); } }); client.on('disconnected', function () { console.log("(" + dateTime() + " |" + dateTime(true) + ")" + " Disconnected... Login in again!"); if (client.steamID == null) { setTimeout(function () { client.logOn(logOptions); }, 10000); // 10 seconds } else { client.webLogOn((err) => { if (err) { console.log("(" + dateTime() + " |" + dateTime(true) + ")" + err.message) } }) } }); Edit 1: Script login correctly but... don't print "Logged in!". client.on('loggedOn', function() { client.setPersona(SteamUser.Steam.EPersonaState.Away); // Set status to Away console.log("(" + dateTime() + " |" + dateTime(true) + ")" + ` Logged in!\n`); // Output: (26/09/2017 | 12:43:36) Logged in! }); PS. Sent 5 usd donate via PayPal Edited September 27, 2017 by Frohser 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.