; trigger in chan #CnR|LV to scan the database for ips (!ip <Name> [full]) or names (!ip <IP> [full])
on *:text:!ip*:#CnR|LV: {
var %ini = $qt($shortfn($mircdirini\ips.ini)), %name = $replace($2,[,$chr(40),],$chr(41))
var %reg = /^(?:\d{1,3}\.){3}\d{1,3}$/, %isIP = $iif($regex(%name,%reg),$true,$false)
ECHO 7 -a scan for %name at ini= %ini - isIP= %isIP
; no match / error outputs
if (!$2) {
msg $chan No nickname/IP given. Use !ip <name> to get matching IPs, $&
or !ip <IP> to get matching names. You can use "full" as second parameter.
}
elseif (!$ini(%ini,0)) { msg $chan IP-database is empty. }
; scan for name matches
elseif (!%isIP) {
ECHO 7 -a scan for name matches
if (!$ini(%ini,%name,0)) { msg $chan No entry for Name $qt($2) found. }
; loop matches for player name
else {
var %t = $ini(%ini,%name,0), %ips = $+($chr(31),IPs used by $2,$chr(15),:)
while ((%t > 0) && ($ini(%ini,%name,%t))) {
var %stamp = $v1, %ip = $readini(%ini,%name,%stamp)
var %ips = %ips $iif(($3 == full),$+($chr(2),%ip,$chr(2)) $asctime(%stamp,(dd.mm.yy, HH:nn)),%ip)
; output of matches
if ($len(%ips) > 300) {
msg $chan $makestringIP(%ips)
var %ips
}
dec %t
}
if (%ips) { msg $chan $makestringIP($v1) }
}
}
; scan for IP matches
else {
ECHO 7 -a scan for IP matches
var %reg = $+(/^\[|,$replace(%name,.,\.),$/), %tempini = $qt($shortfn($mircdirini\ipsTEMP.ini))
; filter the ini to a temporary ini, removing everything that's no ini topic or IP match
filter -ffcg %ini %tempini %reg
ECHO 7 -a TEMPINI $iif(($isfile(%tempini)),created (filter) at %tempini - $lines(%tempini) lines,not created)
; replace the matched IP in the data part of ini items with the player name (ini topic)
var %n = 1
while ($ini(%tempini,%n)) {
var %topic = $v1
if ($ini(%tempini,%topic,1)) { writeini -n %tempini %topic $v1 %topic }
inc %n
}
; filter tempini to remove ini topics (no longer needed), sort it (get timestamps in order)
filter -ffcgxteu 1 61 %tempini %tempini ^\[
ECHO 7 -a results in tempini: $lines(%tempini)
; no matches (no lines left)
if (!$read(%tempini,1)) { msg $chan No entry for IP %name found. }
; loop and output the filtered matches
else {
var %n = 1, %names = $+($chr(31),Names used on IP %name,$chr(15),:)
while ($read(%tempini,%n)) {
ECHO 7 -a output match %n = $v1
var %stamp = $gettok($v1,1,61), %player = $replace($gettok($v1,2,61),$chr(40),[,$chr(41),])
var %names = %names $iif(($3 == full),$+($chr(2),%player,$chr(2)) $asctime(%stamp,(dd.mm.yy, HH:nn)),%player)
if ($len(%names) > 300) {
msg $chan $makestringN(%names)
var %names
}
inc %n
}
if (%names) { msg $chan $makestringN(%names) }
ECHO 7 -a output done, removing tempini
.remove %tempini
}
}
}