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;
54 # do the screen initialisation
60 $has_colors = has_colors();
64 init_pair(0, $foreground, $background);
65 init_pair(1, COLOR_RED, $background);
66 init_pair(2, COLOR_YELLOW, $background);
67 init_pair(3, COLOR_GREEN, $background);
68 init_pair(4, COLOR_CYAN, $background);
69 init_pair(5, COLOR_BLUE, $background);
70 init_pair(6, COLOR_MAGENTA, $background);
71 init_pair(7, COLOR_RED, COLOR_BLUE);
72 init_pair(8, COLOR_YELLOW, COLOR_BLUE);
73 init_pair(9, COLOR_GREEN, COLOR_BLUE);
74 init_pair(10, COLOR_CYAN, COLOR_BLUE);
75 init_pair(11, COLOR_BLUE, COLOR_RED);
76 init_pair(12, COLOR_MAGENTA, COLOR_BLUE);
77 init_pair(13, COLOR_YELLOW, COLOR_GREEN);
78 init_pair(14, COLOR_RED, COLOR_GREEN);
81 $top = $scr->subwin(LINES()-4, COLS, 0, 0);
84 $scr->addstr(LINES()-4, 0, '-' x COLS);
85 $bot = $scr->subwin(3, COLS, LINES()-3, 0);
93 $mycallcolor = COLOR_PAIR(1) unless $mycallcolor;
102 # cease communications
106 if ($conn && $sendz) {
107 $conn->send_now("Z$call|bye...\n");
115 # terminate program from signal
121 # determine the colour of the line
125 foreach my $ref (@colors) {
126 if ($_[0] =~ m{$$ref[0]}) {
127 $top->attrset($$ref[1]);
134 # measure the no of screen lines a line will take
138 return 0 unless $line;
140 my $l = length $line;
141 my $lines = int ($l / COLS());
142 $lines++ if $l / COLS() > $lines;
146 # display the top screen
149 if ($spos == @shistory - 1) {
151 # if we really are scrolling thru at the end of the history
152 my $line = $shistory[$spos];
153 $top->addstr("\n") if $spos > 0;
156 $top->attrset(COLOR_PAIR(0)) if $has_colors;
164 for ($i = 0; $i < $pagel && $p >= 0; ) {
165 $l = measure($shistory[$p]);
172 $top->attrset(COLOR_PAIR(0)) if $has_colors;
174 for ($i = 0; $i < $pagel && $p < @shistory; $p++) {
175 my $line = $shistory[$p];
176 my $lines = measure($line);
177 last if $i + $lines > $pagel;
179 $top->addstr($i, 0, $line);
180 $top->attrset(COLOR_PAIR(0)) if $has_colors;
184 $spos = @shistory if $spos > @shistory;
187 my $add = "-$spos-$shl";
188 my $time = ztime(time);
189 my $str = "-" . $time . '-' x (COLS() - (length($call) + length($add) + length($time) + 1));
190 $scr->addstr(LINES()-4, 0, $str);
192 $scr->attrset($mycallcolor) if $has_colors;
193 $scr->addstr("$call");
194 $scr->attrset(COLOR_PAIR(0)) if $has_colors;
200 # add a line to the end of the top screen
205 push @shistory, $inbuf;
206 shift @shistory if @shistory > $maxshist;
211 # handle incoming messages
214 my ($con, $msg, $err) = @_;
215 if (defined $err && $err) {
219 my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/;
221 if ($sort && $sort eq 'D') {
223 } elsif ($sort && $sort eq 'Z') { # end, disconnect, go, away .....
239 # $prbuf =~ s/\r/\\r/;
240 # $prbuf =~ s/\n/\\n/;
241 # print "sys: $r ($prbuf)\n";
244 if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
248 # check for a pling and do a search back for a command
249 if ($inbuf =~ /^!/o) {
252 for ($i = $#khistory; $i >= 0; $i--) {
253 if ($khistory[$i] =~ /^$inbuf/) {
254 $inbuf = $khistory[$i];
263 push @khistory, $inbuf if $inbuf;
264 shift @khistory if @khistory > $maxkhist;
265 $khistpos = @khistory;
268 $bot->addstr(substr($inbuf, 0, COLS));
271 # add it to the monitor window
272 unless ($spos == @shistory) {
276 addtotop($inbuf) if $inbuf;
278 # send it to the cluster
279 $inbuf = " " unless $inbuf;
280 $conn->send_later("I$call|$inbuf");
283 } elsif ($r eq KEY_UP || $r eq "\020") {
286 $inbuf = $khistory[$khistpos];
287 $pos = $lth = length $inbuf;
291 } elsif ($r eq KEY_DOWN || $r eq "\016") {
292 if ($khistpos < @khistory - 1) {
294 $inbuf = $khistory[$khistpos];
295 $pos = $lth = length $inbuf;
299 } elsif ($r eq KEY_PPAGE || $r eq "\032") {
302 for ($i = 0; $i <= $pagel && $spos >= 0; ) {
303 $l = measure($shistory[$spos]);
305 $spos-- if $i <= $pagel;
307 $spos = 0 if $spos < 0;
312 } elsif ($r eq KEY_NPAGE || $r eq "\026") {
313 if ($spos < @shistory - 1) {
315 for ($i = 0; $i <= $pagel && $spos <= @shistory; ) {
316 $l = measure($shistory[$spos]);
318 $spos++ if $i <= $pagel;
320 $spos = @shistory if $spos >= @shistory - 1;
325 } elsif ($r eq KEY_LEFT || $r eq "\002") {
331 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
337 } elsif ($r eq KEY_HOME || $r eq "\001") {
339 } elsif ($r eq KEY_END || $r eq "\005") {
341 } elsif ($r eq KEY_BACKSPACE || $r eq "\010") {
343 my $a = substr($inbuf, 0, $pos-1);
344 my $b = substr($inbuf, $pos) if $pos < $lth;
353 } elsif ($r eq KEY_DC || $r eq "\004") {
355 my $a = substr($inbuf, 0, $pos);
356 my $b = substr($inbuf, $pos+1) if $pos < $lth;
364 } elsif ($r ge ' ' && $r le '~') {
365 # move the top screen back to the bottom if you type something
366 if ($spos < @shistory) {
371 # insert the character into the keyboard buffer
373 my $a = substr($inbuf, 0, $pos);
374 my $b = substr($inbuf, $pos);
375 $inbuf = $a . $r . $b;
381 } elsif ($r eq "\014" || $r eq "\022") {
384 } elsif ($r eq "\013") {
385 $inbuf = substr($inbuf, 0, $pos);
386 $lth = length $inbuf;
392 $bot->addstr($inbuf);
403 $call = uc shift @ARGV if @ARGV;
404 $call = uc $myalias if !$call;
406 if ($call eq $mycall) {
407 print "You cannot connect as your cluster callsign ($mycall)\n";
411 $conn = Msg->connect("$clusteraddr", $clusterport, \&rec_socket);
413 if (-r "$data/offline") {
414 open IN, "$data/offline" or die;
420 print "Sorry, the cluster $mycall is currently off-line\n";
426 $SIG{'INT'} = \&sig_term;
427 $SIG{'TERM'} = \&sig_term;
428 #$SIG{'WINCH'} = \&do_resize;
429 $SIG{'HUP'} = 'IGNORE';
433 $SIG{__DIE__} = \&sig_term;
435 $conn->send_now("A$call|$connsort");
436 $conn->send_now("I$call|set/page $maxshist");
437 $conn->send_now("I$call|set/nobeep");
439 Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
444 Msg->event_loop(1, 1);
446 if ($t > $lasttime) {
447 my ($min)= (gmtime($t))[1];
448 if ($min != $lastmin) {
454 $top->refresh() if $top->is_wintouched;