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 # handle incoming messages
124 my ($con, $msg, $err) = @_;
125 if (defined $err && $err) {
129 my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/;
132 push @shistory, $line;
133 shift @shistory if @shistory > $maxshist;
134 # $spos = @shistory if $spos >= @shistory - 1;
136 } elsif ($sort eq 'Z') { # end, disconnect, go, away .....
152 # $prbuf =~ s/\r/\\r/;
153 # $prbuf =~ s/\n/\\n/;
154 # print "sys: $r ($prbuf)\n";
156 if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
160 push @khistory, $inbuf if $inbuf;
161 shift @khistory if @khistory > $maxkhist;
162 $khistpos = @khistory;
165 $bot->addstr(substr($inbuf, 0, COLS));
168 # send it to the cluster
169 $inbuf = " " unless $inbuf;
170 $conn->send_later("I$call|$inbuf");
173 } elsif ($r eq KEY_UP || $r eq "\020") {
176 $inbuf = $khistory[$khistpos];
177 $pos = $lth = length $inbuf;
181 } elsif ($r eq KEY_DOWN || $r eq "\016") {
182 if ($khistpos < @khistory - 1) {
184 $inbuf = $khistory[$khistpos];
185 $pos = $lth = length $inbuf;
189 } elsif ($r eq KEY_PPAGE || $r eq "\032") {
192 $spos = 0 if $spos < 0;
197 } elsif ($r eq KEY_NPAGE || $r eq "\026") {
198 if ($spos < @shistory - 1) {
200 $spos = @shistory if $spos > @shistory;
205 } elsif ($r eq KEY_LEFT || $r eq "\002") {
211 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
217 } elsif ($r eq KEY_HOME || $r eq "\001") {
219 } elsif ($r eq KEY_END || $r eq "\005") {
221 } elsif ($r eq KEY_BACKSPACE || $r eq "\010") {
223 my $a = substr($inbuf, 0, $pos-1);
224 my $b = substr($inbuf, $pos) if $pos < $lth;
233 } elsif ($r eq KEY_DC || $r eq "\004") {
235 my $a = substr($inbuf, 0, $pos);
236 my $b = substr($inbuf, $pos+1) if $pos < $lth;
244 } elsif ($r ge ' ' && $r le '~') {
246 my $a = substr($inbuf, 0, $pos);
247 my $b = substr($inbuf, $pos);
248 $inbuf = $a . $r . $b;
254 } elsif ($r eq "\014" || $r eq "\022") {
260 } elsif ($r eq "\013") {
261 $inbuf = substr($inbuf, 0, $pos);
262 $lth = length $inbuf;
268 $bot->addstr($inbuf);
279 $call = uc shift @ARGV if @ARGV;
280 $call = uc $myalias if !$call;
282 if ($call eq $mycall) {
283 print "You cannot connect as your cluster callsign ($mycall)\n";
287 $conn = Msg->connect("$clusteraddr", $clusterport, \&rec_socket);
289 if (-r "$data/offline") {
290 open IN, "$data/offline" or die;
296 print "Sorry, the cluster $mycall is currently off-line\n";
302 $SIG{'INT'} = \&sig_term;
303 $SIG{'TERM'} = \&sig_term;
304 $SIG{'HUP'} = 'IGNORE';
309 $has_colors = has_colors();
313 init_pair(0, $foreground, $background);
314 init_pair(1, COLOR_RED, $background);
315 init_pair(2, COLOR_YELLOW, $background);
316 init_pair(3, COLOR_GREEN, $background);
317 init_pair(4, COLOR_CYAN, $background);
318 init_pair(5, COLOR_BLUE, $background);
319 init_pair(6, COLOR_MAGENTA, $background);
322 $top = $scr->subwin(LINES()-4, COLS, 0, 0);
325 $scr->addstr(LINES()-4, 0, '-' x COLS);
326 $bot = $scr->subwin(3, COLS, LINES()-3, 0);
333 $SIG{__DIE__} = \&sig_term;
337 $conn->send_now("A$call|$connsort");
338 $conn->send_now("I$call|set/page $maxshist");
339 $conn->send_now("I$call|set/nobeep");
341 Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
345 Msg->event_loop(1, 0.010);
346 $top->refresh() if $top->is_wintouched;
349 if ($t > $lasttime) {