From 8659ae2ff8188036f5fe08716e7fac10c982df1d Mon Sep 17 00:00:00 2001 From: David Santiago Date: Sun, 15 Jan 2017 19:18:25 +0100 Subject: [PATCH] Reply to the initial ping command. Some servers send a ping command immediatly after we connect. The bot original behaviour was to reply to the ping commands after the authentication was done. So if the first thing was sent before any authentication happened it would be impossible to proceed with the authentication because the IRC server wouldn't accept it. This would make the bot to be unable to connect. --- IRC/bot.pl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/IRC/bot.pl b/IRC/bot.pl index 891d0cb..6014e1b 100644 --- a/IRC/bot.pl +++ b/IRC/bot.pl @@ -37,6 +37,8 @@ use File::Find; use File::Basename; use Time::HiRes qw/usleep/; +use IO::Select; + $|=1; my $CRLF="\x0D\x0A"; $\=$CRLF; @@ -149,6 +151,7 @@ sub get_IRC_socket{ sub _authenticate{ my ($sock, $nick, $password) = @_; + say "Initial read: "._read_from_socket($sock); # Log on to the server. print $sock "NICK $nick"; #print $sock "USER $login 8 * :NewsUp TEST \r\n"; @@ -156,10 +159,11 @@ sub _authenticate{ print $sock "MSG NickServ identify $password" if (defined $password && $password ne ''); # Read lines from the server until it tells us we have connected. - while (my $input = <$sock>) { + while (my $input = _read_from_socket($sock)) { chomp $input; - # Check the numerical responses from the server. - if ($input =~ /004/) { + if ($input =~ /^PING(.*)$/i) { # If the server + print $sock "PONG $1"; + }elsif ($input =~ /004/) { # Check the numerical responses from the server. # We are now logged in. last; }