Snippets Project Page
Author: maroon
Added: 6y
Updated: Never
mIRC: v7.52 possibly 7.42
Hits: 1,315
Downloads: 9
Review: entropy
Size: 11.44KB
1 0
Login to vote.
Invalid Server Commands Blocker
v0.90
Block invalid commands sent to server which either risk you booted for flooding, or leak private info meant for local alias.
uses RAW 421 to put invalid commands on blacklist, and ON PARSELINE to block them again
If you enable the option to block non-whitelist commands and you experience server problems, check the graylist for commands that belong on the whitelist. It should be obvious where in the script to add new commands to the basic whitelist.
If you're not an OPER at a network, don't add the OPER commands list, so it won't need to search a longer whitelist.
Download
JSON
▲ Review
▼ Source
; Server Commands Blocker by maroon. Lessens chances of being flooded off server due to ; invalid commands, or broadcasting private info meant for a local alias. If your script ; uses a command that isn't an internal command or identifier, and isn't a scripted alias, ; mIRC sends it to the server as a server command, assuming it's an unknown server command. ; This script lets you block commands placed on the blacklist manually or in reply to ; 421 "Unknown command", or you can set the script to block ALL commands not on the whitelist. ; If not blocking all non-whitelist, each invalid command happens at LEAST once per network. ; White/Black/Gray lists are separate by $network because some recognize different commands. ; Rightclick menu -> Status Window ; ; WhiteList = allowed -> server (optional extra commands only needed by IRCOP's) ; Blacklist = -> server is blocked ; GrayList = command going to server that's not on either list. Not blocked unless configured. ; It's a good idea to browse GrayList for possible commands that should move to WhiteList ; If 421 "Unknown command" received from server, command moved -> blacklist even if whitelisted ; Due to Server Lag, while-loop, or multi commands within alias, there might be several/many ; invalid commands before receiving the 421 event ; ; Once you fix script errors, consider removing those bad commands from blacklist or clearing blacklist completely ; length of each *LIST limited to mIRC line length approx 4150 ; uses ON PARSELINE added v7.42, $unsafe added v7.44 alias -l block_msg { if (whitelist isin $1-) var %c -sgt $+($chr(3),0,$chr(44), 4) elseif (blacklist isin $1-) var %c -sgt $+($chr(3),0,$chr(44), 1) elseif ( graylist isin $1-) var %c -sgt $+($chr(3),0,$chr(44),14) else var %c -sgtc ctcp | echo %c $1- $chr(3) } on *:PARSELINE:out:*:{ if (!$hget(server_cmds,$network)) return var %cmd $remove($gettok($parseline,1,32),$lf) if ($istok($hget(server_cmds,$listfmt(whitelist)),%cmd,32)) return if ($istok($hget(server_cmds,$listfmt(blacklist)),%cmd,32)) { block_msg Blocking blacklisted command->server: $parseline | .parseline -ot | halt } if ($hget(server_cmds,$listfmt(blockgrays))) { Add2list graylist %cmd | block_msg If this is a valid server command, move it graylist->whitelist!! Blocking graylisted command->server: $parseline | .parseline -ot | halt } block_msg Unknown outgoing command->server added to graylist: %cmd Add2list graylist %cmd } raw 421:*:{ if (!$hget(server_cmds,$network)) return | Block_msg Raw 421 'Unknown command' moved->blacklist: $2 | Add2List blacklist $2 } alias -l listfmt { return $iif(*.* iswm $1,$1,$+($1,.,$network)) } alias -l listitem { if (($1 isnum 1-) && ($gettok($hget(server_cmds,$listfmt($2)),$1,32))) return $chr(160) $unsafe($gettok($replace($hget(server_cmds,$listfmt($2)),:,$chr(42889)) ,$1,32)) : MoveList $unsafe($gettok($hget(server_cmds,$listfmt($2)),$1,32)) $2 $3 if ($1 == begin) return - if ($1 == end) return - } alias -l listnetwork { if ($1 isnum 1-) { var %a $scid($scon($1)).network | if (%a) return $iif(%a == $network,$style(2)) %a :clonefromnetwork $scid($scon($1)).network $network $2 $3 } if ($1 == begin) return - if ($1 == end) return - } ; itemname fromlist tolist|delete alias -l movelist { if ($3 isin blacklist whitelist graylist) farmout Add2List $3 $1 | elseif ($3 == delete) farmout DelFromList $2 $eval($1,1) } ; determines whether action is for active $network / all open status windows / all same-lists even if not an active network alias -l farmout { var %m $mouse.key & 6 | var %ms %m & 4 | var %mc %m & 2 | if (!%m) { $1 $2- | return } if (%ms) var %j $scon(0) else var %j $hfind(server_cmds,$+($2,.*), 0,w) while (%j) { if (%ms) var %ml $+($2,.,$scon(%j).network) else var %ml $hfind(server_cmds,$+($2,.*), %j,w) if ($hget(server_cmds,$gettok(%ml,2-,46))) { $1 %ml $3- } dec %j } } ; ADD2List *list itemname alias -l ADD2List { if (!$network) return while ($2) { var %f $findtok($hget(server_cmds,$listfmt($1)),$2,1,32) if (!%f) { last_change hadd server_cmds $listfmt($1) $hget(server_cmds,$listfmt($1)) $2 if ($event !isin PARSELINE 421) Block_Msg Added to $1 $+ : $2 if ($1 == whitelist) { DelFromList blacklist $2 | DelFromList graylist $2 } if ($1 == blacklist) { DelFromList whitelist $2 | DelFromList graylist $2 } if ($1 == graylist) { DelFromList whitelist $2 | DelFromList blacklist $2 } } tokenize 32 $1 $3- } } ; *list itemname alias -l DelFromList { if (!$network) return while ($2) { var %f $findtok($hget(server_cmds,$listfmt($1)),$2,1,32) if (%f) { hadd server_cmds $listfmt($1) $deltok($hget(server_cmds,$listfmt($1)),%f,32) if ($event !isin PARSELINE 421) block_msg $last_change Removed from $1 $+ : $2 } if ($hget(server_cmds,$listfmt($1)) == $null) hadd server_cmds $listfmt($1) PlaceHolder tokenize 32 $1 $3- } } menu status,menubar { Server Commands BlackList $+($network,=,$iif($hget(server_cmds,$network),ON,OFF)) .move from whitelist to graylist ..$submenu($listitem($1,whitelist,graylist)) .move from whitelist to blacklist ..$submenu($listitem($1,whitelist,blacklist)) .delete from whitelist ..$submenu($listitem($1,whitelist,delete)) .- .move from graylist to whitelist ..$submenu($listitem($1,graylist,whitelist)) .move from graylist to blacklist ..$submenu($listitem($1,graylist,blacklist)) .delete from graylist ..$submenu($listitem($1,graylist,delete)) .- .move from blacklist to whitelist ..$submenu($listitem($1,blacklist,whitelist)) .move from blacklist to graylist ..$submenu($listitem($1,blacklist,graylist)) .delete from blacklist ..$submenu($listitem($1,blacklist,delete)) .- .manually add item to whitelist: Input2List whitelist .manually add item to graylist: Input2List graylist .manually add item to blacklist: Input2List blacklist .- .Shft+Click=open nets Ctrl+Click=non-blank lists:Block_msg Pressing Shift or Ctrl while clicking, on this page, extends action to all open-status-windows or all lists of same type that aren't blank. .- .CONFIG chg $asctime($hget(server_cmds,last.change),mm.dd HH $+ $chr(58) $+ nn) disk $asctime($hget(server_cmds,last.write),mm.dd HH $+ $chr(58) $+ nn) ..$iif($hget(server_cmds,$network),$style(1)) Toggle *LIST at $network only - Currently is $iif($hget(server_cmds,$network),ON,OFF) :{ last_change | hadd -s server_cmds $network $iif($hget(server_cmds,$network),0,1) } ..$iif( $hget(server_cmds,$listfmt(blockgrays)),$style(1)) Block all non-whitelisted commands (warning): if ($input(Warning: might cause mIRC to not work correctly if needed commands not on the whitelist)) { last_change | hadd -ms server_cmds $listfmt(blockgrays) 1 } ..$iif(!$hget(server_cmds,$listfmt(blockgrays)),$style(1)) Don't BLock graylisted commands too :{ last_change | hadd -ms server_cmds $listfmt(blockgrays) 0 } ..Flush hashtable to disk:server_cmds_timer flush ..- ..Clear $network WhiteList $numtok($hget(server_cmds,$listfmt(whitelist)),32):{ last_change | hdel -s server_cmds $listfmt(WhiteList) } ..Clear $network Gray List $numtok($hget(server_cmds,$listfmt( graylist)),32):{ last_change | hdel -s server_cmds $listfmt( GrayList) } ..Clear $network BlackList $numtok($hget(server_cmds,$listfmt(blacklist)),32):{ last_change | hdel -s server_cmds $listfmt(Blacklist) } ..- ..Clone WhiteList from Other Network ...$submenu($listnetwork($1,whitelist)) ..Clone GrayList from Other Network ...$submenu($listnetwork($1,graylist)) ..Clone BlackList from Other Network ...$submenu($listnetwork($1,blacklist)) ..sort lists alpahbetically ...$iif($hget(server_cmds,$listfmt(whitelist)),sort whitelist):sortlist whitelist ...$iif($hget(server_cmds,$listfmt(blacklist)),sort blacklist):sortlist blacklist ...$iif($hget(server_cmds,$listfmt( graylist)),sort graylist):sortlist graylist ..- ..$iif($hget(server_cmds,auto_enable),$style(1)) Toggle AutoEnable New Networks at Connect - Currently is $iif($hget(server_cmds,auto_enable),ON,OFF) : hadd -s server_cmds auto_enable $iif($hget(server_cmds,auto_enable),0,1) ..reset $network whitelist to ONLY BASIC server commands:reset basic ..add OPER commands to $network whitelist:reset oper ..(Oper commands only needed at networks were you are OPER):reset oper ..remove OPER commands from $network whitelist: reset removeoper } alias -l clonefromnetwork { hadd -s server_cmds $+($3,.,$2) $hget(server_cmds,$listfmt($3)) | last_change } alias -l sortlist { hadd -s server_cmds $listfmt($1) $sorttok($hget(server_cmds,$listfmt($1)),32) | last_change } alias -l input2list { var %f $input(Input Item to add to $1,e) | if (%f) farmout Add2List $1 %f } alias -l reset { var %basic PRIVMSG MODE PONG ISON JOIN KICK NICK NOTICE PART AWAY NAMES NAMESX QUIT CONNECT CNOTICE CPRIVMSG ENCAP ERROR HELP INFO INVITE KNOCK LINKS LIST LUSERS MOTD PING RULES SERVER SERVICE SERVLIST SQUERY SETNAME SILENCE STATS SUMMON TIME TOPIC TRACE UHNAMES USER USERHOST USERIP USERS VERSION WALLOPS WATCH WHO WHOIS WHOWAS PROTOCTL CAP AUTHENTICATE NICKSERV NS CS CHANSERV MS MEMOSERV PASS OPER ADMIN var %oper globops chatops die locops adchat nachat kill kline zline gline shun gzline lag sethost setident chghost chgident chgname dccdeny undccdeny sajoin sapart samode squit rehash restart rping opermotd addmotd addomotd sdesc addline mkpasswd tsctl htm close if ($1 == basic) { hdel -ms server_cmds $listfmt(whitelist) | Add2List whitelist %basic } if ($1 == oper) Add2List whitelist %oper if ($1 == removeoper) DelFromList whitelist %oper if ($hget(server_cmds,$listfmt(blacklist)) == $null) hadd server_cmds $listfmt(blacklist) PlaceHolder if ($hget(server_cmds,$listfmt( graylist)) == $null) hadd server_cmds $listfmt( graylist) PlaceHolder last_change | server_cmds_timer flush } ; alias used only for mIRC v7.42-7.43 where PARSELINE exists but $unsafe doesnt alias -l unsafe return $+($!decode,$chr(40),$encode($1,m),$chr(44),m,$chr(41)) on *:CONNECT:{ if (($network) && ($hget(server_cmds,auto_enable)) && ($hget(server_cmds,$network) == $null)) { hadd -ms server_cmds $network 1 | reset basic } block_msg Server Commands Blacklist by maroon $+ $chr(169) at $network is $iif($hget(server_cmds,$network),ON!,OFF! - Use Status Window to enable!) WhiteList= $numtok($hget(server_cmds,$listfmt(whitelist)),32) BlackList= $numtok($hget(server_cmds,$listfmt(Blacklist)),32) GrayList= $numtok($hget(server_cmds,$listfmt(Graylist)),32) if ($numtok($hget(server_cmds,$listfmt(Graylist)),32)) Block_msg $network Graylist: $hget(server_cmds,$listfmt(Graylist)) } on *:EXIT:{ save_hash } on *:START:{ load_hash | server_cmds_timer } alias -l last_write { hadd -m server_cmds last.write $ctime } alias -l last_change { hadd server_cmds last.change $ctime } alias -l server_cmds_timer { if (!$timer(server_cmds_timer)) .timerserver_cmds_timer -io 0 3600 server_cmds_timer var %lc $calc($ctime - $hget(server_cmds,last.change)) var %lw $calc($ctime - $hget(server_cmds,last.write )) if (($1) || ((%lc < 3600) && (%lw >= 3600))) save_hash } alias -l load_hash { if (!$hget(server_cmds)) hmake -s server_cmds | if ($isfile(server_cmds.txt)) hload -sm server_cmds server_cmds.txt | last_write } alias -l save_hash { hsave server_cmds server_cmds.txt | last_write | server_cmds_timer }
Changelog:
0
0
Review: entropy
This is pretty cool. The documentation and the big list of options makes this an interesting snippet.
It serves its purpose.
Good work, maroon!
This is pretty cool. The documentation and the big list of options makes this an interesting snippet.
It serves its purpose.
Good work, maroon!