]> git.sesse.net Git - remoteglot/blobdiff - remoteglot.pl
Remove the obsolete text.pl.
[remoteglot] / remoteglot.pl
index b546589e5c03bfb56e9fd69caa3b6a13a996b075..61e7237b1d2926b632f141dc50ef481858c41872 100755 (executable)
@@ -268,7 +268,7 @@ sub handle_pgn {
        }
 
        my $pgn = Chess::PGN::Parse->new(undef, $body);
-       if (!defined($pgn) || !$pgn->read_game()) {
+       if (!defined($pgn) || !$pgn->read_game() || $body !~ /^\[/) {
                warn "Error in parsing PGN from $url\n";
        } else {
                eval {
@@ -760,7 +760,7 @@ 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)) {
                atomic_set_contents($remoteglotconf::json_output, $encoded);
        }
 
@@ -983,6 +983,9 @@ sub extract_clock {
        if (exists($tags->{'WhiteClock'}) && exists($tags->{'BlackClock'})) {
                $pos->{'white_clock'} = $tags->{'WhiteClock'};
                $pos->{'black_clock'} = $tags->{'BlackClock'};
+
+               $pos->{'white_clock'} =~ s/\b(\d)\b/0$1/g;
+               $pos->{'black_clock'} =~ s/\b(\d)\b/0$1/g;
                return;
        }
 
@@ -1011,9 +1014,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;
        }
 
@@ -1022,6 +1026,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') {