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(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);
72 $top = $scr->subwin(LINES()-4, COLS, 0, 0);
75 $scr->addstr(LINES()-4, 0, '-' x COLS);
76 $bot = $scr->subwin(3, COLS, LINES()-3, 0);
84 $mycallcolor = COLOR_PAIR(1) unless $mycallcolor;
93 # cease communications
97 if ($conn && $sendz) {
98 $conn->send_now("Z$call|bye...\n");
106 # terminate program from signal
112 # determine the colour of the line
116 foreach my $ref (@colors) {
117 if ($_[0] =~ m{$$ref[0]}) {
118 $top->attrset($$ref[1]);
125 # measure the no of screen lines a line will take
129 return 0 unless $line;
131 my $l = length $line;
132 my $lines = int ($l / COLS());
133 $lines++ if $l / COLS() > $lines;
137 # display the top screen
140 if ($spos == @shistory - 1) {
142 # if we really are scrolling thru at the end of the history
143 my $line = $shistory[$spos];
144 $top->addstr("\n") if $spos > 0;
147 $top->attrset(COLOR_PAIR(0)) if $has_colors;
155 for ($i = 0; $i < $pagel && $p >= 0; ) {
156 $l = measure($shistory[$p]);
163 $top->attrset(COLOR_PAIR(0)) if $has_colors;
165 for ($i = 0; $i < $pagel && $p < @shistory; $p++) {
166 my $line = $shistory[$p];
167 my $lines = measure($line);
168 last if $i + $lines > $pagel;
170 $top->addstr($i, 0, $line);
171 $top->attrset(COLOR_PAIR(0)) if $has_colors;
175 $spos = @shistory if $spos > @shistory;
178 my $add = "-$spos-$shl";
179 $scr->addstr(LINES()-4, 0, '-' x (COLS() - (length($call) + length($add))));
180 $scr->attrset($mycallcolor) if $has_colors;
181 $scr->addstr("$call");
182 $scr->attrset(COLOR_PAIR(0)) if $has_colors;
188 # add a line to the end of the top screen
192 push @shistory, $inbuf;
193 shift @shistory if @shistory > $maxshist;
197 # handle incoming messages
200 my ($con, $msg, $err) = @_;
201 if (defined $err && $err) {
205 my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/;
207 if ($sort && $sort eq 'D') {
209 } elsif ($sort && $sort eq 'Z') { # end, disconnect, go, away .....
225 # $prbuf =~ s/\r/\\r/;
226 # $prbuf =~ s/\n/\\n/;
227 # print "sys: $r ($prbuf)\n";
230 if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
234 # check for a pling and do a search back for a command
235 if ($inbuf =~ /^!/o) {
238 for ($i = $#khistory; $i >= 0; $i--) {
239 if ($khistory[$i] =~ /^$inbuf/) {
240 $inbuf = $khistory[$i];
249 push @khistory, $inbuf if $inbuf;
250 shift @khistory if @khistory > $maxkhist;
251 $khistpos = @khistory;
254 $bot->addstr(substr($inbuf, 0, COLS));
257 # add it to the monitor window
258 unless ($spos == @shistory) {
262 addtotop($inbuf) if $inbuf;
264 # send it to the cluster
265 $inbuf = " " unless $inbuf;
266 $conn->send_later("I$call|$inbuf");
269 } elsif ($r eq KEY_UP || $r eq "\020") {
272 $inbuf = $khistory[$khistpos];
273 $pos = $lth = length $inbuf;
277 } elsif ($r eq KEY_DOWN || $r eq "\016") {
278 if ($khistpos < @khistory - 1) {
280 $inbuf = $khistory[$khistpos];
281 $pos = $lth = length $inbuf;
285 } elsif ($r eq KEY_PPAGE || $r eq "\032") {
288 for ($i = 0; $i <= $pagel && $spos >= 0; ) {
289 $l = measure($shistory[$spos]);
291 $spos-- if $i <= $pagel;
293 $spos = 0 if $spos < 0;
298 } elsif ($r eq KEY_NPAGE || $r eq "\026") {
299 if ($spos < @shistory - 1) {
301 for ($i = 0; $i <= $pagel && $spos <= @shistory; ) {
302 $l = measure($shistory[$spos]);
304 $spos++ if $i <= $pagel;
306 $spos = @shistory if $spos >= @shistory - 1;
311 } elsif ($r eq KEY_LEFT || $r eq "\002") {
317 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
323 } elsif ($r eq KEY_HOME || $r eq "\001") {
325 } elsif ($r eq KEY_END || $r eq "\005") {
327 } elsif ($r eq KEY_BACKSPACE || $r eq "\010") {
329 my $a = substr($inbuf, 0, $pos-1);
330 my $b = substr($inbuf, $pos) if $pos < $lth;
339 } elsif ($r eq KEY_DC || $r eq "\004") {
341 my $a = substr($inbuf, 0, $pos);
342 my $b = substr($inbuf, $pos+1) if $pos < $lth;
350 } elsif ($r ge ' ' && $r le '~') {
351 # move the top screen back to the bottom if you type something
352 if ($spos < @shistory) {
357 # insert the character into the keyboard buffer
359 my $a = substr($inbuf, 0, $pos);
360 my $b = substr($inbuf, $pos);
361 $inbuf = $a . $r . $b;
367 } elsif ($r eq "\014" || $r eq "\022") {
370 } elsif ($r eq "\013") {
371 $inbuf = substr($inbuf, 0, $pos);
372 $lth = length $inbuf;
378 $bot->addstr($inbuf);
389 $call = uc shift @ARGV if @ARGV;
390 $call = uc $myalias if !$call;
392 if ($call eq $mycall) {
393 print "You cannot connect as your cluster callsign ($mycall)\n";
397 $conn = Msg->connect("$clusteraddr", $clusterport, \&rec_socket);
399 if (-r "$data/offline") {
400 open IN, "$data/offline" or die;
406 print "Sorry, the cluster $mycall is currently off-line\n";
412 $SIG{'INT'} = \&sig_term;
413 $SIG{'TERM'} = \&sig_term;
414 #$SIG{'WINCH'} = \&do_resize;
415 $SIG{'HUP'} = 'IGNORE';
419 $SIG{__DIE__} = \&sig_term;
421 $conn->send_now("A$call|$connsort");
422 $conn->send_now("I$call|set/page $maxshist");
423 $conn->send_now("I$call|set/nobeep");
425 Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
429 Msg->event_loop(1, 1);
430 $top->refresh() if $top->is_wintouched;
433 if ($t > $lasttime) {