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";
43 $call = ""; # the callsign being used
44 $conn = 0; # the connection object for the cluster
45 $lasttime = time; # lasttime something happened on the interface
51 $spos = $pos = $lth = 0;
54 # do the screen initialisation
60 $has_colors = has_colors();
64 init_pair(0, $foreground, $background);
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);
73 $top = $scr->subwin(LINES()-4, COLS, 0, 0);
76 $scr->addstr(LINES()-4, 0, '-' x COLS);
77 $bot = $scr->subwin(3, COLS, LINES()-3, 0);
85 $mycallcolor = COLOR_PAIR(1) unless $mycallcolor;
94 # cease communications
98 if ($conn && $sendz) {
99 $conn->send_now("Z$call|bye...\n");
107 # terminate program from signal
113 # determine the colour of the line
117 foreach my $ref (@colors) {
118 if ($_[0] =~ m{$$ref[0]}) {
119 $top->attrset($$ref[1]);
126 # measure the no of screen lines a line will take
130 return 0 unless $line;
132 my $l = length $line;
133 my $lines = int ($l / COLS());
134 $lines++ if $l / COLS() > $lines;
138 # display the top screen
141 if ($spos == @shistory - 1) {
143 # if we really are scrolling thru at the end of the history
144 my $line = $shistory[$spos];
145 $top->addstr("\n") if $spos > 0;
148 $top->attrset(COLOR_PAIR(0)) if $has_colors;
156 for ($i = 0; $i < $pagel && $p >= 0; ) {
157 $l = measure($shistory[$p]);
164 $top->attrset(COLOR_PAIR(0)) if $has_colors;
166 for ($i = 0; $i < $pagel && $p < @shistory; $p++) {
167 my $line = $shistory[$p];
168 my $lines = measure($line);
169 last if $i + $lines > $pagel;
171 $top->addstr($i, 0, $line);
172 $top->attrset(COLOR_PAIR(0)) if $has_colors;
176 $spos = @shistory if $spos > @shistory;
179 my $add = "-$spos-$shl";
180 my $time = ztime(time);
181 my $str = "-" . $time . '-' x (COLS() - (length($call) + length($add) + length($time) + 1));
182 $scr->addstr(LINES()-4, 0, $str);
184 $scr->attrset($mycallcolor) if $has_colors;
185 $scr->addstr("$call");
186 $scr->attrset(COLOR_PAIR(0)) if $has_colors;
192 # add a line to the end of the top screen
197 push @shistory, $inbuf;
198 shift @shistory if @shistory > $maxshist;
203 # handle incoming messages
206 my ($con, $msg, $err) = @_;
207 if (defined $err && $err) {
211 my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/;
213 if ($sort && $sort eq 'D') {
215 } elsif ($sort && $sort eq 'Z') { # end, disconnect, go, away .....
231 # $prbuf =~ s/\r/\\r/;
232 # $prbuf =~ s/\n/\\n/;
233 # print "sys: $r ($prbuf)\n";
236 if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
240 # check for a pling and do a search back for a command
241 if ($inbuf =~ /^!/o) {
244 for ($i = $#khistory; $i >= 0; $i--) {
245 if ($khistory[$i] =~ /^$inbuf/) {
246 $inbuf = $khistory[$i];
255 push @khistory, $inbuf if $inbuf;
256 shift @khistory if @khistory > $maxkhist;
257 $khistpos = @khistory;
260 $bot->addstr(substr($inbuf, 0, COLS));
263 # add it to the monitor window
264 unless ($spos == @shistory) {
268 addtotop($inbuf) if $inbuf;
270 # send it to the cluster
271 $inbuf = " " unless $inbuf;
272 $conn->send_later("I$call|$inbuf");
275 } elsif ($r eq KEY_UP || $r eq "\020") {
278 $inbuf = $khistory[$khistpos];
279 $pos = $lth = length $inbuf;
283 } elsif ($r eq KEY_DOWN || $r eq "\016") {
284 if ($khistpos < @khistory - 1) {
286 $inbuf = $khistory[$khistpos];
287 $pos = $lth = length $inbuf;
291 } elsif ($r eq KEY_PPAGE || $r eq "\032") {
294 for ($i = 0; $i <= $pagel && $spos >= 0; ) {
295 $l = measure($shistory[$spos]);
297 $spos-- if $i <= $pagel;
299 $spos = 0 if $spos < 0;
304 } elsif ($r eq KEY_NPAGE || $r eq "\026") {
305 if ($spos < @shistory - 1) {
307 for ($i = 0; $i <= $pagel && $spos <= @shistory; ) {
308 $l = measure($shistory[$spos]);
310 $spos++ if $i <= $pagel;
312 $spos = @shistory if $spos >= @shistory - 1;
317 } elsif ($r eq KEY_LEFT || $r eq "\002") {
323 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
329 } elsif ($r eq KEY_HOME || $r eq "\001") {
331 } elsif ($r eq KEY_END || $r eq "\005") {
333 } elsif ($r eq KEY_BACKSPACE || $r eq "\010") {
335 my $a = substr($inbuf, 0, $pos-1);
336 my $b = substr($inbuf, $pos) if $pos < $lth;
345 } elsif ($r eq KEY_DC || $r eq "\004") {
347 my $a = substr($inbuf, 0, $pos);
348 my $b = substr($inbuf, $pos+1) if $pos < $lth;
356 } elsif ($r ge ' ' && $r le '~') {
357 # move the top screen back to the bottom if you type something
358 if ($spos < @shistory) {
363 # insert the character into the keyboard buffer
365 my $a = substr($inbuf, 0, $pos);
366 my $b = substr($inbuf, $pos);
367 $inbuf = $a . $r . $b;
373 } elsif ($r eq "\014" || $r eq "\022") {
376 } elsif ($r eq "\013") {
377 $inbuf = substr($inbuf, 0, $pos);
378 $lth = length $inbuf;
384 $bot->addstr($inbuf);
395 $call = uc shift @ARGV if @ARGV;
396 $call = uc $myalias if !$call;
398 if ($call eq $mycall) {
399 print "You cannot connect as your cluster callsign ($mycall)\n";
403 $conn = Msg->connect("$clusteraddr", $clusterport, \&rec_socket);
405 if (-r "$data/offline") {
406 open IN, "$data/offline" or die;
412 print "Sorry, the cluster $mycall is currently off-line\n";
418 $SIG{'INT'} = \&sig_term;
419 $SIG{'TERM'} = \&sig_term;
420 #$SIG{'WINCH'} = \&do_resize;
421 $SIG{'HUP'} = 'IGNORE';
425 $SIG{__DIE__} = \&sig_term;
427 $conn->send_now("A$call|$connsort");
428 $conn->send_now("I$call|set/page $maxshist");
429 $conn->send_now("I$call|set/nobeep");
431 Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
435 Msg->event_loop(1, 1);
437 if ($t > $lasttime) {
441 $top->refresh() if $top->is_wintouched;