Jump to content


Photo
Question

Auto restart

node.js node-steam-user

  • Please log in to reply
7 replies to this topic

#1 FuTTiiZ

FuTTiiZ

    Newbie

  • Member
  • Pip
  • 5 posts

Posted 08 March 2019 - 11:25 PM

I am having issues with making an auto-restart function.. I want to have it so it idles until I start playing steam games, and then continues afterwards.

I haven't been able to find anything related to this, hope you guys can help :)

 

This is my code:

console.log('Script was loaded successfully.');

const SteamUser = require('steam-user');
const SteamTotp = require('steam-totp');
const appid = require('appid');
const config = require('./config');

const client = new SteamUser();

console.log('Node.js packages were loaded successfully.');

const games = [4000];

console.log('game-choices were loaded successfully.');

const logInOptions = {
	accountName: config.username,
	password: config.password,
	twoFactorCode: SteamTotp.generateAuthCode(config.shared_secret)
};

console.log('credentials were loaded');

client.logOn(logInOptions);

function checkForPlaying() {
	client.gamesPlayed(games);
	client.on('playingState', function(blocked, playingApp) {
		console.log(blocked);
		if (blocked == true) {
			setTimeout(checkForPlaying, 5000);
		} else if (blocked == false) {
			client.setPersona(SteamUser.EPersonaState.Offline);
			client.gamesPlayed(games);
		}
	});
}

client.on('loggedOn', () => {
	client.setPersona(SteamUser.EPersonaState.Offline);
	client.gamesPlayed(games);
	console.log(' \n Logged on accoung: ' + config.username);
});

client.on('error', function(err) {
	if (err.eresult == '6') {
		console.log('ERROR');
		checkForPlaying();
	}
});

I would REALLY appreciate if you can help me, I have been trying for days now. This is my last hope :(


Edited by FuTTiiZ, 09 March 2019 - 10:48 AM.


#2 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 2,187 posts

Posted 08 March 2019 - 11:37 PM

When error is emitted, that means you're logged off. You'll need to log on again.



#3 FuTTiiZ

FuTTiiZ

    Newbie

  • Member
  • Pip
  • 5 posts

Posted 09 March 2019 - 05:01 AM

When error is emitted, that means you're logged off. You'll need to log on again.

I have tried loging in again, but when eror is emitted, it exits with status 0 and says crashed.

It also says I can’t login twice.

Edited by FuTTiiZ, 09 March 2019 - 05:02 AM.


#4 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 2,187 posts

Posted 09 March 2019 - 05:22 AM

Try using process.nextTick(() => client.logOn(logInOptions)) when error is emitted. You're going to need to generate a new 2FA code, though.



#5 FuTTiiZ

FuTTiiZ

    Newbie

  • Member
  • Pip
  • 5 posts

Posted 09 March 2019 - 05:36 AM

Try using process.nextTick(() => client.logOn(logInOptions)) when error is emitted. You're going to need to generate a new 2FA code, though.

I already have that set up, thanks for the answer, I’ll check it out now :)

#6 FuTTiiZ

FuTTiiZ

    Newbie

  • Member
  • Pip
  • 5 posts

Posted 09 March 2019 - 06:00 AM

Try using process.nextTick(() => client.logOn(logInOptions)) when error is emitted. You're going to need to generate a new 2FA code, though

I have no idea what to do, can you help me out with the code?

Don't mind the danish console logs, it should still be easy to see it in the console.

console.log('Script blev loaded successfuldt.');

const SteamUser = require('steam-user');
const SteamTotp = require('steam-totp');
const appid = require('appid');
const config = require('./config');

const client = new SteamUser();

console.log('Node.js pakker blev loaded successfuldt.');

//const games = [10,20,30,40,50,60,70,80,100,130,211,218,220,240,280,300,320,340,360,380,400,420,440,500,550,620,730,745,1500,1510,1840,4000,6000,6020,6060,12100,12110,12120,12200,12210,32370,32440,32470,32510,39000,47800,107410,110800,208580,209650,209660,213670,218620,219150,219640,223470,223530,223710,224480,227920,227940,228980,230290,230410,231410,233450,233720,236870,238090,239140,243750,249130,250820,252490,252950,254430,265210,265930,268910,271590,274170,274190,291550,298110,304930,311210,312990,313160,313690,319630,322310,352400,353360,354140,356670,359550,363970,383080,397900,427730,429540,431960,438100,441870,460930,471610,476600,476620,488790,557810,567150,575900,578080,588430,616560,629520,656290,657200,674940,697640,712530,755790,786140,809960,822240,823130,842150,863550,863750,886040,890220,913520,914690,922320,929860,944380,952120,974950,978470,987820];
const games = [4000];

console.log('Spil-valg blev loaded successfuldt.');

const logInOptions = {
	accountName: config.username,
	password: config.password,
	twoFactorCode: SteamTotp.generateAuthCode(config.shared_secret)
};

console.log('Konto-oplysninger blev loaded fra config-filen.');

client.logOn(logInOptions);

client.setPersona(SteamUser.EPersonaState.Offline);
client.gamesPlayed(games);

function checkForPlaying() {
	client.on('playingState', function(blocked, playingApp) {
		console.log(blocked);
		if (blocked == true) {
			setTimeout(checkForPlaying, 5000);
		} else if (blocked == false) {
			client.setPersona(SteamUser.EPersonaState.Offline);
			client.gamesPlayed(games);
		}
	});
}

client.on('loggedOn', () => {
	client.setPersona(SteamUser.EPersonaState.Offline);
	client.gamesPlayed(games);
	console.log(' \n Logged ind på kontoen: ' + config.username);
});

client.on('error', function(err) {
	if (err.eresult == '6') {
		console.log('FEJL!');
		process.nextTick(() => checkForPlaying());
	}
});

Here is the console:

2019-03-09T10:59:43.909660+00:00 app[worker.1]: Script blev loaded successfuldt.
2019-03-09T10:59:46.642463+00:00 app[worker.1]: Node.js pakker blev loaded successfuldt.
2019-03-09T10:59:46.642775+00:00 app[worker.1]: Spil-valg blev loaded successfuldt.
2019-03-09T10:59:46.646221+00:00 app[worker.1]: Konto-oplysninger blev loaded fra config-filen.
2019-03-09T10:59:47.621919+00:00 app[worker.1]:  
2019-03-09T10:59:47.621930+00:00 app[worker.1]:  Logged ind på kontoen: futteboy2
2019-03-09T10:59:56.738752+00:00 heroku[worker.1]: State changed from up to crashed
2019-03-09T10:59:56.608422+00:00 app[worker.1]: Logged in elsewhere.
2019-03-09T10:59:56.718847+00:00 heroku[worker.1]: Process exited with status 0

Edited by FuTTiiZ, 09 March 2019 - 10:48 AM.


#7 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 2,187 posts

Posted 09 March 2019 - 10:04 PM

You need to log back on after error before you do anything else, or else it will crash because you're trying to do things without being logged on. A call to logOn is what needs to go inside the process.nextTick.



#8 FuTTiiZ

FuTTiiZ

    Newbie

  • Member
  • Pip
  • 5 posts

Posted 11 March 2019 - 01:51 AM

Thanks





Also tagged with one or more of these keywords: Question, node.js, node-steam-user

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users