Advertisement
Guest User

test

a guest
Mar 25th, 2017
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const request = require('request');
  2. const net = require('net');
  3. const colors = require('colors/safe');
  4. const XMLParser = require('./util/helpers/xml-parser');
  5.  
  6. class Client {
  7.     constructor(username, password) {
  8.         this.username = username;
  9.         this.password = password;
  10.         this.user_initialized = false;
  11.         this.token = null;
  12.         this.id = null;
  13.         this.socket = null;
  14.         this.buffer = '';
  15.         this.victim = '';
  16.         this.lastCell = '';
  17.     }
  18.  
  19.     login() {
  20.         request.post('http://game.aqworlds.com/game/cf-userlogin.asp', {form: {unm: this.username, pwd: this.password}}, (err, res, body) => {
  21.             let LOGIN_RES = XMLParser(body).login.$;
  22.             this.token = LOGIN_RES.sToken;
  23.             this.id = LOGIN_RES.userid;
  24.             console.log("Successful login.");
  25.             this.connect();
  26.         });
  27.     }
  28.  
  29.     connect() {
  30.         console.log("Connecting");
  31.         //TestingServer2
  32.         this.socket = net.connect(5588, '75.126.77.29');
  33.  
  34.         this.socket.on('connect', () => {
  35.             console.log('Connected');
  36.             this.send('Login', ['N7B5W8W1Y5B1R5VWVZ', this.username, this.token]);
  37.         });
  38.         this.socket.on('data', (data) => {
  39.             this.handleData(data);
  40.         });
  41.         this.socket.on('end', () => {
  42.             console.log('disconnected from server');
  43.         });
  44.     }
  45.  
  46.     send(cmd, params) {
  47.         let parameters = params || [];
  48.         let packet = JSON.stringify({ Cmd: cmd, Params: parameters });
  49.         console.log("Sent: " + packet);
  50.         this.socket.write(packet + '\x00');
  51.         this.buffer = '';
  52.     }
  53.  
  54.     handleData( data ){
  55.         this.buffer += data;
  56.  
  57.         if (this.buffer[this.buffer.length - 1] !== '\x00') return;
  58.         let packets = this.buffer.split('\x00');
  59.         for (let i in packets) {
  60.             if (packets[i] === '') continue;
  61.             this.handlePacket(packets[i]);
  62.         }
  63.         this.buffer = '';
  64.     }
  65.  
  66.     handlePacket( data ) {
  67.         let packet = JSON.parse(data);
  68.  
  69.         switch (packet.Cmd) {
  70.             case 'loginResponse':
  71.                 // if(!this.user_initialized){
  72.                     this.send('LoadUser', []);
  73.                     this.user_initialized = true;
  74.                 // }
  75.                 break;
  76.             case 'initPlayer':
  77.                 this.send('getEquip', []);
  78.                 this.send('firstJoin', []);
  79.                 this.send('cmd', ['ignoreList', '$clearAll']);
  80.                 break;
  81.             case 'moveToArea':
  82.                 this.send('moveToCell', ['Enter', 'Spawn']);
  83.                 break;
  84.             case 'chatm':
  85.                 console.log(packet);
  86.                 const command = packet.msg.trim().split(/ (.+)/)[0];
  87.                 const message = packet.msg.trim().split(/ (.+)/)[1];
  88.  
  89.                 switch(command){
  90.                     case "!goto":
  91.                         console.log(message);
  92.                         this.send('cmd', ['goto', message]);
  93.                         break;
  94.                     case "!join":
  95.                         this.send('tfer', [this.username, message,"1","Enter","Spawn"]);
  96.                         break;
  97.                     case "!follow":
  98.                         this.victim = message;
  99.                         break;
  100.                     case "!stopFollow":
  101.                         this.victim = '';
  102.                         break;
  103.                     case "!test":
  104.                         // this.send('gar', ['aa', 'm:1', 'wvz']);
  105.                         setInterval(() => {
  106.                             this.send('LoadUser', []);
  107.                             setInterval(() => {
  108.                                 this.send('LoadUser', []);
  109.                             });
  110.                         });
  111.                         this.send('getDrop', [266]);
  112.                         break;
  113.                     case "!spam":
  114.                         // setInterval(() => {
  115.                         //     this.send('message', ['Nub', 'zone']);
  116.                         // }, 2000);
  117.  
  118.                         break;
  119.                 }
  120.                 break;
  121.             case 'uotls':
  122.                 if(this.victim != "" && packet.unm == this.victim){
  123.                     console.log(packet);
  124.                   if( this.lastCell != '' && packet.o.strFrame != this.lastCell){
  125.                       this.send('moveToCell', [packet.o.strFrame, 'Spawn']);
  126.                   }else{
  127.                       this.send('mv', [packet.o.tx, packet.o.ty, packet.o.sp]);
  128.                   }
  129.                     this.lastCell = packet.o.strFrame;
  130.                 }
  131.                 break;
  132.             case 'exitArea':
  133.                 console.log(packet);
  134.                 if(this.victim != "" && packet.unm == this.victim) this.send('cmd', ['goto', 'munk']);
  135.                 break;
  136.             default:
  137.                 console.log(packet);
  138.         }
  139.     }
  140. }
  141.  
  142. let user = new Client('nibas', '798140Sa');
  143. user.login();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement