X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=remoteglot.pl;h=f383bb6e41088c38c4ba767d47cbb924eacab23c;hb=8a95f87af48bd7388bf23115537f7e2381a2e17d;hp=4e6edc68308f3524b252c765d61394126107f6cc;hpb=25b4c5b0537cb335c09c7b1bf4e765c5aa6cf412;p=remoteglot diff --git a/remoteglot.pl b/remoteglot.pl index 4e6edc6..f383bb6 100755 --- a/remoteglot.pl +++ b/remoteglot.pl @@ -28,9 +28,10 @@ use warnings; no warnings qw(once); # Program starts here -$SIG{ALRM} = sub { output(); }; 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; @@ -199,7 +200,6 @@ sub handle_fics { }; if ($@) { warn "Error when getting FICS move history: $@"; - exit; $getting_movelist = 0; } } @@ -232,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."); @@ -257,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"; @@ -266,7 +274,8 @@ sub handle_pgn { my $moves = $pgn->moves; my @uci_moves = (); for my $move (@$moves) { - my ($pos, $uci_move) = $pos->make_pretty_move($move); + my $uci_move; + ($pos, $uci_move) = $pos->make_pretty_move($move); push @uci_moves, $uci_move; } $pos->{'history'} = \@uci_moves; @@ -477,7 +486,8 @@ sub output { # Don't update too often. my $age = Time::HiRes::tv_interval($latest_update); if ($age < $remoteglotconf::update_max_interval) { - Time::HiRes::alarm($remoteglotconf::update_max_interval + 0.01 - $age); + my $wait = $remoteglotconf::update_max_interval + 0.01 - $age; + $output_timer = AnyEvent->timer(after => $wait, cb => \&output); return; } @@ -930,7 +940,8 @@ sub handle_tb_lookup_return { my $moves = $pgn->moves; my @uci_moves = (); for my $move (@$moves) { - my ($pvpos, $uci_move) = $pvpos->make_pretty_move($move); + my $uci_move; + ($pvpos, $uci_move) = $pvpos->make_pretty_move($move); push @uci_moves, $uci_move; } $tb_cache{$fen} = {