/**
 * 输出amf格式的内容
 * @param $result 需要输出到浏览器的内容
 * @param $exit 是否在输出后结束脚本
 * @return void
 */
function print_amf_result($result, $exit = true)
{
    if ($GLOBALS['amfphp']['native'] === true && function_exists('amf_decode')) {
        $serializer = new AMFBaseSerializer();
        // Create a serailizer around the output stream
    } else {
        $serializer = new AMFSerializer();
        // Create a serailizer around the output stream
    }
    $body = new MessageBody('', '/1');
    $body->responseURI = $body->responseIndex . "/onResult";
    $body->setResults($result);
    $amfObj = new AMFObject();
    $amfObj->addBody($body);
    $data = $serializer->serialize($amfObj);
    header('Content-type: application/x-amf');
    $dateStr = date('D, j M Y H:i:s', time() - 86400);
    header("Expires: {$dateStr} GMT");
    header('Pragma: no-store');
    header('Cache-Control: no-store');
    header('Content-length: ' . strlen($data));
    echo $data;
    if ($exit) {
        exit;
    }
}
function reportExceptions($code, $descr, $filename, $line)
{
    // obey error_level set by system/user
    if (!($code & error_reporting())) {
        return;
    }
    // init a new error info object
    $error = new MessageException($code, $descr, $filename, $line, "AMFPHP_RUNTIME_ERROR");
    // add the error object to the body of the AMFObject
    $amfbody = new MessageBody(NULL, $GLOBALS['amfphp']['lastMethodCall']);
    MessageException::throwException($amfbody, $error);
    //$amfbody->setResults($error);
    if ($GLOBALS['amfphp']['encoding'] == 'amf0' || $GLOBALS['amfphp']['encoding'] == 'amf3') {
        // build a new AMFObject
        $amfout = new AMFObject("");
        $amfout->addBody($amfbody);
        // Add the trace headers we have so far while we're at it
        debugFilter($amfout);
        // create a new serializer
        $serializer = new AMFSerializer();
        // serialize the data
        $data = $serializer->serialize($amfout);
        // send the correct header
        header('Content-type: application/x-amf');
        // flush the amf data to the client.
        print $data;
        // kill the system after we find a single error
        exit;
    } else {
        serializationAction($amfbody);
        print $amfbody->getResults();
        exit;
    }
}
Пример #3
0
function rpc($reqs, $progress = true)
{
    global $ua, $ch, $swfurl, $cookies, $rpcseq, $rpcmax;
    global $debugout;
    $offset = 0;
    $resps = array();
    while (true) {
        $n = min(count($reqs) - $offset, $rpcmax);
        if ($n == 0) {
            break;
        }
        $req = array(gen_header(), array_slice($reqs, $offset, $n), 0);
        $offset += $n;
        ++$rpcseq;
        $body = new MessageBody();
        $body->setResponseURI("BaseService.dispatchBatch");
        $body->setResponseTarget("/{$rpcseq}");
        $body->setResults($req);
        $amf = new AMFObject();
        $amf->addBody($body);
        $serializer = new AMFSerializer();
        $postdata = $serializer->serialize($amf);
        if ($debugout) {
            file_put_contents("out/{$rpcseq}.req", $postdata);
        }
        curl_setopt_array($ch, array(CURLOPT_POST => true, CURLOPT_BINARYTRANSFER => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => $ua, CURLOPT_REFERER => $swfurl, CURLOPT_COOKIE => $cookies, CURLOPT_POSTFIELDS => $postdata));
        $out = curl_exec($ch);
        if ($debugout) {
            file_put_contents("out/{$rpcseq}.resp", $out);
        }
        if ($progress) {
            print ".";
        }
        $amf = new AMFObject($out);
        $deserializer = new AMFDeserializer($amf->rawData);
        // deserialize the data
        $deserializer->deserialize($amf);
        // run the deserializer
        $v = $amf->getBodyAt(0)->getValue();
        if ($v['errorType'] != 0) {
            die($v['errorData'] . "\n");
        }
        $resps = array_merge($resps, $v['data']);
    }
    return $resps;
}
Пример #4
0
function reportExceptions($code, $descr, $filename, $line)
{
    // obey error_level set by system/user
    if (!($code & error_reporting())) {
        return;
    }
    // build a new AMFObject
    $amfout = new AMFObject("");
    // init a new error info object
    $error = array();
    // pass the code
    $error["code"] = "AMFPHP_RUNTIME_ERROR";
    // pass the description
    $error["description"] = $descr;
    // pass the details
    $error["details"] = $filename;
    // pass the level
    $error["level"] = AMFException::getFriendlyError($code);
    // pass the line number
    $error["line"] = $line;
    // add the error object to the body of the AMFObject
    $amfbody = new AMFBody(NULL, $GLOBALS['amfphp']['lastMethodCall']);
    $amfbody->setResults($error);
    $amfout->addBody($amfbody);
    // Add the trace headers we have so far while we're at it
    debugFilter($amfout);
    // create a new serializer
    $serializer = new AMFSerializer();
    // serialize the data
    $data = $serializer->serialize($amfout);
    // send the correct header
    header('Content-type: application/x-amf');
    // flush the amf data to the client.
    print $data;
    // kill the system after we find a single error
    exit;
}
Пример #5
0
/**
 * Serializes the object
 */
