Leser: 15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#!/usr/bin/perl use IO::Socket; $server = "__IRCSERVER__"; $port = 6667; $channel = "#channel1"; $nick = "perlbot"; my $sock_listen = new IO::Socket::INET(Localhost => '127.0.0.1', LocalPort => '7070', Proto => 'tcp', Listen => 1, => Reuse => 1,); die "Could not create socket: $!\n" unless $sock_listen; $sock_irc = IO::Socket::INET->new(Proto => "tcp", PeerAddr => "$server", PeerPort => "$port") || die "Failed to connect to $server:$port\n"; print $sock_irc "NICK $nick\r\n"; print $sock_irc "USER $nick $server $nick $nick\r\n"; print $sock_irc "JOIN $channel\r\n"; print $sock_irc "PRIVMSG $channel :Hello\r\n"; while(<$sock_irc>) { print $_; if(/PING/) { $line = $_; $line =~ s/PING/PONG/; print $sock_irc $line; } elsif(/PRIVMSG/) { $line = $_; $line =~ s/\r\n//; # Remove \r\n @tokens = split /:/, $line; # Split line into tokens @command = split / /, @tokens[1]; # Split second token (first is just blank in this case) @message = split / /, @tokens[2]; # Split third token @user = split /!/, @command[0]; # Split first command token, which is USERNAME!USERHOST if($message[0] =~ m/.exit/) { print $sock_irc "PRIVMSG $command[2] :Exit command sent by $user[0] ($user[1])\r\n"; print $sock_irc "QUIT :$message[1]\r\n"; close $sock_irc; } if($message[0] =~ m/.join/) { print $sock_irc "PRIVMSG $command[2] :Join command sent by $user[0] ($user[1])\r\n"; print $sock_irc "JOIN $message[1]\r\n"; } if($message[0] =~ m/.msg/) { print $sock_irc "PRIVMSG $command[2] :Message command sent by $user[0] ($user[1])\r\n"; print $sock_irc "PRIVMSG $message[1] :$message[2]\r\n"; } } }