daily pastebin goal
27%
SHARE
TWEET

Untitled

a guest Jan 20th, 2017 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var forever = require('forever-monitor');
  2. var mysql = require('mysql');
  3.  
  4. var pool  = mysql.createPool({
  5.     connectionLimit : 10,
  6.     database: 'csgoturbo',
  7.     host: 'localhost',
  8.     user: 'root',
  9.     password: 'weaboogen'
  10. });
  11.  
  12. query('SELECT * FROM `bots`', function(err, row) {
  13.     if((err) || (!row.length)) {
  14.         console.log('Failed request or empty bot table');
  15.         console.log(err);
  16.         return process.exit(0);
  17.     }
  18.     console.log('List of bots:');
  19.     row.forEach(function(itm) {
  20.         console.log('Launching bot# '+itm.id);
  21.         var bot = new (forever.Monitor)('bot.js', {
  22.             args: [itm.id]
  23.         });
  24.         bot.on('start', function(process, data) {
  25.             console.log('Bot with ID '+itm.id+' started');
  26.         });
  27.         bot.on('exit:code', function(code) {
  28.             console.log('Bot stopped with code '+code);
  29.         });
  30.         bot.on('stdout', function(data) {
  31.             console.log(data);
  32.         });
  33.         bot.start();
  34.     });
  35. });
  36.  
  37. function query(sql, callback) {
  38.     if (typeof callback === 'undefined') {
  39.         callback = function() {};
  40.     }
  41.     pool.getConnection(function(err, connection) {
  42.         if(err) return callback(err);
  43.         console.info('Database connection ID: '+connection.threadId);
  44.         connection.query(sql, function(err, rows) {
  45.             if(err) return callback(err);
  46.             connection.release();
  47.             return callback(null, rows);
  48.         });
  49.     });
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top