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 # check for a pling and do a search back for a command
167 if ($inbuf =~ /^!/o) {
170 for ($i = $#khistory; $i >= 0; $i--) {
171 if ($khistory[$i] =~ /^$inbuf/) {
172 $inbuf = $khistory[$i];
181 push @khistory, $inbuf if $inbuf;
182 shift @khistory if @khistory > $maxkhist;
183 $khistpos = @khistory;
186 $bot->addstr(substr($inbuf, 0, COLS));
189 # add it to the monitor window
190 addtotop($inbuf) if $inbuf;
192 # send it to the cluster
193 $inbuf = " " unless $inbuf;
194 $conn->send_later("I$call|$inbuf");
197 } elsif ($r eq KEY_UP || $r eq "\020") {
200 $inbuf = $khistory[$khistpos];
201 $pos = $lth = length $inbuf;
205 } elsif ($r eq KEY_DOWN || $r eq "\016") {
206 if ($khistpos < @khistory - 1) {
208 $inbuf = $khistory[$khistpos];
209 $pos = $lth = length $inbuf;
213 } elsif ($r eq KEY_PPAGE || $r eq "\032") {
216 $spos = 0 if $spos < 0;
221 } elsif ($r eq KEY_NPAGE || $r eq "\026") {
222 if ($spos < @shistory - 1) {
224 $spos = @shistory if $spos > @shistory;
229 } elsif ($r eq KEY_LEFT || $r eq "\002") {
235 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
241 } elsif ($r eq KEY_HOME || $r eq "\001") {
243 } elsif ($r eq KEY_END || $r eq "\005") {
245 } elsif ($r eq KEY_BACKSPACE || $r eq "\010") {
247 my $a = substr($inbuf, 0, $pos-1);
248 my $b = substr($inbuf, $pos) if $pos < $lth;
257 } elsif ($r eq KEY_DC || $r eq "\004") {
259 my $a = substr($inbuf, 0, $pos);
260 my $b = substr($inbuf, $pos+1) if $pos < $lth;
268 } elsif ($r ge ' ' && $r le '~') {
270 my $a = substr($inbuf, 0, $pos);
271 my $b = substr($inbuf, $pos);
272 $inbuf = $a . $r . $b;
278 } elsif ($r eq "\014" || $r eq "\022") {
279 # curscr()->refresh();
281 } elsif ($r eq "\013") {
282 $inbuf = substr($inbuf, 0, $pos);
283 $lth = length $inbuf;
289 $bot->addstr($inbuf);
300 $call = uc shift @ARGV if @ARGV;
301 $call = uc $myalias if !$call;
303 if ($call eq $mycall) {
304 print "You cannot connect as your cluster callsign ($mycall)\n";
308 $conn = Msg->connect("$clusteraddr", $clusterport, \&rec_socket);
310 if (-r "$data/offline") {
311 open IN, "$data/offline" or die;
317 print "Sorry, the cluster $mycall is currently off-line\n";
323 $SIG{'INT'} = \&sig_term;
324 $SIG{'TERM'} = \&sig_term;
325 $SIG{'HUP'} = 'IGNORE';
330 $has_colors = has_colors();
334 init_pair(0, $foreground, $background);
335 init_pair(1, COLOR_RED, $background);
336 init_pair(2, COLOR_YELLOW, $background);
337 init_pair(3, COLOR_GREEN, $background);
338 init_pair(4, COLOR_CYAN, $background);
339 init_pair(5, COLOR_BLUE, $background);
340 init_pair(6, COLOR_MAGENTA, $background);
343 $top = $scr->subwin(LINES()-4, COLS, 0, 0);
346 $scr->addstr(LINES()-4, 0, '-' x COLS);
347 $bot = $scr->subwin(3, COLS, LINES()-3, 0);
354 $SIG{__DIE__} = \&sig_term;
358 $conn->send_now("A$call|$connsort");
359 $conn->send_now("I$call|set/page $maxshist");
360 $conn->send_now("I$call|set/nobeep");
362 Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
366 Msg->event_loop(1, 0.010);
367 $top->refresh() if $top->is_wintouched;
370 if ($t > $lasttime) {