$| = 1;
select(STDOUT);
-umask 0022;
+umask 0022; # analysis.json should not be served to users.
# open the chess engine
my $engine = open_engine($remoteglotconf::engine_cmdline, 'E1', sub { handle_uci(@_, 1); });
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;
# 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 {
sub prettyprint_pv {
my ($pos, @pvs) = @_;
- my $cachekey = $pos->{'fen'} . join('', @pvs);
+ my $cachekey = $pos->fen() . join('', @pvs);
if (exists($pos->{'prettyprint_cache'}{$cachekey})) {
return @{$pos->{'prettyprint_cache'}{$cachekey}};
} else {
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;
}
if (!$historic_json_only && exists($pos_calculating->{'history'})) {
my %score_history = ();
+ local $dbh->{AutoCommit} = 0;
my $q = $dbh->prepare('SELECT * FROM scores WHERE id=?');
my $pos = Position->start_pos('white', 'black');
my $halfmove_num = 0;
($pos) = $pos->make_pretty_move($move);
}
$q->finish;
+ $dbh->commit;
# If at any point we are missing 10 consecutive moves,
# truncate the history there. This is so we don't get into