From bfa355e84633da6df66c87727641188a59c9632d Mon Sep 17 00:00:00 2001 From: mrkubax10 Date: Tue, 19 Sep 2023 09:32:11 +0200 Subject: [PATCH] Logger: Handle NICK message --- logger.pm | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/logger.pm b/logger.pm index 2180e42..9f389d0 100644 --- a/logger.pm +++ b/logger.pm @@ -308,6 +308,36 @@ sub handlePart { $aLogFiles->{$aCommand->[1]}{"file"}->flush(); } +sub handleNick { + my $aCommand = $_[0]; + my $aServerName = $_[1]; + my $aLogFiles = $_[2]; + + my $aCommandLength = scalar(@$aCommand); + if($aCommandLength!=3) { + print("[error] Encountered invalid NICK command (3 arguments expected, $aCommandLength provided)\n"); + return; + } + my $username = getUsernameFromHost($aCommand->[2]); + foreach my $channel (keys(%$aLogFiles)) { + my $found = 0; + my $i = 0; + foreach $i (0..scalar(@{$aLogFiles->{$channel}{"names"}})-1) { + my $name = \$aLogFiles->{$channel}{"names"}[$i]; + if($$name eq $username) { + $found = 1; + $$name = $aCommand->[1]; + last; + } + } + if(!$found || !prepareLogFile($aLogFiles, $aServerName, $channel)) { + next; + } + $aLogFiles->{$aCommand->[1]}{"file"}->print(sprintf("(%s) %s is now known as %s\n", localtime->strftime("%H:%M:%S"), $username, $aCommand->[1])); + $aLogFiles->{$aCommand->[1]}{"file"}->flush(); + } +} + sub joinChannel { my $aStream = $_[0]; my $aChannel = $_[1]; @@ -388,6 +418,7 @@ sub connectionWorker { when("JOIN") { handleJoin(\@command, $aServerName, \%logFiles); } when("QUIT") { handleQuit(\@command, $aServerName, \%logFiles); } when("PART") { handlePart(\@command, $aServerName, \%logFiles); } + when("NICK") { handleNick(\@command, $aServerName, \%logFiles); } when("376") { joinChannels($stream, $aChannels); } # end of MOTD when("353") { handleNames(\@command, $aChannels, \%logFiles); } # NAMES reply }