]> git.sesse.net Git - remoteglot/blobdiff - remoteglot.pl
Add an option not to connect to FICS at all.
[remoteglot] / remoteglot.pl
index 55464e6e2716abafc287d427ad85d8d3daab58a9..4b674969c204e24c3a575c633cee431fbef4bf42 100755 (executable)
@@ -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:/) {
                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 {
@@ -1090,7 +1097,7 @@ sub score_digest {
                        if ($score == 0 && $info->{'tablebase'}) {
                                return ['d', undef];
                        } else {
-                               return ['cp', $score];
+                               return ['cp', int($score)];
                        }
                }
        }