X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=remoteglot.pl;h=c86eedee530e2a1e879e8b413aa2ceb524a1c551;hb=17c1ac08187cea6c69bd193f43a58bc984d9a5bc;hp=0bfbc4c89dba35c5d7d1986691e0c6ca03df73f0;hpb=749623f7b8722abab1c9c37da4a7c2d7a33bea1c;p=remoteglot diff --git a/remoteglot.pl b/remoteglot.pl index 0bfbc4c..c86eede 100755 --- a/remoteglot.pl +++ b/remoteglot.pl @@ -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); @@ -290,6 +309,7 @@ sub handle_pgn { my $pos; if (exists($tags->{'FEN'})) { $pos = Position->from_fen($tags->{'FEN'}); + $pos->{'last_move'} = 'none'; $pos->{'player_w'} = $white; $pos->{'player_b'} = $black; $pos->{'start_fen'} = $tags->{'FEN'}; @@ -909,6 +929,7 @@ sub output_json { } else { $pos = Position->start_pos('white', 'black'); } + $pos->{'chess960'} = $pos_calculating->{'chess960'}; my $halfmove_num = 0; for my $move (@{$pos_calculating->{'history'}}) { my $id = id_for_pos($pos, $halfmove_num);