Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use IO::Socket;
- my $server = "irc.evilzone.org";
- my $nick = "NullBot";
- my $user = "NullBot";
- my $channel = "#robots";
- my $exit = 0;
- my $sock = new IO::Socket::INET(
- PeerAddr => $server,
- PeerPort => 6667,
- Proto => 'tcp') or
- die "Can't create socket\n";
- print "DEBUG: Socket created properly\n";
- sleep(1);
- #Send the Nick and Username
- print $sock "NICK $nick\r\n";
- print "DEBUG: Nick sent\n";
- print $sock "USER $user 8 * :Null Bot\r\n";
- print "DEBUG: User sent\n";
- while (my $input = <$sock>) {
- chop $input;
- if ($input =~ m/^PING(.*)$/i) {
- print $sock "PONG $1\r\n";
- last;
- }
- if ($input =~ m/004/) {print "$input\n"; last;}
- else {
- print "$input\n";
- }
- }
- #join specified channel
- print $sock "JOIN $channel\r\n";
- #fork starts here:
- my $pid = fork();
- print "DEBUG: Process ID is: ".$pid."\n";
- #If fork was unsuccessful
- if(not defined $pid){
- print "Could not create fork, exiting now...";
- exit(0);
- }
- #If it's the child
- elsif($pid == 0){
- print "DEBUG: Child fork is working\n\n";
- while(1){
- my $message = <STDIN>;
- if($message eq "/exit"){print "Exit child now."; $exit = 1; exit(0);}
- else {print $sock "PRIVMSG $channel :$message\r\n";}
- }
- }
- #IF It's the parent
- else{
- print "DEBUG: Parent fork is working\n\n";
- while (my $input = <$sock>) {
- chop $input;
- if($exit == 1){print "Application will exit in 3 seconds..."; sleep(3); exit(0);}
- else{
- if ($input =~ m/^PING(.*)$/i) {
- print $sock "PONG $1\r\n";
- print "Responded to Ping\n";
- }
- else {
- print "$input\n";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement