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;
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.");
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";
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') {
}
$tb_cache{$fen} = {
result => $pgn->result,
- pv => \@uci_moves
+ pv => \@uci_moves,
+ score => $response->{'Response'}{'Score'},
};
output();
}