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 assume_default_colors($foreground, $background);
85 $top = $scr->subwin($lines-4, $cols, 0, 0);
89 # $scr->addstr($lines-4, 0, '-' x $cols);
90 $bot = $scr->subwin(3, $cols, $lines-3, 0);
100 $mycallcolor = COLOR_PAIR(1) unless $mycallcolor;
111 $has_colors = has_colors();
115 $SIG{'WINCH'} = sub {$winch = 1};
119 # cease communications
123 $conn->disconnect if $conn;
130 # terminate program from signal
136 # determine the colour of the line
140 foreach my $ref (@colors) {
141 if ($_[0] =~ m{$$ref[0]}) {
142 $top->attrset($$ref[1]);
149 # measure the no of screen lines a line will take
153 return 0 unless $line;
155 my $l = length $line;
156 my $lines = int ($l / $cols);
157 $lines++ if $l / $cols > $lines;
161 # display the top screen
164 if ($spos == @shistory - 1) {
166 # if we really are scrolling thru at the end of the history
167 my $line = $shistory[$spos];
168 $top->addstr("\n") if $spos > 0;
171 $top->attrset(COLOR_PAIR(0)) if $has_colors;
179 for ($i = 0; $i < $pagel && $p >= 0; ) {
180 $l = measure($shistory[$p]);
187 $top->attrset(COLOR_PAIR(0)) if $has_colors;
189 for ($i = 0; $i < $pagel && $p < @shistory; $p++) {
190 my $line = $shistory[$p];
191 my $lines = measure($line);
192 last if $i + $lines > $pagel;
194 $top->addstr($i, 0, $line);
195 $top->attrset(COLOR_PAIR(0)) if $has_colors;
199 $spos = @shistory if $spos > @shistory;
202 my $size = $lines . 'x' . $cols . '-';
203 my $add = "-$spos-$shl";
204 my $time = ztime(time);
205 my $str = "-" . $time . '-' x ($cols - (length($size) + length($call) + length($add) + length($time) + 1));
206 $scr->addstr($lines-4, 0, $str);
209 $scr->attrset($mycallcolor) if $has_colors;
211 $scr->attrset(COLOR_PAIR(0)) if $has_colors;
217 # add a line to the end of the top screen
222 push @shistory, $inbuf;
223 shift @shistory if @shistory > $maxshist;
228 # handle incoming messages
231 my ($con, $msg, $err) = @_;
232 if (defined $err && $err) {
236 my ($sort, $call, $line) = $msg =~ /^(\w)([^\|]+)\|(.*)$/;
238 if ($sort && $sort eq 'D') {
240 } elsif ($sort && $sort eq 'Z') { # end, disconnect, go, away .....
243 # ******************************************************
244 # ******************************************************
245 # any other sorts that might happen are silently ignored.
246 # ******************************************************
247 # ******************************************************
261 # $prbuf =~ s/\r/\\r/;
262 # $prbuf =~ s/\n/\\n/;
263 # print "sys: $r ($prbuf)\n";
267 if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
271 # check for a pling and do a search back for a command
272 if ($inbuf =~ /^!/o) {
275 for ($i = $#khistory; $i >= 0; $i--) {
276 if ($khistory[$i] =~ /^$inbuf/) {
277 $inbuf = $khistory[$i];
286 push @khistory, $inbuf if $inbuf;
287 shift @khistory if @khistory > $maxkhist;
288 $khistpos = @khistory;
291 $bot->addstr(substr($inbuf, 0, $cols));
294 # add it to the monitor window
295 unless ($spos == @shistory) {
299 addtotop($inbuf) if $inbuf;
301 # send it to the cluster
302 $inbuf = " " unless $inbuf;
303 $conn->send_later("I$call|$inbuf");
306 } elsif ($r eq KEY_UP || $r eq "\020") {
309 $inbuf = $khistory[$khistpos];
310 $pos = $lth = length $inbuf;
314 } elsif ($r eq KEY_DOWN || $r eq "\016") {
315 if ($khistpos < @khistory - 1) {
317 $inbuf = $khistory[$khistpos];
318 $pos = $lth = length $inbuf;
322 } elsif ($r eq KEY_PPAGE || $r eq "\032") {
325 for ($i = 0; $i <= $pagel && $spos >= 0; ) {
326 $l = measure($shistory[$spos]);
328 $spos-- if $i <= $pagel;
330 $spos = 0 if $spos < 0;
335 } elsif ($r eq KEY_NPAGE || $r eq "\026") {
336 if ($spos < @shistory - 1) {
338 for ($i = 0; $i <= $pagel && $spos <= @shistory; ) {
339 $l = measure($shistory[$spos]);
341 $spos++ if $i <= $pagel;
343 $spos = @shistory if $spos >= @shistory - 1;
348 } elsif ($r eq KEY_LEFT || $r eq "\002") {
354 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
360 } elsif ($r eq KEY_HOME || $r eq "\001") {
362 } elsif ($r eq KEY_END || $r eq "\005") {
364 } elsif ($r eq KEY_BACKSPACE || $r eq "\010") {
366 my $a = substr($inbuf, 0, $pos-1);
367 my $b = substr($inbuf, $pos) if $pos < $lth;
376 } elsif ($r eq KEY_DC || $r eq "\004") {
378 my $a = substr($inbuf, 0, $pos);
379 my $b = substr($inbuf, $pos+1) if $pos < $lth;
387 } elsif ($r eq KEY_RESIZE || $r eq "\0632") {
390 } elsif (is_pctext($r)) {
391 # move the top screen back to the bottom if you type something
392 if ($spos < @shistory) {
397 # $r = ($r lt ' ' || $r gt "\x7e") ? sprintf("'%x", ord $r) : $r;
399 # insert the character into the keyboard buffer
401 my $a = substr($inbuf, 0, $pos);
402 my $b = substr($inbuf, $pos);
403 $inbuf = $a . $r . $b;
409 } elsif ($r eq "\014" || $r eq "\022") {
413 } elsif ($r eq "\013") {
414 $inbuf = substr($inbuf, 0, $pos);
415 $lth = length $inbuf;
421 $bot->addstr($inbuf);
432 $call = uc shift @ARGV if @ARGV;
433 $call = uc $myalias if !$call;
434 my ($scall, $ssid) = split /-/, $call;
435 $ssid = undef unless $ssid && $ssid =~ /^\d+$/;
437 $ssid = 15 if $ssid > 15;
438 $call = "$scall-$ssid";
441 if ($call eq $mycall) {
442 print "You cannot connect as your cluster callsign ($mycall)\n";
448 $conn = IntMsg->connect("$clusteraddr", $clusterport, \&rec_socket);
450 if (-r "$data/offline") {
451 open IN, "$data/offline" or die;
457 print "Sorry, the cluster $mycall is currently off-line\n";
462 $conn->set_error(sub{cease(0)});
465 unless ($DB::VERSION) {
466 $SIG{'INT'} = \&sig_term;
467 $SIG{'TERM'} = \&sig_term;
470 $SIG{'HUP'} = \&sig_term;
475 $SIG{__DIE__} = \&sig_term;
477 $conn->send_later("A$call|$connsort width=$cols");
478 $conn->send_later("I$call|set/page $maxshist");
479 $conn->send_later("I$call|set/nobeep");
481 #Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
486 Msg->event_loop(1, 0.01);
488 if ($t > $lasttime) {
489 my ($min)= (gmtime($t))[1];
490 if ($min != $lastmin) {
496 my $ch = $bot->getch();
498 # mydbg("Got Resize");
507 $top->refresh() if $top->is_wintouched;