function serializationFilter(&$amf)
{
    if ($GLOBALS['amfphp']['native'] === true && function_exists('amf_decode')) {
        $serializer = new AMFBaseSerializer();
        // Create a serializer around the output stream
    } else {
        $serializer = new AMFSerializer();
        // Create a serializer around the output stream
    }
    $result = $serializer->serialize($amf);
    // serialize the data
    $amf->outputStream = $result;
}
Пример #6
0
 private function _fvAMFSend($amf)
 {
     $serializer = new AMFSerializer();
     $result3 = $serializer->serialize($amf);
     // serialize the data
     $answer = Request('', $result3);
     $amf2 = new AMFObject($answer);
     $deserializer2 = new AMFDeserializer($amf2->rawData);
     // deserialize the data
     $deserializer2->deserialize($amf2);
     // run the deserializer
     $doinit = 0;
     if (!isset($amf2->_bodys[0]->_value['data'][0])) {
         DoInit();
         return false;
     }
     Check4Rewards($amf2);
     foreach (@$amf2->_bodys[0]->_value['data'] as $key => $returned) {
         $resp = $returned['errorType'];
         $err = $returned['errorData'];
         if ($resp == 28 || $resp == 29) {
             if (strpos($err, 'MC::lock()') !== false) {
                 //Ignore Quietly Now, even if Debug is on
                 $iguser = load_array('ignores.txt');
                 preg_match('/rts_USER_(.*)_lock/', $err, $matches);
                 $iguser[floatval($matches[1])] = floatval($matches[1]);
                 save_array($iguser, 'ignores.txt');
             } else {
                 if ($this->settings['debug'] == 1 && $err != 'Remaining function') {
                     AddLog2('fvManager Error: ' . $resp . ' - ' . $err);
                 }
             }
             unset($amf2->_bodys[0]->_value['data'][$key]);
             if ($doinit == 0) {
                 DoInit();
             }
             $doinit = 1;
             if ($key == 0) {
                 return false;
             }
         }
     }
     return $amf2;
 }
