Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @todo
- * - Make stuff dynamic
- * - Add more farm spots
- * - Make it pickup specific items
- * - Add a 'stop on level' feature
- * - idk
- * An aqw trainer written in php (unfinished due to lazyness) ;p
- * Based on MINAD's aqw python bot
- * You are free to edit this as long as you do not delete the author's name above
- **/
- set_time_limit(0);
- ob_implicit_flush();
- $username = "enterusername";
- $password = "enterpassword";
- class Client {
- var $uprop;
- var $raw_user;
- var $raw_pass;
- var $socket;
- var $ti;
- var $farm;
- function __construct($username, $password) {
- $this->uprop = new stdClass();
- $this->uprop->logged_in = false;
- $this->raw_user = $username;
- $this->raw_pass = $password;
- $this->ti = 0;
- $this->farm = array();
- $this->farm['newbie'] = array();
- $this->farm['newbie']['targets'] = ['m:2', 'm:3'];
- $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];
- $this->authenticate();
- }
- function connectToServer($ip) {
- /* Create a TCP/IP socket. */
- $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- if ($this->socket === false) {
- echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
- } else {
- echo "OK.\n";
- }
- echo "Attempting to connect to '$ip' on port '5588'...";
- $result = socket_connect($this->socket, $ip, 5588);
- if ($result === false) {
- echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($this->socket)) . "\n";
- } else {
- echo "OK.\n";
- }
- $this->listen();
- socket_set_nonblock($this->socket);
- }
- function send($packet) {
- $packet .= chr(0);
- socket_write($this->socket, $packet, strlen($packet));
- echo "Send packet: " . $packet . "\n";
- }
- function listen() {
- echo "Listening..\n";
- do {
- if (false === ($buf = socket_read($this->socket, 2048))) {
- echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($this->socket)) . "\n";
- break;
- }
- if (!$buf = trim($buf)) {
- continue;
- }
- echo "Recieved: {$buf} \n";
- if (json_decode($buf) == null) {
- if (strpos($buf, "<cross-domain-policy>") !== false) {
- $this->send("<msg t='sys'><body action='verChk' r='0'><ver v='157' /></body></msg>");
- sleep(0.2);
- } else if (strpos($buf, "body action='apiOK'") !== false) {
- $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>");
- sleep(0.4);
- } else if (strpos($buf, "%xt%loginResponse%-1%true%") !== false) {
- $this->send("%xt%zm%firstJoin%1%");
- $this->send('%xt%zm%cmd%1%ignoreList%$clearAll%');
- sleep(0.5);
- $this->send("%xt%zm%moveToCell%{$this->uprop->data->userid}%Enter%Spawn%");
- sleep(1);
- $this->send("%xt%zm%retrieveUserData%{$this->uprop->data->userid}%");
- sleep(1);
- $this->send("%xt%zm%retrieveInventory%{$this->uprop->data->userid}%");
- } else if (strpos($buf, "%xt%server%-1%Character load complete.%") !== false) {
- $this->uprop->aa_count = 0;
- $this->newbieFarm();
- } else if (strpos($buf, "%xt%server%-1%You joined \"newbie-") !== false) {
- $this->newbieFarmArea();
- }
- } else {
- $obj = json_decode($buf);
- $cmd = $obj->b->o->cmd;
- print_r($obj);
- if ($cmd == "ct") {
- $died = [];
- if (isset($obj->b->o->m)) {
- $m = $obj->b->o->m;
- $a = get_object_vars($m);
- foreach($a as $key => $value) {
- if (isset($value)) {
- if ($value->intHP <= 0) {
- if (($this->ti + 1) != count($this->farm[$this->uprop->data->fMap]['targets'])) {
- $this->ti++;
- } else {
- $this->ti = 0;
- }
- }
- }
- }
- } else {
- $this->newbieMobLoop();
- }
- }
- }
- } while (true);
- }
- function gotoMap($name, $roomid, $frame = "Enter", $pad = "Spawn", $farm = false) {
- if (!$farm) {
- $this->uprop->data->cMap = $name;
- } else {
- $this->uprop-data->fMap = $name;
- }
- $this->send("%xt%zm%cmd%1%tfer%{$this->raw_user}%{$name}-{$roomid}%{$frame}%{$pad}%");
- }
- function newbieFarm() {
- $this->gotoMap('newbie', 99311, "Enter", "Spawn", true);
- }
- function newbieFarmArea() {
- foreach($this->farm['newbie']['waypoints'] as $key => $value) {
- $this->send(str_replace("|", $this->uprop->data->userid, $key));
- sleep($value);
- }
- $this->newbieMobLoop();
- }
- function newbieMobLoop() {
- $this->uprop->aa_count++;
- $this->send("%xt%zm%gar%1%{$this->uprop->aa_count}%aa>{$this->farm['newbie']['targets'][$this->ti]}%wvz%");
- }
- function authenticate() {
- $ch = curl_init();
- $uu = urlencode($this->raw_user);
- $pp = urlencode($this->raw_pass);
- curl_setopt($ch, CURLOPT_URL,"http://game.aqworlds.com/game/cf-userlogin.asp?ran=" . rand());
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS,
- "user={$uu}&pass={$pp}&unm={$uu}&pwd={$pp}");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $result = curl_exec($ch);
- echo "{$result}\n";
- $xml = simplexml_load_string($result);
- $success = $xml->attributes()->bSuccess;
- if ($success == 1) {
- $this->uprop->logged_in = true;
- $this->uprop->data = $xml->attributes();
- $this->uprop->server_ip = $this->getAvailableServerFromList($xml->servers);
- $this->connectToServer($this->uprop->server_ip);
- } else {
- $this->uprop->logged_in = false;
- }
- curl_close ($ch);
- }
- function getAvailableServerFromList($list) {
- foreach ($list as $key => $value) {
- 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') {
- return($value->attributes()->sIP[0]);
- }
- }
- }
- }
- $client = new Client($username, $password);
- ?>
Add Comment
Please, Sign In to add comment