nbot

A clone of the eBot by @deStrO fully based on node.js with build in Web Page - WIP
git clone git://archive.git.mtrnord.blog/MTRNord/nbot.git
Log | Files | Refs | README | LICENSE

rcon.js (3308B)


      1 /**
      2 * Rcon connection to csgo Server
      3 *
      4 * @module nBot
      5 * @submodule rcon
      6 * @requires srcds-rcon
      7 */
      8 var rcon_lib = require('srcds-rcon')({
      9     address: '127.0.0.1',
     10     password: '1199'
     11 });
     12 /**
     13 * @class rcon
     14 * @static
     15 */
     16 var rcon = module.exports = {}
     17   /**
     18   * @method start
     19   * @deprecated Could later make problems at start
     20   */
     21   rcon.start = function () {
     22     rcon_lib.connect().then(() => {
     23         return rcon_lib.command('changelevel de_dust2').then(() => {
     24             console.log('changed map');
     25         });
     26     }).then(
     27         () => rcon_lib.command('sv_lan 0').then(() => console.log('changed sv_lan'))
     28     ).then(
     29         () => rcon_lib.command('mp_restartgame 1').then(() => console.log('restarted game'))
     30     ).then(
     31         () => rcon_lib.disconnect()
     32     ).catch(err => {
     33         console.log('caught', err);
     34         console.log(err.stack);
     35     });
     36   },
     37   /**
     38   * @method restart_game
     39   */
     40   rcon.restart_game = function () {
     41     rcon_lib.connect().then(() => {
     42         return rcon_lib.command('mp_restartgame 1').then(() =>{
     43             console.log('game restarted');
     44         });
     45     }).then(
     46         () => rcon_lib.disconnect()
     47     ).catch(err => {
     48         console.log('caught', err);
     49         console.log(err.stack);
     50     });
     51   },
     52   /**
     53   * @method status
     54   * @return {String} Status from the Server.
     55   */
     56   rcon.status = function () {
     57     return rcon_lib.connect().then(() => {
     58         return rcon_lib.command('status')
     59     }).then(
     60         () => rcon_lib.disconnect()
     61     ).catch(err => {
     62         console.log('caught', err);
     63         console.log(err.stack);
     64     });
     65   },
     66   /**
     67   * @method live_on
     68   */
     69   rcon.live_on = function () {
     70     rcon_lib.connect().then(() => {
     71         return rcon_lib.command('mp_restartgame 1').then(() => {
     72             console.log('game restarted 0');
     73         });
     74     }).then(
     75         () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 1'))
     76     ).then(
     77         () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 2'))
     78     ).then(
     79         () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 3'))
     80     ).then(
     81         () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 4'))
     82     ).then(
     83         () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 5'))
     84     ).then(
     85         () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 6'))
     86     ).then(
     87         () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 7'))
     88     ).then(
     89         () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 8'))
     90     ).then(
     91         () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 9'))
     92     ).then(
     93         () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 10'))
     94     ).then(
     95         () => rcon_lib.command('say LIVE!!!').then(() => console.log('LIVE!!!'))
     96     ).then(
     97         () => rcon_lib.command('say LIVE!!!').then(() => console.log('LIVE!!!'))
     98     ).then(
     99         () => rcon_lib.command('say LIVE!!!').then(() => console.log('LIVE!!!'))
    100     ).then(
    101         () => rcon_lib.disconnect()
    102     ).catch(err => {
    103         console.log('caught', err);
    104         console.log(err.stack);
    105     });
    106   }