Now (apparent) apparently working
[spider.git] / perl / DXCommandmode.pm
index d6319f3f6f30fee73a0b34a431f2ce41b7d0a406..cf745c4fd6926ca9911d6fb74f3c257c5e7b3bd6 100644 (file)
@@ -36,7 +36,7 @@ use QSL;
 use DB_File;
 use VE7CC;
 use DXXml;
-use HTTPMsg;
+use AsyncMsg;
 
 use strict;
 use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase %nothereslug
@@ -92,6 +92,7 @@ sub start
        my $host = $self->{conn}->peerhost;
        $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
        $host ||= "unknown";
+       $self->{hostname} = $host;
        LogDbg('DXCommand', "$call connected from $host");
 
        $self->{name} = $name ? $name : $call;
@@ -118,26 +119,30 @@ sub start
        $self->{ann_talk} = $user->wantann_talk;
        $self->{here} = 1;
        $self->{prompt} = $user->prompt if $user->prompt;
+       $self->{lastmsgpoll} = 0;
 
        # sort out new dx spot stuff
        $user->wantdxcq(0) unless defined $user->{wantdxcq};
        $user->wantdxitu(0) unless defined $user->{wantdxitu};  
        $user->wantusstate(0) unless defined $user->{wantusstate};
 
-       # sort out registration
-       if ($main::reqreg == 1) {
-               $self->{registered} = $user->registered;
-       } elsif ($main::reqreg == 2) {
+       # sort out registration (who wanted 2???) Note registration *could* be used even when reqreg == 0
+       if ($main::reqreg == 2) {
                $self->{registered} = !$user->registered;
        } else {
-               $self->{registered} = 1;
+               $self->{registered} = $user->registered;
        }
 
+       # establish slug queue, if required
+    $self->{sluggedpcs} = [];
+    $self->{isslugged} = $DXProt::pc92_slug_changes + $DXProt::last_pc92_slug + 5 if $DXProt::pc92_slug_changes;
+    $self->{isslugged} = 0 if $self->{priv} > 0 || $user->registered || $user->homenode eq $main::mycall;
+
        # send the relevant MOTD
        $self->send_motd;
 
        # sort out privilege reduction
-       $self->{priv} = 0 if $line =~ /^(ax|te)/ && !$self->conn->{usedpasswd};
+       $self->{priv} = 0 unless $self->{hostname} eq '127.0.0.1' || $self->{hostname} eq '::1' || $self->conn->{usedpasswd};
 
        # get the filters
        my $nossid = $call;
@@ -209,7 +214,7 @@ sub start
                }
        }
 
-       $self->lastmsgpoll($main::systime);
+       $self->{lastmsgpoll} = $main::systime;
        $self->prompt;
 }
 
@@ -560,12 +565,12 @@ sub process
        my $dxchan;
        
        foreach $dxchan (@dxchan) {
-               next if $dxchan->sort ne 'U';  
+               next unless $dxchan->is_user;  
        
                # send a outstanding message prompt if required
                if ($t >= $dxchan->lastmsgpoll + $msgpolltime) {
                        $dxchan->send($dxchan->msg('m9')) if DXMsg::for_me($dxchan->call);
-                       $dxchan->lastmsgpoll($t);
+                       $dxchan->{lastmsgpoll} = $t;
                }
                
                # send a prompt if no activity out on this channel
@@ -573,6 +578,18 @@ sub process
                        $dxchan->prompt() if $dxchan->{state} =~ /^prompt/o;
                        $dxchan->t($t);
                }
