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 # cease communications
57 if ($conn && $sendz) {
58 $conn->send_now("Z$call|bye...\n");
66 # terminate program from signal
72 # determine the colour of the line
76 foreach my $ref (@colors) {
77 if ($_[0] =~ m{$$ref[0]}) {
78 $top->attrset($$ref[1]);
85 # display the top screen
88 if ($spos == @shistory - 1) {
90 # if we really are scrolling thru at the end of the history
91 my $line = $shistory[-1];
92 $top->addstr("\n") if $spos > 0;
95 $top->attrset(COLOR_PAIR(0)) if $has_colors;
101 my $p = $spos - $pages;
106 $top->attrset(COLOR_PAIR(0)) if $has_colors;
108 for ($i = 0; $i < $pages && $p < @shistory; $i++, $p++) {
109 my $line = $shistory[$p];
110 $line = substr($line, 0, COLS()) if length $line > COLS();
114 $top->attrset(COLOR_PAIR(0)) if $has_colors;
121 # add a line to the end of the top screen
125 push @shistory, $inbuf;
126 shift @shistory if @shistory > $maxshist;
130 # handle incoming messages
133 my ($con, $msg, $err) = @_;
134 if (defined $err && $err) {
138 my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/;
142 } elsif ($sort eq 'Z') { # end, disconnect, go, away .....
158 # $prbuf =~ s/\r/\\r/;
159 # $prbuf =~ s/\n/\\n/;
160 # print "sys: $r ($prbuf)\n";
163 if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
167 # check for a pling and do a search back for a command
168 if ($inbuf =~ /^!/o) {
171 for ($i = $#khistory; $i >= 0; $i--) {
172 if ($khistory[$i] =~ /^$inbuf/) {
173 $inbuf = $khistory[$i];
182 push @khistory, $inbuf if $inbuf;
183 shift @khistory if @khistory > $maxkhist;
184 $khistpos = @khistory;
187 $bot->addstr(substr($inbuf, 0, COLS));
190 # add it to the monitor window
191 addtotop($inbuf) if $inbuf;
193 # send it to the cluster
194 $inbuf = " " unless $inbuf;
195 $conn->send_later("I$call|$inbuf");
198 } elsif ($r eq KEY_UP || $r eq "\020") {
201 $inbuf = $khistory[$khistpos];
202 $pos = $lth = length $inbuf;
206 } elsif ($r eq KEY_DOWN || $r eq "\016") {
207 if ($khistpos < @khistory - 1) {
209 $inbuf = $khistory[$khistpos];
210 $pos = $lth = length $inbuf;
214 } elsif ($r eq KEY_PPAGE || $r eq "\032") {
217 $spos = 0 if $spos < 0;
222 } elsif ($r eq KEY_NPAGE || $r eq "\026") {
223 if ($spos < @shistory - 1) {
225 $spos = @shistory if $spos > @shistory;
230 } elsif ($r eq KEY_LEFT || $r eq "\002") {
236 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
242 } elsif ($r eq KEY_HOME || $r eq "\001") {
244 } elsif ($r eq KEY_END || $r eq "\005") {
246 } elsif ($r eq KEY_BACKSPACE || $r eq "\010") {
248 my $a = substr($inbuf, 0, $pos-1);
249 my $b = substr($inbuf, $pos) if $pos < $lth;
258 } elsif ($r eq KEY_DC || $r eq "\004") {
260 my $a = substr($inbuf, 0, $pos);
261 my $b = substr($inbuf, $pos+1) if $pos < $lth;
269 } elsif ($r ge ' ' && $r le '~') {
270 # move the top screen back to the bottom if you type something
271 if ($spos < @shistory - 1) {
276 # insert the character into the keyboard buffer
278 my $a = substr($inbuf, 0, $pos);
279 my $b = substr($inbuf, $pos);
280 $inbuf = $a . $r . $b;
286 } elsif ($r eq "\014" || $r eq "\022") {
287 # curscr()->refresh();
289 } elsif ($r eq "\013") {
290 $inbuf = substr($inbuf, 0, $pos);
291 $lth = length $inbuf;
297 $bot->addstr($inbuf);
308 $call = uc shift @ARGV if @ARGV;
309 $call = uc $myalias if !$call;
311 if ($call eq $mycall) {
312 print "You cannot connect as your cluster callsign ($mycall)\n";
316 $conn = Msg->connect("$clusteraddr", $clusterport, \&rec_socket);
318 if (-r "$data/offline") {
319 open IN, "$data/offline" or die;
325 print "Sorry, the cluster $mycall is currently off-line\n";
331 $SIG{'INT'} = \&sig_term;
332 $SIG{'TERM'} = \&sig_term;
333 $SIG{'HUP'} = 'IGNORE';
338 $has_colors = has_colors();
342 init_pair(0, $foreground, $background);
343 init_pair(1, COLOR_RED, $background);
344 init_pair(2, COLOR_YELLOW, $background);
345 init_pair(3, COLOR_GREEN, $background);
346 init_pair(4, COLOR_CYAN, $background);
347 init_pair(5, COLOR_BLUE, $background);
348 init_pair(6, COLOR_MAGENTA, $background);
351 $top = $scr->subwin(LINES()-4, COLS, 0, 0);
354 $scr->addstr(LINES()-4, 0, '-' x COLS);
355 $bot = $scr->subwin(3, COLS, LINES()-3, 0);
362 $SIG{__DIE__} = \&sig_term;
366 $conn->send_now("A$call|$connsort");
367 $conn->send_now("I$call|set/page $maxshist");
368 $conn->send_now("I$call|set/nobeep");
370 Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
374 Msg->event_loop(1, 0.010);
375 $top->refresh() if $top->is_wintouched;
378 if ($t > $lasttime) {