Warning: Undefined array key 1 in /var/www/html/blogg/include/parser.php on line 314
Nu var det faktiskt truncate_url("index.php?pid=148", "någon") som efterfrågade sourcen till min enkla bot. Efter lite redigeringar av den så tror jag att den ska fungera. Jag har dock bara testat den under Linux (Debian Sarge och Gentoo), ingen support kommer att ges på andra OS än Debian Men jag tror inte att det är så mycket som ska strula.
code:
#!/usr/bin/perl #Written and maintained by dr slizer use Socket; #Some bot settings $BotName = \'Anna\'; $BotDescription = \'Jag är en bot!\'; $BotPassword = \'\'; $debug = 1; #Show debug messages (all incomming and outgoing traffic) in STDOUT $ShowPMs = 1; #Show PMs in STDOUT if the come from an OP #Some hub settings $hostname = \'\'; $port = 411; #----Beginning of script----# $Name = \'Boten anna\'; $Version = \'0.1\'; @OpList = (); $tcpProtocolNumber = getprotobyname(\'tcp\') || 6; socket(SOCKET, PF_INET(), SOCK_STREAM(), $tcpProtocolNumber) || die(\"** Socket: $!\"); $address = (gethostbyname($hostname))[4]; $internetPackedAddress = pack(\'Sna4x8\', AF_INET(), $port, $address); print(\"** Connecting to $hostname:$port...\\n\"); connect(SOCKET, $internetPackedAddress) or die (\"** Connect: $!\"); print(\"** Connected\\n\"); $input_buffer = \'\'; $buffer = \'\'; $active = 1; while ($active) { #Clearing the buffer $buffer = \'\'; $get_data=1; #This loop read on \"protocol line\" from the socket while($get_data) { #Reading one byte from the buffer recv(SOCKET, $input_buffer, 1, 0); #print \"$input_buffer\\n\"; #If the buffer doesn\'t contain any data the connection was reset by the server #and we will exit this loop and shutdown the bot if($input_buffer eq \'\') { $active=0; $get_data=0; print(\"** Disconnected\\n\"); } #If the buffer contatins |, we exit the loop because the line is complete #If not we append the read byte to $buffer if($input_buffer eq \'|\') { $get_data=0; } else { $buffer=$buffer.$input_buffer; } } #Some debugging of incoming data if($debug && $active){ print \'>> \'.$buffer.\"\\n\";} @current = split(/ /, $buffer); #The first entry in the array is the command if(@current[0] eq \'$Lock\') { #We got lock, we\'re sending $Key and $ValidateNick send_data(\'$Key \'.Lock2Key(@current[1], 0x05).\'|\'); send_data(\'$ValidateNick \'.$BotName.\'|\'); } elsif(@current[0] eq \'$GetPass\') { print(\"** Sending password...\\n\"); send_data(\'$MyPass \'.$BotPassword.\'|\'); } elsif(@current[0] eq \'$ValidateDenide\') { #Something\'s wrong with our nick, shutting down the script print(\"** Invalid nickname\\n\"); $active=0; } elsif(@current[0] eq \'$BadPass\') { #Wrong password, shutting down the script print(\"** Invalid password\\n\"); $active=0; } elsif(@current[0] eq \'$HubIsFull\') { #The hub is full, shutting down the script print(\"** The hub is full\\n\"); $active=0; } elsif(@current[0] eq \'$Hello\') { if(@current[1] eq $BotName) { #Wieeeeee, we are welcome in the hub :) send_data(\'$Version 1,0091|\'); send_data(\'$GetNickList|\'); send_data(\'$MyINFO $ALL \'.$BotName.\' \'.$BotDescription.\'$ $BOT1$BOT$0$|\'); } } elsif(@current[0] eq \'$OpList\') { my(@new_Ops) = split(/\\$\\$/, @current[1]); my($index) = scalar @OpList; foreach $cur_op (@new_Ops) { if(!in_array($cur_op, @OpList)) { @OpList[$index] = $cur_op; $index++; } } } elsif(@current[0] eq \'$Quit\') { if(in_array(@current[1], @OpList)) { my(@new_OpList) = (); my($index) = 0; foreach $cur_op (@OpList) { if($cur_op ne @current[1]) { @new_OpList[$index]=$cur_op; $index++; } } @OpList = @new_OpList; } } elsif(@current[0] eq \'$To:\') { #Checking if the message really is to the bot, it should be but you never know ;) if(@current[1] eq $BotName) { #Merging all arguments to the command into one string my($arg) = \'\'; my($i) = 6; while ($i<@current) { if($arg ne \'\') { $arg=$arg.\' \'; } $arg=$arg.@current[$i]; $i++ } if($ShowPMs && !$debug && in_array(@current[3], @OpList)) { print($current.\"\\n\"); } #We let the command sub take care of the message command(@current[3], @current[5], $arg); } } else { my($first) = substr(@current[0], 0, 1); if($first ne \'$\') { #Main chat message if(@current[0] ne \'<Anna>\') { #Very quick and dirty matching ;) if($buffer =~ \' anna \' or $buffer =~ \' Anna \' or $buffer =~ \' Basshunter \' or $buffer =~ \' basshunter \') { send_data(\'<\'.$BotName.\'> Jag är en bot!|\'); } } } } } close(SOCKET); sub command { my($user, $command, $arg) = @_; #Removing new line char from $arg $arg =~ s/\\n//ig; ##Administrator functions if($command eq \'+shutdown\' && in_array($user, @OpList)) { print(\"** $user ordered me to shutdown\\n\"); $active = 0; } if($command eq \'+ops\') { send_data(\'$To: \'.$user.\' From: \'.$BotName.\' $<\'.$BotName.\'> I\\\'m aware of these operators:|\'); foreach $cur_op (@OpList) { send_data(\'$To: \'.$user.\' From: \'.$BotName.\' $<\'.$BotName.\'> \'.$cur_op.\'|\'); } } } sub in_array { my($value) = shift; my(@array) = @_; for(@array) { return 1 if $_ eq $value; } return 0; } sub send_data { my($data) = @_; if($debug){print(\"<< $data\\n\");} send(SOCKET, $data, 0) or die(\"** Failed sending data: $!\"); } sub Lock2Key { @_ == 2 or die \"** Usage: convertLockToKey( lock , xorkey )\"; my @lock = split( // , shift ); my $xor_key = scalar( shift ); my $i; my @key = (); # convert to ordinal foreach( @lock ) { $_ = ord; } # calc key[0] with some xor-ing magic push( @key , ( $lock[0] ^ $lock[ $#lock - 1 ] ^ $lock[ $#lock ] ^ $xor_key ) ); # calc rest of key with some other xor-ing magic for( $i = 1 ; $i < @lock ; $i++ ) { push( @key , ( $lock[$i] ^ $lock[$i - 1] ) ); } # nibble swapping for( $i = 0 ; $i < @key ; $i++ ) { $key[$i] = ( ( $key[$i] << 4 ) & 0xF0 ) | ( ( $key[$i] >> 4 ) & 0x0F ); } # escape some foreach( @key ) { if ( $_ == 0 || $_ == 5 || $_ == 36 || $_ == 96 || $_ == 124 || $_ == 126 ) { $_ = sprintf( \'/%%DCN%03i%%/\' , $_ ); } else { $_ = chr; } } # done return join( \'\' , @key ); }