]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/Wingate.pl
use result div in babelfish
[infobot.git] / src / Modules / Wingate.pl
index bb93593bf4f7176ad85a7577a31e86f978b40677..06b163c9dea8972fbb9b7aae7dcd6afeee226c94 100644 (file)
@@ -12,22 +12,22 @@ use strict;
 my $select = IO::Select->new;
 
 sub Wingates {
-    my $file = "$::blootbot_base_dir/$::param{'ircUser'}.wingate";
+    my $file = "$::infobot_base_dir/$::param{'ircUser'}.wingate";
     my @hosts;
 
-    open(IN, $file);
+    open( IN, $file );
     while (<IN>) {
-       chop;
-       next if (/\*$/);        # wingate. or forget about it?
-       push(@hosts,$_);
+        chop;
+        next if (/\*$/);    # wingate. or forget about it?
+        push( @hosts, $_ );
     }
     close IN;
 
     foreach (@_) {
-       next if (grep /^$_$/, @hosts);
+        next if ( grep /^$_$/, @hosts );
 
-       &::DEBUG("W: _ => '$_'.");
-       &Wingate($_);
+        &::DEBUG("W: _ => '$_'.");
+        &Wingate($_);
     }
 }
 
@@ -35,15 +35,15 @@ sub Wingate {
     my ($host) = @_;
 
     my $sock = IO::Socket::INET->new(
-       PeerAddr        => $host,
-       PeerPort        => 'telnet(23)',
-       Proto           => 'tcp'
+        PeerAddr => $host,
+        PeerPort => 'telnet(23)',
+        Proto    => 'tcp'
 ###    Timeout         => 10,          # enough :)
     );
 
-    if (!defined $sock) {
-       &::status("Wingate: connection refused to $host");
-       return;
+    if ( !defined $sock ) {
+        &::status("Wingate: connection refused to $host");
+        return;
     }
 
     $sock->timeout(10);
@@ -51,48 +51,52 @@ sub Wingate {
 
     my $errors = 0;
     my ($luser);
-    foreach $luser ($select->can_read(1)) {
-       my $buf;
-       my $len = 0;
-       if (!defined($len = sysread($luser, $buf, 512))) {
-           &::status("Wingate: connection lost to $luser/$host.");
-           $select->remove($luser);
-           close($luser);
-           next;
-       }
-
-       if ($len == 9) {
-           $len = sysread($luser, $buf, 512);
-       }
-
-       my $wingate = 0;
-       $wingate++ if ($buf =~ /^WinGate\>/);
-       $wingate++ if ($buf =~ /^Too many connected users - try again later$/);
-
-       if ($wingate) {
-           &::status("Wingate: RUNNING ON $host BY $::who.");
-
-           if (&::IsChanConf('wingateBan') > 0) {
-               &::ban("*!*\@$host", "");
-           }
-
-           my $reason  = &::getChanConf('wingateKick');
-           if ($reason) {
-               &::kick($::who, '', $reason);
-           }
-
-           push(@::wingateBad, "$host\*");
-           &::wingateWriteFile();
-       } else {
+    foreach $luser ( $select->can_read(1) ) {
+        my $buf;
+        my $len = 0;
+        if ( !defined( $len = sysread( $luser, $buf, 512 ) ) ) {
+            &::status("Wingate: connection lost to $luser/$host.");
+            $select->remove($luser);
+            close($luser);
+            next;
+        }
+
+        if ( $len == 9 ) {
+            $len = sysread( $luser, $buf, 512 );
+        }
+
+        my $wingate = 0;
+        $wingate++ if ( $buf =~ /^WinGate\>/ );
+        $wingate++
+          if ( $buf =~ /^Too many connected users - try again later$/ );
+
+        if ($wingate) {
+            &::status("Wingate: RUNNING ON $host BY $::who.");
+
+            if ( &::IsChanConf('wingateBan') > 0 ) {
+                &::ban( "*!*\@$host", '' );
+            }
+
+            my $reason = &::getChanConf('wingateKick');
+            if ($reason) {
+                &::kick( $::who, '', $reason );
+            }
+
+            push( @::wingateBad, "$host\*" );
+            &::wingateWriteFile();
+        }
+        else {
 ###        &::DEBUG("no wingate.");
-       }
+        }
 
-       ### TODO: close telnet connection correctly!
-       $select->remove($luser);
-       close($luser);
+        ### TODO: close telnet connection correctly!
+        $select->remove($luser);
+        close($luser);
     }
 
     return;
 }
 
 1;
+
+# vim:ts=4:sw=4:expandtab:tw=80