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