]> git.sesse.net Git - remoteglot/blobdiff - remoteglot.pl
Make sure analysis contempt is off; Stockfish > 9 enables it, and it gives rollercoas...
[remoteglot] / remoteglot.pl
index 049cdabaafaa0f0f824bec3cb0df34f147176fe2..c86eedee530e2a1e879e8b413aa2ceb524a1c551 100755 (executable)
@@ -77,6 +77,7 @@ my $last_text = '';
 my ($pos_calculating, $pos_calculating_second_engine);
 
 uciprint($engine, "setoption name UCI_AnalyseMode value true");
+uciprint($engine, "setoption name Analysis Contempt value Off");
 while (my ($key, $value) = each %remoteglotconf::engine_config) {
        uciprint($engine, "setoption name $key value $value");
 }
@@ -84,6 +85,7 @@ uciprint($engine, "ucinewgame");
 
 if (defined($engine2)) {
        uciprint($engine2, "setoption name UCI_AnalyseMode value true");
+       uciprint($engine2, "setoption name Analysis Contempt value Off");
        while (my ($key, $value) = each %remoteglotconf::engine2_config) {
                uciprint($engine2, "setoption name $key value $value");
        }
@@ -124,7 +126,7 @@ if (defined($remoteglotconf::server)) {
        );
 }
 if (defined($remoteglotconf::target)) {
-       if ($remoteglotconf::target =~ /^https?:/) {
+       if ($remoteglotconf::target =~ /^(?:\/|https?:)/) {
                fetch_pgn($remoteglotconf::target);
        } elsif (defined($t)) {
                $t->cmd("observe $remoteglotconf::target");
@@ -248,9 +250,26 @@ sub handle_fics {
 # Starts periodic fetching of PGNs from the given URL.
 sub fetch_pgn {
        my ($url) = @_;
-       AnyEvent::HTTP::http_get($url, sub {
-               handle_pgn(@_, $url);
-       });
+       if ($url =~ m#^/#) {  # Local file.
+               eval {
+                       local $/ = undef;
+                       open my $fh, "<", $url
+                               or die "$url: $!";
+                       my $pgn = <$fh>;
+                       close $fh;
+                       handle_pgn($pgn, '', $url);
+               };
+               if ($@) {
+                       warn "$url: $@";
+                       $http_timer = AnyEvent->timer(after => 1.0, cb => sub {
+                               fetch_pgn($url);
+                       });
+               }
+       } else {
+               AnyEvent::HTTP::http_get($url, sub {
+                       handle_pgn(@_, $url);
+               });
+       }
 }
 
 my ($last_pgn_white, $last_pgn_black);