0

さて、このスクリプトを起動して実行するために何時間も費やしてきましたが、今私が遭遇している唯一の問題は、時折発生する GET および POST エラーで、スクリプトが再起動されることです。これは非常に厄介です。

sub Fight {
my($cpm);
$parsed = 0; while ($parsed == 0) {sleep(3);
$mech->get("http://www.lordsoflords.com/m3/fight_control.php");
$a = $mech->content();if ($a =~ m/Skeleton/) {$parsed = 1;}}
$mech->form_number(2);
$mech->field("Difficulty", $level);
$mech->click();
$cpm = $mech->content();
$cpm =~ m/(\<option\>208.*Duke)/;
$cpm = $1;
$cpm =~ s/ - Shadowlord Duke//g;
$cpm =~ s/\>209/\>/;
$cpm =~ s/<.*?>//g;
if($debug == 1) {
    print $cpm . "\n";
}
$mech->form_number(1);
$mech->select("Monster", $cpm);
$mech->click();
$a = $mech->content();
$a =~ m/(You win.*exp )/;
$a =~ m/(battle)/;
$a =~ m/(You have been jailed for violating our rules)/;
print $1 . "\n";
my $antal = 500 + int rand (500);
my $antal = 5000;
my $jail;

# REPEAT:
while($antal > 0) {
    sleep($loopwait); #default = 0.3
    $antal = $antal -1;
    $mech->reload();
    $a = $mech->content();
    $b = $a;
    $c = $a;

エラーが発生している行の 1 つは、リピート セクションの $mech->reload() コマンドで、次のようなエラーを返しています。 php : booyaka.pl 行 299 の不正なリクエスト」。

また、「Error GETing http://www.lordsoflords.com/m3/steal.php : Can't connect to www.lordsoflords.com:80 (Bad hostname) at booyaka.pl line 97」というエラーが返されることもあります。

これが接続されている関数は次のとおりです。

sub Stealwait {
    $stealwait = 3600;
    $stealtime = time;
    $stealtime = $stealtime + $stealwait; # if stealer can't be found, click for 1k seconds
    print time . "|" . $stealtime . "\n";
    print "stealtime: " . $stealtime . "\n";
    $parsed = 0; $stealcount = 0;
    while ($parsed == 0) {sleep(3);
    print $stealcount . "\n";
    $mech->get("http://www.lordsoflords.com/m3/steal.php");
    $a = $mech->content();
    if ($a =~ m/Parsed/) {$parsed = 1; $stealwait = 0;}
    $stealcount = $stealcount+1; if ($stealcount == 5) {
    }
if ($a =~ m/recover/)
{
    $a = $mech->content();
    $a =~ m/(Take.*This)/s;
    $b = $1;
    $b =~ s/<.*?>//sg;
    $b =~ m/(Take.*seconds)/s;
    $b = $1;
     print $b . "\n";
    $b =~ m/(for.*seconds)/s;
    $b = $1;
    $b =~ s/for//sg;
    $b =~ s/seconds//sg;
    $b =~ s/<.*?>//sg;
    $b =~ s/,//g;
            $b = 2*$b;
            $stealwait = $b;
            print "In recover, gotta wait " . $stealwait . " seconds before I can steal...\n";
            $stealtime = time;
            $stealtime = $stealtime + $stealwait;
    }


    sub Steal {
$parsed = 0; while ($parsed == 0) {sleep(3);
$mech->get("http://www.lordsoflords.com/m3/steal.php");
$a = $mech->content();if ($a =~ m/Parsed/) {$parsed = 1;}}
    $a = $mech->content();
    if ($a =~ m/Freeplay/) { # steal only if we have freeplay
            $a = "\<option\>" . "$stealchar" . ".*?\<\/option\>";
            $tmp = $mech->content();
            #print $tmp;
            if($tmp =~ m/($a)/) {print "Stealer found\n";} else {print "Stealer not found! - not stealing!\n"; return();}
            $tmp =~ m/($a)/s;
            $tmp = $1;
            $tmp =~ s/<.*?>//sg;
            print "Stealing from: " . $tmp;
            $mech->form_name(0);
            $mech->select("Opp", $tmp);
            $mech->click_button('value' => 'Steal Stats or Items');
            $a = $mech->content();
            $a =~ m/(sleepers.*This)/s;
            $b = $1;
            $b =~ s/<.*?>//sg;
            $b =~ s/sleepers//sg;
            $b =~ s/This//sg;
            print $b;
    } else {$stealtime = time; $stealtime = $stealtime + 2000; print "Freeplay not detected, stealing cancelled...\n";}
}

私はスクリプトに関しては専門家ではありません。この問題を修正する方法や Mechanize のタイムアウトをオーバーライドする方法についての洞察をいただければ幸いです。

4

1 に答える 1