Skip to content

Commit

Permalink
Reply to the initial ping command.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
demanuel committed Jan 15, 2017
1 parent 9a18fc6 commit 8659ae2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions IRC/bot.pl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
use File::Find;
use File::Basename;
use Time::HiRes qw/usleep/;
use IO::Select;

$|=1;
my $CRLF="\x0D\x0A";
$\=$CRLF;
Expand Down Expand Up @@ -149,17 +151,19 @@ 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";
print $sock "USER $nick * * :NewsUP News_UP";
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;
}
Expand Down

0 comments on commit 8659ae2

Please # to comment.