; text event: add IPs announced in channel #admin to an ini-file
on $*:text:/^(\S+) \(ID\W\d+\)'s Ip is ((\d{1,3}\.){3}\d{1,3})\.$/:#admin: {
var %ini = $qt($shortfn($mircdirini\ips.ini))
; remove existing entry of that user and that ip
if ($ini(%ini,$regml(1))) {
var %n = 1
while ($ini(%ini,$regml(1),%n)) {
if ($readini(%ini,$regml(1),$v1) == $regml(2)) {
remini -n %ini $regml(1) $ini(%ini,$regml(1),%n)
break
}
inc %n
}
}
; and readd (updating the "timestamp") or simply add the entry to to the ini
writeini -n %ini $regml(1) $ctime $regml(2)
}
; trigger to scan the database for ips: !ip <Name> or !ip <Name> full
on *:text:!ip*:#CnR|LV: {
var %ini = $qt($shortfn($mircdirini\ips.ini))
; no match / error outputs
if (!$ini(%ini,0)) { msg $chan IP-database is empty. }
elseif (!$2) { msg $chan No nickname given. Use !ip <nick> }
elseif (!$ini(%ini,$2,0)) { msg $chan No entry for $qt($2) found. }
; loop matches for player
else {
var %t = $ini(%ini,$2,0), %ips = IPs used by $2 $+ :
while ((%t > 0) && ($ini(%ini,$2,%t))) {
var %stamp = $v1, %ip = $readini(%ini,$2,%stamp)
var %ips = %ips $iif(($3 == full),$asctime(%stamp,(dd.mm.yy, HH:nn)) $+($chr(2),%ip,$chr(2)),%ip)
; output of matches
if ($len(%ips) > 300) {
msg $chan $makestring(%ips)
var %ips
}
dec %t
}
if (%ips) { msg $chan $makestring($v1) }
}
}
; text formatting routine (IP output of !ip)
alias -l makestring { return $regsubex($1-,/(?<=\d\x2|\d)\s/g,$+($chr(32),-,$chr(32))) }
; text trigger for database cleanup: !cleanips <deadline>.
; (restricted to opped users at #CnR|LV)
on @*:text:!cleanips*:#CnR|LV: {
if (($2 !isnum) && ($duration($2-) > 0)) {
var %ini = $qt($shortfn($mircdirini\ips.ini))
msg $chan There are currently $ini(%ini,0) players in the database. $&
Start removing all IPs older than $duration($v1) ...
set -e %ips.c.duration $v1
set -e %ips.c.kept 0
set -e %ips.c.removed 0
; init the cleaning (filter through an alias)
if ($window(@ips.c)) { window -c @ips.c }
window -h @ips.c
filter -fk %ini clean.ips
filter -wfc @ips.c %ini
window -c @ips.c
; remove "dead" nick topics in the ini as well
var %n = 1
while ($ini(%ini,%n)) {
var %name = $v1
if (!$ini(%ini,%name,1)) { writeini -n %ini %name x y | remini -n %ini %name }
inc %n
}
msg $chan ... Done. IPs kept: %ips.c.kept • IPs removed: %ips.c.removed • $&
Players remaining in database: $ini(%ini,0) $+ .
unset %ips.c.*
}
else {
msg $chan Syntax is: !cleanips <deadline>
msg $chan e.g. "!cleanips 3d" will remove all entries older than 3 days; $&
"!cleanips 2 weeks 3 hrs"
}
}
; ip cleaning routine (filter-alias for !cleanips)
alias -l clean.ips {
if ($gettok($1,1,61) isnum) {
if ($v1 >= $calc($ctime - %ips.c.duration)) { aline @ips.c $1- | inc %ips.c.kept }
else { inc %ips.c.removed }
}
elseif ($1) { aline @ips.c $1- }
}