function start_party($account, $village) { global $server; $url = "http://{$server}/build.php?gid=24"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); if (preg_match('#<span id=timer1>([0-9]+):([0-9]+):([0-9]+)</span>#', $result, $match)) { $hour = $match[1]; $minute = $match[2]; $second = $match[3]; $due_time = time() + $hour * 3600 + $minute * 60 + $second; $sql = "update villages set party_due_time = {$due_time} where account = {$account} and id = {$village}"; if (!mysql_query($sql)) { die(mysql_error()); } echo $sql . "\n"; echo "Party due time {$hour}:{$minute}:{$second} ...\n"; } else { if (preg_match('#<a href="build.php\\?id=([0-9]+)&a=1">[^<]+</a>#', $result, $match)) { $id = $match[1]; $referer = $url; $url = "http://{$server}/build.php?id={$id}&a=1"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); echo "Party ...\n"; } } }
function being_attacked() { global $server; // <td><b class="c5 f10" align="right">» 1</b></td> // <td><b class="c5 f10">攻擊</b></td> // <td align="center" class="f10">在</td> // <td class="f10"><span id=timer2>0:27:23</span> 小時</td> $url = "http://{$server}/dorf1.php"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); $pos = strpos($result, '<td><b class="c5 f10" align="right">»'); if ($pos === false) { return false; } echo "************ Being ATTACKED !!! ************\n"; $ret = preg_match('/<td class="f10"><span id=timer[0-9]>([0-9]+):[0-9]+:[0-9]+<\\/span>/', $result, $matches, 0, $pos); if ($ret) { echo intval($matches[1]) . " hours remain. \n"; if (intval($matches[1]) <= 1) { return true; } } return false; }
function get_a2b_page() { global $server; // get a2b page $url = "http://{$server}/build.php?gid=16"; echo $url . "\n"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); return $result; }
function get_map($basic_x, $basic_y, $my_villages) { global $server; $url = "http://{$server}/karte.php"; // 21x21 35x35 49x49 63x63 77x77 91x91 define("RANGE", 49); $range = (RANGE - 7) / 2; for ($x = $basic_x - $range; $x <= $basic_x + $range; $x = $x + 7) { for ($y = $basic_y - $range; $y <= $basic_y + $range; $y = $y + 7) { // xp=-124&yp=-54&s1.x=&s1.y=&s1=ok $postfields = "xp={$x}&yp={$y}&s1.x=&s1.y=&s1=ok"; echo $postfields . "\n"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_REFERER, $url); $result = curl_exec($ch); curl_close($ch); parse($result, $my_villages); } } }
} $account = $_GET['a']; require_once "common.php"; require_once "db.php"; $sql = "select server, user, password, race, main_village, last_report from accounts where id = {$account}"; $res = mysql_query($sql); if (!$res) { die(mysql_error()); } $row = mysql_fetch_row($res); if (!$row) { die("Account not found. {$account} \n"); } $server = $row[0]; $url = "http://{$server}/dorf1.php"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); $all_id = parse_html($result); $db_all = array(); $sql = "select id from villages where account = {$account}"; $res = mysql_query($sql); if (!$res) { die(mysql_error()); } while ($row = mysql_fetch_row($res)) { $id = $row[0]; array_push($db_all, $id); } foreach ($all_id as $id => $val) {
<?php require_once 'common.php'; $url = "http://{$server}/a2b.php"; $ch = my_curl_init(true); echo $argv[1] . "\n"; echo $argv[2] . "\n"; usleep($argv[2]); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $argv[1]); curl_setopt($ch, CURLOPT_REFERER, $url); $result = curl_exec($ch); curl_close($ch);
function attack_func($target_x, $target_y, $t1, $t3, $t6, $t7, $t8, $t11, $result, $target_player = "") { global $server; $url = "http://{$server}/a2b.php"; assert($t1 > 0 || $t1 == ''); assert($t3 > 0 || $t3 == ''); assert($t6 > 0 || $t6 == ''); assert($t7 > 0 || $t7 == ''); assert($t8 > 0 || $t8 == ''); assert($t11 == 1 || $t11 == ''); $hero_post_str = ''; // onClick="document.snd.t11.value=1; return false;" if (preg_match('/on[cC]lick="document\\.snd\\.t11\\.value=1; return false;/', $result, $matches)) { // echo "Hero in home.\n"; if ($t11 == '') { $hero_post_str = '&t11='; } else { $hero_post_str = '&t11=1'; } } // <input type="hidden" name="timestamp" value="1252545240" /> $ret = preg_match('/<input type="hidden" name="timestamp" value="([0-9]+)"/', $result, $matches); if (!$ret) { die("get timestamp failed."); } $timestamp = $matches[1]; // <input type="hidden" name="timestamp_checksum" value="c831c6" /> $ret = preg_match('/<input type="hidden" name="timestamp_checksum" value="([a-z0-9]+)"/', $result, $matches); if (!$ret) { die("get timestamp_checksum failed."); } $timestamp_checksum = $matches[1]; // Post it // b=1&t1=1&t4=&t7=&t9=&t2=&t5=&t8=&t10=&t3=&t6=&c=3&dname=&x=-69&y=-2&s1.x=&s1.y=&s1=ok // b=1&t1=50&t4=&t7=&t9=&t2=&t5=&t8=&t10=&t3=&t6=&t11=1&c=3&dname=&x=-122&y=-45&s1.x=&s1.y=&s1=ok $postfields = 'timestamp=' . $timestamp . '×tamp_checksum=' . $timestamp_checksum . '&b=1&t1=' . $t1 . '&t4=&t7=' . $t7 . '&t9=&t2=&t5=&t8=' . $t8 . '&t10=&t3=' . $t3 . '&t6=' . $t6 . $hero_post_str . '&c=3&dname=&x=' . $target_x . '&y=' . $target_y . '&s1.x=&s1.y=&s1=ok'; echo $postfields . "\n"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_REFERER, $url); $result = curl_exec($ch); curl_close($ch); // Check if succeeded // "hidden" name="kid" $ret = preg_match('/"hidden" name="kid"/', $result, $matches); if ($ret) { // <input type="hidden" name="id" value="39"> $ret = preg_match('/<input type="hidden" name="id" value="([0-9]+)"/', $result, $matches); if (!$ret) { die("get id failed."); } $id = $matches[1]; // echo "id = " . $id . "\n"; // <input type="hidden" name="a" value="46137"> $ret = preg_match('/<input type="hidden" name="a" value="([0-9]+)"/', $result, $matches); if (!$ret) { die("get a failed."); } $a = $matches[1]; // echo "a = " . $a . "\n"; // <input type="hidden" name="c" value="3"> $ret = preg_match('/<input type="hidden" name="c" value="([0-9]+)"/', $result, $matches); if (!$ret) { die("get c failed."); } $c = $matches[1]; // echo "c = " . $c . "\n"; // <input type="hidden" name="kid" value="356724"> $ret = preg_match('/<input type="hidden" name="kid" value="([0-9]+)"/', $result, $matches); if (!$ret) { die("get kid failed."); } $kid = $matches[1]; // echo "kid = " . $kid . "\n"; // <input type="hidden" name="t1" value="10"> $ret = preg_match('/<input type="hidden" name="t1" value="([0-9]+)"/', $result, $matches); if (!$ret) { die("get t1 failed."); } $t1 = $matches[1]; // echo "t1 = " . $t1 . "\n"; // <input type="hidden" name="t3" value="10"> $ret = preg_match('/<input type="hidden" name="t3" value="([0-9]+)"/', $result, $matches); if (!$ret) { die("get t3 failed."); } $t3 = $matches[1]; // echo "t3 = " . $t3 . "\n"; // <input type="hidden" name="t6" value="10"> $ret = preg_match('/<input type="hidden" name="t6" value="([0-9]+)"/', $result, $matches); if (!$ret) { die("get t6 failed."); } $t6 = $matches[1]; // echo "t6 = " . $t6 . "\n"; // <input type="hidden" name="t7" value="10"> $ret = preg_match('/<input type="hidden" name="t7" value="([0-9]+)"/', $result, $matches); if (!$ret) { die("get t7 failed."); } $t7 = $matches[1]; // echo "t7 = " . $t7 . "\n"; // <input type="hidden" name="t8" value="10"> $ret = preg_match('/<input type="hidden" name="t8" value="([0-9]+)"/', $result, $matches); if (!$ret) { die("get t8 failed."); } $t8 = $matches[1]; // echo "t8 = " . $t8 . "\n"; // <input type="hidden" name="t11" value="10"> $ret = preg_match('/<input type="hidden" name="t11" value="([0-9]+)"/', $result, $matches); if (!$ret) { die("get t11 failed."); } $t11 = $matches[1]; // echo "t11 = " . $t11 . "\n"; // <input type="hidden" name="timestamp" value="1252545240" /> $ret = preg_match('/<input type="hidden" name="timestamp" value="([0-9]+)"/', $result, $matches); if (!$ret) { die("get timestamp failed."); } $timestamp = $matches[1]; // <input type="hidden" name="timestamp_checksum" value="c831c6" /> $ret = preg_match('/<input type="hidden" name="timestamp_checksum" value="([a-z0-9]+)"/', $result, $matches); if (!$ret) { die("get timestamp_checksum failed."); } $timestamp_checksum = $matches[1]; if ($target_player) { // <td class="s7"><a href="spieler.php?uid=11783">Vinsfeld</a></td></tr> $ret = preg_match('#<a href="spieler\\.php\\?uid=[0-9]+">([^<]+)</a></td>#', $result, $matches); if (!$ret) { die("get player failed."); } $player = $matches[1]; if ($player != $target_player) { echo "Error: player changed.\n"; $sql = "update `targets` set `invalid` = 1, `invalid_msg` = '名義変更' where x = " . $target_x . " and y = " . $target_y; if (!mysql_query($sql)) { die(mysql_error()); } return false; } } // id=39&a=5941&c=3&kid=322334&t1=1&t2=0&t3=0&t4=0&t5=0&t6=0&t7=0&t8=0&t9=0&t10=0&t11=0&s1.x=&s1.y=&s1=ok $postfields = 'timestamp=' . $timestamp . '×tamp_checksum=' . $timestamp_checksum . '&id=' . $id . '&a=' . $a . '&c=' . $c . '&kid=' . $kid . '&t1=' . $t1 . '&t2=0&t3=' . $t3 . '&t4=0&t5=0&t6=' . $t6 . '&t7=' . $t7 . '&t8=' . $t8 . '&t9=0&t10=0' . '&t11=' . $t11 . '&s1.x=&s1.y=&s1=ok'; echo $postfields . "\n"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_REFERER, $url); $result = curl_exec($ch); curl_close($ch); if (!$result) { die(curl_error($ch)); } echo "Attacking (" . $target_x . " , " . $target_y . ")\n"; return true; } else { echo "Error: no kid found.\n"; handle_bad_target($result, $target_x, $target_y); return false; } }
function auto_reinforce_tk($x, $y, $num) { global $server; $url = "http://{$server}/a2b.php"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); // How many army there ? // onClick="document.snd.t1.value=1; return false; if (!preg_match('/onClick="document\\.snd\\.t6\\.value=([0-9]+); return false;/', $result, $matches)) { echo "failed to get current army.\n"; return false; } $curr_army = $matches[1]; echo $curr_army . " army.\n"; if ($curr_army < $num) { echo "no engouth reinforce army there. {$curr_army} need {$num} \n"; return false; } $curr_army = $num; // b=1&t1=80&t4=&t7=&t9=&t2=&t5=&t8=&t10=&t3=&t6=&c=2&dname=&x=-128&y=-46&s1.x=&s1.y=&s1=ok $postfields = 'b=1&t1=&t4=&t7=&t9=&t2=&t5=&t8=&t10=&t3=&t6=' . $curr_army . '&c=2&dname=&x=' . $x . '&y=' . $y . '&s1.x=&s1.y=&s1=ok'; echo $postfields . "\n"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_REFERER, $url); $result = curl_exec($ch); curl_close($ch); // Check if succeeded // "hidden" name="kid" if (!preg_match('/"hidden" name="kid"/', $result, $matches)) { echo "no kid found.\n"; return false; } // <input type="hidden" name="id" value="39"> $ret = preg_match('/<input type="hidden" name="id" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get id failed."); } $id = $matches[1]; echo "id = " . $id . "\n"; // <input type="hidden" name="a" value="46137"> $ret = preg_match('/<input type="hidden" name="a" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get a failed."); } $a = $matches[1]; echo "a = " . $a . "\n"; // <input type="hidden" name="c" value="3"> $ret = preg_match('/<input type="hidden" name="c" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get c failed."); } $c = $matches[1]; echo "c = " . $c . "\n"; // <input type="hidden" name="kid" value="356724"> $ret = preg_match('/<input type="hidden" name="kid" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get kid failed."); } $kid = $matches[1]; echo "kid = " . $kid . "\n"; // <input type="hidden" name="t2" value="10"> $ret = preg_match('/<input type="hidden" name="t6" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get t6 failed."); } $t6 = $matches[1]; echo "t6 = " . $t6 . "\n"; // id=39&a=3953&c=2&kid=357519&t1=80&t2=0&t3=0&t4=0&t5=0&t6=0&t7=0&t8=0&t9=0&t10=0&t11=0&s1.x=&s1.y=&s1=ok $postfields = 'id=' . $id . '&a=' . $a . '&c=' . $c . '&kid=' . $kid . '&t1=0&t2=0&t3=0&t4=0&t5=0&t6=' . $t6 . '&t7=0&t8=0&t9=0&t10=0' . '&t11=0&s1.x=&s1.y=&s1=ok'; echo $postfields . "\n"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_REFERER, $url); $result = curl_exec($ch); curl_close($ch); if (!$result) { echo curl_error($ch); return false; } echo "reinforcing ({$x}, {$y}) {$num} tk ... \n"; return true; }
function build_settler() { global $server, $village, $main_village; if ($village == $main_village && $village != 0) { $url = "http://{$server}/build.php?gid=26"; } else { $url = "http://{$server}/build.php?gid=25"; } echo $url . "\n"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); // onClick="document.snd.t10.value=0 if (!preg_match('/on[cC]lick="document\\.snd\\.t10\\.value=([0-9]+)/', $result, $matches)) { echo "Failed to build settler.\n"; return; } $num = intval($matches[1]); if ($num <= 0) { echo "No resource to build settler.\n"; return; } // <input type="hidden" name="id" value="19"> if (!preg_match('/<input type="hidden" name="id" value="([0-9]+)"/', $result, $matches)) { echo "get id failed.\n"; return; } $id = $matches[1]; echo "id = " . $id . "\n"; // <input type="hidden" name="z" value="15"> if (!preg_match('/<input type="hidden" name="z" value="([0-9]+)"/', $result, $matches)) { echo "get z failed.\n"; return; } $z = $matches[1]; echo "z = " . $z . "\n"; // <input type="hidden" name="a" value="2"> if (!preg_match('/<input type="hidden" name="a" value="([0-9]+)"/', $result, $matches)) { echo "get a failed.\n"; return; } $a = $matches[1]; echo "a = " . $a . "\n"; // id=19&z=4802&a=2&t10=1&s1.x=&s1.y=&s1=ok $postfields = 'id=' . $id . '&z=' . $z . '&a=' . $a . '&t10=' . $num . '&s1.x=&s1.y=&s1=ok'; echo $postfields . "\n"; $referer = $url; $url = "http://{$server}/build.php"; echo $url . "\n"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_REFERER, $referer); $result = curl_exec($ch); curl_close($ch); if (!$result) { echo curl_error($ch) . "\n"; } echo "Building... {$num} settlers.\n"; }
function sell($m1, $rid1, $m2, $rid2, $free = 2, $reserve = 0) { global $server; $url = "http://{$server}/build.php?gid=17&t=2"; echo $url; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); // get current resource $curr_res = get_res_info($result); if ($curr_res[$rid1 - 1] < $m1) { echo "No enough resource to sell.\n"; return false; } if ($curr_res[$rid1 - 1] < $reserve) { echo "Resource too few.\n"; return false; } // get free merchants // <p class="f10">���l�F 19/20</p><p><input type="image" $ret = preg_match('/<p class="f10">\\S+ ([0-9]+)\\/[0-9]+<\\/p><p><input type="image"/', $result, $matches); if (!$ret) { echo "FAILED : get free merchants.\n"; return false; } $free_m = $matches[1]; echo "Free merchants : {$free_m} \n"; if ($free_m <= $free) { echo "No enough free merchants.\n"; return false; } // <input type="hidden" name="id" value="27"> $ret = preg_match('/<input type="hidden" name="id" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get id failed."); } $id = $matches[1]; // <input type="hidden" name="a" value="113321"> $ret = preg_match('/<input type="hidden" name="a" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get a failed."); } $a = $matches[1]; //id=23&t=2&a=4&m1=1000&rid1=2&d2=2&m2=2000&rid2=4&s1.x=21&s1.y=7&s1=ok $postfields = "id={$id}&t=2&a={$a}&m1={$m1}&rid1={$rid1}&d2=2&m2={$m2}&rid2={$rid2}&s1.x=21&s1.y=7&s1=ok"; echo "{$postfields}\n"; $referer = $url; $url = "http://{$server}/build.php"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_REFERER, $referer); $result = curl_exec($ch); curl_close($ch); return true; }
function build_or_upgrade($id, $gid = 0) { global $server; $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]+&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]+&id=' . $id . '&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 . '&id=' . $id . '&c=[0-9a-z]+)">/', $result, $matches); } } } if (!$ret) { echo "Busy or lacking resources or failed .. {$gid} {$id}\n"; return false; } $url2 = "http://{$server}/" . html_entity_decode($matches[1]); echo $url2 . "\n"; $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); return true; }
function attack_func($target_x, $target_y, $t1, $t3, $t6, $t7, $t8, $t11, $result) { global $server; $url = "http://{$server}/a2b.php"; assert($t1 > 0 || $t1 == ''); assert($t3 > 0 || $t3 == ''); assert($t6 > 0 || $t6 == ''); assert($t7 > 0 || $t7 == ''); assert($t8 > 0 || $t8 == ''); assert($t11 == 1 || $t11 == ''); $hero_post_str = ''; // onClick="document.snd.t11.value=1; return false;" if (preg_match('/onClick="document\\.snd\\.t11\\.value=1; return false;/', $result, $matches)) { echo "Hero in home.\n"; if ($t11 == '') { $hero_post_str = '&t11='; } else { $hero_post_str = '&t11=1'; } } // Post it // b=1&t1=1&t4=&t7=&t9=&t2=&t5=&t8=&t10=&t3=&t6=&c=3&dname=&x=-69&y=-2&s1.x=&s1.y=&s1=ok // b=1&t1=50&t4=&t7=&t9=&t2=&t5=&t8=&t10=&t3=&t6=&t11=1&c=3&dname=&x=-122&y=-45&s1.x=&s1.y=&s1=ok $postfields = 'b=1&t1=' . $t1 . '&t4=&t7=' . $t7 . '&t9=&t2=&t5=&t8=' . $t8 . '&t10=&t3=' . $t3 . '&t6=' . $t6 . $hero_post_str . '&c=3&dname=&x=' . $target_x . '&y=' . $target_y . '&s1.x=&s1.y=&s1=ok'; echo $postfields . "\n"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_REFERER, $url); $result = curl_exec($ch); curl_close($ch); // Check if succeeded // "hidden" name="kid" $ret = preg_match('/"hidden" name="kid"/', $result, $matches); if ($ret) { // <input type="hidden" name="id" value="39"> $ret = preg_match('/<input type="hidden" name="id" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get id failed."); } $id = $matches[1]; echo "id = " . $id . "\n"; // <input type="hidden" name="a" value="46137"> $ret = preg_match('/<input type="hidden" name="a" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get a failed."); } $a = $matches[1]; echo "a = " . $a . "\n"; // <input type="hidden" name="c" value="3"> $ret = preg_match('/<input type="hidden" name="c" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get c failed."); } $c = $matches[1]; echo "c = " . $c . "\n"; // <input type="hidden" name="kid" value="356724"> $ret = preg_match('/<input type="hidden" name="kid" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get kid failed."); } $kid = $matches[1]; echo "kid = " . $kid . "\n"; // <input type="hidden" name="t1" value="10"> $ret = preg_match('/<input type="hidden" name="t1" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get t1 failed."); } $t1 = $matches[1]; echo "t1 = " . $t1 . "\n"; // <input type="hidden" name="t3" value="10"> $ret = preg_match('/<input type="hidden" name="t3" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get t3 failed."); } $t3 = $matches[1]; echo "t3 = " . $t3 . "\n"; // <input type="hidden" name="t6" value="10"> $ret = preg_match('/<input type="hidden" name="t6" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get t6 failed."); } $t6 = $matches[1]; echo "t6 = " . $t6 . "\n"; // <input type="hidden" name="t7" value="10"> $ret = preg_match('/<input type="hidden" name="t7" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get t7 failed."); } $t7 = $matches[1]; echo "t7 = " . $t7 . "\n"; // <input type="hidden" name="t8" value="10"> $ret = preg_match('/<input type="hidden" name="t8" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get t8 failed."); } $t8 = $matches[1]; echo "t8 = " . $t8 . "\n"; // <input type="hidden" name="t11" value="10"> $ret = preg_match('/<input type="hidden" name="t11" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get t11 failed."); } $t11 = $matches[1]; echo "t11 = " . $t11 . "\n"; // id=39&a=5941&c=3&kid=322334&t1=1&t2=0&t3=0&t4=0&t5=0&t6=0&t7=0&t8=0&t9=0&t10=0&t11=0&s1.x=&s1.y=&s1=ok $postfields = 'id=' . $id . '&a=' . $a . '&c=' . $c . '&kid=' . $kid . '&t1=' . $t1 . '&t2=0&t3=' . $t3 . '&t4=0&t5=0&t6=' . $t6 . '&t7=' . $t7 . '&t8=' . $t8 . '&t9=0&t10=0' . '&t11=' . $t11 . '&s1.x=&s1.y=&s1=ok'; echo $postfields . "\n"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_REFERER, $url); $result = curl_exec($ch); curl_close($ch); if (!$result) { die(curl_error($ch)); } echo "attacking (" . $target_x . " , " . $target_y . ")\n"; return true; } else { echo "Error: no kid found.\n"; handle_bad_target($result, $target_x, $target_y); return false; } }
function delete_self_trade_reports() { global $server; $village_names = array(); for ($s = 0; $s <= 10; $s = $s + 10) { $url = "http://{$server}/berichte.php?s={$s}&t=2"; echo $url . "\n"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); if (empty($village_names)) { $village_names = get_all_village_names($result); // print_r($village_names); } for ($i = 0; $i < 10; $i++) { // <td class="s7"><a href="berichte.php?id=605449">öが新しい村に供給しました</a> (新)</td> if (!preg_match_all('#<td class="s7"><a href="berichte\\.php\\?id=([0-9]+)">([^<]+)が([^<]+)に供給しました</a> [^<]+</td>#', $result, $matches, PREG_SET_ORDER)) { break; } $targets = array(); foreach ($matches as $match) { $id = $match[1]; $from = $match[2]; $to = $match[3]; if (in_array($from, $village_names) && in_array($to, $village_names)) { // <td width="22"><input type="Checkbox" name="n1" value="605561"></td> if (preg_match('#<td width="22"><input type="Checkbox" name="(n[0-9]+)" value="' . $id . '"></td>#', $result, $match)) { $targets[$id] = $match[1]; } else { echo "delete_self_trade_reports : failed to get post var name. {$id}\n"; } } } if (!empty($targets)) { // t=2&n1=605561&del=%E6%B6%88%E5%8E%BB // <input class="std" name="del" type="Submit" value="消去"> $referer = $url; $url = "http://{$server}/berichte.php"; $postfields = 't=2&'; foreach ($targets as $id => $pname) { $postfields = $postfields . $pname . '=' . $id . '&'; } $postfields .= 'del=%E6%B6%88%E5%8E%BB'; echo $postfields . "\n"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_REFERER, $referer); $result = curl_exec($ch); curl_close($ch); } else { break; } } } }
function login() { global $server; global $user; global $password; $url = "http://{$server}/dorf1.php"; echo $url . "\n"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); // check if need login $ret = preg_match('/<td><img class="res"/', $result); //echo $result; if (!$ret) { // Announce if (preg_match('/<a href="dorf1\\.php\\?ok/', $result)) { echo "ANNOUNCE ...\n"; // file_put_contents("announce.html", $result); $filename = "announce.html"; if (!($handle = fopen($filename, 'w'))) { die("Cannot open file ({$filename})"); } if (fwrite($handle, $result) === FALSE) { die("Cannot write to file ({$filename})"); } fclose($handle); $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url . '?ok=1'); $result = curl_exec($ch); curl_close($ch); if (preg_match('/<td><img class="res"/', $result)) { echo "login ok ....\n"; return $result; } else { die("FAILED: login ...."); } } // <input type="hidden" name="login" value="1198128845"> $ret = preg_match('/<input type="hidden" name="login" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get post value login failed."); } $login = $matches[1]; // echo $login . "\n"; // <input class="fm fm110" type="text" name="e96c60c" value="" maxlength="15"> <span class="e f7"></span> $ret = preg_match('/<input class="fm fm110" type="text" name="([a-z0-9]+)" value=".*?" maxlength="15"> <span class="e f7"><\\/span>/', $result, $matches); if (!$ret) { die("get post name user failed."); } $var_user = $matches[1]; // echo $var_user . "\n"; // <input class="fm fm110" type="password" name="ee54ffc" value="" maxlength="20"> <span class="e f7"></span> $ret = preg_match('/<input class="fm fm110" type="password" name="([a-z0-9]+)" value=".*?" maxlength="20"> <span class="e f7"><\\/span>/', $result, $matches); if (!$ret) { die("get post name password failed."); } $var_password = $matches[1]; // echo $var_password . "\n"; // <p align="center"><input type="hidden" name="e50439e" value=""> $ret = preg_match('/<p align="center"><input type="hidden" name="([a-z0-9]+)" value="([a-z0-9]*)">/', $result, $matches); if (!$ret) { die("get post anonymous name and value failed."); } $var_anonymous_name = $matches[1]; $var_anonymous_value = $matches[2]; // echo $var_anonymous_name . "\n"; // echo $var_anonymous_value . "\n"; // w=1152%3A864&login=1198128731&e96c60c=Kimon&ee54ffc=********&e50439e=cc87212bcd&s1.x=&s1.y=&s1=login&autologin=ja $postfields = 'w=1152%3A864' . '&login='******'&' . $var_user . '=' . urlencode($user) . '&' . $var_password . '=' . $password . '&' . $var_anonymous_name . '=' . $var_anonymous_value . '&s1.x=&s1.y=&s1=login'; echo $postfields . "\n"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); $result = curl_exec($ch); curl_close($ch); // echo $result; $ret = preg_match('/<td><img class="res"/', $result); if ($ret) { echo "login ok.\n"; } else { echo $result; die("FAILED: login."); } } else { echo "cookie login ok.\n"; } return $result; }
function auto_defence_oasis($home_x, $home_y, $defence_unit, $defence_unit_speed) { global $server; $url = "http://{$server}/build.php?gid=16"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); $res = get_defence_oasis($result); print_r($res); if (empty($res)) { return false; } foreach ($res as &$a) { $x = $a[0]; $y = $a[1]; $remain = $a[2]; $arrive = $a[3]; $distance = calc_distance($home_x, $home_y, $x, $y); $need_time = 3600 * $distance / $defence_unit_speed; $wait_time = $remain - $need_time; array_push($a, $wait_time); } usort($res, "cmp"); print_r($res); $last_wait_time = 0; foreach ($res as $b) { $x = $b[0]; $y = $b[1]; $arrive = $b[3]; $wait_time = $b[4]; //print_r($a); // too late if ($wait_time < 0) { echo "wait time < 0\n"; continue; } // 20 minutes if ($wait_time - $last_wait_time > 1200) { echo "wait time - last wait time > 1200\n"; break; } $arrive2 = minus_time_str($arrive, 30); echo "raid {$x}, {$y} {$arrive2}\n"; raid($x, $y, array($defence_unit => 2), $arrive2); $last_wait_time = $wait_time; } }
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; }
function build_infantry($t, $base) { global $server; $url = "http://{$server}/build.php?gid=19"; echo $url . "\n"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); curl_close($ch); // onClick="document.snd.t1.value=0" $ret = preg_match('/onClick="document.snd.t' . $t . '.value=([0-9]+)/', $result, $matches); if (!$ret) { echo "Failed to build infantry.\n"; return; } $num = intval($matches[1]); if ($num <= $base) { echo "No resource to build infantry.\n"; return; } $num = $num - $base; // <input type="hidden" name="id" value="19"> $ret = preg_match('/<input type="hidden" name="id" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get id failed."); } $id = $matches[1]; echo "id = " . $id . "\n"; // <input type="hidden" name="z" value="15"> $ret = preg_match('/<input type="hidden" name="z" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get z failed."); } $z = $matches[1]; echo "z = " . $z . "\n"; // <input type="hidden" name="a" value="2"> $ret = preg_match('/<input type="hidden" name="a" value="([0-9]+)">/', $result, $matches); if (!$ret) { die("get a failed."); } $a = $matches[1]; echo "a = " . $a . "\n"; $str = ''; // t1 $str .= generate_post_str($result, $t, 1, $num); // t2 $str .= generate_post_str($result, $t, 2, $num); // t3 $str .= generate_post_str($result, $t, 3, $num); // t4 $str .= generate_post_str($result, $t, 4, $num); // id=19&z=4802&a=2&t1=1&s1.x=&s1.y=&s1=ok $postfields = 'id=' . $id . '&z=' . $z . '&a=' . $a . $str . '&s1.x=&s1.y=&s1=ok'; echo $postfields . "\n"; $referer = $url; $url = "http://{$server}/build.php"; echo $url . "\n"; $ch = my_curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_REFERER, $referer); $result = curl_exec($ch); curl_close($ch); if (!$result) { die(curl_error($ch)); } echo "Building... {$num} infantry.\n"; }