balabam Posted August 20, 2018 Report Posted August 20, 2018 var _ = require('lodash'); var carrier = require('carrier'); var crypto = require('crypto'); var fs = require('fs'); var net = require('net'); var path = require('path'); var prompt = require('prompt'); var steamid = require('steamidconvert')() var Steam = require('steam'); var steamClient = new Steam.SteamClient(); var steamFriends = new Steam.SteamFriends(steamClient); var steamUser = new Steam.SteamUser(steamClient); var config = require(path.join(__dirname,'config.json')); config.sentryPath = path.join(__dirname, config.login+'-sentry.bin'); var q = {}; var usersLastLogoff = []; var schema = { properties: { steamauth: { description: 'Enter your steam auth code: ', message: 'This should be emailed to you.', type: 'string', required: true, pattern: /[0-9a-zA-Z\s]*/ } } }; steamClient.connect(); steamClient.on('connected', function() { var sha = undefined; if(fs.existsSync(config.sentryPath)) { console.log('Sentry file found. Sending to server.') var file = fs.readFileSync(config.sentryPath); sha = crypto.createHash('sha1').update(file).digest(); } steamUser.logOn({ account_name: config.login, password: config.pass, auth_code: config.auth, sha_sentryfile: sha }); }); steamClient.on('logOnResponse', function(logonResp) { if (logonResp.eresult === Steam.EResult.AccountLogonDenied) { steamClient.disconnect(); prompt.get(schema, function (err, result) { if (result.steamauth){ config.auth = result.steamauth; steamClient.connect(); } }); prompt.start(); }else if (logonResp.eresult === Steam.EResult.OK) { console.log('Logged in!'); steamFriends.setPersonaState(Steam.EPersonaState.Online); steamFriends.setPersonaName(config.displayName); }else{ console.log('Login failed.'); } }); steamUser.on('updateMachineAuth', function(sentry, cb) { console.log('Obtained sentry. Writing to '+config.sentryPath); fs.writeFileSync(config.sentryPath, sentry.bytes); cb({ sha_file: crypto.createHash('sha1').update(sentry.bytes).digest() }); }); steamFriends.on('relationships', function(){ checkFriendsLimit(); var friends = steamFriends.friends; for(var friend in friends){ if (friends[friend] === 2){ steamFriends.addFriend(friend); } } }); steamFriends.on('friend', function(friend, type){ checkFriendsLimit(); if(type === 2){ steamFriends.addFriend(friend); } }); steamFriends.on('personaState', function(state){ if ((_.has(state, 'last_logoff')) && !(_.has(state, 'persona_state'))){ usersLastLogoff.push(state); cleanUsers(); }else{ var id = state.friendid; if (_.has(q, id)){ _.each(q[id], function(message){ steamFriends.sendMessage(id, message); }); delete q[id]; } } }); var checkFriendsLimit = _.debounce(function (){ var friends = steamFriends.friends; var friendsArray = Object.keys(friends); if (friendsArray.length > config.maxFriends){ steamFriends.requestFriendData(friendsArray, Steam.EClientPersonaStateFlag.LastSeen); } } , 5000); var cleanUsers = _.debounce(function (){ if (steamClient.connected){ var sorted = _.sortBy(usersLastLogoff, 'last_logoff'); var purgeAmount = sorted.length - config.maxFriends; console.log('Purging old friends.') _.times(purgeAmount, function(i){ var id = sorted[i].friendid; console.log('Removing: ', id); steamFriends.removeFriend(id); }); usersLastLogoff = []; } } , 5000); var connect = _.debounce(function (){ steamClient.connect(); } , 5000); steamClient.on('error', function (e){ console.log(e); connect(); }); net.createServer(function (socket) { socket.on('error', function(err){ console.log('Socket Error: \n', err); }); carrier.carry(socket, function(line) { if (steamClient.connected){ if ((_.startsWith(line, 'BCMD')) && (line.length > 12)) { var cmd = line.substring(4, 8); var packet = line.substring(8).split('|'); var id = steamid.convertTo64(packet[0]); var msg = packet[1]; if (_.has(steamFriends, ['friends', id])){ if (steamFriends.friends[id] === 3){ steamFriends.sendMessage(id, msg); } if (steamFriends.friends[id] === 4){ q[id].push(msg); } }else{ checkFriendsLimit(); steamFriends.addFriend(id); if (!(_.has(q, id))){ q[id] = []; } q[id].push(msg); } } } }); }).listen(config.port); console.log('Server running on port '+config.port+'\n'); it was working very well script but When I change my vds suddenly its not working, its not login to steam account.. someone can help me ? Quote
Revadike Posted August 30, 2018 Report Posted August 30, 2018 This doesn't really involve McKay's libraries. 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.