X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=remoteglot.pl;h=6a5778a0b96b3c321d0095b21fa92bd67d018904;hp=917a6a01300a145e4f537d9ab07394da01d16cea;hb=09af5a0331f744f3dec83173be53835c53bba3c8;hpb=ea605b127d018d0b3e4927826e48f7dd69944aaa diff --git a/remoteglot.pl b/remoteglot.pl index 917a6a0..6a5778a 100755 --- a/remoteglot.pl +++ b/remoteglot.pl @@ -35,6 +35,7 @@ my $stop_pgn_fetch = 0; my $tb_retry_timer = undef; my %tb_cache = (); my $tb_lookup_running = 0; +my $last_written_json = undef; # TODO: Persist (parts of) this so that we can restart. my %clock_target_for_pos = (); @@ -760,8 +761,10 @@ sub output_json { $json->{'refutation_lines'} = \%refutation_lines; my $encoded = JSON::XS::encode_json($json); - unless ($historic_json_only) { + unless ($historic_json_only || !defined($remoteglotconf::json_output) || + (defined($last_written_json) && $last_written_json eq $encoded)) { atomic_set_contents($remoteglotconf::json_output, $encoded); + $last_written_json = $encoded; } if (exists($pos_calculating->{'pretty_history'}) && @@ -1014,9 +1017,10 @@ sub find_clock_start { my $pos = shift; # If the game is over, the clock is stopped. - if ($pos->{'result'} eq '1-0' || - $pos->{'result'} eq '1/2-1/2' || - $pos->{'result'} eq '0-1') { + if (exists($pos->{'result'}) && + ($pos->{'result'} eq '1-0' || + $pos->{'result'} eq '1/2-1/2' || + $pos->{'result'} eq '0-1')) { return; } @@ -1025,6 +1029,11 @@ sub find_clock_start { return; } + # TODO(sesse): Maybe we can get the number of moves somehow else for FICS games. + if (!exists($pos->{'pretty_history'})) { + return; + } + my $id = id_for_pos($pos); if (exists($clock_target_for_pos{$id})) { if ($pos->{'toplay'} eq 'W') {