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)([^\|]+)\|(.*)$/;
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 # ******************************************************
244 # $prbuf =~ s/\r/\\r/;
245 # $prbuf =~ s/\n/\\n/;
246 # print "sys: $r ($prbuf)\n";
249 if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
253 # check for a pling and do a search back for a command
254 if ($inbuf =~ /^!/o) {
257 for ($i = $#khistory; $i >= 0; $i--) {
258 if ($khistory[$i] =~ /^$inbuf/) {
259 $inbuf = $khistory[$i];
268 push @khistory, $inbuf if $inbuf;
269 shift @khistory if @khistory > $maxkhist;
270 $khistpos = @khistory;
273 $bot->addstr(substr($inbuf, 0, COLS));
276 # add it to the monitor window
277 unless ($spos == @shistory) {
281 addtotop($inbuf) if $inbuf;
283 # send it to the cluster
284 $inbuf = " " unless $inbuf;
285 $conn->send_later("I$call|$inbuf");
288 } elsif ($r eq KEY_UP || $r eq "\020") {
291 $inbuf = $khistory[$khistpos];
292 $pos = $lth = length $inbuf;
296 } elsif ($r eq KEY_DOWN || $r eq "\016") {
297 if ($khistpos < @khistory - 1) {
299 $inbuf = $khistory[$khistpos];
300 $pos = $lth = length $inbuf;
304 } elsif ($r eq KEY_PPAGE || $r eq "\032") {
307 for ($i = 0; $i <= $pagel && $spos >= 0; ) {
308 $l = measure($shistory[$spos]);
310 $spos-- if $i <= $pagel;
312 $spos = 0 if $spos < 0;
317 } elsif ($r eq KEY_NPAGE || $r eq "\026") {
318 if ($spos < @shistory - 1) {
320 for ($i = 0; $i <= $pagel && $spos <= @shistory; ) {
321 $l = measure($shistory[$spos]);
323 $spos++ if $i <= $pagel;
325 $spos = @shistory if $spos >= @shistory - 1;
330 } elsif ($r eq KEY_LEFT || $r eq "\002") {
336 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
342 } elsif ($r eq KEY_HOME || $r eq "\001") {
344 } elsif ($r eq KEY_END || $r eq "\005") {
346 } elsif ($r eq KEY_BACKSPACE || $r eq "\010") {
348 my $a = substr($inbuf, 0, $pos-1);
349 my $b = substr($inbuf, $pos) if $pos < $lth;
358 } elsif ($r eq KEY_DC || $r eq "\004") {
360 my $a = substr($inbuf, 0, $pos);
361 my $b = substr($inbuf, $pos+1) if $pos < $lth;
369 } elsif ($r ge ' ' && $r le '~') {
370 # move the top screen back to the bottom if you type something
371 if ($spos < @shistory) {
376 # insert the character into the keyboard buffer
378 my $a = substr($inbuf, 0, $pos);
379 my $b = substr($inbuf, $pos);
380 $inbuf = $a . $r . $b;
386 } elsif ($r eq "\014" || $r eq "\022") {
389 } elsif ($r eq "\013") {
390 $inbuf = substr($inbuf, 0, $pos);
391 $lth = length $inbuf;
397 $bot->addstr($inbuf);
408 $call = uc shift @ARGV if @ARGV;
409 $call = uc $myalias if !$call;
410 my ($scall, $ssid) = split /-/, $call;
411 $ssid = undef unless $ssid && $ssid =~ /^\d+$/;
413 $ssid = 15 if $ssid > 15;
414 $call = "$scall-$ssid";
417 if ($call eq $mycall) {
418 print "You cannot connect as your cluster callsign ($mycall)\n";
422 $conn = Msg->connect("$clusteraddr", $clusterport, \&rec_socket);
424 if (-r "$data/offline") {
425 open IN, "$data/offline" or die;
431 print "Sorry, the cluster $mycall is currently off-line\n";
437 $SIG{'INT'} = \&sig_term;
438 $SIG{'TERM'} = \&sig_term;
439 #$SIG{'WINCH'} = \&do_resize;
440 $SIG{'HUP'} = \&sig_term;
444 $SIG{__DIE__} = \&sig_term;
446 $conn->send_later("A$call|$connsort");
447 $conn->send_later("I$call|set/page $maxshist");
448 $conn->send_later("I$call|set/nobeep");
450 Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
455 Msg->event_loop(1, 1);
457 if ($t > $lasttime) {
458 my ($min)= (gmtime($t))[1];
459 if ($min != $lastmin) {
465 $top->refresh() if $top->is_wintouched;