diff --git a/logger.pm b/logger.pm index e13af3b..1359155 100644 --- a/logger.pm +++ b/logger.pm @@ -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(); }