Advertisement
NullSet

NullBot0.2

Apr 22nd, 2011
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.68 KB | None | 0 0
  1. use strict;
  2. use IO::Socket;
  3.  
  4. my $server = "irc.evilzone.org";
  5. my $nick = "NullBot";
  6. my $user = "NullBot";
  7. my $channel = "#robots";
  8. my $exit = 0;
  9.  
  10.  
  11. my $sock = new IO::Socket::INET(
  12.                             PeerAddr => $server,
  13.                             PeerPort => 6667,
  14.                             Proto => 'tcp') or
  15.                             die "Can't create socket\n";
  16. print "DEBUG: Socket created properly\n";
  17. sleep(1);
  18. #Send the Nick and Username
  19. print $sock "NICK $nick\r\n";
  20. print "DEBUG: Nick sent\n";
  21. print $sock "USER $user 8 * :Null Bot\r\n";
  22. print "DEBUG: User sent\n";
  23. while (my $input = <$sock>) {
  24.     chop $input;
  25.     if ($input =~ m/^PING(.*)$/i) {
  26.         print $sock "PONG $1\r\n";
  27.         last;
  28.     }
  29.     if ($input =~ m/004/) {print "$input\n"; last;}
  30.     else {
  31.         print "$input\n";
  32.     }
  33. }
  34.  
  35.  
  36. #join specified channel
  37. print $sock "JOIN $channel\r\n";
  38.  
  39. #fork starts here:
  40. my $pid = fork();
  41. print "DEBUG: Process ID is: ".$pid."\n";
  42.  
  43. #If fork was unsuccessful
  44. if(not defined $pid){
  45.     print "Could not create fork, exiting now...";
  46.     exit(0);
  47.     }
  48. #If it's the child
  49. elsif($pid == 0){
  50.     print "DEBUG: Child fork is working\n\n";
  51.     while(1){
  52.         my $message = <STDIN>;
  53.         if($message eq "/exit"){print "Exit child now."; $exit = 1; exit(0);}
  54.         else {print $sock "PRIVMSG $channel :$message\r\n";}
  55.     }
  56. }
  57. #IF It's the parent
  58. else{
  59.     print "DEBUG: Parent fork is working\n\n";
  60.     while (my $input = <$sock>) {
  61.         chop $input;
  62.         if($exit == 1){print "Application will exit in 3 seconds..."; sleep(3); exit(0);}
  63.             else{
  64.             if ($input =~ m/^PING(.*)$/i) {
  65.                 print $sock "PONG $1\r\n";
  66.                 print "Responded to Ping\n";
  67.             }
  68.             else {
  69.                 print "$input\n";
  70.             }
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement