Basic — File Browser
Basicv23042002 / Basicv23042002 / basic / sys / ulist.mrc
ulist.mrc — 37.41 KB — Download this file
; ###################################
;
; Basic v23042002
; blue-elf, belf@mircscripter.com
;
; basic's userlist, originally based
; from bitchx's userlist. it's
; evolved into i don't know what :P
;
; ###################################
alias userlist {
if (($1 == on) || ($1 == off)) {
_set userlist ulist $iif($1 == on,1,0)
if ($show) iecho Userlist is now $upper($1)
}
else _opendlg userlist
}
dialog userlist {
title "Userlist"
size -1 -1 303 193
option dbu
button "&Ok", 1, 268 147 32 12, ok
button "&Cancel", 2, 268 162 32 12, cancel
button "&Help", 3, 268 177 32 12
tab "Userlist", 4, -30 -30 600 600
list 6, 3 24 260 140, tab 4 size
check "Enable userlist.", 22, 3 167 50 8, tab 4
text "Default mask:", 10, 13 180 36 8, tab 4
combo 11, 50 178 116 150, tab 4 drop
tab "Banlist", 23
list 24, 3 24 260 140, tab 23 size
check "Enable banlist.", 25, 3 167 50 8, tab 23
text "Default mask:", 5, 13 180 36 8, tab 23
combo 9, 50 178 116 50, tab 23 drop
combo 18, 31 6 74 40, drop
text "List type:", 13, 4 7 25 8
button "&Add...", 17, 268 24 32 12
button "&Edit...", 7, 268 39 32 12
button "&Remove", 8, 268 54 32 12
list 26, 1 1 1 1, hide
list 27, 1 1 1 1, hide
}
on *:dialog:userlist:sclick:*:{
var %d = $did
; ok button
if (%d == 1) {
; enable/disable userlist/shitlist
if ($did(9).sel) _set UserList UserMask $calc($ifmatch -1)
if ($did(11).sel) _set UserList ShitMask $calc($ifmatch -1)
; start updating
.rlevel 40
var %did = 26, %file = $_userfile, %text = Userlist, %com = .adduser
:again
write -c %file
var %i = 1, %total = $did(%did).lines
if (%total) _progress Updating %text
while ($did(%did,%i)) {
tokenize 9 $ifmatch
%com $+(+,$2) $1 $3-5 $remove($6,$chr(160)) $7-
_progress² %i %total
inc %i
}
if (%total) iecho %text updated. Total entries: %total
if (%did == 26) {
var %did = 27, %file = $_banlist, %text = Banlist, %com = .addban
goto again
}
if ($_isfile($_banlist)) flushini $ifmatch
if ($_isfile($_userfile)) flushini $ifmatch
_set userlist ulist $did(22).state
_set userlist slist $did(25).state
if ($server) {
_loadusers userlist
_loadusers banlist
}
}
; cancel
if (%d == 2) unset %sys.user.edit
if (%d == 3) { _bld $dname | bhelp userlist }
; list type
if (%d == 18) did -c $dname $iif($did(18).sel == 2,23,4)
; add
if (%d == 17) {
var %d = $iif($did(18).sel == 1,adduser,addban)
_opendlg %d
}
; edit
if (%d == 7) {
if (($did(18).sel == 1) && ($did(6).sel) && ($ifmatch > 1)) {
var %line = $ifmatch
tokenize 32 $mdxgetline($did(6,%line))
set -u %addf.mask $1
set -u %addf.flags $2
set -u %addf.net $3
set -u %addf.chan $4
set -u %addf.pass $5
set -u %addf.nick $6
set %sys.user.edit %line $1-
did -d $dname 6 %line
did -d $dname 26 $calc(%line - 1)
_opendlg adduser
}
elseif (($did(18).sel == 2) && ($did(24).sel) && ($ifmatch > 1)) {
var %line = $ifmatch
tokenize 32 $mdxgetline($did(24,%line))
set -u %addban.mask $1
set -u %addban.type $2
set -u %addban.net $3
set -u %addban.chan $4
set -u %addban.dur $5
set -u %addban.why $6-
set %sys.user.edit %line $1-
did -d $dname 24 %line
did -d $dname 27 $calc(%line - 1)
_opendlg addban
}
}
; remove
if (%d == 8) {
if (($did(18).sel == 1) && ($did(6).sel)) {
did -d $dname 6 $ifmatch
did -d $dname 26 $calc($ifmatch - 1)
}
if (($did(18).sel == 2) && ($did(24).sel)) {
did -d $dname 24 $ifmatch
did -d $dname 27 $calc($ifmatch - 1)
}
}
; sort
if ((%d == 6) || (%d == 24)) {
did -i $dname %d 1 page $devent
tokenize 32 $did(%d,1)
if (($1-2 === headerclick HEADEREVENT) && ($3 isnum)) {
var %n = $ifmatch
if (%_ulist.sort) unset %_ulist.sort
else set -u120 %_ulist.sort 1
filter $_ulistfilterswitch %n 9 $dname $iif(%d == 6,26,27) $dname %d *
; filter $_ulistfilterswitch $+(2-,$did(%d).lines) %n 9 $dname %d $dname %d *
}
}
; tabs
if ((%d == 4) || (%d == 23)) did -c $dname 18 $iif(%d == 4,1,2)
}
alias -l _ulistfilterswitch { return $iif(%_ulist.sort,-ectio,-ctio) }
; alias -l _ulistfilterswitch { return $iif(%_ulist.sort,-ectior,-ctior) }
alias mdxgetline {
var %x = 1, %r, %tmp
while ($gettok($1-,%x,9)) {
%tmp = $ifmatch
if (%x == 1) %r = $gettok(%tmp,6-,32)
else %r = %r $gettok(%tmp,5-,32)
inc %x
}
return %r
}
on *:dialog:userlist:init:*:{
mdx SetMircVersion $version
mdx MarkDialog $dname
mdx SetControlMDX $dname 6,24 listview report showsel rowselect > dll\mdx\views.mdx
listview $dname 6,24 report showsel rowselect
;headersizes $dname 6 260 50 105 100 50 50
headersizes $dname 6 180 50 73 76 71 64
headers $dname 6 $tab(Hostmask,Flags,Network,Channel,Password,Nick)
headersizes $dname 24 185 50 60 60 60 100
headers $dname 24 $tab(Hostmask,Flags,Network,Channel,Duration,Reason)
var %i = 1, %m = blue-elf!bdc@brf-68-78.tm.net.my, %n = $dname, %a = did -a %n, %c = did -c %n
%a 9,11 blue-elf!*@*
while (%i <= 19) {
%a 9,11 $mask(%m,%i)
if ($gettok(Users Bans,%i,32)) %a 18 $ifmatch
inc %i
}
%c 9,11 4
if ($_(UserList,UserMask) isnum 0-19) %c 9 $calc($ifmatch + 1)
if ($_(UserList,ShitMask) isnum 0-19) %c 11 $calc($ifmatch + 1)
%c 18 1
var %x = 1, %f = $_userfile, %total = $ini(%f,0), %i, %text = userlist, %did = 6
:again
if (%total) _progress Loading %text
while ($ini(%f,%x)) {
var %i = 1, %topic = $ifmatch, %tmp
while ($ini(%f,%topic,%i)) {
var %blah = $ifmatch, %tmp = $readini(%f,%topic,%blah)
if (*.date_added !iswm %blah) {
tokenize 32 %blah $gettok(%tmp,1,32) $replace(%topic,.,$chr(32)) $gettok(%tmp,2-,32)
if (%did == 6) {
%tmp = $tab($1,$2,$3,$4,$iif($5 isnum,$+($chr(160),$5),$5),$6-)
%a %did %tmp
%a 26 %tmp
}
else {
if ($_istd($5)) %tmp = $tab($1,$2,$3,$4,$5,$6-)
else %tmp = $tab($1,$2,$3,$4,$chr(160),$5-)
%a %did %tmp
%a 27 %tmp
}
}
inc %i
}
_progress² %x %total
inc %x
}
if (%did == 6) {
var %x = 1, %f = $_banlist, %total = $ini(%f,0), %i, %text = banlist, %did = 24
goto again
}
did -z $dname 6,24
if ($_(userlist,ulist)) did -c $dname 22
if ($_(userlist,slist)) did -c $dname 25
}
dialog adduser {
title "Add user"
size -1 -1 160 156
option dbu
button "&Ok", 1, 30 143 32 12, ok
button "&Cancel", 2, 64 143 32 12, cancel
button "&Help", 3, 98 143 32 12, disable
text "Hostmask:", 4, 3 3 30 8, right
text "Channels:", 5, 3 14 30 8, right
text "Networks:", 6, 3 26 30 8, right
text "Nickname:", 7, 3 39 30 8, right
text "Password:", 8, 88 39 25 8
combo 9, 37 1 119 47, edit drop
edit "", 10, 36 13 120 11, autohs
edit "", 11, 36 25 120 11, autohs
edit "", 12, 36 37 50 11, autohs
edit "", 13, 115 38 41 11, autohs
box "Flags:", 14, 2 49 156 79
check "Auto-accept DCC sends.", 15, 8 56 92 10
check "Auto-accept DCC chats.", 16, 8 68 92 10
check "Exempt from channel protections.", 17, 8 80 92 10
check "CTCP ident.", 18, 8 92 50 10
check "CTCP op.", 19, 104 56 50 10
check "CTCP voice.", 20, 104 68 50 10
check "CTCP unban.", 21, 104 80 50 10
check "CTCP invite.", 22, 104 92 50 10
check "Auto op.", 24, 104 104 32 10
check "Auto voice.", 25, 104 115 40 10
check "Exempt from requests filter.", 27, 8 104 77 10
check "Protected.", 28, 8 115 40 10
check "Inform the user that they have been added.", 23, 2 130 115 10
}
on *:dialog:adduser:init:0:{
var %a = did -a $dname, %c = did -c $dname, %i = did -i $dname
if (%addf.mask) _loadmasks $dname 9 $ifmatch
if (%addf.chan) %a 10 $ifmatch
if (%addf.net ) %a 11 $ifmatch
if (%addf.nick) %a 12 $ifmatch
if (%addf.pass) %a 13 $ifmatch
if (%addf.flags) %c $replace($right($_f2id($ifmatch),-1),.,$chr(44))
did -f $dname 9
; disable the send notice if adding from the main userlist dialog
if ($dialog(userlist)) did -b $dname 23
}
; /_loadmasks dname id mask
alias -l _loadmasks {
if (* isin $3) did -a $1-
else {
var %i = 0
while (%i <= 19) {
did -i $1-2 1 $mask($3,%i)
inc %i
}
did -i $1-2 1 $+($gettok($3,1,33),!*@*)
}
did -c $1-2 1
}
on *:dialog:adduser:sclick:1:{
; get the flags first
; up to 22 only since request filter and mirc lists are treated differently.
var %flags, %i = 15
while (%i <= 22) {
if ($did(%i).state) %flags = $+(%flags,$_id2f(%i))
inc %i
}
; aop/aov/protect
var %l, %y = 1
while ($gettok(24 25 27 28,%y,32)) {
%l = $ifmatch
if ($did(%l).state) %flags = $+(%flags,$_id2f(%l))
inc %y
}
_ldlg $dname
var %pass
if ($did(13) == $null) goto skip
var %r = ^([-\._0-9a-zA-Z]){4,}$
if ($regex($did(13),%r)) %pass = $did(13)
else _err Invalid password. It can only contain numbers 0-9 and letters a-z and the characters '_-.'
:skip
if (($did(12) != $null) && (%pass == $null)) %pass = changeme
if ($dialog(userlist)) {
if ((%flags) && ($did(11)) && ($did(10)) && ($did(9))) {
var %l = $tab($did(9),%flags,$did(11),$did(10),%pass,$did(12))
did -a userlist 6 %l
did -a userlist 26 %l
}
else {
beep
halt
}
}
else adduser $+(+,%flags) $did(9) $did(11) $did(10) %pass $did(12)
if (($did(23).state) && ($did(12)) && ($status == connected)) {
var %notice = !.notice $did(12)
%notice You have been added to my userlist as $did(9)
%notice Type /CTCP $me HELP for command info.
if (%pass == $null) %notice You do not have a password set. Use /CTCP $me PASS <newpassword> to set one.
else %notice Your password is temporarily set to $+(',%pass,'). Use /CTCP $me PASS %pass <newpassword> to change it.
}
_showdlg userlist
unset %sys.user.edit
}
on *:dialog:adduser:sclick:2:{
if (($dialog(userlist)) && (%sys.user.edit)) {
tokenize 32 $ifmatch
var %line = $tab($2,$3,$4,$5-)
did -i userlist 6 $1 %line
did -i userlist 26 $calc($1 - 1) %line
}
_showdlg userlist
unset %sys.user.edit
}
alias -l _id2f { return $replacecs($1,15,s,16,c,17,x,18,I,19,o,20,v,21,u,22,i,24,O,25,V,27,a,28,p) }
alias -l _f2id { return $replacecs($1,s,.15,c,.16,x,.17,I,.18,o,.19,v,.20,u,.21,i,.22,O,.24,V,.25,a,.27,p,.28) }
alias -l _uset {
if (($3 == $null) && ($2 != $null)) remini $_userfile $1-2
elseif ($3 != $null) writeini $_userfile $1-
}
alias _userfile { return sys\users.ini }
alias _userflags { return ovcsuiIxaOVp }
alias _exrf {
var %w = $+(@,$rand(A,Z),$ticks), %f = $exmpt.dat
window -hl %w 1 1 1 1
if ($isfile(%f)) filter -fw %f %w *
if (!$fline(%w,$1,1)) write %f $1
if ($hget(_SysFilter)) hadd $ifmatch $1 1
window -c %w
}
; Usage: /UNUSER <hostmask> [network] [channels]
; removes a hostmask from a network and channel
; if the network (or channel) is specified,
; the user is removed for that network or channel only.
; if just the hostmask is given, then all matching hostmasks
; in all networks will be removed from the userlist.
;
; the 2nd parameter is *always* assumed as a network. to remove
; a user from a specific network and channel, both have to be specified.
;
; note: add -w switch later to remove all matching hostmasks (wildcard match)
;
alias unuser {
set -u %sys.show $show
if (!$1) _err /unuser: Insufficient parameters.
var %network = $2, %channel = $3, %userlist = $_userfile, %remove
; remove all
if ((%network == $null) && (%channel == $null)) {
.ruser $1
.dcc trust -r $1
; remove the sucker from the _SysFilter list as well..
; for specific removals, the address isn't removed from the filter exemption list
; it'll take effect on next connection
if ($hget(_sysfilter)) hdel $ifmatch $1
var %i = 1
while ($ini(%userlist,%i)) {
var %x = 1, %topic = $ifmatch
while ($ini(%userlist,%i,%x)) {
if ($ifmatch == $1) {
; grab the nick first because /protect didn't add by hostmask.
; /protect [-rw] <on|off|nick> [#channel1,#channel2,...] [type]
var %nick = $readini(%userlist,%topic,$1)
if ($numtok(%nick,32) == 3) .protect -rw $gettok(%nick,3,32)
; remove from the ini
remini %userlist %topic $1
; remove from the hash table
if ($hget($+(sys.userlist.,%topic))) hdel $ifmatch $1
%remove = Removed $1 from userlist.
break
}
inc %x
}
inc %i
}
}
; specific removal
elseif ($readini(%userlist,$+(%network,.,%channel),$1)) {
; grab the nick first before doing a /remini so that we can use /protect -r
var %nick = $ifmatch
if ($numtok(%nick,32) == 3) .protect -rw $gettok(%nick,3,32) $iif(%channel != *,%channel)
remini %userlist $+(%network,.,%channel) $1
if ($hget($+(sys.userlist.,%network,.%channel))) hdel $ifmatch $1
%remove = Removed $1 from userlist (from %network and %channel $+ ).
; remove from mIRC's userlist or simply update the info
.dcc trust -r $1
var %ulistInfo = $ulist($1,40,1).info, %newnets = $remtok($gettok(%ulistInfo,1,32),%network,1,44), $&
%newchans = $remtok($gettok(%ulistInfo,2,32),%channel,1,44)
if ((!%newchans) || (!%newnets)) .ruser $1
else .iuser $1 %newnets %newchans
}
else _err /unuser: $1 doesn't seem to be in the userlist.
if ($show) if (%remove) iecho $ifmatch
}
; Usage: /ADDUSER <+|-flags> <hostmask> <network> <#channels|*> [pass] [nick]
; - adds <nick|hostmask> to userlist for <#channels|*>
; - Available flags:
; - o ctcp op
; - v ctcp voice
; - c accept chats
; - s accept sends
; - u ctcp unban
; - i ctcp invite
; - I ctcp ident
; - x exempt user from channel protections
; - a allow private requests
; - p protected user <- mirc list
; - V auto voice <- mirc list
; - O auto op <- mirc list
alias adduser {
set -u %sys.show $show
if ($4 == $null) _err /adduser: No channels specified.
; check if there's anything that'll remain if these flags are removed ; syntax $_isuser(network,channel,fulladdress)
if ((-* iswm $1) && (+ !isin $1) && (!$removecs($_isuser($3,$4,$2).flags,$remove($1,-)))) _err $&
Use /unuser command to remove an entry from the userlist.
if ($left($1,1) !isin +-) _err /adduser: Invalid flags.
if (($left($4,1) !isin &#+) && ($4 != *)) _err /adduser: Invalid channelname.
var %mask = $2, %mid, %pre, %channel = $4, %i = 1, %addflags, %remflags, %dm = $_(UserList,UserMask)
while ($mid($1,%i,1)) {
%mid = $ifmatch
if (%mid isin +-) %pre = %mid
if (%mid isincs $_userflags) {
if (%pre == +) %addflags = %addflags $+ %mid
else %remflags = %remflags $+ %mid
}
inc %i
}
if ((!%remflags) && (!%addflags)) _err /adduser: Invalid flags.
if (*!*@* !iswm %mask) {
%mask = $address(%mask,%dm)
if ((!%dm) || (!%mask)) %mask = %mask $+ !*@*
}
var %x = 1, %net, %newnets, %newchans
while ($gettok($3,%x,44)) {
var %i = 1, %chan, %net = $ifmatch
while ($gettok(%channel,%i,44)) {
%chan = $ifmatch
if (%remflags) _upduser %remflags %mask %net %chan $5-
if (%addflags) _adduser %addflags %mask %net %chan $5-
; add the user to mIRC's userlist for easier lookup in CTCP events *phew*
; 40:*!*@*.address Network,Network Channel,Channel
if ($ulist(%mask,40,1).info) {
%newnets = $addtok( $gettok($ifmatch,1,32) , %net , 44 )
%newchans = $addtok( $gettok($ifmatch,2,32) , %chan, 44 )
}
else {
%newnets = %net
%newchans = %chan
}
.auser 40 %mask %newnets %newchans
inc %i
}
inc %x
}
; load to hash table only if connected
if ($server) _loadusers userlist
}
; /_adduser oviuIcs <hostmask>!*@* <network> #channels [pass] [nick]
; $1 $2 $3 $4
alias -l _adduser {
var %pre = $+($3,.,$4)
_uset %pre $2 $1 $_repc($5) $6
var %tmp = $readini($_userfile,%pre,$2), %flags = $gettok(%tmp,1,32)
;/dcc trust [-r] <on | off | nick | address | level>
if (c isincs %flags) .dcc trust $2
else .dcc trust -r $2
; _mirculist %flags $2-
if (a isincs $1) _exrf $2
if (%sys.show) {
iecho Added $2 to userlist.
iecho Network: $3
iecho Channel: $4
iecho Flags : %flags
}
}
alias -l _upduser {
var %pre = $+($3,.,$4), %info = $readini($_userfile,%pre,$2), %flags = $gettok(%info,1,32)
_uset %pre $2 $removecs(%flags,$1) $_repc($5) $6
if (a isincs $1) _exrf $2
if (c isincs $1) .dcc trust $2
else .dcc trust -r $2
; _mirculist $1-
}
; useless /avoice /aop
alias -l _mirculist {
;/aop [-rw] <on|off|nick/address> [#channel1,#channel2,...] [type]
if (O isincs $1) .aop $iif($3 == *,-w) $2 $iif($4 != *,$4)
else .aop $iif($3 == *,-wr,-r) $2 $iif($4 != *,$4)
if (V isincs $1) .avoice $iif($3 == *,-w) $2 $iif($4 != *,$4)
else .avoice $iif($3 == *,-wr,-r) $2 $iif($4 != *,$4)
; /protect [-rw] <on|off|nick> [#channel1,#channel2,...] [type]
if ((p isincs $1) && ($6)) .protect $iif($3 == *,-w) $6 $iif($4 != *,$4)
elseif ($6) .protect $iif($3 == *,-wr,-r) $6 $iif($4 != *,$4)
}
; $_isuser($_network,$chan,$fulladdress)
; $_isuser().flags
alias _isuser {
if (!$_(userlist,ulist)) return
var %u = sys.userlist., %r, %h, %a = $+(%u,$1,.,$2), %b = $+(%u,*.,$2), %c = $+(%u,$1,.*), %d = $+(%u,*.*)
if ($hmatch(%a,$3)) var %r = $ifmatch, %h = %a
elseif ($hmatch(%b,$3)) var %r = $ifmatch, %h = %b
elseif ($hmatch(%c,$3)) var %r = $ifmatch, %h = %c
elseif ($hmatch(%d,$3)) var %r = $ifmatch, %h = %d
if ($prop == flags) return $gettok($hget(%h,%r),1,32)
if ($prop == exempt) return $iif(x isincs $hget(%h,%r),1,0)
return %r
}
; /_loadusers <userlist|banlist>
alias _loadusers {
var %f = $iif($1 == userlist,$_userfile,$_banlist)
if (!$isfile(%f)) return
var %total = $ini(%f,0)
while (%total) {
var %header = $ini(%f,%total), %h2 = $+(sys.,$1,.,%header), %i = 1
_hfree %h2
while ($ini(%f,%header,%i)) {
hadd -m %h2 $ifmatch $readini(%f,%header,$ifmatch)
inc %i
}
dec %total
}
}
on *:connect:{
_loadusers userlist
_loadusers banlist
}
; auto-op/voice because mirc's /aop doesn't work in mirc 6.x
on @40:join:#:{
var %flags = $_isuser($_network,#,$fulladdress).flags
if (O isincs %flags) mode # +o $nick
elseif (V isincs %flags) mode # +v $nick
}
; protect event
; shall we add deop events too?
on @40:ban:#:{
if (p isincs $_isuser($_network,#,$banmask).flags) {
mode # -b $banmask
.notice $nick $banmask is protected in my userlist.
}
}
on @5:kick:#:{
if (p isincs $_isuser($_network,#,$banmask).flags) {
invite $knick #
.notice $nick $knick is protected in my userlist.
}
}
;
; This has to be treated differently because a user who requests an IDENT
; may not have his hostmask in the userlist.
;
ctcp *:IDENT:?:{
iecho USERLIST CTCP (IDENT/ $+ $2- $+ ) REQUEST from $nick ( $+ $address $+ )
; /CTCP $me IDENT <password> [hostmask]
; flag = I
if (!$2) halt
var %defaultmask = $iif($_(UserList,UserMask) isnum 0-19,$ifmatch,3)
var %alltables = $hgetw(sys.userlist.*,0), %i = 1, %curtable, %hostmask = $_iif($3,$mask($fulladdress,%defaultmask))
while ($gettok(%alltables,%i,32)) {
var %curtable = $ifmatch, %x = 1
while ($hmatch(%curtable,*,%x)) {
var %oldInfo = $hget(%curtable,$ifmatch)
; to use CTCP IDENT, the PASSWORD and the NICKNAME of the user who requests MUST be in the userlist entry.
if ((I isincs $gettok(%oldInfo,1,32)) && ($gettok(%oldInfo,2,32) === $2) && ($gettok(%oldInfo,3,32) == $nick)) {
var %tmp = $gettok(%curtable,3-,36)
if (%tmp == *.*) var %net = *, %chan = *
else var %pos = $pos(%tmp,$chr(35)), %net = $mid(%tmp,1,$calc(%pos -2)), %chan = $mid(%tmp,%pos)
; skip this if the network isn't the same, but don't skip if the network is * (meaning all)
if ((%net == $_network) || (%net == *)) {
.adduser $+(+,$gettok(%oldInfo,1,32)) %hostmask %net %chan $gettok(%oldInfo,2-,32)
.timerCTCP.IDENT $+ %x 1 $calc(%i + 2) !.notice $nick %hostmask has been added to my access list for $&
network(s) $+(",%net,") and channel(s) $+(",%chan,") with flags ( $+ $gettok(%oldInfo,1,32) $+ )
}
}
inc %x
}
inc %i
}
halt
}
ctcp +40:*:?:{
if (!$istok(OP VOICE INVITE UNBAN IDENT PASS HELP,$1,32)) return
iecho USERLIST CTCP ( $+ $1 $+ / $+ $2- $+ ) REQUEST from $nick ( $+ $address $+ )
; first find the matching hostmask for $fulladdress
var %m = $!ulist($fulladdress,40,1), %info = $($+(%m,.info),2), %tempInfo, %flags
var %hostmask = $(%m,2), %networks = $gettok(%info,1,32), %channels = $gettok(%info,2,32)
; halt if the user doesn't have access for this network.. sorry =/
if ((%networks != *) && (!$istok(%networks,$_network,44))) {
!.notice $nick Sorry. You're in my userlist, but not for this network.
halt
}
; react to specific CTCP requests
; PASS and IDENT are a bit tricky and MUST consider *.* entries
; not just for specific network.channel entries.
if ($1 == PASS) {
; /CTCP $me PASS <password>
if (!$2) halt
var %alltables = $hgetw(sys.userlist.*,0), %i = 1, %curtable
while ($gettok(%alltables,%i,32)) {
%curtable = $ifmatch
if ($hmatch($ifmatch,%hostmask)) {
var %oldinfo = $hget(%curtable,$ifmatch)
; grab the channel name and network from the hash tablename
var %tmp = $gettok(%curtable,3-,46)
if (%tmp == *.*) var %net = *, %chan = *
else var %pos = $pos(%tmp,$chr(35)), %net = $mid(%tmp,1,$calc(%pos -2)), %chan = $mid(%tmp,%pos)
; if the user doesn't have a password set, take the $3 as the pass if given.
; if there's no $3, use $2
if ($gettok(%oldInfo,2-,32) == $null) .adduser $+(+,%oldInfo) %hostmask %net %chan $_iif($3,$2)
; if the user has an old password, compare it with the one given
else {
; if the user attempts to set a password and he already has an old password, it'll fail
if ($3 == $null) {
!.notice $nick You already have a password set.
!.notice $nick To change your password, please provide your old password with the new one.
halt
}
elseif ($2 !== $gettok(%oldInfo,2,32)) halt
else {
var %r = ^([-\._0-9a-zA-Z]){4,}$
if ($regex($3,%r)) {
.adduser $+(+,$gettok(%oldInfo,1,32)) %hostmask %net %chan $3 $iif($gettok(%oldInfo,3,32),$gettok(%oldInfo,3,32))
!.notice $nick Your password is now set to $3
}
else {
!.notice $nick Invalid password. It must be at least 4 characters and can only contain alphanumeric characters (letters A to Z and numbers) and ._-.
halt
}
}
}
}
inc %i
}
halt
}
elseif ($istok(OP VOICE INVITE UNBAN,$1,32)) {
; $1 = CTCP Request, $2 = #channel, $3 = password
; if there's no channel or password, halt
if ((!$3) || (!$2)) halt
if ($2 == *) {
%tempInfo = $hget($+(sys.userlist.,$_network,.*),%hostmask)
%flags = $gettok(%tempInfo,1,32)
if (($gettok(%tempInfo,2,32) === $3) && ($lower($left($1,1)) isincs %flags)) ctcp.all $1 $fulladdress
halt
}
var %i = 1, %tempchan
while ($gettok($2,%i,44)) {
%tempchan = $ifmatch
if ($istok(%channels,%tempchan,44)) {
; In a userinfo, the format is always:
; <flags> <password> <nickname>
;
; If a nick isn't specified or a password is specified but a nick is specified when
; adding a user, it is assumed as the password. Meaning, passwords take precedence over nicks.
%tempInfo = $hget($+(sys.userlist.,$_network,.,%tempchan),%hostmask)
%flags = $gettok(%tempInfo,1,32)
if (($gettok(%tempInfo,2,32) === $3) && ($me isop %tempchan)) {
if ((O* iswm $1) && (o isincs %flags)) mode %tempchan +o $nick
if ((V* iswm $1) && (v isincs %flags)) mode %tempchan +v $nick
if ((U* iswm $1) && (u isincs %flags)) ctcp.unban %tempchan $fulladdress
if ((I* iswm $1) && (i isincs %flags)) { if ($nick !ison %tempchan) .raw INVITE $nick %tempchan }
}
}
inc %i
}
halt
}
if ($1 == HELP) {
var %req = $+(%,basic.help.request.,$cid,$wildsite), %notice = !.notice $nick
if ($(%req,2)) var %bd1 = 3, %bd2 = 5
else var %bd1 = 1, %bd2 = 3
if ($2 == PASS) {
.timer 1 %bd1 %notice Usage: /CTCP $me PASS <password>
.timer 1 %bd2 %notice - This sets a password, which lets you use other commands, like INVITE.
.timer 1 $calc(%bd2 + 2) %notice - /CTCP $me PASS <password> <newpass>
.timer 1 $calc(%bd1 + 4) %notice - This is how you change your password.
}
elseif ($2 == IDENT) {
.timer 1 %bd1 %notice Usage: /CTCP $me IDENT <password> [hostmask]
.timer 1 %bd2 %notice - Allows you to add your current hostmask or [hostmask] to my userlist.
.timer 1 $calc(%bd2 + 2) You must use your password (the one you set with PASS) and
.timer 1 $calc(%bd2 + 4) you must also be using your original nick so I know it's really you.
}
elseif ($istok(OP VOICE INVITE UNBAN,$2,32)) {
.timer 1 %bd1 %notice Usage: /CTCP $me $2 <#channel1,#channel2..|*> <password>
.timer 1 %bd2 %notice - $matchctcp($2) <#channel1,#channel2..|*> - use * for all channels.
}
else {
.timer 1 %bd1 %notice Usage: /CTCP $me HELP [topic]
.timer 1 %bd2 %notice - Shows help for [topic] or all topics.
}
set -u5 $(%req) 1
halt
}
}
alias -l matchctcp {
goto $left($1,1)
:U | return Unbans you from
:I | return Invites you to
:O | return Ops you in
:V | return Voices you in
}
alias -l ctcp.all {
if (($1 == VOICE) || ($1 == OP)) {
var %i = 1, %nick = $gettok($2,1,33), %chan
while ($comchan(%nick,%i)) {
%chan = $ifmatch
if ($me isop %chan) mode %chan $+(+,$lower($left($1,1))) %nick
inc %i
}
}
elseif ($1 == UNBAN) {
var %i = 1, %chan
while ($chan(%i)) {
%chan = $ifmatch
if ($me isop %chan) ctcp.unban %chan $2
inc %i
}
}
elseif ($1 == INVITE) {
var %i = 1, %chan, %nick = $gettok($2,1,33)
while ($chan(%i)) {
%chan = $ifmatch
if (($me isop %chan) && (%nick !ison %chan)) !.raw INVITE %nick %chan
inc %i
}
}
}
alias -l ctcp.unban {
var %i = 1
while ($ibl($1,%i)) {
if ($ifmatch iswm $2) {
mode $1 -b $ifmatch
.timer.unban $+ $2 1 %i !.notice $gettok($2,1,33) You're now unbanned from $1
}
inc %i
}
}
; banlist
alias banlist {
if (($1 == on) || ($1 == off)) {
_set userlist slist $iif($1 == on,1,0)
if ($show) iecho Banlist is now $upper($1)
}
elseif ($1) addban $1-
else _opendlg addban
}
dialog addban {
title "Add Ban"
size -1 -1 174 141
option dbu
button "&Ok", 1, 37 128 32 12, ok
button "&Cancel", 2, 72 128 32 12, cancel
button "&Help", 3, 107 128 32 12, disable
text "Hostmask:", 4, 5 6 27 8
text "Networks:", 5, 5 19 27 8
text "Channels:", 6, 5 32 27 8
text "Reason:", 7, 5 45 27 8
combo 8, 38 4 129 90, drop edit
edit "", 9, 37 17 131 11
edit "", 10, 37 30 131 11
edit "", 11, 37 43 131 11
box "Level:", 12, 5 55 163 46
radio "Prevent user from being opped.", 13, 30 64 115 10, group
radio "Kickban user on join.", 14, 30 75 115 10
radio "Ban user always and ignore permanently.", 15, 30 86 115 10
box "Duration:", 16, 5 102 163 22
text "Remove this ban after...", 17, 10 112 70 10
edit "", 18, 83 109 79 11
}
on *:dialog:addban:init:*:{
if (%addban.mask) _loadmasks $dname 8 $ifmatch
if (%addban.type) did -c $dname $replace($ifmatch,d,13,k,14,b,15)
if (%addban.net ) did -a $dname 9 $ifmatch
if (%addban.chan) did -a $dname 10 $ifmatch
if (%addban.why ) did -a $dname 11 $ifmatch
if ((%addban.dur) && ($ifmatch != $chr(160))) did -a $dname 18 $ifmatch
did -f $dname 8
}
on *:dialog:addban:sclick:2:{
if (($dialog(userlist)) && (%sys.user.edit)) {
tokenize 32 $ifmatch
did -i userlist 24 $1 $tab($2,$3,$4,$5,$6,$7-)
}
unset %sys.user.edit
_showdlg userlist
}
on *:dialog:addban:sclick:1:{
var %f
if ($did(13).state) %f = d
if ($did(14).state) %f = k
if ($did(15).state) %f = b
var %h = $did(8), %n = $did(9), %c = $did(10), %r = $did(11), %d = $did(18), %e = $str($crlf,2)
if ((%d != $null) && (!$_istd(%d))) {
_ldlg $dname
_err Invalid expiry format. Must be 'wdhm'. $+ %e $+ Example: 1w2d3h5m $+ %e $+ $&
This means the ban will expire after: $+ $crlf $+ 1 (w)eek $+ $crlf $+ 2 (d)ays $+ $crlf $+ $&
3 (h)ours $+ $crlf $+ 5 (m)inutes.
}
if ((%f) && (%h) && (%n) && (%c)) {
if ($dialog(userlist)) {
var %u = $ifmatch, %b
if (%d == $null) %d = $chr(160)
%b = $tab(%h,%f,%n,%c,%d,%r)
; I have to do /did -a twice because MDX tabbed lists do not like id,id for /did commands.
did -a %u 24 %b
did -a %u 27 %b
}
else addban %f %h %n %c %d %r
}
else {
beep
halt
}
unset %sys.user.edit
_showdlg userlist
}
on *:input:*:if (($left($1,1) == $readini($mircini,text,commandchar)) && ($remove($1,$ifmatch) == addban) && (!$ctrlenter)) set -u1 %addb.input 1
; /addban <+dkb> <hostmask> <network,network> <#channels,#channels> [duration] [reason]
; flags:
; d = deop user on op
; k = kickban on join
; b = ban always
; duration:
; w = week
; d = day
; h = hour
; n = min
alias addban {
set -u %sys.show $show
if (!$1) {
if (%addb.input) {
_opendlg addban
return
}
_err Syntax: /addban <+dkb> <hostmask> <network,network|*> <#channels,#channels|*> [dur] [reason]
}
if (!$4) _err /addban: No channels specified.
if (!$3) _err /addban: No networks specified.
if (!$2) _err /addban: No hostmask specified.
if (($left($4,1) !isin +#&) && ($4 != *)) _err /addban: Invalid channelname.
; flags
var %flag, %flags = $remove($1,+), %i = 1
while ($mid(%flags,%i,1)) {
if ($ifmatch !isincs $_banflags) _err /addban: Invalid flags.
inc %i
}
; b will override k and d, k will override d
if (d isincs %flags) %flag = d
if (k isincs %flags) %flag = k
if (b isincs %flags) %flag = b
; hostmask
var %hostmask = $2, %dm = $_(Userlist,ShitMask)
if (*!*@* !iswm $2) {
%hostmask = $address($2,%dm)
if ((!%dm) || (!%hostmask)) %hostmask = $2 $+ !*@*
}
; duration and reason
var %a, %d, %r = $5-
if ($_istd($5)) {
%a = $removecs($5,w,d,h,m)
if ((%a isnum) && (%a > 0)) var %d = $5, %r = $6-
}
var %x = 1
while ($gettok($3,%x,44)) {
var %net = $ifmatch, %y = 1, %head
while ($gettok($4,%y,44)) {
%head = $+(%net,.,$ifmatch)
_bset %head %hostmask %flag %d $_repc(%r)
_bset %head $+(%hostmask,.date_added) $ctime
inc %y
}
inc %x
}
if ($show) {
iecho Added %hostmask to banlist
iecho Ban level: $_banflag(%flag)
iecho Channels : $4
iecho $+($align(Network,9),:) $3
if (%r) iecho $+($align(Reason,9),:) %r
if (%d) iecho $+($align(Duration,9),:) $5
}
if ($server) _loadusers banlist
}
alias -l _banflag {
if ($1 == d) return deop on op
if ($1 == k) return kickban on join
return ban always
}
alias _banflags { return dkb }
; text to seconds
alias -l _$duration_already_supports_this {
:w | return $calc($1 * (7 * (24 * (60 ^ 2))))
:d | return $calc($1 * (24 * (60 ^ 2)))
:h | return $calc($1 * (60 ^ 2))
:n | return $calc($1 * 60)
}
; $_istd() "is trimmed duration", regex courtesy of qwerty-
alias _istd { return $regex($1,^(?:\d+[wdhm])+$) }
; $_fddur(value) = $duration($duration(text))
alias _fddur { return $duration($replace($1,w,$+(w,$chr(32)),d,$+(d,$chr(32)),h,$+(h,$chr(32)),m,$+(m,$chr(32)))) }
alias _banlist { return sys\banlist.ini }
alias -l _bset {
if (($3 == $null) && ($2 != $null)) remini $_banlist $1-2
elseif ($3 != $null) writeini -n $_banlist $1-
}
; $_isbanned($_network,$chan,$fulladdress)
; returns matching hostmask
; properties: .flags, .reason, .dur .all (returns the hostmask + info without channel and network)
alias _isbanned {
if (!$_(userlist,slist)) return
var %p = $prop, %u = sys.banlist., %r, %h, %a = $+(%u,$1,.,$2), %b = $+(%u,*.,$2), %c = $+(%u,$1,.*), %d = $+(%u,*.*)
if ($hmatch(%a,$3)) var %r = $ifmatch, %h = %a
elseif ($hmatch(%b,$3)) var %r = $ifmatch, %h = %b
elseif ($hmatch(%c,$3)) var %r = $ifmatch, %h = %c
elseif ($hmatch(%d,$3)) var %r = $ifmatch, %h = %d
tokenize 32 $hget(%h,%r)
if (%p == all) return %r $1-
if (%p == flags) return $1
if (%p == reason) {
; to $iif() or not to $iif(), that is the question.
if ($_istd($2)) return $3-
return $2-
}
if (%p == dur) {
if ($_istd($2)) return $2
return
}
return %r
}
; /_bancleanup - remove expired bans.
alias _bancleanup {
if ($_isfile($_banlist)) {
var %file = $ifmatch, %i = 1, %total = $ini(%file,0)
while ($ini(%file,%i)) {
var %header = $ifmatch, %z = 1
while ($ini(%file,%header,%z)) {
var %mask = $ifmatch, %dur = $gettok($readini(%file,n,%header,%mask),2,32)
if (($_istd(%dur)) && ($calc($ctime - $readini(%file,n,$+(%mask,.date_added))) >= $_fddur(%dur))) {
_bset %header %mask
_bset %header $+(%mask,.date_added)
}
inc %z
}
inc %i
}
}
}
; ignore
dialog ignore {
title "Ignore"
size -1 -1 146 103
option dbu
text "Address:", 1, 2 4 24 8
combo 2, 29 3 114 50, drop
box "Ignore options:", 3, 2 15 141 70
check "Private", 4, 18 24 40 10
check "Channel", 5, 18 34 40 10
check "Notice", 6, 18 44 40 10
check "CTCP", 7, 18 54 41 10
check "DCC", 8, 83 24 41 10
check "Invite", 9, 83 34 41 10
check "Codes", 10, 83 44 41 10
check "Exclude", 11, 83 54 41 10
check "Remove in:", 12, 18 69 40 10
combo 13, 61 68 30 50, drop size edit
text "mins", 14, 94 70 14 8
button "Ok", 15, 39 89 32 12, ok
button "Cancel", 16, 75 89 32 12, cancel
}
on *:dialog:ignore:sclick:15:{
if (!$did(2)) return
var %x = 4, %s = pcntdikxu, %f
while (%x <= 12) {
if ($did(%x).state) %f = %f $+ $mid(%s,$calc(%x - 3),1)
inc %x
}
if ($did(13)) %f = $iif(u !isin %f,$+(%f,u),%f) $+ $calc($did(13) * 60)
if (%f) %f = - $+ %f
ignore %f $did(2)
}
; /_aig [fulladdress]
alias _aig {
if ($1) set -u %_sys.igmask $1
var %d = $dialog(ignore,ignore,-3)
}
on *:dialog:ignore:init:*:{
if (%_sys.igmask) {
var %i = 1, %s = $ifmatch, %t = 4
did -a ignore 2 $gettok(%s,1,33) $+ !*@*
while (%i <= 19) {
did -a ignore 2 $mask(%s,%i)
did -a ignore 13 $calc(%i + %t)
inc %i
inc %t 4
}
did -c ignore 2 4
}
}
; ---------
; botlist
; ---------
; general botlist events
on *:dialog:botlist:init:*:{ _addnetload }
; cancel button
on *:dialog:botlist:sclick:33:{ window -c $_hnetw }
; ok button
on *:dialog:botlist:sclick:32:{ window -c $_hnetw }
; login/id
on *:dialog:botlist:sclick:5:{
if ($_addnet) {
did -a $dname 4 $ifmatch
did -c $dname 4 $didwm(4,$ifmatch,1)
}
_showdlg $dname
}
; command
on *:dialog:botlist:edit:8:{
var %net = $did(4,$did(4).sel)
if (!%net) return
.timer -m 1 0 hadd -m %net com $did(8)
}
dialog botlist {
title "BotList"
size -1 -1 180 164
option dbu
tab "Login or ID", 1, 3 2 173 141
text "Network:", 3, 13 46 27 8, tab 1 right
combo 4, 42 45 66 50, tab 1 drop
button "Add", 5, 111 45 25 10, tab 1
button "Rem", 6, 139 45 25 10, tab 1
text "Command:", 7, 13 60 27 8, tab 1 right
edit "", 8, 41 58 124 11, tab 1 autohs
box "Options:", 9, 15 70 150 43, tab 1
check "Delay command for...", 10, 22 83 66 10, tab 1
edit "", 11, 101 82 18 11, tab 1
text "second(s).", 12, 122 84 27 8, tab 1
check "Perform only if my nick is...", 13, 22 96 78 10, tab 1
edit "", 14, 101 94 58 11, tab 1 autohs
tab "Request Op", 2
text "Network:", 15, 8 28 25 8, tab 2 right
combo 16, 35 27 60 50, tab 2 size drop
button "Add", 17, 97 27 25 10, tab 2
button "Rem", 18, 124 27 25 10, tab 2
text "Channel:", 19, 8 42 25 8, tab 2 right
combo 20, 35 41 60 50, tab 2 size drop
button "Add", 21, 97 41 25 10, tab 2
button "Rem", 22, 124 41 25 10, tab 2
list 23, 9 56 128 67, tab 2 size extsel
button "Add...", 24, 141 56 30 11, tab 2
button "Edit...", 25, 141 68 30 11, tab 2
button "Remove", 26, 141 80 30 11, tab 2
button "Up", 27, 141 99 30 11, tab 2
button "Down", 28, 141 111 30 11, tab 2
check "Delay request for...", 29, 10 129 60 10, tab 2
edit "", 30, 72 128 18 11, tab 2 autohs
text "second(s).", 31, 94 130 28 8, tab 2
button "Ok", 32, 32 148 37 12, ok
button "Cancel", 33, 71 148 37 12, cancel
button "Help", 34, 110 148 37 12
}
alias botlist { _opendlg botlist }
; eof