X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=remoteglot.pl;h=675ef5011ec20788b08a343b0596083b5c853366;hb=be27a8c1495840effbd3c0044e205bfa5ca06808;hp=b018e3841d8c336036f9fb8366d13fd1c5218a19;hpb=d65c5b5001e2a61c2aa9e5fc97859515db69d72f;p=remoteglot diff --git a/remoteglot.pl b/remoteglot.pl index b018e38..675ef50 100755 --- a/remoteglot.pl +++ b/remoteglot.pl @@ -31,6 +31,7 @@ no warnings qw(once); my $latest_update = undef; my $output_timer = undef; my $http_timer = undef; +my $stop_pgn_fetch = 0; my $tb_retry_timer = undef; my %tb_cache = (); my $tb_lookup_running = 0; @@ -231,6 +232,7 @@ sub handle_fics { fetch_pgn($url); } elsif ($msg =~ /^stoppgn$/) { $t->cmd("tell $who Stopping poll."); + $stop_pgn_fetch = 1; $http_timer = undef; } elsif ($msg =~ /^quit$/) { $t->cmd("tell $who Bye bye."); @@ -256,6 +258,13 @@ my $pgn_hysteresis_counter = 0; sub handle_pgn { my ($body, $header, $url) = @_; + + if ($stop_pgn_fetch) { + $stop_pgn_fetch = 0; + $http_timer = undef; + return; + } + my $pgn = Chess::PGN::Parse->new(undef, $body); if (!defined($pgn) || !$pgn->read_game()) { warn "Error in parsing PGN from $url\n"; @@ -502,7 +511,7 @@ sub output { my $t = $tb_cache{$fen}; my $pv = $t->{'pv'}; - my $matelen = int((1 + scalar @$pv) / 2); + my $matelen = int((1 + $t->{'score'}) / 2); if ($t->{'result'} eq '1/2-1/2') { $info->{'score_cp'} = 0; } elsif ($t->{'result'} eq '1-0') { @@ -937,7 +946,8 @@ sub handle_tb_lookup_return { } $tb_cache{$fen} = { result => $pgn->result, - pv => \@uci_moves + pv => \@uci_moves, + score => $response->{'Response'}{'Score'}, }; output(); }