]> git.sesse.net Git - remoteglot/blobdiff - remoteglot.pl
Version bump.
[remoteglot] / remoteglot.pl
index 287909f8d8a63590c5cd1f9d0e028470495259bf..e1f36528b802f1c9023e6e81531cd2999ceb8976 100755 (executable)
@@ -291,7 +291,11 @@ sub handle_pgn {
                        }
 
                        $pgn->parse_game({ save_comments => 'yes' });
-                       my $pos = Position->start_pos($pgn->white, $pgn->black);
+                       my $white = $pgn->white;
+                       my $black = $pgn->black;
+                       $white =~ s/,.*//;  # Remove first name.
+                       $black =~ s/,.*//;  # Remove first name.
+                       my $pos = Position->start_pos($white, $black);
                        my $moves = $pgn->moves;
                        my @uci_moves = ();
                        my @repretty_moves = ();
@@ -305,7 +309,9 @@ sub handle_pgn {
                                push @repretty_moves, $pretty;
                                $pos = $npos;
                        }
-                       $pos->{'result'} = $pgn->result;
+                       if ($pgn->result eq '1-0' || $pgn->result eq '1/2-1/2' || $pgn->result eq '0-1') {
+                               $pos->{'result'} = $pgn->result;
+                       }
                        $pos->{'pretty_history'} = \@repretty_moves;
 
                        extract_clock($pgn, $pos);
@@ -912,6 +918,7 @@ sub output_json {
        }
 
        # Give out a list of other games going on. (Empty is fine.)
+       # TODO: Don't bother reading our own file, the data will be stale anyway.
        if (!$historic_json_only) {
                my @games = ();
 
@@ -926,11 +933,18 @@ sub output_json {
                                my $white = $other_game_json->{'position'}{'player_w'} // die 'Missing white';
                                my $black = $other_game_json->{'position'}{'player_b'} // die 'Missing black';
 
-                               push @games, {
+                               my $game = {
                                        id => $ref->{'id'},
                                        name => "$white–$black",
-                                       url => $ref->{'url'}
+                                       url => $ref->{'url'},
+                                       hashurl => $ref->{'hash_url'},
                                };
+                               if (defined($other_game_json->{'position'}{'result'})) {
+                                       $game->{'result'} = $other_game_json->{'position'}{'result'};
+                               } else {
+                                       $game->{'score'} = $other_game_json->{'score'};
+                               }
+                               push @games, $game;
                        };
                        if ($@) {
                                warn "Could not add external game " . $ref->{'json_path'} . ": $@";
@@ -972,7 +986,7 @@ sub output_json {
                                $dbh->do('INSERT INTO scores (id, score_type, score_value, engine, depth, nodes) VALUES (?,?,?,?,?,?) ' .
                                         '    ON CONFLICT (id) DO UPDATE SET ' .
                                         '        score_type=EXCLUDED.score_type, ' .
-                                        '        score_value=EXCLUDED.score_vlaue, ' .
+                                        '        score_value=EXCLUDED.score_value, ' .
                                         '        engine=EXCLUDED.engine, ' .
                                         '        depth=EXCLUDED.depth, ' .
                                         '        nodes=EXCLUDED.nodes',