Jump to content
McKay Development

Recommended Posts

The is my steam bot code. Idk what is wrong to code bot it don't work very good because after 1-2 days it brakes. That are the errors that i get:

Error: Disconnected
    at SteamClient._disconnected (/var/server/node_modules/steam/lib/steam_client.js:189:24)
    at Connection.emit (events.js:189:13)
    at TCP._handle.close (net.js:600:12)

TypeError: Cannot read property 'send' of undefined
    at SteamClient._send (/var/server/node_modules/steam/lib/steam_client.js:117:20)
    at SteamClient.send (/var/server/node_modules/steam/lib/steam_client.js:126:8)
    at SteamUser.requestWebAPIAuthenticateUserNonce (/var/server/node_modules/steam/lib/handlers/user/index.js:37:16)
    at SteamWebLogOn.<anonymous> (/var/server/node_modules/steam-weblogon/index.js:34:23)
    at ClientRequest.<anonymous> (/var/server/node_modules/steam-web-api/index.js:34:9)
    at Object.onceWrapper (events.js:277:13)
    at ClientRequest.emit (events.js:189:13)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:556:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
    at TLSSocket.socketOnData (_http_client.js:442:20)
    at TLSSocket.emit (events.js:189:13)
    at addChunk (_stream_readable.js:284:12)
    at readableAddChunk (_stream_readable.js:265:11)
    at TLSSocket.Readable.push (_stream_readable.js:220:10)
    at TLSWrap.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)

And more errors.

I want the best code the this bot without disconnects and with auto session cookies set after expires. Thanks.

BOT CODE

var bots = {
	steam: {
		botname: config.bot_steam.botname,
		username: config.bot_steam.username,
		password: config.bot_steam.password,
		identitySecret: config.bot_steam.identitySecret,
		sharedSecret: config.bot_steam.sharedSecret
	}
}

var new_steam_bot = function() {
	var connected = false;
	
	var community = new SteamCommunity();
	var client = new Steam.SteamClient();
	var user = new Steam.SteamUser(client);
	var friends = new Steam.SteamFriends(client);
	var webLogon = new SteamWebLogon(client, user);
	var manager = new TradeOfferManager({
		steam: client,
		community: community,
		domain: 'localhost',
		language: 'en',
		cancelTime: 150000
	});
	
	client.connect();
	 
	return {
		connected,
		
		community,
		client,
		user,
		friends,
		webLogon,
		manager,
	}
}

var Steam = require('steam');
var TradeOfferManager = require('steam-tradeoffer-manager');
var SteamTotp = require('steam-totp');
var SteamWebLogon = require('steam-weblogon');
var SteamCommunity = require('steamcommunity');
var q = require('q');
var protos = require('./protos');

var steam_bots = new_steam_bot();

steam_bots.client.on('connected', function() {
	logger.warn('[BOT] Client Connected');
	
	steam_bots.user.logOn({
		account_name: bots.steam.username,
		password: bots.steam.password,
		two_factor_code: SteamTotp.generateAuthCode(bots.steam.sharedSecret)
	});
});

steam_bots.client.on('logOnResponse', function(response) {
	if(response.eresult !== Steam.EResult.OK) {
		logger.warn('[BOT] Client Login Failed');
		
		steam_bots.client.connect();  
		return;
	}
	
	logger.warn('[BOT] Client Login Success');

	setWebLogOn();
});

steam_bots.client.on('loggedOff', function(eresult, msg) {
	logger.warn('[BOT] Client Logout. Message: ' + msg);
	
    steam_bots.client.connect();
});

steam_bots.client.on('error', function(err) {
	logger.warn('[BOT] Client Error. Error: ' + err.message);
	logger.error(err);
	writeError(err);
	
	if(err.message == 'Disconnected') {
		logger.error('[BOT] Client Disconnected. Reconnecting!');
		
		steam_bots.client.connect();  
	}
});

steam_bots.community.on('confKeyNeeded', function(deepDataAndEvents, updateFunc) {
	logger.warn('[BOT] Need Conf Key');
	
	updateFunc(null, time, SteamTotp.getConfirmationKey(bots.steam.identitySecret, time(), deepDataAndEvents));
});

steam_bots.community.on('sessionExpired', function(err) {
	logger.warn('[BOT] Session expired, logging in...');
	bots.steam.connected = false;
	
	steam_bots.community.stopConfirmationChecker();
	
	setWebLogOn();
});

steam_bots.user.on('updateMachineAuth', function( sentry, callback ) { 
	callback({
		sha_file: getSHA1(sentry.bytes)
	});
});

function getSHA1(bytes) {
	var shasum = crypto.createHash('sha1');
	shasum.end(bytes);
	
	return shasum.read();
}

function setWebLogOn(){
	try{
		steam_bots.webLogon.webLogOn(function(sessionID, cookies) { 
			logger.warn('[BOT] Session cookies set');
			
			steam_bots.manager.setCookies(cookies, function(err) {
				if (err) {
					logger.error(err);
					writeError(err);
					process.exit(1);
				}
			});
			
			steam_bots.community.setCookies(cookies);
			
			steam_bots.community.startConfirmationChecker(5000, bots.steam.identitySecret);
			
			setTimeout(function(){
				steam_bots.connected = true;
			
				loadOffersSent();
				loadPricesAll();
			}, 1000);
		});
	} catch(err){
		logger.warn('[BOT] Error Web Log On. Error: ' + err.message);
		logger.error(err);
		
		if(client.loggedOn){
			user.requestWebAPIAuthenticateUserNonce(function(result){
				logger.error('Error: Request Web API Authenticate User Nonce. ' + result);
			});
		} else {
			client.connect();
		}
	}
}

 

Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...