Logger: Update names list for channel

This commit is contained in:
mrkubax10 2023-09-18 17:57:30 +02:00
parent 060f27cb1d
commit 3b3c82f417

View File

@ -242,7 +242,9 @@ sub handleJoin {
if(!prepareLogFile($aLogFiles, $aServerName, $aCommand->[1])) {
return;
}
$aLogFiles->{$aCommand->[1]}{"file"}->print(sprintf("(%s) %s has joined %s\n", localtime->strftime("%H:%M:%S"), getUsernameFromHost($aCommand->[2]), $aCommand->[1]));
my $username = getUsernameFromHost($aCommand->[2]);
push(@{$aLogFiles->{$aCommand->[1]}{"names"}}, $username);
$aLogFiles->{$aCommand->[1]}{"file"}->print(sprintf("(%s) %s has joined %s\n", localtime->strftime("%H:%M:%S"), $username, $aCommand->[1]));
$aLogFiles->{$aCommand->[1]}{"file"}->flush();
}
@ -263,9 +265,12 @@ sub handleQuit {
my $username = getUsernameFromHost($aCommand->[$aCommandLength-1]);
foreach my $channel (keys(%$aLogFiles)) {
my $found = 0;
foreach my $name (@{$aLogFiles->{$channel}{"names"}}) {
my $i = 0;
foreach $i (0..scalar(@{$aLogFiles->{$channel}{"names"}})-1) {
my $name = $aLogFiles->{$channel}{"names"}[$i];
if($name eq $username) {
$found = 1;
splice(@{$aLogFiles->{$channel}{"names"}}, $i, 1);
last;
}
}
@ -290,7 +295,15 @@ sub handlePart {
if(!prepareLogFile($aLogFiles, $aServerName, $aCommand->[1])) {
return;
}
$aLogFiles->{$aCommand->[1]}{"file"}->print(sprintf("(%s) %s has left %s\n", localtime->strftime("%H:%M:%S"), getUsernameFromHost($aCommand->[2]), $aCommand->[1]));
my $username = getUsernameFromHost($aCommand->[2]);
foreach my $i (0..scalar(@{$aLogFiles->{$aCommand->[1]}{"names"}})-1) {
my $name = $aLogFiles->{$aCommand->[1]}{"names"}[$i];
if($name eq $username) {
splice(@{$aLogFiles->{$aCommand->[1]}{"names"}}, $i, 1);
last;
}
}
$aLogFiles->{$aCommand->[1]}{"file"}->print(sprintf("(%s) %s has left %s\n", localtime->strftime("%H:%M:%S"), $username, $aCommand->[1]));
$aLogFiles->{$aCommand->[1]}{"file"}->flush();
}