+
+               if ($dxchan->{isslugged} && $main::systime > $dxchan->{isslugged}) {
+                       foreach my $ref (@{$dxchan->{sluggedpcs}}) {
+                               if ($ref->[0] == 61) {
+                                       Spot::add(@{$ref->[2]});
+                                       DXProt::send_dx_spot($dxchan, $ref->[1], @{$ref->[2]});
+                               }
+                       }
+
+                       $dxchan->{isslugged} = 0;
+                       $dxchan->{sluggedpcs} = [];
+               }
        }
 
        while (my ($k, $v) = each %nothereslug) {
@@ -803,7 +820,7 @@ sub find_cmd_name {
                };
                
                #wrap the code into a subroutine inside our unique package
-               my $eval = qq(package DXCommandmode::$package; use POSIX qw{:math_h}; use DXLog; use DXDebug; use DXUser; use DXUtil; use Minimuf; use Sun; use HTTPMsg; our \@ISA = qw{DXCommandmode}; );
+               my $eval = qq(package DXCommandmode::$package; use POSIX qw{:math_h}; use DXLog; use DXDebug; use DXUser; use DXUtil; our \@ISA = qw{DXCommandmode}; );
 
 
                if ($sub =~ m|\s*sub\s+handle\n|) {
@@ -960,29 +977,51 @@ sub format_dx_spot
 
        my $t = ztime($_[2]);
        my $loc = '';
-       my $clth = $self->{consort} eq 'local' ? 29 : 30;
+       my ($slot1, $slot2) = ('', '');
+       
+       my $clth = 30 + $self->{width} - 80;    # allow comment to grow according the screen width 
        my $comment = substr (($_[3] || ''), 0, $clth);
-       $comment .= ' ' x ($clth - length($comment));
-       if ($self->{user}->wantgrid) {
-               my $ref = DXUser::get_current($_[4]);
-               if ($ref) {
-                       $loc = $ref->qra || '';
-                       $loc = ' ' . substr($loc, 0, 4) if $loc;
+       $comment =~ s/\t/ /g;
+       $comment .= ' ' x ($clth - (length($comment)));
+
+       if (!$slot1 && $self->{user}->wantgrid) {
+               my $ref = DXUser::get_current($_[1]);
+               if ($ref && $ref->qra) {
+                       $slot1 = ' ' . substr($ref->qra, 0, 4);
                }
        }
-
-       if ($self->{user}->wantdxitu) {
-               $loc = ' ' . sprintf("%2d", $_[10]) if defined $_[10];
-               $comment = substr($comment, 0,  $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[8]) if defined $_[8]; 
-       } elsif ($self->{user}->wantdxcq) {
-               $loc = ' ' . sprintf("%2d", $_[11]) if defined $_[11];
-               $comment = substr($comment, 0,  $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[9]) if defined $_[9]; 
-       } elsif ($self->{user}->wantusstate) {
-               $loc = ' ' . $_[13] if $_[13];
-               $comment = substr($comment, 0,  $self->{consort} eq 'local' ? 26 : 27) . ' ' . $_[12] if $_[12]; 
+       if (!$slot1 && $self->{user}->wantusstate) {
+               $slot1 = " $_[12]" if $_[12];
+       }
+       unless ($slot1) {
+               if ($self->{user}->wantdxitu) {
+                       $slot1 = sprintf(" %2d", $_[8]) if defined $_[8]; 
+               } elsif ($self->{user}->wantdxcq) {
+                       $slot1 = sprintf(" %2d", $_[9]) if defined $_[9];
+               }
+       }
+       $comment = substr($comment, 0,  $clth-length($slot1)) . $slot1 if $slot1;
+       
+    if (!$slot2 && $self->{user}->wantgrid) {
+               my $origin = $_[4];
+               $origin =~ s/-#$//;                     # sigh......
+               my $ref = DXUser::get_current($origin);
+               if ($ref && $ref->qra) {
+                       $slot2 = ' ' . substr($ref->qra, 0, 4);
+               }
+       }
+       if (!$slot2 && $self->{user}->wantusstate) {
+               $slot2 = " $_[13]" if $_[13];
+       }
+       unless ($slot2) {
+               if ($self->{user}->wantdxitu) {
+                       $slot2 = sprintf(" %2d", $_[10]) if defined $_[10]; 
+               } elsif ($self->{user}->wantdxcq) {
+                       $slot2 = sprintf(" %2d", $_[11]) if defined $_[11]; 
+               }
        }
 
-       return sprintf "DX de %-7.7s%11.1f  %-12.12s %-s $t$loc", "$_[4]:", $_[0], $_[1], $comment;
+       return sprintf "DX de %-8.8s%10.1f  %-12.12s %-s $t$slot2", "$_[4]:", $_[0], $_[1], $comment;
 }
 
 # send a dx spot
@@ -1194,7 +1233,7 @@ sub import_cmd
                                                $dxchan->{priv} = $u->priv;
                                                $dxchan->{user} = $u;
                                                @out = $s->run($dxchan, 1);
-                                               $dxchan->{call} = $call;
+                                               $dxchan->{call} = $old;
                                                $dxchan->{priv} = $priv;
                                                $dxchan->{user} = $user;
                                        } else {
@@ -1226,7 +1265,7 @@ sub send_motd
        my $self = shift;
        my $motd;
 
-       unless ($self->{registered}) {
+       unless ($self->registered) {
                $motd = "${main::motd}_nor_$self->{lang}";
                $motd = "${main::motd}_nor" unless -e $motd;
        }
@@ -1241,5 +1280,7 @@ sub send_motd
        }
        $self->send_file($motd) if -e $motd;
 }
+
+
 1;
 __END__