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 push @shistory, $inbuf;
228 shift @shistory if @shistory > $maxshist;
233 # handle incoming messages
236 my ($con, $msg, $err) = @_;
237 if (defined $err && $err) {
241 my ($sort, $call, $line) = $msg =~ /^(\w)([^\|]+)\|(.*)$/;
243 if ($sort && $sort eq 'D') {
244 $line = " " unless length($line);
246 } elsif ($sort && $sort eq 'Z') { # end, disconnect, go, away .....
249 # ******************************************************
250 # ******************************************************
251 # any other sorts that might happen are silently ignored.
252 # ******************************************************
253 # ******************************************************
267 # $prbuf =~ s/\r/\\r/;
268 # $prbuf =~ s/\n/\\n/;
269 # print "sys: $r ($prbuf)\n";
274 if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
277 $inbuf = " " unless length($inbuf);
279 # check for a pling and do a search back for a command
280 if ($inbuf =~ /^!/o) {
283 for ($i = $#khistory; $i >= 0; $i--) {
284 if ($khistory[$i] =~ /^$inbuf/) {
285 $inbuf = $khistory[$i];
294 push @khistory, $inbuf if $inbuf;
295 shift @khistory if @khistory > $maxkhist;
296 $khistpos = @khistory;
299 $bot->addstr(substr($inbuf, 0, $cols));
301 # add it to the monitor window
302 unless ($spos == @shistory) {
308 # send it to the cluster
309 $conn->send_later("I$call|$inbuf");
312 } elsif ($r eq KEY_UP || $r eq "\020") {
315 $inbuf = $khistory[$khistpos];
316 $pos = $lth = length $inbuf;
320 } elsif ($r eq KEY_DOWN || $r eq "\016") {
321 if ($khistpos < @khistory - 1) {
323 $inbuf = $khistory[$khistpos];
324 $pos = $lth = length $inbuf;
328 } elsif ($r eq KEY_PPAGE || $r eq "\032") {
331 for ($i = 0; $i <= $pagel && $spos >= 0; ) {
332 $l = measure($shistory[$spos]);
334 $spos-- if $i <= $pagel;
336 $spos = 0 if $spos < 0;
341 } elsif ($r eq KEY_NPAGE || $r eq "\026") {
342 if ($spos < @shistory - 1) {
344 for ($i = 0; $i <= $pagel && $spos <= @shistory; ) {
345 $l = measure($shistory[$spos]);
347 $spos++ if $i <= $pagel;
349 $spos = @shistory if $spos >= @shistory - 1;
354 } elsif ($r eq KEY_LEFT || $r eq "\002") {
360 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
366 } elsif ($r eq KEY_HOME || $r eq "\001") {
368 } elsif ($r eq KEY_END || $r eq "\005") {
370 } elsif ($r eq KEY_BACKSPACE || $r eq "\010" || $r eq "\0177") {
372 my $a = substr($inbuf, 0, $pos-1);
373 my $b = substr($inbuf, $pos) if $pos < $lth;
382 } elsif ($r eq KEY_DC || $r eq "\004") {
384 my $a = substr($inbuf, 0, $pos);
385 my $b = substr($inbuf, $pos+1) if $pos < $lth;
393 } elsif ($r eq KEY_RESIZE || $r eq "\0632") {
396 } elsif (defined is_pctext($r)) {
397 # move the top screen back to the bottom if you type something
398 if ($spos < @shistory) {
403 # $r = ($r lt ' ' || $r gt "\x7e") ? sprintf("'%x", ord $r) : $r;
405 # insert the character into the keyboard buffer
407 my $a = substr($inbuf, 0, $pos);
408 my $b = substr($inbuf, $pos);
409 $inbuf = $a . $r . $b;
415 } elsif ($r eq "\014" || $r eq "\022") {
419 } elsif ($r eq "\013") {
420 $inbuf = substr($inbuf, 0, $pos);
421 $lth = length $inbuf;
427 $bot->addstr($inbuf);
438 $call = uc shift @ARGV if @ARGV;
439 $call = uc $myalias if !$call;
440 my ($scall, $ssid) = split /-/, $call;
441 $ssid = undef unless $ssid && $ssid =~ /^\d+$/;
443 $ssid = 15 if $ssid > 15;
444 $call = "$scall-$ssid";
447 if ($call eq $mycall) {
448 print "You cannot connect as your cluster callsign ($mycall)\n";
454 $conn = IntMsg->connect("$clusteraddr", $clusterport, \&rec_socket);
456 if (-r "$data/offline") {
457 open IN, "$data/offline" or die;
463 print "Sorry, the cluster $mycall is currently off-line\n";
468 $conn->set_error(sub{cease(0)});
471 unless ($DB::VERSION) {
472 $SIG{'INT'} = \&sig_term;
473 $SIG{'TERM'} = \&sig_term;
476 $SIG{'HUP'} = \&sig_term;
481 $SIG{__DIE__} = \&sig_term;
483 $conn->send_later("A$call|$connsort width=$cols");
484 $conn->send_later("I$call|set/page $maxshist");
485 $conn->send_later("I$call|set/nobeep");
487 #Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
492 Msg->event_loop(1, 0.01);
494 if ($t > $lasttime) {
495 my ($min)= (gmtime($t))[1];
496 if ($min != $lastmin) {
502 my $ch = $bot->getch();
504 # mydbg("Got Resize");
513 $top->refresh() if $top->is_wintouched;