Exemplo n.º 1
0
function build($village, $result)
{
    global $server;
    // Get a build task
    $sql = "select `seq`, `id` from `build` where `village` = {$village} order by `seq` limit 1";
    $res = mysql_query($sql);
    if (!$res) {
        die(mysql_error());
    }
    $row = mysql_fetch_row($res);
    if (!$row) {
        echo "No build task more. Try to auto build.\n";
        $id = get_auto_build_resource_field_id($result);
        $seq = -1;
    } else {
        $seq = $row[0];
        $id = $row[1];
    }
    $referer = "http://{$server}/dorf" . ($id <= 18 ? "1" : "2") . ".php";
    $url = "http://{$server}/build.php?id={$id}";
    echo $url . "\n";
    $ch = my_curl_init();
    curl_setopt($ch, CURLOPT_REFERER, $referer);
    curl_setopt($ch, CURLOPT_URL, $url);
    $result = curl_exec($ch);
    curl_close($ch);
    // <a href="dorf2.php?a=28&c=23d">
    $ret = preg_match('/<a href="(dorf[12]\\.php\\?a=[0-9]+&c=[0-9a-z]+)">/', $result, $matches);
    if (!$ret) {
        echo "Busy or lacking resources or failed.\n";
        return;
    }
    $url2 = "http://{$server}/" . $matches[1];
    echo $url2 . "\n";
    if ($seq >= 0) {
        // Update the target
        $sql = "delete from `build` where `seq` = {$seq}";
        if (!mysql_query($sql)) {
            die(mysql_error());
        }
    }
    $ch = my_curl_init();
    curl_setopt($ch, CURLOPT_URL, $url2);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    $result = curl_exec($ch);
    curl_close($ch);
    //echo $result;
}
Exemplo n.º 2
0
function build($village, $result, $newbie = 0)
{
    global $server;
    global $account;
    global $race;
    // ^<div class="f10 b">.+<span id=timer1>
    // <span id="timer1">1:51:21</span>
    if (preg_match('/<td><span id="timer1">[0-9]+:[0-9]+:[0-9]+<\\/span>/', $result, $matches)) {
        if ($race == "roman") {
            if (preg_match('/<td><span id="timer2">[0-9]+:[0-9]+:[0-9]+<\\/span>/', $result, $matches)) {
                echo "Building timer2 (roman) found.\n";
                return;
            }
        } else {
            echo "Building timer1 found.\n";
            return;
        }
    }
    $orginal_result = $result;
    // Get a build task
    $sql = "select `seq`, `id`, `gid` from `build` where account = {$account} and `village` = {$village} order by `seq` limit 1";
    $res = mysql_query($sql);
    if (!$res) {
        die(mysql_error());
    }
    $row = mysql_fetch_row($res);
    if (!$row) {
        echo "No build task more. Try to auto build.\n";
        list(, , , $crop_production) = get_production($result);
        if ($crop_production < 5) {
            echo "Low crop...\n";
            build_on_low_crop($result);
            return;
        }
        $id = get_auto_build_resource_field_id($result);
        if (!$id) {
            return;
        }
        $seq = -1;
        $gid = 0;
    } else {
        $seq = $row[0];
        $id = $row[1];
        $gid = $row[2];
    }
    $referer = "http://{$server}/dorf" . ($id <= 18 ? "1" : "2") . ".php";
    $url = "http://{$server}/build.php?id={$id}";
    echo $url . "\n";
    $ch = my_curl_init();
    curl_setopt($ch, CURLOPT_REFERER, $referer);
    curl_setopt($ch, CURLOPT_URL, $url);
    $result = curl_exec($ch);
    curl_close($ch);
    // <a href="dorf2.php?a=28&c=23d">
    $ret = preg_match('/href="(dorf[12]\\.php\\?a=[0-9]+&amp;c=[0-9a-z]+)">/', $result, $matches);
    if (!$ret) {
        // relay point
        // dorf2.php?a=16&id=39&c=2e0
        if ($id == 39) {
            $gid = 16;
        }
        // wall
        // dorf2.php?a=31&id=40&c=061
        if ($id == 40) {
            $ret = preg_match('/href="(dorf2\\.php\\?a=[0-9]+&amp;id=' . $id . '&amp;c=[0-9a-z]+)">/', $result, $matches);
        } else {
            if ($gid > 0) {
                // <a href="dorf2.php?a=23&id=33&c=0c6">
                $ret = preg_match('/href="(dorf[12]\\.php\\?a=' . $gid . '&amp;id=' . $id . '&amp;c=[0-9a-z]+)">/', $result, $matches);
            }
        }
    }
    if (!$ret) {
        echo "Busy or lacking resources or failed.\n";
        // roman
        if ($race == "roman" && $id > 18) {
            $id = get_auto_build_resource_field_id($orginal_result);
            if (!$id) {
                return;
            }
            $seq = -1;
            $referer = "http://{$server}/dorf" . ($id <= 18 ? "1" : "2") . ".php";
            $url = "http://{$server}/build.php?id={$id}";
            echo $url . "\n";
            $ch = my_curl_init();
            curl_setopt($ch, CURLOPT_REFERER, $referer);
            curl_setopt($ch, CURLOPT_URL, $url);
            $result = curl_exec($ch);
            curl_close($ch);
            // <a href="dorf2.php?a=28&c=23d">
            $ret = preg_match('/href="(dorf[12]\\.php\\?a=[0-9]+&amp;c=[0-9a-z]+)">/', $result, $matches);
            if (!$ret) {
                return;
            }
            echo "roman auto building..\n";
        } else {
            return;
        }
    }
    $url2 = "http://{$server}/" . html_entity_decode($matches[1]);
    echo $url2 . "\n";
    if ($seq >= 0) {
        // Update the target
        $sql = "delete from `build` where account = {$account} and `seq` = {$seq}";
        if (!mysql_query($sql)) {
            die(mysql_error());
        }
    }
    $ch = my_curl_init();
    curl_setopt($ch, CURLOPT_URL, $url2);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    $result = curl_exec($ch);
    curl_close($ch);
    update_check_time($result);
    //echo $result;
}