tidied up login: changes in client.pl
[spider.git] / perl / client.pl
index a7185ab208de387c0a58df593ca3c4597e2a5151..84ab5d530ee7e770636299302306469c2ad3dc18 100755 (executable)
@@ -41,6 +41,7 @@ BEGIN {
 use Msg;
 use DXVars;
 use DXDebug;
+use DXUtil;
 use Net::Telnet qw(TELOPT_ECHO);
 use IO::File;
 use IO::Socket;
@@ -53,6 +54,7 @@ sub cease
        my $sendz = shift;
        if ($conn && $sendz) {
                $conn->send_now("Z$call|bye...\n");
+               sleep(1);
        }
        $stdout->flush if $stdout;
        if ($pid) {
@@ -62,6 +64,9 @@ sub cease
        dbgclose();
 #      $SIG{__WARN__} = sub {my $a = shift; cluck($a); };
        sleep(1);
+
+       # do we need this ?
+       $conn->disconnect if $conn;
        exit(0);        
 }
 
@@ -270,6 +275,10 @@ sub dochat
                                $line = <$rfh>;
                                $line =~ s/\r//og;
                        }
+                       if (length $line == 0) {
+                               dbg('connect', "received 0 length line, aborting...");
+                               cease(11);
+                       }
                        dbg('connect', "received \"$line\"");
                        if ($abort && $line =~ /$abort/i) {
                                dbg('connect', "aborted on /$abort/");
@@ -360,6 +369,9 @@ if ($loginreq) {
        my $user;
        my $s;
 
+       $connsort = 'telnet' if $connsort eq 'local';
+       setmode();
+
        if (-e "$data/issue") {
                open(I, "$data/issue") or die;
                local $/ = undef;
@@ -370,42 +382,25 @@ if ($loginreq) {
                $stdout->print($issue) if $issue;
        }
        
-
-       use DXUser;
-       
-       DXUser->init($userfn);
-       
        # allow a login from an existing user. I could create a user but
        # I want to check for valid callsigns and I don't have the 
        # necessary info / regular expression yet
-       for ($state = 0; $state < 2; ) {
-               alarm($timeout);
+       alarm($timeout);
                
-               if ($state == 0) {
-                       $stdout->print('login: ');
-                       $stdout->flush();
-                       local $\ = $nl;
-                       $s = $stdin->getline();
-                       chomp $s;
-                       $s =~ s/\s+//og;
-                       $s =~ s/-\d+$//o;            # no ssids!
-                       cease(0) unless $s gt ' ';
-                       $call = uc $s;
-                       $user = DXUser->get($call);
-                       $state = 1;
-               } elsif ($state == 1) {
-                       $stdout->print('password: ');
-                       $stdout->flush();
-                       local $\ = $nl;
-                       $s = $stdin->getline();
-                       chomp $s;
-                       $state = 2;
-                       if (!$user || ($user->passwd && $user->passwd ne $s)) {
-                               $stdout->print("sorry...$nl");
-                               cease(0);
-                       }
-               }
-       }
+       $stdout->print('login: ');
+       $stdout->flush();
+       local $\ = $mynl;
+       $s = $stdin->getline();
+       chomp $s;
+       $s =~ s/\s+//og;
+       $s =~ s/-\d+$//o;            # no ssids!
+       cease(0) unless $s && $s gt ' ';
+       unless (iscallsign($s)) {
+               $stdout->print("Sorry, $s is an invalid callsign");
+               cease(0);
+       } 
+       $call = uc $s;
+       alarm(0);
 }
 
 # handle callsign and connection type firtling