Changeset 234 for trollforge/jmax


Ignore:
Timestamp:
07/06/06 00:35:01 (7 years ago)
Author:
jmax
Message:

added multi-network support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trollforge/jmax/asian.pl

    r233 r234  
    3333 
    3434# TODO: 
    35 # 18:47:34 <@Rucas> jmax, keep proxies in a list and remove them if they do not connect, and keep a list for each server and as they are banned for each server remove from list 
    36 # file flooding with adjustments for nick-length 
    37 # fix warnings 
    38 # connect to a network other than the control channel 
    39 # add to help msg 
    40 # dictionary for nick ? 
    41 # make username and nick different 
     35# X 18:47:34 <@Rucas> jmax, keep proxies in a list and remove them if they do not connect, and keep a list for each server and as they are banned for each server remove from list 
     36#   file flooding with adjustments for nick-length 
     37# X fix warnings 
     38# X connect to a network other than the control channel 
     39# X add to help msg  
     40#   dictionary for nick ? 
     41#   make username and nick different 
    4242 
    4343use warnings; 
     
    5454$VERSION = "2.0-beta2"; 
    5555 
    56 print "Please run using the --help argument\n" and exit 666 unless $ARGV[0]; 
     56print "!!! please run using the --help argument\n" and exit 666 unless $ARGV[0]; 
    5757my ($server, $port, $channel); 
    5858if ($ARGV[0] eq '--help') { 
     
    6060          "\n". 
    6161          "\n". 
    62           "    Invocation:\n". 
     62          "  Invocation:\n". 
    6363          "      perl ".__FILE__." server[:port] \"#channel\"\n". 
    6464          "\n". 
     
    7070          "\n". 
    7171          "\n". 
    72           "    Usage:\n". 
     72          "  Usage:\n". 
    7373          "      all <raw IRC command> [space-delimited arguments] :[arguments with spaces]\n". 
    7474          "      all connect <server>\n". 
     
    7878          "    Simply privmsg your command to the control channel, and the respective bots will follow.\n". 
    7979          "\n". 
    80           "    Examples:\n". 
     80          "  Examples:\n". 
    8181          "      <~supers> all join #gnaa gnaa\n". 
    8282          "        All bots will join #gnaa using the key 'gnaa'\n". 
     
    9595    exit 0; 
    9696} else { 
    97     print "Please run using the --help argument\n" and exit 666 unless $ARGV[1]; 
     97    print "!!!! please run using the --help argument\n" and exit 666 unless $ARGV[1]; 
    9898    if ($ARGV[0] =~ /(.+):(\d+)/) { 
    9999        $server = $1; 
     
    105105    $channel = $ARGV[1];     
    106106} 
    107 my (undef, undef, undef, undef, @servers) = gethostbyname($server); 
    108 unless (@servers) { 
    109     print "Cannot resolve server $ARGV[0]: $?\n"; 
    110     exit 666; 
    111 } 
    112 my @servers_ip; 
    113 foreach my $server (@servers) { 
    114     my ($a, $b, $c, $d) = unpack('C4', $server); 
    115     my $server_ip = "$a.$b.$c.$d"; 
    116     push (@servers_ip, $server_ip); 
    117 } 
     107 
     108my @servers = resolve($server); 
    118109my %proxies = load_socks(); 
    119110my @proxylist; 
    120 foreach my $key (keys %proxies) { 
    121     push(@proxylist, $key); 
    122 } 
     111sub clean_proxylist { push(@proxylist, $key) foreach my $key (keys %proxies); } 
     112clean_proxylist(); 
     113 
    123114for ($forkcount = 0; $forkcount < $maxfork; $forkcount++) { # $forkcount must _not_ be local to here 
    124115    sleep 1;                          # so we don't overload ourselves 
     
    129120            my $proxy_ip = $proxylist[int rand @proxylist]; 
    130121            my $proxy_port = $proxies{$proxy_ip}; 
    131             spawn_bot($proxy_ip, $proxy_port, $servers_ip[int rand @servers_ip], $port)  
    132                 or delete $proxies{$proxy_ip}; 
     122            spawn_bot($proxy_ip, $proxy_port, $servers[int rand @servers], $port)  
     123               or delete $proxies{$proxy_ip} and clean_proxylist; 
    133124            sleep 1; 
    134125        } 
     
    169160    }; 
    170161    if ($@) { 
    171       warn "!!!! unkown error: $@" unless $@ eq "alarm\n";   # propagate unexpected errors 
    172       warn "TIMEOUT / CONNECTION REFUSED, SOCKS == SHIT (probably); DELETING AND LOADING NEW;";  
     162      warn "!!!! unkown error: $@" unless $@ eq "alarm\n"; # propagate unexpected errors 
     163      print "!!!! TIMEOUT / CONNECTION REFUSED; SOCKS == SHIT; DELETING AND LOADING NEW;";  
    173164      return 0; 
    174165    } 
     
    201192            print $sock "$cmd\r\n"; 
    202193            print STDOUT "<<<< $nick] $cmd\r\n"; 
    203         } elsif ($line =~ /PRIVMSG $channel :\S*$nick\S* (.*)$/) { 
     194        } elsif ($line =~ /PRIVMSG $channel :\S*$nick\S* (.*)$/i) { 
    204195            my $cmd = $1; 
    205196            if ($cmd =~ /nick (\S*)/i) { 
    206197                $nick = $1; 
    207             } 
     198            }  
    208199            print $sock "$cmd\r\n"; 
    209200            print STDOUT "<<<< $nick] $cmd\r\n"; 
     201        } elsif ($line =~ /PRIVMSG $channel :all connect (.*)$/i) { 
     202            my $net = $1; 
     203            if ($net =~ /(.+):(\d+)/) { 
     204                my $remote_server = $1; 
     205                my $remote_port = $2; 
     206            } 
     207            my @remote_ips = resolve($remote_server); 
     208            my $altsock = connect_to_socks_proxy($socks_ip, $socks_port, $remote_ips[int rand @remote_ips], $remote_port); 
     209            print STDOUT "<<<< $nick] connecting to $net\r\n";                         
     210        } elsif ($line =~ /PRIVMSG $channel :\S*$nick\S* connect (.*)$/i) { 
     211            my $net = $1; 
     212            if ($net =~ /(.+):(\d+)/) { 
     213                my $remote_server = $1; 
     214                my $remote_port = $2; 
     215            } 
     216            my @remote_ips = resolve($remote_server); 
     217            my $altsock = connect_to_socks_proxy($socks_ip, $socks_port, $remote_ips[int rand @remote_ips], $remote_port); 
     218            print STDOUT "<<<< $nick] connecting to $net\r\n";             
     219        } elsif ($line =~ /PRIVMSG $channel :all:(\S*) (.*)$/i) { 
     220            my $net = $1; 
     221            my $cmd = $2; 
     222            print $altsock "$2\r\n"; 
     223            print STDOUT "<<<< $nick] $cmd\r\n";             
     224        } elsif ($line =~ /PRIVMSG $channel :\S*$nick\S*:(\S*) connect (.*)$/i) { 
     225            my $net = $1; 
     226            my $cmd = $2; 
     227            print $altsock "$2\r\n"; 
     228            print STDOUT "<<<< $nick] $cmd\r\n";             
    210229        } else { 
    211230            print STDOUT "<<<< $line\n"; 
     
    245264    return $str; 
    246265} 
     266 
     267sub resolve { 
     268    my $host = shift; 
     269    my (undef, undef, undef, undef, @servers) = gethostbyname($server); 
     270    unless (@servers) { 
     271        print "!!!! cannot resolve server $ARGV[0]: $?\n"; 
     272        return 0; 
     273    } 
     274    my @servers_ip; 
     275    foreach my $server (@servers) { 
     276        my ($a, $b, $c, $d) = unpack('C4', $server); 
     277        my $server_ip = "$a.$b.$c.$d"; 
     278        push (@servers_ip, $server_ip); 
     279   } 
     280   return @servers_ip; 
     281} 
     282 
Note: See TracChangeset for help on using the changeset viewer.