GOSTRA_FX

AQW PHP Bot

Feb 2nd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.      
  3.     /**
  4.      * @todo
  5.      *              - Make stuff dynamic
  6.      *              - Add more farm spots
  7.      *              - Make it pickup specific items
  8.      *              - Add a 'stop on level' feature
  9.      *              - idk
  10.      * An aqw trainer written in php (unfinished due to lazyness) ;p
  11.      * Based on MINAD's aqw python bot
  12.      * You are free to edit this as long as you do not delete the author's name above
  13.      **/
  14.      
  15.     set_time_limit(0);
  16.      
  17.      
  18.     ob_implicit_flush();
  19.      
  20.     $username = "enterusername";
  21.     $password = "enterpassword";
  22.      
  23.     class Client {
  24.            
  25.             var $uprop;
  26.             var $raw_user;
  27.             var $raw_pass;
  28.             var $socket;
  29.             var $ti;
  30.             var $farm;
  31.            
  32.             function __construct($username, $password) {
  33.                     $this->uprop = new stdClass();
  34.                     $this->uprop->logged_in = false;
  35.                    
  36.                     $this->raw_user = $username;
  37.                     $this->raw_pass = $password;
  38.                    
  39.                     $this->ti = 0;
  40.                    
  41.                     $this->farm = array();
  42.                    
  43.                     $this->farm['newbie'] = array();
  44.                     $this->farm['newbie']['targets'] = ['m:2', 'm:3'];
  45.                     $this->farm['newbie']['waypoints'] = ['%xt%zm%mv%|%548%242%9%' => 2, '%xt%zm%moveToCell%|%r2%Left%' => 0.4, '%xt%zm%mv%|%936%218%9%' => 2, '%xt%zm%moveToCell%|%r3%Left%' => 0.4, '%xt%zm%mv%|%928%414%9%' => 2, '%xt%zm%moveToCell%|%r5%Left%' => 0.4];
  46.                    
  47.                     $this->authenticate();
  48.             }
  49.            
  50.             function connectToServer($ip) {
  51.                     /* Create a TCP/IP socket. */
  52.                     $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  53.                     if ($this->socket === false) {
  54.                             echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
  55.                     } else {
  56.                             echo "OK.\n";
  57.                     }
  58.                    
  59.                     echo "Attempting to connect to '$ip' on port '5588'...";
  60.                     $result = socket_connect($this->socket, $ip, 5588);
  61.                     if ($result === false) {
  62.                             echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($this->socket)) . "\n";
  63.                     } else {
  64.                             echo "OK.\n";
  65.                     }
  66.                    
  67.                    
  68.                     $this->listen();
  69.                    
  70.                     socket_set_nonblock($this->socket);
  71.                    
  72.                    
  73.             }
  74.            
  75.             function send($packet) {
  76.                     $packet .= chr(0);
  77.                     socket_write($this->socket, $packet, strlen($packet));
  78.                     echo "Send packet: " . $packet . "\n";
  79.             }
  80.            
  81.             function listen() {
  82.                     echo "Listening..\n";
  83.                     do {
  84.                             if (false === ($buf = socket_read($this->socket, 2048))) {
  85.                                     echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($this->socket)) . "\n";
  86.                                     break;
  87.                             }
  88.                             if (!$buf = trim($buf)) {
  89.                                     continue;
  90.                             }
  91.                             echo "Recieved: {$buf} \n";
  92.                             if (json_decode($buf) == null) {
  93.                                     if (strpos($buf, "<cross-domain-policy>") !== false) {
  94.                                             $this->send("<msg t='sys'><body action='verChk' r='0'><ver v='157' /></body></msg>");
  95.                                             sleep(0.2);
  96.                                     } else if (strpos($buf, "body action='apiOK'") !== false) {
  97.                                             $this->send("<msg t='sys'><body action='login' r='0'><login z='zone_master'><nick><![CDATA[N7B5W8W1Y5B1R5VWVZ~". strtolower($this->raw_user) ."]]></nick><pword><![CDATA[" . $this->uprop->data->sToken . "]]></pword></login></body></msg>");
  98.                                             sleep(0.4);
  99.                                     } else if (strpos($buf, "%xt%loginResponse%-1%true%") !== false) {
  100.                                             $this->send("%xt%zm%firstJoin%1%");
  101.                                             $this->send('%xt%zm%cmd%1%ignoreList%$clearAll%');
  102.                                             sleep(0.5);
  103.                                             $this->send("%xt%zm%moveToCell%{$this->uprop->data->userid}%Enter%Spawn%");
  104.                                             sleep(1);
  105.                                             $this->send("%xt%zm%retrieveUserData%{$this->uprop->data->userid}%");
  106.                                             sleep(1);
  107.                                             $this->send("%xt%zm%retrieveInventory%{$this->uprop->data->userid}%");
  108.                                     } else if (strpos($buf, "%xt%server%-1%Character load complete.%") !== false) {
  109.                                             $this->uprop->aa_count = 0;
  110.                                             $this->newbieFarm();
  111.                                     } else if (strpos($buf, "%xt%server%-1%You joined \"newbie-") !== false) {
  112.                                             $this->newbieFarmArea();
  113.                                     }
  114.                             } else {
  115.                                     $obj = json_decode($buf);
  116.                                     $cmd = $obj->b->o->cmd;
  117.                                    
  118.                                     print_r($obj);
  119.                                    
  120.                                     if ($cmd == "ct") {
  121.                                             $died = [];
  122.                                             if (isset($obj->b->o->m)) {
  123.                                                     $m = $obj->b->o->m;
  124.                                                     $a = get_object_vars($m);
  125.                                                     foreach($a as $key => $value) {
  126.                                                             if (isset($value)) {
  127.                                                                     if ($value->intHP <= 0) {
  128.                                                                             if (($this->ti + 1) != count($this->farm[$this->uprop->data->fMap]['targets'])) {
  129.                                                                                     $this->ti++;
  130.                                                                             } else {
  131.                                                                                     $this->ti = 0;
  132.                                                                             }
  133.                                                                     }
  134.                                                             }
  135.                                                     }
  136.                                             } else {
  137.                                                     $this->newbieMobLoop();
  138.                                             }
  139.                                     }
  140.                             }
  141.                     } while (true);
  142.             }
  143.            
  144.             function gotoMap($name, $roomid, $frame = "Enter", $pad = "Spawn", $farm = false) {
  145.                     if (!$farm) {
  146.                             $this->uprop->data->cMap = $name;
  147.                     } else {
  148.                             $this->uprop-data->fMap = $name;
  149.                     }
  150.                     $this->send("%xt%zm%cmd%1%tfer%{$this->raw_user}%{$name}-{$roomid}%{$frame}%{$pad}%");
  151.             }
  152.            
  153.             function newbieFarm() {
  154.                     $this->gotoMap('newbie', 99311, "Enter", "Spawn", true);
  155.             }
  156.            
  157.             function newbieFarmArea() {
  158.                     foreach($this->farm['newbie']['waypoints'] as $key => $value) {
  159.                             $this->send(str_replace("|", $this->uprop->data->userid, $key));
  160.                             sleep($value);
  161.                     }
  162.                     $this->newbieMobLoop();
  163.             }
  164.            
  165.             function newbieMobLoop() {
  166.                     $this->uprop->aa_count++;
  167.                     $this->send("%xt%zm%gar%1%{$this->uprop->aa_count}%aa>{$this->farm['newbie']['targets'][$this->ti]}%wvz%");
  168.             }
  169.            
  170.             function authenticate() {
  171.                     $ch = curl_init();
  172.            
  173.                     $uu = urlencode($this->raw_user);
  174.                     $pp = urlencode($this->raw_pass);
  175.      
  176.                     curl_setopt($ch, CURLOPT_URL,"http://game.aqworlds.com/game/cf-userlogin.asp?ran=" . rand());
  177.                     curl_setopt($ch, CURLOPT_POST, 1);
  178.                     curl_setopt($ch, CURLOPT_POSTFIELDS,
  179.                                             "user={$uu}&pass={$pp}&unm={$uu}&pwd={$pp}");
  180.      
  181.                     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  182.      
  183.                     $result = curl_exec($ch);
  184.                    
  185.                     echo "{$result}\n";
  186.                    
  187.                     $xml = simplexml_load_string($result);
  188.                    
  189.                    
  190.                     $success = $xml->attributes()->bSuccess;
  191.                    
  192.                     if ($success == 1) {
  193.                             $this->uprop->logged_in = true;
  194.                             $this->uprop->data = $xml->attributes();
  195.                             $this->uprop->server_ip = $this->getAvailableServerFromList($xml->servers);
  196.                             $this->connectToServer($this->uprop->server_ip);
  197.                     } else {
  198.                             $this->uprop->logged_in = false;
  199.                     }
  200.      
  201.                     curl_close ($ch);
  202.             }
  203.            
  204.             function getAvailableServerFromList($list) {
  205.                     foreach ($list as $key => $value) {
  206.                             if ((int)$value->attributes()->iCount[0] < (int)$value->attributes()->iMax[0] AND (int)$value->attributes()->bOnline[0] == 1 AND (int)$value->attributes()->bUpg[0] == 0 AND (string)$value->attributes()->sLang == 'ph') {
  207.                                     return($value->attributes()->sIP[0]);
  208.                             }
  209.                     }
  210.             }
  211.     }
  212.      
  213.     $client = new Client($username, $password);
  214.      
  215.      
  216.      
  217.     ?>
Add Comment
Please, Sign In to add comment