Пример #7
0
function RequestAMF2($amf)
{
    $serializer = new AMFSerializer();
    $result = $serializer->serialize($amf);
    // serialize the data
    $answer = Request('', $result);
    $amf2 = new AMFObject($answer);
    $deserializer2 = new AMFDeserializer($amf2->rawData);
    // deserialize the data
    $deserializer2->deserialize($amf2);
    // run the deserializer
    Check4Rewards($amf2);
    // Check if there was a error
    // Check if there was data[0] and or data[1]
    $errorfound = 'N';
    $errorType = '';
    $errorData = '';
    if (@$amf2->_bodys[0]->_value['errorType'] != 0) {
        $errorfound = 'Y';
        $errorType = $amf2->_bodys[0]->_value['errorType'];
        $errorData = $amf2->_bodys[0]->_value['errorData'];
    }
    if (isset($amf2->_bodys[0]->_value['data'][0])) {
        if (@$amf2->_bodys[0]->_value['data'][0]['errorType'] != 0) {
            $errorfound = 'Y';
            $errorType = $amf2->_bodys[0]->_value['data'][0]['errorType'];
            $errorData = $amf2->_bodys[0]->_value['data'][0]['errorData'];
        }
    }
    if (isset($amf2->_bodys[0]->_value['data'][1])) {
        if (@$amf2->_bodys[0]->_value['data'][1]['errorType'] != 0) {
            $errorfound = 'Y';
            $errorType = $amf2->_bodys[0]->_value['data'][1]['errorType'];
            $errorData = $amf2->_bodys[0]->_value['data'][1]['errorData'];
        }
    }
    if ($errorfound == 'Y') {
        if ($errorData == "There is a new version of the farm game released") {
            AddLog2('FV UPDATE: New Version of FV Released');
            AddLog2('Work Will Restart in 15 Seconds');
            unlink('unit_check.txt');
            RestartBot();
        } else {
            if ($errorData == "token value failed") {
                AddLog2('FV FUBAR: Game Opened in Another Browser');
                AddLog2('Work Will Restart in 15 Seconds');
                RestartBot();
            } else {
                if ($errorData == "token too old") {
                    AddLog2('FV FUBAR: Your Session Has Expired');
                    AddLog2('Work Will Restart in 15 Seconds');
                    RestartBot();
                } else {
                    if ($errorType == 29) {
                        AddLog2('FV FUBAR: Server Sequence Was Reset');
                        DoInit();
                    } else {
                        $res = "Error: " . $errorType . " " . $errorData;
                        DoInit();
                    }
                }
            }
        }
    } else {
        if (!isset($amf2->_bodys[0]->_value['data'][0])) {
            echo "\n*****\nError:\n BAD AMF REPLY - Possible Server problem or farm badly out of sync\n*****\n";
            $res = "BAD AMF REPLY (OOS?)";
        } else {
            if ($errorType == '' && $errorData == '') {
                $res = 'OK';
            } else {
                $res = 'Unknown';
            }
        }
    }
    //if (isset($amf2->_bodys[0]->_value['data'][0])) {
    //$res = $errorType . " " . $errorData;
    //}
    //}
    return $res;
}
Пример #8
0
 /**
  * Wraps a string into an error AMF message
  * @param $data the original AMF data (needed to get the response index
  * @param $error The error to send back
  * @returns String containing the AMF data
  */
 function sendError($data, $error)
 {
     //Get the last response index, otherwise the error will not register
     //In the NetConnection debugger
     $amf = new AMFObject($data);
     // create the amf object
     $deserializer = new AMFDeserializer($data);
     $deserializer->deserialize($amf);
     $lastBody =& $amf->getBodyAt($amf->numBody() - 1);
     $lastIndex = $lastBody->responseIndex;
     // add the error object to the body of the AMFObject
     $amfout = new AMFObject(NULL);
     $amfbody = new AMFBody($lastIndex . "/onStatus", $lastIndex);
     //Get line number
     preg_match("/in ([A-Za-z0-9\\/\\.\\:]+) on line ([0-9]+)/", str_replace('\\', '/', $error), $matches);
     $file = $matches[1];
     $line = $matches[2];
     $level = substr($error, 0, strpos($error, ': '));
     $amfbody->setResults(array('description' => $error, 'line' => $line, 'file' => $file, 'level' => $level, 'code' => 'AMFPHP_DEBUG_ERROR'));
     $amfout->addBody($amfbody);
     // create a new serializer
     $serializer = new AMFSerializer();
     // serialize the data
     $result = $serializer->serialize($amfout);
     return $result;
 }
Пример #9
0
function RequestAMFIntern($amf)
{
    $serializer = new AMFSerializer();
    $result = $serializer->serialize($amf);
    // serialize the data
    $answer = Request('', $result);
    $amf2 = new AMFObject($answer);
    $deserializer2 = new AMFDeserializer($amf2->rawData);
    // deserialize the data
    $deserializer2->deserialize($amf2);
    // run the deserializer
    return $amf2;
}
Пример #10
0
 private function _fvAMFSend($amf)
 {
     $serializer = new AMFSerializer();
     $result3 = $serializer->serialize($amf);
     // serialize the data
     $answer = Request('', $result3);
     $amf2 = new AMFObject($answer);
     $deserializer2 = new AMFDeserializer($amf2->rawData);
     // deserialize the data
     $deserializer2->deserialize($amf2);
     // run the deserializer
     $doinit = 0;
     if (!isset($amf2->_bodys[0]->_value['data'][0])) {
         DoInit();
         return false;
     }
     Check4Rewards($amf2);
     foreach (@$amf2->_bodys[0]->_value['data'] as $key => $returned) {
         $resp = $returned['errorType'];
         $err = $returned['errorData'];
         if ($resp == 28 || $resp == 29) {
             if ($err != 'Remaining function') {
                 AddLog2('fvFarmer Error: ' . $resp . ' - ' . $err);
             }
             unset($amf2->_bodys[0]->_value['data'][$key]);
             if ($doinit == 0) {
                 DoInit();
             }
             $doinit = 1;
             if ($key == 0) {
                 return false;
             }
         }
     }
     return $amf2;
 }
