X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=remoteglot.pl;h=163e16666cf108d41cbfbb271a2c0d3e6e1c035c;hp=9439a4bc4d0b063c59b1eb2738cc9cd0c4b987d5;hb=703728497c14b57cb2e7db9e90376ba82468ecf3;hpb=f26a218756768fcbbbcd332e56029053e359003c diff --git a/remoteglot.pl b/remoteglot.pl index 9439a4b..163e166 100755 --- a/remoteglot.pl +++ b/remoteglot.pl @@ -67,7 +67,7 @@ select(TBLOG); $| = 1; select(STDOUT); -umask 0022; +umask 0027; # analysis.json should not be served to users. # open the chess engine my $engine = open_engine($remoteglotconf::engine_cmdline, 'E1', sub { handle_uci(@_, 1); }); @@ -94,40 +94,45 @@ if (defined($engine2)) { print "Chess engine ready.\n"; # now talk to FICS -my $t = Net::Telnet->new(Timeout => 10, Prompt => '/fics% /'); -$t->input_log(\*FICSLOG); -$t->open($remoteglotconf::server); -$t->print($remoteglotconf::nick); -$t->waitfor('/Press return to enter the server/'); -$t->cmd(""); - -# set some options -$t->cmd("set shout 0"); -$t->cmd("set seek 0"); -$t->cmd("set style 12"); - -my $ev1 = AnyEvent->io( - fh => fileno($t), - poll => 'r', - cb => sub { # what callback to execute - while (1) { - my $line = $t->getline(Timeout => 0, errmode => 'return'); - return if (!defined($line)); - - chomp $line; - $line =~ tr/\r//d; - handle_fics($line); +my ($t, $ev1); +if (defined($remoteglotconf::server)) { + $t = Net::Telnet->new(Timeout => 10, Prompt => '/fics% /'); + $t->input_log(\*FICSLOG); + $t->open($remoteglotconf::server); + $t->print($remoteglotconf::nick); + $t->waitfor('/Press return to enter the server/'); + $t->cmd(""); + + # set some options + $t->cmd("set shout 0"); + $t->cmd("set seek 0"); + $t->cmd("set style 12"); + + $ev1 = AnyEvent->io( + fh => fileno($t), + poll => 'r', + cb => sub { # what callback to execute + while (1) { + my $line = $t->getline(Timeout => 0, errmode => 'return'); + return if (!defined($line)); + + chomp $line; + $line =~ tr/\r//d; + handle_fics($line); + } } - } -); + ); +} if (defined($remoteglotconf::target)) { - if ($remoteglotconf::target =~ /^http:/) { + if ($remoteglotconf::target =~ /^https?:/) { fetch_pgn($remoteglotconf::target); - } else { + } elsif (defined($t)) { $t->cmd("observe $remoteglotconf::target"); } } -print "FICS ready.\n"; +if (defined($t)) { + print "FICS ready.\n"; +} # Engine events have already been set up by Engine.pm. EV::run; @@ -423,7 +428,9 @@ sub handle_position { # hour, the analysis/relay has most likely stopped # and we should stop hogging server resources. # - $t->cmd("date"); + if (defined($t)) { + $t->cmd("date"); + } } sub parse_infos { @@ -526,7 +533,7 @@ sub prettyprint_pv_no_cache { sub prettyprint_pv { my ($pos, @pvs) = @_; - my $cachekey = join('', @pvs); + my $cachekey = $pos->fen() . join('', @pvs); if (exists($pos->{'prettyprint_cache'}{$cachekey})) { return @{$pos->{'prettyprint_cache'}{$cachekey}}; } else { @@ -536,6 +543,8 @@ sub prettyprint_pv { } } +my %tbprobe_cache = (); + sub complete_using_tbprobe { my ($pos, $info, $mpv) = @_; @@ -553,10 +562,10 @@ sub complete_using_tbprobe { # Run through the PV until we are at a 6-man position. # TODO: We could in theory only have 5-man data. my @pv = @{$info->{'pv' . $mpv}}; - my $key = join('', @pv); + my $key = $pos->fen() . " " . join('', @pv); my @moves = (); - if (exists($pos->{'tbprobe_cache'}{$key})) { - @moves = $pos->{'tbprobe_cache'}{$key}; + if (exists($tbprobe_cache{$key})) { + @moves = @{$tbprobe_cache{$key}}; } else { if ($mpv ne '') { # Force doing at least one move of the PV. @@ -586,6 +595,8 @@ sub complete_using_tbprobe { ($pos, $uci_move) = $pos->make_pretty_move($move); push @moves, $uci_move; } + + $tbprobe_cache{$key} = \@moves; } $info->{'pv' . $mpv} = \@moves; @@ -836,6 +847,14 @@ sub output_json { if (defined($remoteglotconf::engine_details)) { $json->{'engine'}{'details'} = $remoteglotconf::engine_details; } + my @grpc_backends = (); + if (defined($remoteglotconf::engine_grpc_backend)) { + push @grpc_backends, $remoteglotconf::engine_grpc_backend; + } + if (defined($remoteglotconf::engine2_grpc_backend)) { + push @grpc_backends, $remoteglotconf::engine2_grpc_backend; + } + $json->{'internal'}{'grpc_backends'} = \@grpc_backends; if (defined($remoteglotconf::move_source)) { $json->{'move_source'} = $remoteglotconf::move_source; } @@ -1086,7 +1105,7 @@ sub score_digest { if ($score == 0 && $info->{'tablebase'}) { return ['d', undef]; } else { - return ['cp', $score]; + return ['cp', int($score)]; } } }