A blacklist snippet. When you join a channel it checks for any users in the blacklist(Blacklist.txt) and, if found, kick/bans them.
on @1:JOIN:#:{
var %z = 1
while ($read(Blacklist.txt,%z)) {
if ($address($nick,1) == $read(Blacklist.txt,%z)) {
mode $chan +b $address($nick,1)
kick $chan $nick 07B14lacklisted
halt
}
else {
inc %z
}
}
}
menu nicklist {
-
Blacklist
.Add:{
write Blacklist.txt $address($1,1)
mode $chan +b $address($nick,1)
kick $chan $nick 07B14lacklisted
echo -at 07Added14 $address($1,1) 07to blacklist.
}
.Del:{
write -d Blacklist.txt $address($1,1)
echo -at 07Deleted14 $address($1,1) 07from blacklist.
}
.Clear:{
write -c Blacklist.txt
echo -at 07Cleared blacklist.
}
.View:run Blacklist.txt
.Purge:purge
}
alias -l purge {
var %x = 1
while ($nick($active,%x)) {
var %z = 1
while ($read(Blacklist.txt,%z)) {
if ($address($nick($active,%x),1) == $read(Blacklist.txt,%z)) {
mode $active +b $address($nick($active,%x),1)
kick $active $nick($active,%x) 07B14lacklisted
inc %z
}
else {
inc %z
}
}
inc %x
}
}
simple edit turned it into a dialog.
added a version checker since chatspace/ircd/unreal use different identifiers for the hostmask 1/2/3 i had it check the version and set the identifier accordingly for the type of site it is being opened on
on @1:JOIN:#:{
var %z = 1
while ($read(Blacklist.txt,%z)) {
if ($address($nick,1) == $read(Blacklist.txt,%z)) {
mode $chan +b $address($nick,%banmask)
kick $chan $nick 07B14lacklisted
halt
}
else {
inc %z
}
}
}
Menu Menubar,Nicklist,Channel {
Blacklist.System
.Blacklist.System: dialog $iif($dialog(Blacklist.System),-v,-md Blacklist.System) Blacklist.System
}
Dialog Blacklist.System {
Title "Blacklistsystem"
Size -1 -1 110 177
Option dbu
text "blacklisted", 1, 02 0 100 8
list 2, 02 10 50 100, hsbar vsbar
text "Nicks", 3, 56 0 100 8
list 4, 55 10 50 100, hsbar vsbar
Button "Blacklist" 5, 02 106 30 15, flat
Button "DeBlacklist" 6, 32 106 30 15, flat
Button "ClearBlist" 7, 62 106 30 15, flat
Button "Purge" 8, 02 126 30 15, flat
}
on *:dialog:Blacklist.System:init:*:{
nickzz
blacklistednicks
checkversion
}
on *:dialog:Blacklist.System:*:*:{
if ($devent == sclick) {
if ($did == 5) {
if (!$did(4).sel) { noop $input(please select a nick from the nick list to add to the blacklist) } | else {
.set %knick $did(4).seltext
write Blacklist.txt $address($did(4).seltext,%banmask)
mode $active +b $address($did(4).seltext,%banmask)
kick $active %knick 07B14lacklisted
echo -at 07Added14 $address($did(4).seltext,%banmask) 07to blacklist.
did -r blacklist.system 2
.timer 1 1 blacklistednicks
}
}
if ($did == 6) {
if (!$did(2).sel) { noop $input(please select a a blacklisted ip from blacklisted list to remove from blacklist) } | else {
write -d Blacklist.txt $did(2).seltext
echo -at 07Deleted14 $did(2).seltext 07from blacklist.
did -r blacklist.system 2
.timer 1 1 blacklistednicks
}
}
if ($did == 7) {
write -c Blacklist.txt
echo -at 07Cleared blacklist.
did -r blacklist.system 2
.timer 1 1 blacklistednicks
}
if ($did == 8) {
purge
}
}
}
alias nickzz {
var -s %curr 1, %nick $nick($active,0)
did -r Blacklist.System 4
while (%curr <= %nick) {
did -az Blacklist.System 4 $nick($active,%curr)
inc %curr
}
}
alias blacklistednicks {
var %a = 1, %b = $lines(Blacklist.txt)
while (%a <= %b) {
did -az blacklist.system 2 $read(Blacklist.txt, %a)
inc %a
}
}
alias -l purge {
var %x = 1
while ($nick($active,%x)) {
var %z = 1
while ($read(Blacklist.txt,%z)) {
if ($address($nick($active,%x),1) == $read(Blacklist.txt,%z)) {
mode $active +b $address($nick($active,%x),1)
kick $active $nick($active,%x) 07B14lacklisted
inc %z
}
else {
inc %z
}
}
inc %x
}
}
alias checkversion {
version
}
Raw 351 :*: { if ($dialog(Blacklist.System)) {
if (Unreal isin $$1- ) {
.set %banmask 1
}
elseif (ircd isin $$1- ) {
.set %banmask 2
}
elseif (cs isin $$1- ) {
.set %banmask 3
}
}
}
dlsocool, slower than what? you haven't provided an alternative method to use as a basis for comparison. instead, you've observed that the outer loop uses $nick() and have come to the conclusion that it acts as a bottleneck, which is false. the $read() construction is more significant here; a loop through blacklist.txt is conducted with each iteration of the outer loop, and a call to $read() is more intensive than a call to $nick().
Tidum, in general it is always advisable to avoid repeatedly calling non-trivial pieces of code when you know the result cannot possibly change. for example, $read(blacklist.txt, %z) is called twice for the same value of %z; $nick($active, %x) is called 4 times for the same value of %x. instead, save those in temporary %variables and re-use those variables. even if you cannot notice a difference in practice, try to recognize the importance of those techniques in principle. you wouldn't make 3 right turns in place of a left, would you? or look up the same number in the yellow pages 5 times if you knew in advance that you'd need it 5 times?
in case you're interested, there is a far more efficient method that involves using lower level file handling to iterate through the lines in the file, and $ialchan() to search for matching addresses in the channel:
alias -l purge {
.fopen bl blacklist.txt
if (!$ferr) {
while (!$feof) {
var %line = $fread(bl), %i = 1
while ($ialchan(%line, #, %i).nick) {
ban -k # $v1 1 Blacklisted.
inc %i
}
}
}
.fclose bl
}
this is greatly simplified but still an example you can work from. some things to take into consideration:
these may or may not be important considerations depending upon the size of the black list, the size of the channel and the server's tolerance for flood.
alias -l purge {
var %x = 1
while ($nick($active,%x)) {
var %z = 1
while ($read(Blacklist.txt,%z)) {
if ($address($nick($active,%x),1) == $read(Blacklist.txt,%z)) {
mode $active +b $address($nick($active,%x),1)
kick $active $nick($active,%x) 07B14lacklisted
inc %z
}
else {
inc %z
}
}
inc %x
}
}
This loop would be slower. If user in channel is more than 300...
umm most likely but to really be able to answer i'd have to get on justin.tv on mIRC to see about it