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(1, COLOR_RED, $background);
64 init_pair(2, COLOR_YELLOW, $background);
65 init_pair(3, COLOR_GREEN, $background);
66 init_pair(4, COLOR_CYAN, $background);
67 init_pair(5, COLOR_BLUE, $background);
68 init_pair(6, COLOR_MAGENTA, $background);
69 init_pair(7, COLOR_RED, COLOR_BLUE);
70 init_pair(8, COLOR_YELLOW, COLOR_BLUE);
71 init_pair(9, COLOR_GREEN, COLOR_BLUE);
72 init_pair(10, COLOR_CYAN, COLOR_BLUE);
73 init_pair(11, COLOR_BLUE, COLOR_RED);
74 init_pair(12, COLOR_MAGENTA, COLOR_BLUE);
75 init_pair(13, COLOR_YELLOW, COLOR_GREEN);
76 init_pair(14, COLOR_RED, COLOR_GREEN);
79 $top = $scr->subwin(LINES()-4, COLS, 0, 0);
82 $scr->addstr(LINES()-4, 0, '-' x COLS);
83 $bot = $scr->subwin(3, COLS, LINES()-3, 0);
91 $mycallcolor = COLOR_PAIR(1) unless $mycallcolor;
100 # cease communications
104 if ($conn && $sendz) {
105 $conn->send_now("Z$call|bye...");
113 # terminate program from signal
119 # determine the colour of the line
123 foreach my $ref (@colors) {
124 if ($_[0] =~ m{$$ref[0]}) {
125 $top->attrset($$ref[1]);
132 # measure the no of screen lines a line will take
136 return 0 unless $line;
138 my $l = length $line;
139 my $lines = int ($l / COLS());
140 $lines++ if $l / COLS() > $lines;
144 # display the top screen
147 if ($spos == @shistory - 1) {
149 # if we really are scrolling thru at the end of the history
150 my $line = $shistory[$spos];
151 $top->addstr("\n") if $spos > 0;
154 $top->attrset(COLOR_PAIR(0)) if $has_colors;
162 for ($i = 0; $i < $pagel && $p >= 0; ) {
163 $l = measure($shistory[$p]);
170 $top->attrset(COLOR_PAIR(0)) if $has_colors;
172 for ($i = 0; $i < $pagel && $p < @shistory; $p++) {
173 my $line = $shistory[$p];
174 my $lines = measure($line);
175 last if $i + $lines > $pagel;
177 $top->addstr($i, 0, $line);
178 $top->attrset(COLOR_PAIR(0)) if $has_colors;
182 $spos = @shistory if $spos > @shistory;
185 my $add = "-$spos-$shl";
186 my $time = ztime(time);
187 my $str = "-" . $time . '-' x (COLS() - (length($call) + length($add) + length($time) + 1));
188 $scr->addstr(LINES()-4, 0, $str);
190 $scr->attrset($mycallcolor) if $has_colors;
191 $scr->addstr("$call");
192 $scr->attrset(COLOR_PAIR(0)) if $has_colors;
198 # add a line to the end of the top screen
203 push @shistory, $inbuf;
204 shift @shistory if @shistory > $maxshist;
209 # handle incoming messages
212 my ($con, $msg, $err) = @_;
213 if (defined $err && $err) {
217 my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/;
219 if ($sort && $sort eq 'D') {
221 } elsif ($sort && $sort eq 'Z') { # end, disconnect, go, away .....
224 # ******************************************************
225 # ******************************************************
226 # any other sorts that might happen are silently ignored.
227 # ******************************************************
228 # ******************************************************
242 # $prbuf =~ s/\r/\\r/;
243 # $prbuf =~ s/\n/\\n/;
244 # print "sys: $r ($prbuf)\n";
247 if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
251 # check for a pling and do a search back for a command
252 if ($inbuf =~ /^!/o) {
255 for ($i = $#khistory; $i >= 0; $i--) {
256 if ($khistory[$i] =~ /^$inbuf/) {
257 $inbuf = $khistory[$i];
266 push @khistory, $inbuf if $inbuf;
267 shift @khistory if @khistory > $maxkhist;
268 $khistpos = @khistory;
271 $bot->addstr(substr($inbuf, 0, COLS));
274 # add it to the monitor window
275 unless ($spos == @shistory) {
279 addtotop($inbuf) if $inbuf;
281 # send it to the cluster
282 $inbuf = " " unless $inbuf;
283 $conn->send_later("I$call|$inbuf");
286 } elsif ($r eq KEY_UP || $r eq "\020") {
289 $inbuf = $khistory[$khistpos];
290 $pos = $lth = length $inbuf;
294 } elsif ($r eq KEY_DOWN || $r eq "\016") {
295 if ($khistpos < @khistory - 1) {
297 $inbuf = $khistory[$khistpos];
298 $pos = $lth = length $inbuf;
302 } elsif ($r eq KEY_PPAGE || $r eq "\032") {
305 for ($i = 0; $i <= $pagel && $spos >= 0; ) {
306 $l = measure($shistory[$spos]);
308 $spos-- if $i <= $pagel;
310 $spos = 0 if $spos < 0;
315 } elsif ($r eq KEY_NPAGE || $r eq "\026") {
316 if ($spos < @shistory - 1) {
318 for ($i = 0; $i <= $pagel && $spos <= @shistory; ) {
319 $l = measure($shistory[$spos]);
321 $spos++ if $i <= $pagel;
323 $spos = @shistory if $spos >= @shistory - 1;
328 } elsif ($r eq KEY_LEFT || $r eq "\002") {
334 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
340 } elsif ($r eq KEY_HOME || $r eq "\001") {
342 } elsif ($r eq KEY_END || $r eq "\005") {
344 } elsif ($r eq KEY_BACKSPACE || $r eq "\010") {
346 my $a = substr($inbuf, 0, $pos-1);
347 my $b = substr($inbuf, $pos) if $pos < $lth;
356 } elsif ($r eq KEY_DC || $r eq "\004") {
358 my $a = substr($inbuf, 0, $pos);
359 my $b = substr($inbuf, $pos+1) if $pos < $lth;
367 } elsif ($r ge ' ' && $r le '~') {
368 # move the top screen back to the bottom if you type something
369 if ($spos < @shistory) {
374 # insert the character into the keyboard buffer
376 my $a = substr($inbuf, 0, $pos);
377 my $b = substr($inbuf, $pos);
378 $inbuf = $a . $r . $b;
384 } elsif ($r eq "\014" || $r eq "\022") {
387 } elsif ($r eq "\013") {
388 $inbuf = substr($inbuf, 0, $pos);
389 $lth = length $inbuf;
395 $bot->addstr($inbuf);
406 $call = uc shift @ARGV if @ARGV;
407 $call = uc $myalias if !$call;
408 my ($scall, $ssid) = split /-/, $call;
409 $ssid = undef unless $ssid && $ssid =~ /^\d+$/;
411 $ssid = 15 if $ssid > 15;
412 $call = "$scall-$ssid";
415 if ($call eq $mycall) {
416 print "You cannot connect as your cluster callsign ($mycall)\n";
420 $conn = Msg->connect("$clusteraddr", $clusterport, \&rec_socket);
422 if (-r "$data/offline") {
423 open IN, "$data/offline" or die;
429 print "Sorry, the cluster $mycall is currently off-line\n";
435 $SIG{'INT'} = \&sig_term;
436 $SIG{'TERM'} = \&sig_term;
437 #$SIG{'WINCH'} = \&do_resize;
438 $SIG{'HUP'} = \&sig_term;
442 $SIG{__DIE__} = \&sig_term;
444 $conn->send_later("A$call|$connsort");
445 $conn->send_later("I$call|set/page $maxshist");
446 $conn->send_later("I$call|set/nobeep");
448 Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
453 Msg->event_loop(1, 1);
455 if ($t > $lasttime) {
456 my ($min)= (gmtime($t))[1];
457 if ($min != $lastmin) {
463 $top->refresh() if $top->is_wintouched;