# CETK epic Userlist script 0.0 # unload cetk.userlist package cetk.userlist # # External dependancies: /purge is required to be defined elsewhere in the # script that calls this one if /userdel is to work. "load commandqueues" can # also be run to get rid of the /builduser requirement. # # # For each alias definition, define two. One each for userlist and shitlist. # stack push alias alias.tt alias alias.tt fe (user shit) foo { alias $sar(g/\${foo}/$foo/$*) } # # $findusers() and $findshits(). Find the name of matching users or shits from # the appropriate list given a n!u@h and a channel. # # These functions are the primary back end for most of the other functions, but # they have their uses in other scripts too. # alias.tt find${foo}s { xdebug dword { fe ($*) nuh chan pass { @ :nuh = [.] == nuh ? last[$last[eserv]][from] : nuh return $corpattern("$nuh,$chan" ulcache[${foo}][mask] ulcache[${foo}][user]) } } } # # $checkusers(), $checkshits(). Given a decimal bitwise mask, a channel and a # list of n!u@h's, return the n!u@h's that match at least one bit of the mask. # # These functions are scripting interfaces. # alias.tt check${foo}s (args) { @ :mask = shift(args) @ :chan = shift(args) fe args arg { @ arg = mask & check${foo}($arg $chan) ? arg : [] } return $args } # # $matchuser() and $matchshit() act just like $find*s() for two arguments. # Additional arguments are usernames and shitnames and cause a decimal bitmask # to be returned indicating which names matched. This is a very esoteric # function. # alias.tt match${foo} { @ :masks = [$2-] @ :users = find${foo}s($0-1) unless (2<#) {return $users} fe ($uniq($users)) foo { @ :ret |= 1 << rmatch($foo $masks) } return ${(ret & -2) >> 1} } # # Works on the same principle as alias.tt defined above. # alias alias.tt fe (user -1 &= shit -0 |=) cmd lev func { @ :args = [$*] alias $msar(gr/\${cmd}/$cmd/\${lev}/$lev/\${func}/$func/args) } # # $checkuser(): Given the same information as $findusers(), return the # userlevel of all matching users bitwise _anded_ together. # # $checkshit(): Given the same information as $findshits(), return the # shitlevel of all matching users bitwise _ored_ together. # # These functions are the primary scripting interfaces. # alias.tt check${cmd} { @ :users = find${cmd}s($*) @ :levels = #users ? ${lev}:[] fe ($users) user { @ levels ${func} userlist[$user][${cmd}level] } return $levels } # # This is a simple one. Return non-zero or zero depending on whether a given # n!u@h and channel pair are found in the combined userlist and shitlist. # alias isuser xdebug dword {return $rpattern($0,$1 $ulcache.shit.mask $ulcache.user.mask)} # # /useradd, /userdel. Add and remove users, their user/shit levels, and # nuh/chan masks used to find them. # alias useradd { xdebug -dword extractw { if ((5!=#) || !isnumber($1) || !isnumber($2)) { echo \($unsplit(" " $0-2)\): usage: /useradd {user} {userlevel} {shitlevel} {nick!user@host[,...]} {chan[,...]} } else { @ userlist[$0][userlevel] = 0+[$1] @ userlist[$0][shitlevel] = 0+[$2] @ userlist[$0][nuhs] = split(|, $3)) @ userlist[$0][chans] = split(|, $4)) } } 1cmd 1 defer builduser } alias userdel foreach userlist foo {if (foo =~ [$*]) {purge userlist[$foo]}};purge ulcache;1cmd 1 defer builduser # # Maintainance. Once all the /useradd commands have been run, /builduser is # used to "compile" the list into something that works much faster. # # This command _must_ be run before /useradd and /userdel will take effect. # alias builduser { xdebug dword extractw { fe (user shit) map { @ ::ulcache[$map][mask] = ::ulcache[$map][user] = [] foreach userlist user { fe ($userlist[$user][nuhs]) nuh { fe ($userlist[$user][chans]) chan { if (userlist[$user][${map}level]) { @ push(ulcache[$map][mask] $nuh,$chan) @ push(ulcache[$map][user] $user) } } } } } } } alias userlist { @ :oxd = xdebug(dword) xdebug dword foreach userlist user { if (match("\\[$*\\]" $user $userlist[$user][nuhs] $userlist[$user][chans])) { echo USER: $user LEVELS: $userlist[$user][userlevel] $userlist[$user][shitlevel] echo NUHS: $userlist[$user][nuhs] echo CHANS: $userlist[$user][chans] if (userlist[$user][userlevel]) { push :users $user } if (userlist[$user][shitlevel]) { push :shits $user } } } if (users) { echo Users: $users } if (shits) { echo Shits: $shits } xdebug $oxd } stack pop alias alias.tt