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";
42 $call = ""; # the callsign being used
43 $conn = 0; # the connection object for the cluster
44 $lasttime = time; # lasttime something happened on the interface
50 $spos = $pos = $lth = 0;
53 # do the screen initialisation
59 $has_colors = has_colors();
63 init_pair("0", $foreground, $background);
64 # init_pair(0, $background, $foreground);
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);
79 $scr->attrset(COLOR_PAIR(0));
82 $top = $scr->subwin(LINES()-4, COLS, 0, 0);
85 $scr->addstr(LINES()-4, 0, '-' x COLS);
86 $bot = $scr->subwin(3, COLS, LINES()-3, 0);
94 $mycallcolor = COLOR_PAIR(1) unless $mycallcolor;
103 # cease communications
107 # if ($conn && $sendz) {
108 # $conn->send_now("Z$call|bye...");
116 # terminate program from signal
122 # determine the colour of the line
126 foreach my $ref (@colors) {
127 if ($_[0] =~ m{$$ref[0]}) {
128 $top->attrset($$ref[1]);
135 # measure the no of screen lines a line will take
139 return 0 unless $line;
141 my $l = length $line;
142 my $lines = int ($l / COLS());
143 $lines++ if $l / COLS() > $lines;
147 # display the top screen
150 if ($spos == @shistory - 1) {
152 # if we really are scrolling thru at the end of the history
153 my $line = $shistory[$spos];
154 $top->addstr("\n") if $spos > 0;
157 $top->attrset(COLOR_PAIR(0)) if $has_colors;
165 for ($i = 0; $i < $pagel && $p >= 0; ) {
166 $l = measure($shistory[$p]);
173 $top->attrset(COLOR_PAIR(0)) if $has_colors;
175 for ($i = 0; $i < $pagel && $p < @shistory; $p++) {
176 my $line = $shistory[$p];
177 my $lines = measure($line);
178 last if $i + $lines > $pagel;
180 $top->addstr($i, 0, $line);
181 $top->attrset(COLOR_PAIR(0)) if $has_colors;
185 $spos = @shistory if $spos > @shistory;
188 my $add = "-$spos-$shl";
189 my $time = ztime(time);
190 my $str = "-" . $time . '-' x (COLS() - (length($call) + length($add) + length($time) + 1));
191 $scr->addstr(LINES()-4, 0, $str);
193 $scr->attrset($mycallcolor) if $has_colors;
194 $scr->addstr("$call");
195 $scr->attrset(COLOR_PAIR(0)) if $has_colors;
201 # add a line to the end of the top screen
206 push @shistory, $inbuf;
207 shift @shistory if @shistory > $maxshist;
212 # handle incoming messages
215 my ($con, $msg, $err) = @_;
216 if (defined $err && $err) {
220 my ($sort, $call, $line) = $msg =~ /^(\w)([^\|]+)\|(.*)$/;
222 if ($sort && $sort eq 'D') {
224 } elsif ($sort && $sort eq 'Z') { # end, disconnect, go, away .....
227 # ******************************************************
228 # ******************************************************
229 # any other sorts that might happen are silently ignored.
230 # ******************************************************
231 # ******************************************************
247 # $prbuf =~ s/\r/\\r/;
248 # $prbuf =~ s/\n/\\n/;
249 # print "sys: $r ($prbuf)\n";
252 if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
256 # check for a pling and do a search back for a command
257 if ($inbuf =~ /^!/o) {
260 for ($i = $#khistory; $i >= 0; $i--) {
261 if ($khistory[$i] =~ /^$inbuf/) {
262 $inbuf = $khistory[$i];
271 push @khistory, $inbuf if $inbuf;
272 shift @khistory if @khistory > $maxkhist;
273 $khistpos = @khistory;
276 $bot->addstr(substr($inbuf, 0, COLS));
279 # add it to the monitor window
280 unless ($spos == @shistory) {
284 addtotop($inbuf) if $inbuf;
286 # send it to the cluster
287 $inbuf = " " unless $inbuf;
288 $conn->send_later("I$call|$inbuf");
291 } elsif ($r eq KEY_UP || $r eq "\020") {
294 $inbuf = $khistory[$khistpos];
295 $pos = $lth = length $inbuf;
299 } elsif ($r eq KEY_DOWN || $r eq "\016") {
300 if ($khistpos < @khistory - 1) {
302 $inbuf = $khistory[$khistpos];
303 $pos = $lth = length $inbuf;
307 } elsif ($r eq KEY_PPAGE || $r eq "\032") {
310 for ($i = 0; $i <= $pagel && $spos >= 0; ) {
311 $l = measure($shistory[$spos]);
313 $spos-- if $i <= $pagel;
315 $spos = 0 if $spos < 0;
320 } elsif ($r eq KEY_NPAGE || $r eq "\026") {
321 if ($spos < @shistory - 1) {
323 for ($i = 0; $i <= $pagel && $spos <= @shistory; ) {
324 $l = measure($shistory[$spos]);
326 $spos++ if $i <= $pagel;
328 $spos = @shistory if $spos >= @shistory - 1;
333 } elsif ($r eq KEY_LEFT || $r eq "\002") {
339 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
345 } elsif ($r eq KEY_HOME || $r eq "\001") {
347 } elsif ($r eq KEY_END || $r eq "\005") {
349 } elsif ($r eq KEY_BACKSPACE || $r eq "\010") {
351 my $a = substr($inbuf, 0, $pos-1);
352 my $b = substr($inbuf, $pos) if $pos < $lth;
361 } elsif ($r eq KEY_DC || $r eq "\004") {
363 my $a = substr($inbuf, 0, $pos);
364 my $b = substr($inbuf, $pos+1) if $pos < $lth;
372 } elsif (is_pctext($r)) {
373 # move the top screen back to the bottom if you type something
374 if ($spos < @shistory) {
379 # insert the character into the keyboard buffer
381 my $a = substr($inbuf, 0, $pos);
382 my $b = substr($inbuf, $pos);
383 $inbuf = $a . $r . $b;
389 } elsif ($r eq "\014" || $r eq "\022") {
390 touchwin($curscr, 1);
393 } elsif ($r eq "\013") {
394 $inbuf = substr($inbuf, 0, $pos);
395 $lth = length $inbuf;
401 $bot->addstr($inbuf);
412 $call = uc shift @ARGV if @ARGV;
413 $call = uc $myalias if !$call;
414 my ($scall, $ssid) = split /-/, $call;
415 $ssid = undef unless $ssid && $ssid =~ /^\d+$/;
417 $ssid = 15 if $ssid > 15;
418 $call = "$scall-$ssid";
421 if ($call eq $mycall) {
422 print "You cannot connect as your cluster callsign ($mycall)\n";
426 $conn = IntMsg->connect("$clusteraddr", $clusterport, \&rec_socket);
428 if (-r "$data/offline") {
429 open IN, "$data/offline" or die;
435 print "Sorry, the cluster $mycall is currently off-line\n";
441 unless ($DB::VERSION) {
442 $SIG{'INT'} = \&sig_term;
443 $SIG{'TERM'} = \&sig_term;
446 #$SIG{'WINCH'} = \&do_resize;
447 $SIG{'HUP'} = \&sig_term;
451 $SIG{__DIE__} = \&sig_term;
453 $conn->send_later("A$call|$connsort");
454 $conn->send_later("I$call|set/page $maxshist");
455 $conn->send_later("I$call|set/nobeep");
457 Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
462 Msg->event_loop(1, 0.1);
464 if ($t > $lasttime) {
465 my ($min)= (gmtime($t))[1];
466 if ($min != $lastmin) {
472 $top->refresh() if $top->is_wintouched;