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";
41 $call = ""; # the callsign being used
42 $conn = 0; # the connection object for the cluster
43 $lasttime = time; # lasttime something happened on the interface
49 $spos = $pos = $lth = 0;
52 # do the screen initialisation
58 $has_colors = has_colors();
62 init_pair("0", $foreground, $background);
63 # init_pair(0, $background, $foreground);
64 init_pair(1, COLOR_RED, $background);
65 init_pair(2, COLOR_YELLOW, $background);
66 init_pair(3, COLOR_GREEN, $background);
67 init_pair(4, COLOR_CYAN, $background);
68 init_pair(5, COLOR_BLUE, $background);
69 init_pair(6, COLOR_MAGENTA, $background);
70 init_pair(7, COLOR_RED, COLOR_BLUE);
71 init_pair(8, COLOR_YELLOW, COLOR_BLUE);
72 init_pair(9, COLOR_GREEN, COLOR_BLUE);
73 init_pair(10, COLOR_CYAN, COLOR_BLUE);
74 init_pair(11, COLOR_BLUE, COLOR_RED);
75 init_pair(12, COLOR_MAGENTA, COLOR_BLUE);
76 init_pair(13, COLOR_YELLOW, COLOR_GREEN);
77 init_pair(14, COLOR_RED, COLOR_GREEN);
78 $scr->attrset(COLOR_PAIR(0));
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...");
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)([^\|]+)\|(.*)$/;
221 if ($sort && $sort eq 'D') {
223 } elsif ($sort && $sort eq 'Z') { # end, disconnect, go, away .....
226 # ******************************************************
227 # ******************************************************
228 # any other sorts that might happen are silently ignored.
229 # ******************************************************
230 # ******************************************************
246 # $prbuf =~ s/\r/\\r/;
247 # $prbuf =~ s/\n/\\n/;
248 # print "sys: $r ($prbuf)\n";
251 if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
255 # check for a pling and do a search back for a command
256 if ($inbuf =~ /^!/o) {
259 for ($i = $#khistory; $i >= 0; $i--) {
260 if ($khistory[$i] =~ /^$inbuf/) {
261 $inbuf = $khistory[$i];
270 push @khistory, $inbuf if $inbuf;
271 shift @khistory if @khistory > $maxkhist;
272 $khistpos = @khistory;
275 $bot->addstr(substr($inbuf, 0, COLS));
278 # add it to the monitor window
279 unless ($spos == @shistory) {
283 addtotop($inbuf) if $inbuf;
285 # send it to the cluster
286 $inbuf = " " unless $inbuf;
287 $conn->send_later("I$call|$inbuf");
290 } elsif ($r eq KEY_UP || $r eq "\020") {
293 $inbuf = $khistory[$khistpos];
294 $pos = $lth = length $inbuf;
298 } elsif ($r eq KEY_DOWN || $r eq "\016") {
299 if ($khistpos < @khistory - 1) {
301 $inbuf = $khistory[$khistpos];
302 $pos = $lth = length $inbuf;
306 } elsif ($r eq KEY_PPAGE || $r eq "\032") {
309 for ($i = 0; $i <= $pagel && $spos >= 0; ) {
310 $l = measure($shistory[$spos]);
312 $spos-- if $i <= $pagel;
314 $spos = 0 if $spos < 0;
319 } elsif ($r eq KEY_NPAGE || $r eq "\026") {
320 if ($spos < @shistory - 1) {
322 for ($i = 0; $i <= $pagel && $spos <= @shistory; ) {
323 $l = measure($shistory[$spos]);
325 $spos++ if $i <= $pagel;
327 $spos = @shistory if $spos >= @shistory - 1;
332 } elsif ($r eq KEY_LEFT || $r eq "\002") {
338 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
344 } elsif ($r eq KEY_HOME || $r eq "\001") {
346 } elsif ($r eq KEY_END || $r eq "\005") {
348 } elsif ($r eq KEY_BACKSPACE || $r eq "\010") {
350 my $a = substr($inbuf, 0, $pos-1);
351 my $b = substr($inbuf, $pos) if $pos < $lth;
360 } elsif ($r eq KEY_DC || $r eq "\004") {
362 my $a = substr($inbuf, 0, $pos);
363 my $b = substr($inbuf, $pos+1) if $pos < $lth;
371 } elsif (is_pctext($r)) {
372 # move the top screen back to the bottom if you type something
373 if ($spos < @shistory) {
378 # insert the character into the keyboard buffer
380 my $a = substr($inbuf, 0, $pos);
381 my $b = substr($inbuf, $pos);
382 $inbuf = $a . $r . $b;
388 } elsif ($r eq "\014" || $r eq "\022") {
389 touchwin($curscr, 1);
392 } elsif ($r eq "\013") {
393 $inbuf = substr($inbuf, 0, $pos);
394 $lth = length $inbuf;
400 $bot->addstr($inbuf);
411 $call = uc shift @ARGV if @ARGV;
412 $call = uc $myalias if !$call;
413 my ($scall, $ssid) = split /-/, $call;
414 $ssid = undef unless $ssid && $ssid =~ /^\d+$/;
416 $ssid = 15 if $ssid > 15;
417 $call = "$scall-$ssid";
420 if ($call eq $mycall) {
421 print "You cannot connect as your cluster callsign ($mycall)\n";
425 $conn = Msg->connect("$clusteraddr", $clusterport, \&rec_socket);
427 if (-r "$data/offline") {
428 open IN, "$data/offline" or die;
434 print "Sorry, the cluster $mycall is currently off-line\n";
440 $SIG{'INT'} = \&sig_term;
441 $SIG{'TERM'} = \&sig_term;
442 #$SIG{'WINCH'} = \&do_resize;
443 $SIG{'HUP'} = \&sig_term;
447 $SIG{__DIE__} = \&sig_term;
449 $conn->send_later("A$call|$connsort");
450 $conn->send_later("I$call|set/page $maxshist");
451 $conn->send_later("I$call|set/nobeep");
453 Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
458 Msg->event_loop(1, 1);
460 if ($t > $lasttime) {
461 my ($min)= (gmtime($t))[1];
462 if ($min != $lastmin) {
468 $top->refresh() if $top->is_wintouched;