andrewda / node-steam-guide

A guide to creating Steam bots and websites using Node.js
Creative Commons Attribution 4.0 International
645 stars 131 forks source link

NPM modules are broken and have wrong code #102

Closed 2cab closed 4 years ago

2cab commented 4 years ago

so basically when i launch bot,js under node.js it will say that the module file manager has a syntax error:unexpected token (

this is what the code looks like

FileManager.prototype.saveFiles = FileManager.prototype.writeFiles = function(files) { return new Promise(async (resolve, reject) => { try { await Promise.all(Object.keys(files).map(filename => this.saveFile(filename, files[filename]))); resolve(); } catch (ex) { reject(ex); } }); };

it also lists many other proplems with other files

andrewda commented 4 years ago

Hi, could you post the full error message?

2cab commented 4 years ago

Hi, could you post the full error message?

(btw im using node 12.16.1 which is the current recomended one and have tried downloading different versions of the module and nothing has worked and i cant figure out how to fix the code so idk what to do bc that is not the only file that has come up with similar errors)

succesfully logged on.
C:\Users\serbe\Downloads\bot\node_modules\steam-user\components\connection.js:21
        this._connection.stream.setTimeout(0);
                                ^

TypeError: Cannot read property 'setTimeout' of undefined
    at SteamUser.<anonymous> (C:\Users\serbe\Downloads\bot\node_modules\steam-user\components\connection.js:21:26)
    at C:\Users\serbe\Downloads\bot\node_modules\steam-user\components\classes\HandlerManager.js:37:12
    at Array.forEach (<anonymous>)
    at HandlerManager.emit (C:\Users\serbe\Downloads\bot\node_modules\steam-user\components\classes\HandlerManager.js:36:12)
    at SteamUser._handleMessage (C:\Users\serbe\Downloads\bot\node_modules\steam-user\components\messages.js:545:24)
    at SteamUser._handleNetMessage (C:\Users\serbe\Downloads\bot\node_modules\steam-user\components\messages.js:480:7)
    at TCPConnection._readMessage (C:\Users\serbe\Downloads\bot\node_modules\steam-user\components\connection_protocols\tcp.js:193:12)
    at Socket.emit (events.js:311:20)
    at emitReadable_ (_stream_readable.js:562:12)
    at processTicksAndRejections (internal/process/task_queues.js:83:21)
2cab commented 4 years ago

any thoughts?

2cab commented 4 years ago

`succesfully logged on. Connected to tf2 game server. Loaded our backpack. craft error. craft error. C:\Users\serbe\Downloads\bot\node_modules\bytebuffer\dist\bytebuffer-node.js:2764 throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.length); ^

RangeError: Illegal range: 0 <= 8 <= 2068278345 <= 96 at ByteBuffer.module.exports.ByteBufferPrototype.slice (C:\Users\serbe\Downloads\bot\node_modules\bytebuffer\dist\bytebuffer-node.js:2764:23) at SteamUser._handleNetMessage (C:\Users\serbe\Downloads\bot\node_modules\steam-user\components\messages.js:453:69) at TCPConnection._readMessage (C:\Users\serbe\Downloads\bot\node_modules\steam-user\components\connectionprotocols\tcp.js:193:12) at Socket.emit (events.js:311:20) at emitReadable (_stream_readable.js:562:12) at processTicksAndRejections (internal/process/task_queues.js:83:21)`

found some other non working code

andrewda commented 4 years ago

@2cab hmm, I'm not sure, but looks like you're using some custom code that's not in the guide. I'll need to see all the code you're using to help diagnose.

2cab commented 4 years ago

when i install the steam-user file it downloads allot of other files in the node-module folder

andrewda commented 4 years ago

That's expected. Please post the code you're trying to run here.

2cab commented 4 years ago
const SteamUser = require('steam-user');
const SteamTotp = require('steam-totp');
const SteamCommunity = require('steamcommunity');
const TradeOfferManager = require('steam-tradeoffer-manager');
const TeamFortress2 = require('tf2');

const Prices = require('./prices.json');
const config = require('./config.json');

const client = new SteamUser();
const tf2 = new TeamFortress2(client);
const community = new SteamCommunity();
const manager = new TradeOfferManager({
    steam: client,
    community: community,
    language: 'en'
});

const logOnOptions = {
  accountName: 'config.username',
  password: 'config.password',
  twoFactorCode: SteamTotp.generateAuthCode('config.sharedSecret')
};

client.logOn(logOnOptions);

    console.log('succesfully logged on.');
client.on('loggedOn', () => {

    client.setPersona(SteamUser.EPersonaState.Online);
    client.gamesPlayed(440);
});

client.on("friendMessage", function(steamID, message) {
    if (message == "!rules") {
        client.chatMessage(steamID, "This bot is made for tradeing and you should not try to exploit this bot because it can log errors and ban you so trying to brake the trade is not allowed (This also includes continous attempts to underpay the bots price listings) Thanks!")
    }
});

client.on('friendRelationship', (steamid, relationship) => {
    if (relationship === 2) {
        client.addFriend(steamid);
        client.chatMessage(steamid, 'Hello there! Thanks for adding this Bot!');
    }
  });

client.on('webSession', (sessionid, cookies) => {
    manager.setCookies(cookies);

    community.setCookies(cookies);
    community.startConfirmationChecker(20000, 'config.IdentitySecret');
});

client.logOn(logOnOptions);

client.on('loggedOn', () => {
});

function acceptOffer(offer) {
    offer.accept((err) => {
        if (err) console.log("There was an error accepting the offer")
    });
}

function declineOffer(offer) {
    offer.decline((err) => {
        if (err) console.log("There was an error declining the offer")
    });
}

function processOffer(offer) {
    if (offer.isGlitched() || offer.state === 11) {
        console.log("Offer Was glitched, declining.");
        declineOffer(offer);
    } else if (offer.partner.getSteamID64() === '76561198408825419') {
        acceptOffer(offer);
    }else{
        var ourItems = offer.itemsToGive;
        var theirItems = offer.itemsToReceive;
        var ourValue = 0;
        var theirValue = 0;
        for (var i in ourItems) {
            var item = ourItems[i].market_name;
            if(Prices[item]) {
                ourValue += Prices[item].sell;
            } else {
                console.log("Invalid Value.");
                ourValue += 99999;
            }
        }
        for(var i in theirItems) {
            var item= theirItems[i].market_name;
            if(Prices[item]) {
                theirValue += Prices[item].buy;
            } else {
            console.log("Their value was different.")
            }
        }

    console.log("Our value: "+ourValue);
    console.log("Their value: "+theirValue);

    if (ourValue <= theirValue) {
        acceptOffer(offer);
    } else {
        declineOffer(offer);
    }
    }
}

client.setOption("promptSteamGuardCode", false);

manager.on('newOffer', (offer) => {
     processOffer(offer);
});

/* Crafting */

var scrapAmt = 25;
var pollCraft = 30;

tf2.on('connectedToGC', function() {
    console.log("Connected to tf2 game server.");
});

tf2.on('backpackLoaded', function () {
    console.log("Loaded our backpack.");
});

function craftS(amtNeedScrap) {
    if (tf2.backpack == undefined) {
        console.log("unable to load backpack, can't craft.");
        return
    } else {
        console.log("attempting to craft...");
        var amtOfScrap = 0;
        for (var i = 0; i <tf2.backpack.length; i++) {
            if (tf2.backpack[i].defIndex === 5000) {
                amtOfScrap++;
            }
        }
        for (var i = 0; i <tf2.backpack.length; i++) {
            if (tf2.backpack[i].defIndex === 5002) {
                amtOfScrap +=9;
                var beep = new Array;
                beep.push(parseInt(tf2.backpack[i].id));
                tf2.craft(beep);

    } else if (tf2.backpack[i].defIndex === 5001) {
                amtOfScrap +=3;
                var beep = new Array;
                beep.push(parseInt(tf2.backpack[i].id));
                tf2.craft(beep);
            }
            if (amtOfScrap >= amtNeedScrap) {
                break;
            }
        }

    }
}

tf2.on('craftingComplete', function(e) {
    console.log("Finished crafting.");
});

client.on('friendMessage#'+'76561198408825419', function(steamID, message) {
    if (message == "craft") {
        craftS(scrapAmt);
        console.log("Recieved order to craft from admin.")
    } else {
        console.log("craft error.")
    }
});

 client.on("friendMessage", function(steamID, message) {
    if (message == "hi") {
        client.chatMessage(steamID, "Hewo! :)")
    }
});

setInterval(function() {
    craftS(scrapAmt);
}, 1000 * 60 * pollCraft)
2cab commented 4 years ago

I think that it is the vulnerabilities in the modules because when i download them and do in cmd "npm audit" it show what has the problems

  Manual Review
             Some vulnerabilities require your attention to resolve

          Visit https://go.npm.me/audit-guide for additional guidance

  Low             Directory Traversal

  Package         send

  Patched in      >= 0.8.4

  Dependency of   totp

  Path            totp > phpjs > send

  More info       https://npmjs.com/advisories/32

  Low             Root Path Disclosure

  Package         send

  Patched in      >=0.11.1

  Dependency of   totp

  Path            totp > phpjs > send

  More info       https://npmjs.com/advisories/56

  Low             Incorrect Handling of Non-Boolean Comparisons During
                  Minification

  Package         uglify-js

  Patched in      >= 2.4.24

  Dependency of   require

  Path            require > uglify-js

  More info       https://npmjs.com/advisories/39

  Low             Regular Expression Denial of Service

  Package         uglify-js

  Patched in      >=2.6.0

  Dependency of   require

  Path            require > uglify-js

  More info       https://npmjs.com/advisories/48

  High            Regular Expression Denial of Service

  Package         minimatch

  Patched in      >=3.0.2

  Dependency of   totp

  Path            totp > phpjs > glob > minimatch

  More info       https://npmjs.com/advisories/118

  High            Regular Expression Denial of Service

  Package         minimatch

  Patched in      >=3.0.2

  Dependency of   totp

  Path            totp > phpjs > mocha > glob > minimatch

  More info       https://npmjs.com/advisories/118

  Critical        Command Injection

  Package         growl

  Patched in      >=1.10.2

  Dependency of   totp

  Path            totp > phpjs > mocha > growl

  More info       https://npmjs.com/advisories/146

  Moderate        Remote Memory Exposure

  Package         request

  Patched in      >=2.68.0

  Dependency of   steam-community [dev]

  Path            steam-community > request

  More info       https://npmjs.com/advisories/309

  High            Regular Expression Denial of Service

  Package         fresh

  Patched in      >= 0.5.2

  Dependency of   totp

  Path            totp > phpjs > send > fresh

  More info       https://npmjs.com/advisories/526

  Moderate        Regular Expression Denial of Service

  Package         mime

  Patched in      >= 1.4.1 < 2.0.0 || >= 2.0.3

  Dependency of   totp

  Path            totp > phpjs > send > mime

  More info       https://npmjs.com/advisories/535

found 10 vulnerabilities (4 low, 2 moderate, 3 high, 1 critical) in 597 scanned packages
  10 vulnerabilities require manual review. See the full report for details.