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";
43 $call = ""; # the callsign being used
44 $conn = 0; # the connection object for the cluster
45 $lasttime = time; # lasttime something happened on the interface
51 $spos = $pos = $lth = 0;
56 local *STDOUT = undef;
60 # do the screen initialisation
66 init_pair("0", $foreground, $background);
67 # init_pair(0, $background, $foreground);
68 init_pair(1, COLOR_RED, $background);
69 init_pair(2, COLOR_YELLOW, $background);
70 init_pair(3, COLOR_GREEN, $background);
71 init_pair(4, COLOR_CYAN, $background);
72 init_pair(5, COLOR_BLUE, $background);
73 init_pair(6, COLOR_MAGENTA, $background);
74 init_pair(7, COLOR_RED, COLOR_BLUE);
75 init_pair(8, COLOR_YELLOW, COLOR_BLUE);
76 init_pair(9, COLOR_GREEN, COLOR_BLUE);
77 init_pair(10, COLOR_CYAN, COLOR_BLUE);
78 init_pair(11, COLOR_BLUE, COLOR_RED);
79 init_pair(12, COLOR_MAGENTA, COLOR_BLUE);
80 init_pair(13, COLOR_YELLOW, COLOR_GREEN);
81 init_pair(14, COLOR_RED, COLOR_GREEN);
82 eval { assume_default_colors($foreground, $background) };
85 $top = $scr->subwin($lines-4, $cols, 0, 0);
90 # $scr->addstr($lines-4, 0, '-' x $cols);
91 $bot = $scr->subwin(3, $cols, $lines-3, 0);
102 $mycallcolor = COLOR_PAIR(1) unless $mycallcolor;
114 $has_colors = has_colors();
118 $SIG{'WINCH'} = sub {$winch = 1};
122 # cease communications
126 $conn->disconnect if $conn;
133 # terminate program from signal
139 # determine the colour of the line
143 foreach my $ref (@colors) {
144 if ($_[0] =~ m{$$ref[0]}) {
145 $top->attrset($$ref[1]);
152 # measure the no of screen lines a line will take
156 return 0 unless $line;
158 my $l = length $line;
159 my $lines = int ($l / $cols);
160 $lines++ if $l / $cols > $lines;
164 # display the top screen
167 if ($spos == @shistory - 1) {
169 # if we really are scrolling thru at the end of the history
170 my $line = $shistory[$spos];
171 $top->addstr("\n") if $spos > 0;
174 # $top->addstr("\n");
175 $top->attrset(COLOR_PAIR(0)) if $has_colors;
183 for ($i = 0; $i < $pagel && $p >= 0; ) {
184 $l = measure($shistory[$p]);
191 $top->attrset(COLOR_PAIR(0)) if $has_colors;
193 for ($i = 0; $i < $pagel && $p < @shistory; $p++) {
194 my $line = $shistory[$p];
195 my $lines = measure($line);
196 last if $i + $lines > $pagel;
197 $top->addstr("\n") if $i;
200 $top->attrset(COLOR_PAIR(0)) if $has_colors;
204 $spos = @shistory if $spos > @shistory;
207 my $size = $lines . 'x' . $cols . '-';
208 my $add = "-$spos-$shl";
209 my $time = ztime(time);
210 my $str = "-" . $time . '-' x ($cols - (length($size) + length($call) + length($add) + length($time) + 1));
211 $scr->addstr($lines-4, 0, $str);
214 $scr->attrset($mycallcolor) if $has_colors;
216 $scr->attrset(COLOR_PAIR(0)) if $has_colors;
222 # add a line to the end of the top screen
227 if ($inbuf =~ s/\x07+$//) {
230 push @shistory, $inbuf;
231 shift @shistory if @shistory > $maxshist;
236 # handle incoming messages
239 my ($con, $msg, $err) = @_;
240 if (defined $err && $err) {
244 my ($sort, $call, $line) = $msg =~ /^(\w)([^\|]+)\|(.*)$/;
246 $line =~ s/[\x00-\x06\x08\x0a-\x19\x1b-\x1f\x80-\x9f\xf0-\xff]/./g; # immutable CSI sequence + control characters
247 if ($sort && $sort eq 'D') {
248 $line = " " unless length($line);
250 } elsif ($sort && $sort eq 'Z') { # end, disconnect, go, away .....
253 # ******************************************************
254 # ******************************************************
255 # any other sorts that might happen are silently ignored.
256 # ******************************************************
257 # ******************************************************
271 # $prbuf =~ s/\r/\\r/;
272 # $prbuf =~ s/\n/\\n/;
273 # print "sys: $r ($prbuf)\n";
278 if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
281 $inbuf = " " unless length($inbuf);
283 # check for a pling and do a search back for a command
284 if ($inbuf =~ /^!/o) {
287 for ($i = $#khistory; $i >= 0; $i--) {
288 if ($khistory[$i] =~ /^$inbuf/) {
289 $inbuf = $khistory[$i];
298 push @khistory, $inbuf if $inbuf;
299 shift @khistory if @khistory > $maxkhist;
300 $khistpos = @khistory;
303 $bot->addstr(substr($inbuf, 0, $cols));
305 # add it to the monitor window
306 unless ($spos == @shistory) {
312 # send it to the cluster
313 $conn->send_later("I$call|$inbuf");
316 } elsif ($r eq KEY_UP || $r eq "\020") {
319 $inbuf = $khistory[$khistpos];
320 $pos = $lth = length $inbuf;
324 } elsif ($r eq KEY_DOWN || $r eq "\016") {
325 if ($khistpos < @khistory - 1) {
327 $inbuf = $khistory[$khistpos];
328 $pos = $lth = length $inbuf;
332 } elsif ($r eq KEY_PPAGE || $r eq "\032") {
335 for ($i = 0; $i <= $pagel && $spos >= 0; ) {
336 $l = measure($shistory[$spos]);
338 $spos-- if $i <= $pagel;
340 $spos = 0 if $spos < 0;
345 } elsif ($r eq KEY_NPAGE || $r eq "\026") {
346 if ($spos < @shistory - 1) {
348 for ($i = 0; $i <= $pagel && $spos <= @shistory; ) {
349 $l = measure($shistory[$spos]);
351 $spos++ if $i <= $pagel;
353 $spos = @shistory if $spos >= @shistory - 1;
358 } elsif ($r eq KEY_LEFT || $r eq "\002") {
364 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
370 } elsif ($r eq KEY_HOME || $r eq "\001") {
372 } elsif ($r eq KEY_END || $r eq "\005") {
374 } elsif ($r eq KEY_BACKSPACE || $r eq "\010" || $r eq "\x7f") {
376 my $a = substr($inbuf, 0, $pos-1);
377 my $b = substr($inbuf, $pos) if $pos < $lth;
386 } elsif ($r eq KEY_DC || $r eq "\004") {
388 my $a = substr($inbuf, 0, $pos);
389 my $b = substr($inbuf, $pos+1) if $pos < $lth;
397 } elsif ($r eq KEY_RESIZE || $r eq "\0632") {
400 } elsif (defined is_pctext($r)) {
401 # move the top screen back to the bottom if you type something
402 if ($spos < @shistory) {
407 # $r = ($r lt ' ' || $r gt "\x7e") ? sprintf("'%x", ord $r) : $r;
409 # insert the character into the keyboard buffer
411 my $a = substr($inbuf, 0, $pos);
412 my $b = substr($inbuf, $pos);
413 $inbuf = $a . $r . $b;
419 } elsif ($r eq "\014" || $r eq "\022") {
423 } elsif ($r eq "\013") {
424 $inbuf = substr($inbuf, 0, $pos);
425 $lth = length $inbuf;
431 $bot->addstr($inbuf);
442 $call = uc shift @ARGV if @ARGV;
443 $call = uc $myalias if !$call;
444 my ($scall, $ssid) = split /-/, $call;
445 $ssid = undef unless $ssid && $ssid =~ /^\d+$/;
447 $ssid = 15 if $ssid > 15;
448 $call = "$scall-$ssid";
451 if ($call eq $mycall) {
452 print "You cannot connect as your cluster callsign ($mycall)\n";
458 $conn = IntMsg->connect("$clusteraddr", $clusterport, \&rec_socket);
460 if (-r "$data/offline") {
461 open IN, "$data/offline" or die;
467 print "Sorry, the cluster $mycall is currently off-line\n";
472 $conn->set_error(sub{cease(0)});
475 unless ($DB::VERSION) {
476 $SIG{'INT'} = \&sig_term;
477 $SIG{'TERM'} = \&sig_term;
480 $SIG{'HUP'} = \&sig_term;
485 $SIG{__DIE__} = \&sig_term;
487 $conn->send_later("A$call|$connsort width=$cols");
488 $conn->send_later("I$call|set/page $maxshist");
489 #$conn->send_later("I$call|set/nobeep");
491 #Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
496 Msg->event_loop(1, 0.01);
498 if ($t > $lasttime) {
499 my ($min)= (gmtime($t))[1];
500 if ($min != $lastmin) {
506 my $ch = $bot->getch();
508 # mydbg("Got Resize");
517 $top->refresh() if $top->is_wintouched;