3 # this is the operators console.
7 # console.pl [callsign]
9 # if the callsign isn't given then the sysop callsign in DXVars.pm is assumed
11 # Copyright (c) 1999 Dirk Koopman G1TLH
18 # search local then perl directories
20 # root of directory tree for this system
22 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
24 unshift @INC, "$root/perl"; # this IS the right way round!
25 unshift @INC, "$root/local";
30 my ($v, $b) = $s =~ /(\d+\.\d+)(?:\.(\d+\.\d+))?/;
31 $main::build += sprintf "%.3f", $v;
32 $main::branch += sprintf("%.3f", $b) if $b;
43 use Time::HiRes qw(gettimeofday tv_interval);
52 $call = ""; # the callsign being used
53 $conn = 0; # the connection object for the cluster
54 $lasttime = time; # lasttime something happened on the interface
60 $spos = $pos = $lth = 0;
64 $SIG{WINCH} = sub {@time = gettimeofday};
68 local *STDOUT = undef;
72 # do the screen initialisation
78 init_pair("0", $foreground, $background);
79 # init_pair(0, $background, $foreground);
80 init_pair(1, COLOR_RED, $background);
81 init_pair(2, COLOR_YELLOW, $background);
82 init_pair(3, COLOR_GREEN, $background);
83 init_pair(4, COLOR_CYAN, $background);
84 init_pair(5, COLOR_BLUE, $background);
85 init_pair(6, COLOR_MAGENTA, $background);
86 init_pair(7, COLOR_RED, COLOR_BLUE);
87 init_pair(8, COLOR_YELLOW, COLOR_BLUE);
88 init_pair(9, COLOR_GREEN, COLOR_BLUE);
89 init_pair(10, COLOR_CYAN, COLOR_BLUE);
90 init_pair(11, COLOR_BLUE, COLOR_RED);
91 init_pair(12, COLOR_MAGENTA, COLOR_BLUE);
92 init_pair(13, COLOR_YELLOW, COLOR_GREEN);
93 init_pair(14, COLOR_RED, COLOR_GREEN);
94 eval { assume_default_colors($foreground, $background) };
97 $top = $scr->subwin($lines-4, $cols, 0, 0);
102 # $scr->addstr($lines-4, 0, '-' x $cols);
103 $bot = $scr->subwin(3, $cols, $lines-3, 0);
114 $mycallcolor = COLOR_PAIR(1) unless $mycallcolor;
126 $has_colors = has_colors();
132 # cease communications
136 $conn->disconnect if $conn;
143 # terminate program from signal
149 # determine the colour of the line
153 foreach my $ref (@colors) {
154 if ($_[0] =~ m{$$ref[0]}) {
155 $top->attrset($$ref[1]);
162 # measure the no of screen lines a line will take
166 return 0 unless $line;
168 my $l = length $line;
169 my $lines = int ($l / $cols);
170 $lines++ if $l / $cols > $lines;
174 # display the top screen
177 if ($spos == @shistory - 1) {
179 # if we really are scrolling thru at the end of the history
180 my $line = $shistory[$spos];
181 $top->addstr("\n") if $spos > 0;
184 # $top->addstr("\n");
185 $top->attrset(COLOR_PAIR(0)) if $has_colors;
193 for ($i = 0; $i < $pagel && $p >= 0; ) {
194 $l = measure($shistory[$p]);
201 $top->attrset(COLOR_PAIR(0)) if $has_colors;
203 for ($i = 0; $i < $pagel && $p < @shistory; $p++) {
204 my $line = $shistory[$p];
205 my $lines = measure($line);
206 last if $i + $lines > $pagel;
207 $top->addstr("\n") if $i;
210 $top->attrset(COLOR_PAIR(0)) if $has_colors;
214 $spos = @shistory if $spos > @shistory;
217 my $size = $lines . 'x' . $cols . '-';
218 my $add = "-$spos-$shl";
219 my $time = ztime(time);
220 my $str = "-" . $time . '-' x ($cols - (length($size) + length($call) + length($add) + length($time) + 1));
221 $scr->addstr($lines-4, 0, $str);
224 $scr->attrset($mycallcolor) if $has_colors;
226 $scr->attrset(COLOR_PAIR(0)) if $has_colors;
232 # add a line to the end of the top screen
237 if ($inbuf =~ s/\x07+$//) {
240 push @shistory, $inbuf;
241 shift @shistory if @shistory > $maxshist;
246 # handle incoming messages
249 my ($con, $msg, $err) = @_;
250 if (defined $err && $err) {
254 my ($sort, $call, $line) = $msg =~ /^(\w)([^\|]+)\|(.*)$/;
256 $line =~ s/[\x00-\x06\x08\x0a-\x19\x1b-\x1f\x80-\x9f]/./g; # immutable CSI sequence + control characters
257 if ($sort && $sort eq 'D') {
258 $line = " " unless length($line);
260 } elsif ($sort && $sort eq 'Z') { # end, disconnect, go, away .....
263 # ******************************************************
264 # ******************************************************
265 # any other sorts that might happen are silently ignored.
266 # ******************************************************
267 # ******************************************************
281 # $prbuf =~ s/\r/\\r/;
282 # $prbuf =~ s/\n/\\n/;
283 # print "sys: $r ($prbuf)\n";
288 if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
291 $inbuf = " " unless length $inbuf;
293 # check for a pling and do a search back for a command
294 if ($inbuf =~ /^!/o) {
297 for ($i = $#khistory; $i >= 0; $i--) {
298 if ($khistory[$i] =~ /^$inbuf/) {
299 $inbuf = $khistory[$i];
308 push @khistory, $inbuf if length $inbuf;
309 shift @khistory if @khistory > $maxkhist;
310 $khistpos = @khistory;
313 $bot->addstr(substr($inbuf, 0, $cols));
315 # add it to the monitor window
316 unless ($spos == @shistory) {
322 # send it to the cluster
323 $conn->send_later("I$call|$inbuf");
326 } elsif ($r eq KEY_UP || $r eq "\020") {
329 $inbuf = $khistory[$khistpos];
330 $pos = $lth = length $inbuf;
334 } elsif ($r eq KEY_DOWN || $r eq "\016") {
335 if ($khistpos < @khistory - 1) {
337 $inbuf = $khistory[$khistpos];
338 $pos = $lth = length $inbuf;
342 } elsif ($r eq KEY_PPAGE || $r eq "\032") {
345 for ($i = 0; $i <= $pagel-1 && $spos >= 0; ) {
346 $l = measure($shistory[$spos]);
348 $spos-- if $i <= $pagel;
350 $spos = 0 if $spos < 0;
355 } elsif ($r eq KEY_NPAGE || $r eq "\026") {
356 if ($spos < @shistory - 1) {
358 for ($i = 0; $i <= $pagel && $spos <= @shistory; ) {
359 $l = measure($shistory[$spos]);
361 $spos++ if $i <= $pagel;
363 $spos = @shistory if $spos >= @shistory - 1;
368 } elsif ($r eq KEY_LEFT || $r eq "\002") {
374 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
380 } elsif ($r eq KEY_HOME || $r eq "\001") {
382 } elsif ($r eq KEY_END || $r eq "\005") {
384 } elsif ($r eq KEY_BACKSPACE || $r eq "\010" || $r eq "\x7f") {
386 my $a = substr($inbuf, 0, $pos-1);
387 my $b = substr($inbuf, $pos) if $pos < $lth;
396 } elsif ($r eq KEY_DC || $r eq "\004") {
398 my $a = substr($inbuf, 0, $pos);
399 my $b = substr($inbuf, $pos+1) if $pos < $lth;
407 } elsif ($r eq KEY_RESIZE || $r eq "\0632") {
410 } elsif (defined $r && is_pctext($r)) {
411 # move the top screen back to the bottom if you type something
412 if ($spos < @shistory) {
417 # $r = ($r lt ' ' || $r gt "\x7e") ? sprintf("'%x", ord $r) : $r;
419 # insert the character into the keyboard buffer
421 my $a = substr($inbuf, 0, $pos);
422 my $b = substr($inbuf, $pos);
423 $inbuf = $a . $r . $b;
429 } elsif ($r eq "\014" || $r eq "\022") {
433 } elsif ($r eq "\013") {
434 $inbuf = substr($inbuf, 0, $pos);
435 $lth = length $inbuf;
441 $bot->addstr($inbuf);
452 $call = uc shift @ARGV if @ARGV;
453 $call = uc $myalias if !$call;
454 my ($scall, $ssid) = split /-/, $call;
455 $ssid = undef unless $ssid && $ssid =~ /^\d+$/;
457 $ssid = 15 if $ssid > 15;
458 $call = "$scall-$ssid";
461 if ($call eq $mycall) {
462 print "You cannot connect as your cluster callsign ($mycall)\n";
468 $conn = IntMsg->connect("$clusteraddr", $clusterport, \&rec_socket);
470 if (-r "$data/offline") {
471 open IN, "$data/offline" or die;
477 print "Sorry, the cluster $mycall is currently off-line\n";
482 $conn->set_error(sub{cease(0)});
485 unless ($DB::VERSION) {
486 $SIG{'INT'} = \&sig_term;
487 $SIG{'TERM'} = \&sig_term;
490 $SIG{'HUP'} = \&sig_term;
495 $SIG{__DIE__} = \&sig_term;
497 $conn->send_later("A$call|$connsort width=$cols");
498 $conn->send_later("I$call|set/page $maxshist");
499 #$conn->send_later("I$call|set/nobeep");
501 #Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
506 Msg->event_loop(1, 0.01);
508 if ($t > $lasttime) {
509 my ($min)= (gmtime($t))[1];
510 if ($min != $lastmin) {
516 my $ch = $bot->getch();
517 if (@time && tv_interval(\@time, [gettimeofday]) >= 1) {
518 # mydbg("Got Resize");
527 $top->refresh() if $top->is_wintouched;