rendered paste body<?php
$Log=fopen("php://stdin", "r");
$DateChanges=0;
$CurrentDate="";
$Cleaned=FALSE;
$SumTime=0;
declare(ticks=1);
pcntl_signal(SIGTERM, "Terminate", false);
pcntl_signal(SIGINT, "Terminate", false);
while(!feof($Log)) {
$Line=fgets($Log);
if(!ereg("^(\[... ... ..? ....\]) \[..:..:..\] Join[[:space:]]+([^ ]+) has joined this channel \(([^@]+)@([^)]+)\)", $Line, $Parts)) continue;
// $StartTime=microtime(TRUE);
// print "$Date $Nick $Ident $Host\n";
$Date=$Parts[1]; $Nick=trim($Parts[2], "^_`-"); $Ident=$Parts[3]; $Host=$Parts[4];
if($Date!=$CurrentDate) {
$CurrentDate=$Date;
$DateChanges+=1;
$Cleaned=FALSE;
}
if(isset($Who[$Nick]) and $Who[$Nick]['ident']==$Ident and $Host!=$Who[$Nick]['host']) {
// if(abs($Who[$Nick]['dc']-$DateChanges)<3) print $Who[$Nick]['host']." ".$Host."\n";
$CandidateWild="";
foreach($Wilds[$Nick] as $Key => $Wild) {
if($Wild['m']==$Host) continue;
$LeftWild=$RightWild="";
for($i=0; $i<strlen($Wild['m']); $i++) {
if(substr($Wild['m'], $i, 1)==substr($Host, $i, 1)) $LeftWild.=substr($Host, $i, 1);
else break;
}
for($i=1; $i<=strlen($Wild['m']); $i++) {
if(substr($Wild['m'], -$i, 1)==substr($Host, -$i, 1)) $RightWild=substr($Host, -$i, 1).$RightWild;
else break;
}
if(strlen($LeftWild."*".$RightWild)>strlen($CandidateWild)) {
$CandidateWild=$LeftWild."*".$RightWild;
$CandidateKey=$Key;
}
}
if(strlen($CandidateWild)>0.4*strlen($Host)) {
$Wilds[$Nick][$CandidateKey]['m']=$CandidateWild;
$Wilds[$Nick][$CandidateKey]['c']+=1;
} else {
$Wilds[$Nick][]['m']=$Host;
$Wilds[$Nick][]['c']=0;
}
}
$Who[$Nick]['dc']=$DateChanges; $Who[$Nick]['ident']=$Ident; $Who[$Nick]['host']=$Host;
if(!isset($Wilds[$Nick])) {
$Wilds[$Nick][]['m']=$Host;
$Wilds[$Nick][]['c']=0;
}
// $SumTime+=microtime(TRUE)-$StartTime;
if($DateChanges%5==0 And !$Cleaned) {
print ".";
// $StartTime=microtime(TRUE);
foreach($Who as $k => $w) if($DateChanges-$w['dc']>5) unset($Who[$k]);
foreach($Wilds as $k1 => $W1) {
foreach($W1 as $k2 => $Wild) if(strpos($Wild['m'], "*")!==FALSE And strlen($Wild['m'])>=6); else unset($W1[$k2]);
if(count($W1)==0) unset($Wilds[$k1], $Who[$k1]);
}
// print microtime(TRUE)-$StartTime."\n";
$Cleaned=TRUE;
}
}
print "\n";
Terminate(0);
function Terminate($Signal) {
global $Wilds, $Who;
foreach($Wilds as $k1 => $W1) {
foreach($W1 as $k2 => $Wild) if(strpos($Wild['m'], "*")!==FALSE And strlen($Wild['m'])>=7) print $Wild['m']."\n"; else unset($W1[$k2]);
// if(count($W1)==0) unset($Wilds[$k1]);
}
exit(0);
}
?>