Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const request = require('request');
- const net = require('net');
- const colors = require('colors/safe');
- const XMLParser = require('./util/helpers/xml-parser');
- class Client {
- constructor(username, password) {
- this.username = username;
- this.password = password;
- this.user_initialized = false;
- this.token = null;
- this.id = null;
- this.socket = null;
- this.buffer = '';
- this.victim = '';
- this.lastCell = '';
- }
- login() {
- request.post('http://game.aqworlds.com/game/cf-userlogin.asp', {form: {unm: this.username, pwd: this.password}}, (err, res, body) => {
- let LOGIN_RES = XMLParser(body).login.$;
- this.token = LOGIN_RES.sToken;
- this.id = LOGIN_RES.userid;
- console.log("Successful login.");
- this.connect();
- });
- }
- connect() {
- console.log("Connecting");
- //TestingServer2
- this.socket = net.connect(5588, '75.126.77.29');
- this.socket.on('connect', () => {
- console.log('Connected');
- this.send('Login', ['N7B5W8W1Y5B1R5VWVZ', this.username, this.token]);
- });
- this.socket.on('data', (data) => {
- this.handleData(data);
- });
- this.socket.on('end', () => {
- console.log('disconnected from server');
- });
- }
- send(cmd, params) {
- let parameters = params || [];
- let packet = JSON.stringify({ Cmd: cmd, Params: parameters });
- console.log("Sent: " + packet);
- this.socket.write(packet + '\x00');
- this.buffer = '';
- }
- handleData( data ){
- this.buffer += data;
- if (this.buffer[this.buffer.length - 1] !== '\x00') return;
- let packets = this.buffer.split('\x00');
- for (let i in packets) {
- if (packets[i] === '') continue;
- this.handlePacket(packets[i]);
- }
- this.buffer = '';
- }
- handlePacket( data ) {
- let packet = JSON.parse(data);
- switch (packet.Cmd) {
- case 'loginResponse':
- // if(!this.user_initialized){
- this.send('LoadUser', []);
- this.user_initialized = true;
- // }
- break;
- case 'initPlayer':
- this.send('getEquip', []);
- this.send('firstJoin', []);
- this.send('cmd', ['ignoreList', '$clearAll']);
- break;
- case 'moveToArea':
- this.send('moveToCell', ['Enter', 'Spawn']);
- break;
- case 'chatm':
- console.log(packet);
- const command = packet.msg.trim().split(/ (.+)/)[0];
- const message = packet.msg.trim().split(/ (.+)/)[1];
- switch(command){
- case "!goto":
- console.log(message);
- this.send('cmd', ['goto', message]);
- break;
- case "!join":
- this.send('tfer', [this.username, message,"1","Enter","Spawn"]);
- break;
- case "!follow":
- this.victim = message;
- break;
- case "!stopFollow":
- this.victim = '';
- break;
- case "!test":
- // this.send('gar', ['aa', 'm:1', 'wvz']);
- setInterval(() => {
- this.send('LoadUser', []);
- setInterval(() => {
- this.send('LoadUser', []);
- });
- });
- this.send('getDrop', [266]);
- break;
- case "!spam":
- // setInterval(() => {
- // this.send('message', ['Nub', 'zone']);
- // }, 2000);
- break;
- }
- break;
- case 'uotls':
- if(this.victim != "" && packet.unm == this.victim){
- console.log(packet);
- if( this.lastCell != '' && packet.o.strFrame != this.lastCell){
- this.send('moveToCell', [packet.o.strFrame, 'Spawn']);
- }else{
- this.send('mv', [packet.o.tx, packet.o.ty, packet.o.sp]);
- }
- this.lastCell = packet.o.strFrame;
- }
- break;
- case 'exitArea':
- console.log(packet);
- if(this.victim != "" && packet.unm == this.victim) this.send('cmd', ['goto', 'munk']);
- break;
- default:
- console.log(packet);
- }
- }
- }
- let user = new Client('nibas', '798140Sa');
- user.login();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement