Logger: Handle NICK message

This commit is contained in:
mrkubax10 2023-09-19 09:32:11 +02:00
parent c41173c06f
commit bfa355e846

View File

@ -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
}