Пример #11
0
 private function _fvAMFSend($amf)
 {
     $serializer = new AMFSerializer();
     $result3 = $serializer->serialize($amf);
     // serialize the data
     $answer = Request('', $result3);
     $amf2 = new AMFObject($answer);
     $deserializer2 = new AMFDeserializer($amf2->rawData);
     // deserialize the data
     $deserializer2->deserialize($amf2);
     // run the deserializer
     if (!isset($amf2->_bodys[0]->_value['data'][0])) {
         DoInit();
         return false;
     }
     Check4Rewards($amf2);
     foreach (@$amf2->_bodys[0]->_value['data'] as $key => $returned) {
         $resp = $returned['errorType'];
         $err = $returned['errorData'];
         if ($resp == 28 || $resp == 29) {
             $this->reload = true;
         }
     }
     return $amf2;
 }
Пример #12
0
/**
 * Serializes the object
 */
function serializationFilter(&$amf)
{
    $serializer = new AMFSerializer();
    // Create a serailizer around the output stream
    $result = $serializer->serialize($amf);
    // serialize the data
    $amf->outputStream = $result;
}
Пример #13
0
function TB_sendRequest($amf)
{
    //start parser
    $serializer = new AMFSerializer();
    $result = $serializer->serialize($amf);
    // serialize the data
    $answer = Request('', $result);
    $amf2 = new AMFObject($answer);
    $deserializer2 = new AMFDeserializer($amf2->rawData);
    // deserialize the data
    $deserializer2->deserialize($amf2);
    // run the deserializer
    if (@$amf2->_bodys[0]->_value['errorType'] != 0) {
        if ($amf2->_bodys[0]->_value['errorData'] == "There is a new version of the farm game released") {
            AddLog2("New version of the game released");
            echo "\n*****\nGame version out of date\n*****\n";
            echo "\n Restarting Bot in 15 seconds. \n";
            sleep(15);
            touch('need_restart.txt');
            //creating this file will cause the game to restart
        } else {
            if ($amf2->_bodys[0]->_value['errorData'] == "token value failed") {
                AddLog2("Error: token value failed");
                AddLog2("You opened the game in another browser");
                AddLog2("Restart the game or wait for forced restart");
                echo "\n*****\nError: token value failed\nThis error is caused by opening the game in another browser\nRestart the bot or wait 15 seconds for forced restart.\n*****\n";
                sleep(15);
                touch('need_restart.txt');
            } else {
                if ($amf2->_bodys[0]->_value['errorData'] == "token too old") {
                    AddLog2("Error: token too old");
                    AddLog2("The session expired");
                    AddLog2("Restart the game or wait for forced restart");
                    echo "\n*****\nError: token too old\nThe session has expired\nRestart the bot or wait 15 seconds for forced restart.\n*****\n";
                    sleep(15);
                    touch('need_restart.txt');
                    //creating this file will cause the game to restart
                } else {
                    echo "\n*****\nError: \n" . $amf2->_bodys[0]->_value['errorType'] . " " . $amf2->_bodys[0]->_value['errorData'] . "\n";
                    $res = "Error: " . $amf2->_bodys[0]->_value['errorType'] . " " . $amf2->_bodys[0]->_value['errorData'];
                }
            }
        }
    } else {
        if (!isset($amf2->_bodys[0]->_value['data'][0])) {
            echo "\n*****\nError:\n BAD AMF REPLY - Possible Server problem or farm badly out of sync\n*****\n";
            $res = "BAD AMF REPLY (OOS?)";
        } else {
            if (isset($amf2->_bodys[0]->_value['data'][0]['errorType']) && $amf2->_bodys[0]->_value['data'][0]['errorType'] == 0) {
                $res = 'OK';
            } else {
                if (isset($amf2->_bodys[0]->_value['data'][0])) {
                    $res = $amf2->_bodys[0]->_value['data'][0]['errorType'] . " " . $amf2->_bodys[0]->_value['data'][0]['errorData'];
                }
            }
        }
    }
    //end parser
    $return['amf2'] = $amf2;
    $return['res'] = $res;
    return $return;
}