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";
162 if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
166 push @khistory, $inbuf if $inbuf;
167 shift @khistory if @khistory > $maxkhist;
168 $khistpos = @khistory;
171 $bot->addstr(substr($inbuf, 0, COLS));
174 # add it to the monitor window
175 addtotop($inbuf) if $inbuf;
177 # send it to the cluster
178 $inbuf = " " unless $inbuf;
179 $conn->send_later("I$call|$inbuf");
182 } elsif ($r eq KEY_UP || $r eq "\020") {
185 $inbuf = $khistory[$khistpos];
186 $pos = $lth = length $inbuf;
190 } elsif ($r eq KEY_DOWN || $r eq "\016") {
191 if ($khistpos < @khistory - 1) {
193 $inbuf = $khistory[$khistpos];
194 $pos = $lth = length $inbuf;
198 } elsif ($r eq KEY_PPAGE || $r eq "\032") {
201 $spos = 0 if $spos < 0;
206 } elsif ($r eq KEY_NPAGE || $r eq "\026") {
207 if ($spos < @shistory - 1) {
209 $spos = @shistory if $spos > @shistory;
214 } elsif ($r eq KEY_LEFT || $r eq "\002") {
220 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
226 } elsif ($r eq KEY_HOME || $r eq "\001") {
228 } elsif ($r eq KEY_END || $r eq "\005") {
230 } elsif ($r eq KEY_BACKSPACE || $r eq "\010") {
232 my $a = substr($inbuf, 0, $pos-1);
233 my $b = substr($inbuf, $pos) if $pos < $lth;
242 } elsif ($r eq KEY_DC || $r eq "\004") {
244 my $a = substr($inbuf, 0, $pos);
245 my $b = substr($inbuf, $pos+1) if $pos < $lth;
253 } elsif ($r ge ' ' && $r le '~') {
255 my $a = substr($inbuf, 0, $pos);
256 my $b = substr($inbuf, $pos);
257 $inbuf = $a . $r . $b;
263 } elsif ($r eq "\014" || $r eq "\022") {
264 # curscr()->refresh();
266 } elsif ($r eq "\013") {
267 $inbuf = substr($inbuf, 0, $pos);
268 $lth = length $inbuf;
274 $bot->addstr($inbuf);
285 $call = uc shift @ARGV if @ARGV;
286 $call = uc $myalias if !$call;
288 if ($call eq $mycall) {
289 print "You cannot connect as your cluster callsign ($mycall)\n";
293 $conn = Msg->connect("$clusteraddr", $clusterport, \&rec_socket);
295 if (-r "$data/offline") {
296 open IN, "$data/offline" or die;
302 print "Sorry, the cluster $mycall is currently off-line\n";
308 $SIG{'INT'} = \&sig_term;
309 $SIG{'TERM'} = \&sig_term;
310 $SIG{'HUP'} = 'IGNORE';
315 $has_colors = has_colors();
319 init_pair(0, $foreground, $background);
320 init_pair(1, COLOR_RED, $background);
321 init_pair(2, COLOR_YELLOW, $background);
322 init_pair(3, COLOR_GREEN, $background);
323 init_pair(4, COLOR_CYAN, $background);
324 init_pair(5, COLOR_BLUE, $background);
325 init_pair(6, COLOR_MAGENTA, $background);
328 $top = $scr->subwin(LINES()-4, COLS, 0, 0);
331 $scr->addstr(LINES()-4, 0, '-' x COLS);
332 $bot = $scr->subwin(3, COLS, LINES()-3, 0);
339 $SIG{__DIE__} = \&sig_term;
343 $conn->send_now("A$call|$connsort");
344 $conn->send_now("I$call|set/page $maxshist");
345 $conn->send_now("I$call|set/nobeep");
347 Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
351 Msg->event_loop(1, 0.010);
352 $top->refresh() if $top->is_wintouched;
355 if ($t > $lasttime) {