Advertisement
DarkTexas

Pushmode mIRC

Jan 3rd, 2016
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 33.68 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PUSHMODE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;info:
  3. ;
  4. ;  by wiebe @ QuakeNet
  5. ;  version 1.31     (written and tested on mIRC 6.15)
  6. ;
  7. ;  last edit: Fri Apr 30 2004
  8. ;
  9. ;
  10. ;What does this script do?
  11. ;
  12. ;  Queues and dumps modes together as much as possible.
  13. ;
  14. ;
  15. ;Some examples:
  16. ;
  17. ;  Example 1: from within same command
  18. ;  voicing some users with the following command:
  19. ;   //var %x = $nick($chan,0,r) | while (%x) { mode $chan +v $nick($chan,%x,r) | dec %x }
  20. ;  and this happens:
  21. ;
  22. ;   [18:45:32] * dev-mirc sets mode: +v zyrtepf
  23. ;   [18:45:32] * dev-mirc sets mode: +v zcttchv
  24. ;   [18:45:32] * dev-mirc sets mode: +v yznzko
  25. ;   [18:45:32] * dev-mirc sets mode: +v yuxf
  26. ;   [18:45:32] * dev-mirc sets mode: +v twyqh
  27. ;   [18:45:34] * dev-mirc sets mode: +v pitqxpg
  28. ;   [18:45:36] * dev-mirc sets mode: +v nsln
  29. ;   [18:45:38] * dev-mirc sets mode: +v moypfnk
  30. ;   [18:45:40] * dev-mirc sets mode: +v gibuhee
  31. ;   [18:45:42] * dev-mirc sets mode: +v evuwntm
  32. ;
  33. ;  This sends a mode command +v <nick> for each nick
  34. ;
  35. ;  Now we do the same but with pushmode instead of the normal mode command:
  36. ;   //var %x = $nick($chan,0,r) | while (%x) { pushmode $chan +v $nick($chan,%x,r) | dec %x }
  37. ;  and this happens:
  38. ;
  39. ;   [18:48:03] * dev-mirc sets mode: +vvvvvv zyrtepf zcttchv yznzko yuxf twyqh pitqxpg
  40. ;   [18:48:04] * dev-mirc sets mode: +vvvv nsln moypfnk gibuhee evuwntm
  41. ;
  42. ;  The modes were now pushed together, so only 2 mode commands are needed instead of 10
  43. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  44. ;
  45. ;  Example 2: the same event repeated
  46. ;  An normal anti-flood script for example does this:
  47. ;
  48. ;   [18:23:32] <zcttchv> AVERAGE ANTI FLOOD SCRIPT WITHOUT PUSHMODE
  49. ;   [18:23:32] <evuwntm> AVERAGE ANTI FLOOD SCRIPT WITHOUT PUSHMODE
  50. ;   [18:23:32] <moypfnk> AVERAGE ANTI FLOOD SCRIPT WITHOUT PUSHMODE
  51. ;   [18:23:33] <zyrtepf> AVERAGE ANTI FLOOD SCRIPT WITHOUT PUSHMODE
  52. ;   [18:23:33] <gibuhee> AVERAGE ANTI FLOOD SCRIPT WITHOUT PUSHMODE
  53. ;   [18:23:33] <yznzko> AVERAGE ANTI FLOOD SCRIPT WITHOUT PUSHMODE
  54. ;   [18:23:33] <yuxf> AVERAGE ANTI FLOOD SCRIPT WITHOUT PUSHMODE
  55. ;   [18:23:33] <pitqxpg> AVERAGE ANTI FLOOD SCRIPT WITHOUT PUSHMODE
  56. ;   [18:23:33] <nsln> AVERAGE ANTI FLOOD SCRIPT WITHOUT PUSHMODE
  57. ;   [18:23:33] <twyqh> AVERAGE ANTI FLOOD SCRIPT WITHOUT PUSHMODE
  58. ;   [18:23:33] * dev-mirc sets mode: +b *!*qgeqd@8V5Ry4.8vtU30.virtual
  59. ;   [18:23:33] * dev-mirc sets mode: +b *!*ihgkzu@8V5Ry4.8vtU30.virtual
  60. ;   [18:23:33] * dev-mirc sets mode: +b *!*dqqyex@8V5Ry4.8vtU30.virtual
  61. ;   [18:23:36] * dev-mirc sets mode: +b *!*qfzzq@8V5Ry4.8vtU30.virtual
  62. ;   [18:23:40] * dev-mirc sets mode: +b *!*alavec@8V5Ry4.8vtU30.virtual
  63. ;   [18:23:44] * dev-mirc sets mode: +b *!*avwy@8V5Ry4.8vtU30.virtual
  64. ;   [18:23:48] * dev-mirc sets mode: +b *!*tqkukhp@8V5Ry4.8vtU30.virtual
  65. ;   [18:23:52] * dev-mirc sets mode: +b *!*xrvdohn@8V5Ry4.8vtU30.virtual
  66. ;   [18:23:56] * dev-mirc sets mode: +b *!*ujundvh@8V5Ry4.8vtU30.virtual
  67. ;   [18:24:00] * dev-mirc sets mode: +b *!*kid@8V5Ry4.8vtU30.virtual
  68. ;
  69. ;  The anti-flood script sends each ban with a mode command
  70. ;
  71. ;  The same script using pushmode does the following:
  72. ;
  73. ;   [18:25:11] <zcttchv> AVERAGE ANTI FLOOD SCRIPT WITH PUSHMODE
  74. ;   [18:25:11] <evuwntm> AVERAGE ANTI FLOOD SCRIPT WITH PUSHMODE
  75. ;   [18:25:11] <moypfnk> AVERAGE ANTI FLOOD SCRIPT WITH PUSHMODE
  76. ;   [18:25:11] <zyrtepf> AVERAGE ANTI FLOOD SCRIPT WITH PUSHMODE
  77. ;   [18:25:11] <gibuhee> AVERAGE ANTI FLOOD SCRIPT WITH PUSHMODE
  78. ;   [18:25:11] <yznzko> AVERAGE ANTI FLOOD SCRIPT WITH PUSHMODE
  79. ;   [18:25:11] <yuxf> AVERAGE ANTI FLOOD SCRIPT WITH PUSHMODE
  80. ;   [18:25:11] <pitqxpg> AVERAGE ANTI FLOOD SCRIPT WITH PUSHMODE
  81. ;   [18:25:11] <nsln> AVERAGE ANTI FLOOD SCRIPT WITH PUSHMODE
  82. ;   [18:25:12] <twyqh> AVERAGE ANTI FLOOD SCRIPT WITH PUSHMODE
  83. ;   [18:25:12] * dev-mirc sets mode: +bbbbbb *!*qgeqd@8V5Ry4.8vtU30.virtual *!*ihgkzu@8V5Ry4.8vtU30.virtual *!*dqqyex@8V5Ry4.8vtU30.virtual *!*qfzzq@8V5Ry4.8vtU30.virtual *!*alavec@8V5Ry4.8vtU30.virtual *!*avwy@8V5Ry4.8vtU30.virtual
  84. ;   [18:25:13] * dev-mirc sets mode: +bbbb *!*tqkukhp@8V5Ry4.8vtU30.virtual *!*xrvdohn@8V5Ry4.8vtU30.virtual *!*ujundvh@8V5Ry4.8vtU30.virtual *!*kid@8V5Ry4.8vtU30.virtual
  85. ;
  86. ;  The anti-flood script sends the modes to pushmode, which turns 10 mode commands into 2
  87. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  88. ;
  89. ;  Example 3: multiple events
  90. ;  Some form of a bitchmode script:
  91. ;
  92. ;   on @!*:op:#channel:{ if ($opnick != $me) { mode $chan -o $opnick } }
  93. ;   on @!*:voice:#channel:{ if ($vnick != $me) { mode $chan -v $vnick } }
  94. ;   on @!*:help:#channel:{ if ($hnick != $me) { mode $chan -h $hnick } }
  95. ;   on @!*:mode:#channel:{
  96. ;     if (n isincs $1) && (n !isincs $gettok($chan($chan).mode,1,32)) { mode $chan +n }
  97. ;     if (t isincs $1) && (t !isincs $gettok($chan($chan).mode,1,32)) { mode $chan +t }
  98. ;   }
  99. ;
  100. ;   [13:54:31] * wiebe sets mode: -nt+ovh nick1 nick2 nick3
  101. ;   [13:54:31] * dev-mirc sets mode: +n
  102. ;   [13:54:31] * dev-mirc sets mode: +t
  103. ;   [13:54:31] * dev-mirc sets mode: -o nick1
  104. ;   [13:54:31] * dev-mirc sets mode: -v nick2
  105. ;   [13:54:31] * dev-mirc sets mode: -h nick3
  106. ;
  107. ;  With pushmode:
  108. ;
  109. ;   on @!*:op:#channel:{ if ($opnick != $me) { pushmode $chan -o $opnick } }
  110. ;   on @!*:voice:#channel:{ if ($vnick != $me) { pushmode $chan -v $vnick } }
  111. ;   on @!*:help:#channel:{ if ($hnick != $me) { pushmode $chan -h $hnick } }
  112. ;   on @!*:mode:#channel:{
  113. ;     if (n isincs $1) && (n !isincs $gettok($chan($chan).mode,1,32)) { pushmode $chan +n }
  114. ;     if (t isincs $1) && (t !isincs $gettok($chan($chan).mode,1,32)) { pushmode $chan +t }
  115. ;   }
  116. ;
  117. ;   [13:55:36] * wiebe sets mode: -nt+ohv nick1 nick2 nick3
  118. ;   [13:55:36] * dev-mirc sets mode: -ohv+nt nick1 nick2 nick3
  119. ;
  120. ;  only 1 mode line needed for the 4 events
  121. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  122. ;
  123. ;
  124. ;How to use this script?
  125. ;
  126. ;  pushmode [-cdflnprswuNeM] <channel> <+/-mode> [arg]
  127. ;
  128. ;    can be used to push channel modes together, see below
  129. ;
  130. ;
  131. ;   The script has 4 different queue's,
  132. ;   a queue for single modes (like +m) is emptied everytime pushmode is sending modes
  133. ;   a faster queue, a normal queue (default) and a slower queue for modes with a parameter (like +b banmask)
  134. ;   first the faster queue is emptied, then the default queue and last the slower queue
  135. ;
  136. ;   The -n switch (next) queues the mode in the faster queue, the -l switch (low) can be used for the slower queue
  137. ;   this is only for modes with a parameter
  138. ;     pushmode #channel +v nick      adds +v nick to the default queue
  139. ;     pushmode -l #channel -v nick   adds -v nick to the slower queue
  140. ;     pushmode -n #channel +o nick   adds +o nick to the faster queue
  141. ;
  142. ;   The -c switch (clear) can be used to clear the queues
  143. ;   the -l (low), -d (default), -n (next) and -s (single) switch
  144. ;   can be used to clear a specific queue or multiple queues
  145. ;     pushmode -c                    clears all queues for all channels
  146. ;     pushmode -dc                   clears the default queue for all channels
  147. ;     pushmode -nc #channel          clears the faster queue for #channel
  148. ;     pushmode -cs #channel          clears the single queue for #channel
  149. ;     pushmode -cdl #channel         clears the default and slower queue for #channel
  150. ;
  151. ;   The -f switch (flush) starts to empty the queue at once without waiting for the timer to start it
  152. ;     pushmode -f                    starts pushmode for all channels
  153. ;     pushmode -f #channel           starts pushmode for #channel
  154. ;     pushmode -f #channel +o nick   starts pushmode for #channel after adding +o nick to the queue
  155. ;
  156. ;   The -p switch (passive) can be used to only add a mode to the queue,
  157. ;   but it will not cause pushmode to empty the queue,
  158. ;   this mode will be send the next time pushmode is dumping modes
  159. ;   or when the number of modes in the queues equals $modespl
  160. ;     pushmode -p #channel +b                queues in the default queue and
  161. ;                                            sends +b (request banlist) the next time pushmode is dumping modes
  162. ;     pushmode -p #channel -b *!*@host.com   queues in the default queue and
  163. ;                                            sends -b *!*@host.com the next chance it gets
  164. ;
  165. ;   The -r switch (remove) removes a mode from the queue,
  166. ;   the -l (low), -d (default) and -n (next) switch
  167. ;   can be used to remove a mode from a specific queue or from multiple queues
  168. ;   when combined with the -w a wildcardmatch is done
  169. ;   if you want to clear the entire queue, it is better (read faster) to use the -c switch
  170. ;   usefull when you want to set a key with pushmode and you first clear any +k and -k modes
  171. ;     pushmode -dr #channel +b *!*@host.com    removes +b *!*@host.com from the default queue
  172. ;     pushmode -r #channel +v nick             removes +v nick from all queues
  173. ;     pushmode -rw #channel +b *               removes all bans from all queues
  174. ;     pushmode -rw #channel +?                 removes all single + modes from the queue
  175. ;     pushmode -rdl #channel +k key            removes +k key from the default and slower queue
  176. ;
  177. ;   The -uN switch can be used to remove a ban after N seconds using pushmode
  178. ;   using 0 for N, makes the script remove the ban from the internal tempban list
  179. ;   this will not remove the ban from the channel
  180. ;     pushmode -u120 #channel +b *!*@host.com        removes the ban *!*@host.com after 120 seconds
  181. ;     pushmode -u0 #channel +b *!*@leave.this.ban    removes *!*@leave.this.ban from the internal tempban list
  182. ;
  183. ;   The -eM switch (expire) removes the mode from the queue after M seconds,
  184. ;   so if the mode is not send within M seconds, it will not be send
  185. ;     pushmode -e10 #channel +m      mode +m will only be send within 10 seconds or not
  186. ;     pushmode -e60 #channel +l 100  mode +l 100 will only be send within 60 seconds or not
  187. ;
  188. ;   Combinations are possible, for example:
  189. ;     pushmode -nfpe60u600 #channel +b *!*user@*.host.com
  190. ;
  191. ;   The script can voice/devoice users even if they changed nick since the mode was in the queue
  192. ;   this can be done by giving nick!user@host as parameter
  193. ;   the default settings makes the script understand that @%+ is ohv, if you are on a server with additional
  194. ;   modes which can be set on users on a channel, you have to edit the prefix setting below
  195. ;   the target needs to be in your IAL list for this to work
  196. ;   the script adds/removes a tag to the IAL using ialmark and finds the nick when sending the mode
  197. ;   other scripts using ialmark may break this part
  198. ;
  199. ;     pushmode #channel +v goober!~bla@123.abc.isp.com                  will voice the user goober, even if he would
  200. ;                                                                       change nick before the mode is send
  201. ;
  202. ;     pushmode #channel -h somenick!someuser@abc.users.undernet.org     dehalfops somenick, even if he would
  203. ;                                                                       change nick before the mode is send
  204. ;
  205. ;     pushmode #channel +o dev-mirc!dev-mirc@def.users.quakenet.org     will op dev-mirc, even if he would
  206. ;                                                                       change nick before the mode is send
  207. ;
  208. ;
  209. ;  pushuser <+/-mode> [arg]
  210. ;
  211. ;    can be used for usermodes, usefull if you have several scripts setting usermodes on connect
  212. ;    pushuser will send them all at once instead of N times a mode command
  213. ;
  214. ;
  215. ;  Pushmode (pushuser) can only take 1 mode at a time
  216. ;  The - or + needs to be included
  217. ;  The script does not allow duplicates in the same queue
  218. ;  Temp bans work only if nick!user@host format is used (like *!*@host.com and not *host.com or just host.com)
  219. ;    this is because of the isban operator
  220. ;
  221. ;  Script is uses $modespl (MODES= setting),
  222. ;  here meaning how many parameter modes (like +b banmask) can be put into 1 line
  223. ;  the number of modes without parameter (like +m) is unlimited
  224. ;  if you want to use this script on a server where this is different, you have to change the script a bit
  225. ;  see the pushmode.dump alias
  226. ;
  227. ;  Some checks are done on the modes, like if the mode exists, if the mode makes "sense" etc.
  228. ;  it uses $chanmodes (with b,k,l,imnpst as default modes), checks op/halfop status.
  229. ;  you can see the checks and change them in the pushmode.dump alias
  230. ;
  231. ;
  232. ;What use has this script?
  233. ;
  234. ;  not only can you simply 'queue' mode changes from within the same event or script
  235. ;  but mode changes by all scripts can be pushed together
  236. ;
  237. ;
  238. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  239.  
  240. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ALIAS PUSHMODE.DELAY ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  241. ; when first called, the script will wait N seconds before sending a mode change
  242. alias -l pushmode.delay {
  243.   return 1
  244. }
  245.  
  246. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ALIAS PUSHMODE.RESTART ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  247. ; set here the delay (seconds) pushmode should have between multiple mode lines
  248. ; after sending a mode change and there are items left in the queue,
  249. ; it will wait N seconds before sending the next mode change
  250. alias -l pushmode.restart {
  251.   return 2
  252. }
  253.  
  254. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ALIAS PUSHMODE.BAN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  255. ; set here the delay (seconds) for checking which bans are to be unset
  256. ; a timer runs with this interval
  257. ; it checks the temp bans set by this script for all channels and unbans them with pushmode
  258. ; settings this to 600 (10 min) for example, makes a temp ban set for 5min being unset after 5~15 minutes
  259. ; so this setting defines how accurate the time of a temp ban is
  260. alias -l pushmode.ban {
  261.   return 600
  262. }
  263.  
  264. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ALIAS PUSHMODE.PREFIX ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  265. ; set here what modes can be set on a user on a channel (this is NOT b or any other list mode)
  266. ; default @ = o, % = h, + = v
  267. ; leave empty if you dont want to use this
  268. ; if you are not sure what this is, leave it
  269. ; replace each char with their mode char, @ is o for example
  270. alias -l pushmode.prefix {
  271.   return $nickmode
  272.   ; should $nickmode not work, remove it and use the following line
  273.   return $replace($prefix,@,o,%,h,+,v)
  274. }
  275.  
  276. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ALIAS PUSHMODE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  277. ; pushmode [-cdflnprswuNeM] <channel> <+/-mode> [arg]
  278. alias pushmode {
  279.   var %f, %q, %p, %e, %u
  280.  
  281.   ; part for switches
  282.   if ($left($1,1) == -) {
  283.  
  284.     ; c switch is there
  285.     if (c isin $1) {
  286.  
  287.       ; no channel
  288.       if (!$2) {
  289.  
  290.         ; d switch is there, clear all default queues for this connection
  291.         if (d isin $1) { $pushmode.queue($+($cid,.pushmode.*.default)).clear }
  292.  
  293.         ; n switch is there, clear all next queues for this connection
  294.         if (n isin $1) { $pushmode.queue($+($cid,.pushmode.*.next)).clear }
  295.  
  296.         ; l switch is there, clear all low queues for this connection
  297.         if (l isin $1) { $pushmode.queue($+($cid,.pushmode.*.low)).clear }
  298.  
  299.         ; s switch is there, clear all single queues for this connection
  300.         if (s isin $1) { $pushmode.queue($+($cid,.pushmode.*.single)).clear }
  301.  
  302.         ; no other switches, clear all queues for this connection
  303.         if (n !isin $1) && (d !isin $1) && (l !isin $1) && (s !isin $1) { $pushmode.queue($+($cid,.pushmode.*)).clear }
  304.       }
  305.       else {
  306.  
  307.         ; d switch is there, clear the default queue for the channel
  308.         if (d isin $1) { $pushmode.queue($+($cid,.pushmode.,$hash($2,32),.default)).clear }
  309.  
  310.         ; n switch is there, clear the next queue for the channel
  311.         if (n isin $1) { $pushmode.queue($+($cid,.pushmode.,$hash($2,32),.next)).clear }
  312.  
  313.         ; l switch is there, clear the low queue for the channel
  314.         if (l isin $1) { $pushmode.queue($+($cid,.pushmode.,$hash($2,32),.low)).clear }
  315.  
  316.         ; s switch is there, clear the single queue for this connection
  317.         if (s isin $1) { $pushmode.queue($+($cid,.pushmode.,$hash($2,32),.single)).clear }
  318.  
  319.         ; no other switches, clear all queues for the channel
  320.         if (n !isin $1) && (d !isin $1) && (l !isin $1) && (s !isin $1) {
  321.           $pushmode.queue($+($cid,.pushmode.,$hash($2,32),.next)).clear
  322.           $pushmode.queue($+($cid,.pushmode.,$hash($2,32),.default)).clear
  323.           $pushmode.queue($+($cid,.pushmode.,$hash($2,32),.low)).clear
  324.           $pushmode.queue($+($cid,.pushmode.,$hash($2,32),.single)).clear
  325.         }
  326.       }
  327.       return
  328.     }
  329.  
  330.     ; f switch is there, set a var
  331.     if (f isin $1) { var %f = 1 }
  332.  
  333.     ; n switch is there, set a var
  334.     if (n isin $1) { var %q = next }
  335.  
  336.     ; l switch is there, set a var
  337.     elseif (l isin $1) { var %q = low }
  338.  
  339.     ; p switch is there, set a var
  340.     if (p isin $1) { var %p = 1 }
  341.  
  342.     ; u or e switch is used, set a var
  343.     if (u isin $1) || (e isin $1) { var %string = $remove($1,-,d,c,f,l,n,p,r,s,w) , %x = 1
  344.  
  345.       ; loop through all chars
  346.       while (%x <= $len(%string)) {
  347.  
  348.         ; found u, set a var
  349.         if ($mid(%string,%x,1) == u) { var %y = $calc(%x +1)
  350.  
  351.           ; as long as it is numbers, set a var, next char
  352.           while ($mid(%string,%y,1) isnum) { var %u = %u $+ $mid(%string,%y,1) | inc %y }
  353.         }
  354.  
  355.         ; found e, set a var
  356.         if ($mid(%string,%x,1) == e) { var %y = $calc(%x +1)
  357.  
  358.           ; as long as it is numbers, set a var, next char
  359.           while ($mid(%string,%y,1) isnum) { var %e = %e $+ $mid(%string,%y,1) | inc %y }
  360.         }
  361.         inc %x
  362.       }
  363.  
  364.       ; '%e' is a number, set a var
  365.       if (%e isnum) { var %e = -e $+ %e }
  366.     }
  367.  
  368.     ; u switch is there with a number, +b and a banmask, add to the hash table, make it decrease each second
  369.     if (u isin $1) && ($3 == +b) && ($4) && (%u > 0) {
  370.       hadd -m $+($cid,.pushmode.,$hash($2,32),.bans) $4 %u | hdec -c $+($cid,.pushmode.,$hash($2,32),.bans) $4
  371.  
  372.       ; check the timer, start the timer
  373.       if (!$timer($+($cid,.pushmode.bans))) {
  374.         .timer $+ $cid $+ .pushmode.bans 1 $$pushmode.ban pushmode.tempban
  375.       }
  376.     }
  377.  
  378.     ; number with u is 0
  379.     if (%u == 0) && ($3 == +b) && ($4) {
  380.  
  381.       ; check if it is already in the hash table as temp ban,  delete it
  382.       if ($hget($+($cid,.pushmode.,$hash($2,32),.bans))) && ($hget($+($cid,.pushmode.,$hash($2,32),.bans),$4)) {
  383.         hdel $+($cid,.pushmode.,$hash($2,32),.bans) $4
  384.  
  385.         ; check if the hash table is empty, free the hash table
  386.         if ($hget($+($cid,.pushmode.,$hash($2,32),.bans),0).item == 0) {
  387.           hfree $+($cid,.pushmode.,$hash($2,32),.bans)
  388.         }
  389.       }
  390.       return
  391.     }
  392.  
  393.     ; r switch is there and mode '$3'
  394.     if (r isin $1) && ($3) {
  395.  
  396.       ; w switch is there
  397.       if (w isin $1) {
  398.  
  399.         ; no parameter, remove the mode from the single queue
  400.         if ($4 == $null) { pushmode.queue -rw $+($cid,.pushmode.,$hash($2,32),.single) $3 }
  401.         else {
  402.  
  403.           ; d switch is there, remove the mode from the default queue
  404.           if (d isin $1) { pushmode.queue -rw $+($cid,.pushmode.,$hash($2,32),.default) $3-4 }
  405.  
  406.           ; n switch is there, remove the mode from the next queue
  407.           if (n isin $1) { pushmode.queue -rw $+($cid,.pushmode.,$hash($2,32),.next) $3-4 }
  408.  
  409.           ; l switch is there, remove the mode from the low queue
  410.           if (l isin $1) { pushmode.queue -rw $+($cid,.pushmode.,$hash($2,32),.low) $3-4 }
  411.  
  412.           ; no other switch is there, remove the mode from all queues
  413.           if (n !isin $1) && (d !isin $1) && (l !isin $1) {
  414.             pushmode.queue -rw $+($cid,.pushmode.,$hash($2,32),.next) $3-4 | pushmode.queue -rw $+($cid,.pushmode.,$hash($2,32),.low) $3-4 | pushmode.queue -rw $+($cid,.pushmode.,$hash($2,32),.default) $3-4
  415.           }
  416.         }
  417.       }
  418.       else {
  419.  
  420.         ; no parameter, remove mode from the single queue
  421.         if ($4 == $null) { pushmode.queue -r $+($cid,.pushmode.,$hash($2,32),.single) $3 }
  422.         else {
  423.  
  424.           ; d switch is there, remove mode form the default queue
  425.           if (d isin $1) { pushmode.queue -r $+($cid,.pushmode.,$hash($2,32),.default) $3-4 }
  426.  
  427.           ; n switch is there, remove mode form next queue
  428.           if (n isin $1) { pushmode.queue -r $+($cid,.pushmode.,$hash($2,32),.next) $3-4 }
  429.  
  430.           ; l switch is there, remove mode form the low queue
  431.           if (l isin $1) { pushmode.queue -r $+($cid,.pushmode.,$hash($2,32),.low) $3-4 }
  432.  
  433.           ; no other switch is there, remove mode form all queues
  434.           if (n !isin $1) && (d !isin $1) && (l !isin $1) && (s !isin $1) {
  435.             pushmode.queue -r $+($cid,.pushmode.,$hash($2,32),.next) $3-4 | pushmode.queue -r $+($cid,.pushmode.,$hash($2,32),.low) $3-4 | pushmode.queue -r $+($cid,.pushmode.,$hash($2,32),.default) $3-4
  436.           }
  437.         }
  438.       }
  439.       return
  440.     }
  441.     tokenize 32 $2-
  442.   }
  443.  
  444.   ; leave multiple modes out
  445.   tokenize 32 $1 $left($2,2) $3
  446.  
  447.   ; '$2' starts with '+' or with '-', we are on channel '$1'
  448.   if ($istok(+ -,$left($2,1),32)) && ($me ison $1) {
  449.  
  450.     ; '$3' does exist
  451.     if ($3 != $null) {
  452.  
  453.       ; -n switch was used, queue mode '$2 $3' in the next queue
  454.       if (%q == next) { pushmode.queue %e $+($cid,.pushmode.,$hash($1,32),.next) $2-3 }
  455.  
  456.       ; -l switch was used, queue mode '$2 $3' in the low queue
  457.       elseif (%q == low) { pushmode.queue %e $+($cid,.pushmode.,$hash($1,32),.low) $2-3 }
  458.  
  459.       ; use default queue, queue mode '$2 $3' in the 'default' queue
  460.       else { pushmode.queue %e $+($cid,.pushmode.,$hash($1,32),.default) $2-3 }
  461.     }
  462.  
  463.     ; the mode does not have a parameter, queue mode '$2' it in the single queue
  464.     else { pushmode.queue $+($cid,.pushmode.,$hash($1,32),.single) $2 }
  465.  
  466.     ; check if the timer is not already running and check the -p switch, start the timer
  467.     if (!$timer($+($cid,.pushmode.,$hash($1,32)))) && (%p != 1) {
  468.       .timer $+ $cid $+ .pushmode. $+ $hash($1,32) 1 $$pushmode.delay pushmode.dump $1
  469.     }
  470.  
  471.     ; no timer, and passive switch, set a var
  472.     if (!$timer($+($cid,.pushmode.,$hash($1,32)))) && (%p == 1) {
  473.       var %x = 1, %queue = .next .default .low, %q = 1, %t = 0
  474.  
  475.       ; loop through each queue, inc var, next queue
  476.       while ($gettok(%queue,%q,32)) {
  477.         inc %t $pushmode.queue($+($cid,.pushmode.,$hash($1,32),$gettok(%queue,%q,32))).size | inc %q
  478.       }
  479.  
  480.       ; at least $modespl modes in the queues, start the timer
  481.       if (%t >= $modespl) {
  482.         .timer $+ $cid $+ .pushmode. $+ $hash($1,32) 1 $$pushmode.delay pushmode.dump $1
  483.       }
  484.     }
  485.  
  486.     ; f switch was used
  487.     if (%f == 1) {
  488.  
  489.       ; no channel, set a var
  490.       if (!$1) { var %x = $chan(0)
  491.  
  492.         ; loop through all the channels, stop the timer, run 'pushmode.dump chan', decrease '%x' and go on to the next channel
  493.         while (%x) {
  494.           .timer $+ $+($cid,.pushmode.,$hash($chan(%x),32)) off | pushmode.dump $chan(%x) | dec %x
  495.         }
  496.       }
  497.  
  498.       ; we are on '$1', stop the timer, run 'pushmode.dump $1'
  499.       elseif ($me ison $1) {
  500.         .timer $+ $+($cid,.pushmode.,$hash($1,32)) off | pushmode.dump $1
  501.       }
  502.     }
  503.   }
  504. }
  505.  
  506. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ALIAS PUSHMODE.DUMP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  507. ; $1 = #channel
  508. alias -l pushmode.dump {
  509.  
  510.   ; we are on channel '$1',  set vars
  511.   if ($me ison $1) { var %x = 1, %queue = .next .default .low, %q = 1, %mode, %check, %smode
  512.  
  513.     ; loop through each queue
  514.     while ($gettok(%queue,%q,32)) {
  515.  
  516.       ; we loop as long as '%x' <= '$modespl' and as long as the size of the queue is greater then 0
  517.       while (%x <= $modespl) && ($pushmode.queue($+($cid,.pushmode.,$hash($1,32),$gettok(%queue,%q,32))).size > 0) {
  518.  
  519.         ; save the next item in a var
  520.         var %next = $pushmode.queue($+($cid,.pushmode.,$hash($1,32),$gettok(%queue,%q,32))).next
  521.  
  522.         ; check if mode is not already going to be set
  523.         if (!$istokcs(%check,%next,44)) && (%next) { var %1 = $gettok(%next,1,32), %2 = $gettok(%next,2,32)
  524.  
  525.           ; some checks / examples of checks
  526.           if (%1 === +o) && (%2 isop $1) { }
  527.           elseif (%1 === -o) && (%2 !isop $1) { }
  528.           elseif (%1 === +h) && (%2 ishop $1) { }
  529.           elseif (%1 === -h) && (%2 !ison $1) { }
  530.           elseif (%1 === +v) && (%2 isvoice $1) { }
  531.           elseif (%1 === -v) && (%2 !ison $1) { }
  532.           elseif (%1 === +b) && (%2 isban $1) { }
  533.           elseif (%1 === +l) && ((%2 !isnum) || (%2 < 1)) { }
  534.           elseif (%1 === +l) && (%2 == $chan($1).limit) { }
  535.           elseif (%1 === +k) && ($chan($1).key) { }
  536.           elseif (%1 === -k) && (%2 !=== $chan($1).key) { }
  537.           elseif ($right(%1,1) === o) && ($me !isop $1) { }
  538.           elseif ($right(%1,1) === h) && ($me !isop $1) { }
  539.           elseif ($me !isop $1) && ($me !ishop $1) { }
  540.  
  541.           ; add '%next' to '%check', add the mode in the var
  542.           else { var %check = $addtok(%check,%next,44) | var %mode = $+($gettok(%mode,1,32),$gettok(%next,1,32)) $gettok(%mode,2-,32) $gettok(%next,2,32) }
  543.           inc %x
  544.         }
  545.       }
  546.       inc %q
  547.     }
  548.  
  549.     ; we loop as long as the size of the single queue is greater then 0, set vars
  550.     while ($pushmode.queue($+($cid,.pushmode.,$hash($1,32),.single)).size > 0) {
  551.       var %next = $pushmode.queue($+($cid,.pushmode.,$hash($1,32),.single)).next
  552.       var %a = $+($gettok($chanmodes,1,44),b), %b = $+($gettok($chanmodes,2,44),k)
  553.       var %c = $+($gettok($chanmodes,3,44),l), %d = $+($gettok($chanmodes,4,44),imnpst)
  554.  
  555.       ; some checks / examples of checks
  556.       if ($right(%next,1) isincs %b) { }
  557.       elseif ($right(%next,1) isincs %c) && ($left(%next,1) == +) { }
  558.       elseif ($right(%next,1) isincs %b) { }
  559.       elseif ($me !isop $1) && ($me !ishop $1) && ($right(%next,1) !isincs %a) { }
  560.  
  561.       ; add next mode to the var
  562.       else { var %smode = $+(%smode,%next) }
  563.     }
  564.  
  565.     ; if the ibl isnt filled for that channel, add +b to request the banlist
  566.     ; if you want this uncomment the following line
  567.     ;if (b !isincs %smode) && (!$chan($1).ibl) { var %smode = $+(%smode,+b) }
  568.  
  569.     ; add the mode in the var
  570.     var %mode = $+($gettok(%mode,1,32),%smode) $gettok(%mode,2-,32)
  571.  
  572.     ; there are modes in '%mode', send the modes
  573.     if (%mode) { .quote MODE $1 %mode }
  574.     var %q = 1
  575.  
  576.     ; loop through the queues
  577.     while ($gettok(%queue,%q,32)) {
  578.  
  579.       ; items left, break
  580.       if ($pushmode.queue($+($cid,.pushmode.,$hash($1,32),$gettok(%queue,%q,32))).size > 0) { break }
  581.       inc %q
  582.     }
  583.  
  584.     ; loop was ended with break, start the timer
  585.     if (%q <= $numtok(%queue,32)) {
  586.       .timer $+ $cid $+ .pushmode. $+ $hash($1,32) 1 $$pushmode.restart pushmode.dump $1
  587.     }
  588.   }
  589. }
  590.  
  591. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ALIAS PUSHUSER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  592. ; $1 = +/-mode, $2 = param
  593. alias pushuser {
  594.  
  595.   ; remove multiple modes, only use the 1st one given
  596.   tokenize 32 $left($1,2) $2
  597.  
  598.   ; '$2' is 2 chars long and '$1' starts with '+' or with '-'
  599.   if ($len($1) == 2) && ($istok(+ -, $left($1,1),32)) {
  600.  
  601.     ; '$2' exists, add the mode to the user queue
  602.     if ($2 != $null) { pushmode.queue $+($cid,.user) $1-2 }
  603.  
  604.     ; '$2' does not exist, add the mode to the user queue
  605.     else { pushmode.queue $+($cid,.user) $1 }
  606.  
  607.     ; check if the timer already runs, start the timer
  608.     if (!$timer($+($cid,.pushuser))) {
  609.       .timer $+ $cid $+ .pushuser 1 $$pushmode.delay pushuser.dump
  610.     }
  611.   }
  612. }
  613.  
  614. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ALIAS PUSHUSER.DUMP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  615. alias -l pushuser.dump {
  616.  
  617.   ; loop as long as there are items in the user queue, set a var with the next item, add the mode to the var
  618.   while ($pushmode.queue($+($cid,.user)).size > 0) { var %next = $pushmode.queue($+($cid,.user)).next
  619.   var %mode = $+($gettok(%mode,1,32),$gettok(%next,1,32)) $gettok(%mode,2-,32) $gettok(%next,2,32) }
  620.  
  621.   ; if '%mode' exists, send the modes
  622.   if (%mode) { .quote MODE $me %mode }
  623. }
  624.  
  625. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ALIAS PUSHMODE.QUEUE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  626. ; pushmode.queue [-eNrw] table mode param
  627. alias -l pushmode.queue {
  628.   var %e
  629.  
  630.   ; switch is used
  631.   if ($left($1,1) == -) {
  632.  
  633.     ; got a switch, there are numbers, set a var
  634.     if (e isin $1) { if ($right($1,-2) isnum) { var %e = $+(-u,$right($1,-2)) } }
  635.  
  636.     ; r switch, w switch, set var
  637.     if (r isin $1) { if (w isin $1) { var %x = $hfind($2,$3-4,0,w).data
  638.         while (%x) {
  639.  
  640.           ; check hash table, delete
  641.           if ($gettok($hget($2,$hfind($2,$3-4,%x,w).data),1,32) === $3) || ($3 iswm $gettok($hget($2,$hfind($2,$3-4,%x,w).data),1,32)) {
  642.             hdel $2 $hfind($2,$3-4,%x,w).data
  643.           }
  644.           dec %x
  645.         }
  646.       }
  647.  
  648.       ; no w switch, set vars
  649.       else {
  650.         var %param = $replace($4,\,\\,|,\|,$chr(40),$+(\,$chr(40)),$chr(41),$+(\,$chr(41)),$chr(91),$+(\,$chr(91)),$chr(93),$+(\,$chr(93)),^,\^,$chr(123),$+(\,$chr(123)),$chr(125),$+(\,$chr(125)),.,\.,$,\$,+,\+,*,\*,?,\?)
  651.         var %mode = \ $+ $left($3,1) $+ $chr(91) $+ $replace($left($3,2),\,\\,|,\|,$chr(40),$+(\,$chr(40)),$chr(41),$+(\,$chr(41)),$chr(91),$+(\,$chr(91)),$chr(93),$+(\,$chr(93)),^,\^,$chr(123),$+(\,$chr(123)),$chr(125),$+(\,$chr(125)),.,\.,$,\$,+,\+,*,\*,?,\?) $+ $chr(93)
  652.  
  653.         ; check hash table, delete
  654.         if ($hfind($2,%mode %param,1,r).data) { hdel $2 $hfind($2,%mode %param,1,r).data }
  655.       }
  656.  
  657.       ; 1 item left, free hash table
  658.       if ($hget($2,0).item == 1) { hfree $2 }
  659.       return
  660.     }
  661.     tokenize 32 $2-4
  662.   }
  663.  
  664.   ; mode is a usermode, it matches *!*@* and no * or ? are there, and its not for the umode queue
  665.   if ($right($2,1) isin $pushmode.prefix) && (*!*@* iswm $3) && (* !isin $3) && (? !isin $3) && (*.user !iswm $1) {
  666.  
  667.     ; the user is in the ial, add tag to ialmark, tokenize
  668.     if ($ial($gettok($3,1,33))) {
  669.       .ialmark $gettok($3,1,33) $ial($gettok($3,1,33)).mark $+($1,.,$iif($hget($1,last),$calc($ifmatch +1),1))
  670.       tokenize 32 $1 $2 $+(*!,$gettok($3,2,33))
  671.     }
  672.  
  673.     ; user is not in ial, tokenize
  674.     else { tokenize 32 $1 $2 $gettok($3,1,33) }
  675.   }
  676.  
  677.   ; set a var, prefix special chars in a regex with a \
  678.   var %param = $replace($3,\,\\,|,\|,$chr(40),$+(\,$chr(40)),$chr(41),$+(\,$chr(41)),$chr(91),$+(\,$chr(91)),$chr(93),$+(\,$chr(93)),^,\^,$chr(123),$+(\,$chr(123)),$chr(125),$+(\,$chr(125)),.,\.,$,\$,+,\+,*,\*,?,\?)
  679.   var %mode = \ $+ $left($2,1) $+ $chr(91) $+ $replace($left($2,2),\,\\,|,\|,$chr(40),$+(\,$chr(40)),$chr(41),$+(\,$chr(41)),$chr(91),$+(\,$chr(91)),$chr(93),$+(\,$chr(93)),^,\^,$chr(123),$+(\,$chr(123)),$chr(125),$+(\,$chr(125)),.,\.,$,\$,+,\+,*,\*,?,\?) $+ $chr(93)
  680.  
  681.   ; there is a 2nd parameter and mode '%mode %param' is not already in the queue, where '%mode' is case sensitive
  682.   if ($2 != $null) && ($hfind($1,%mode %param,0,r).data == 0) {
  683.  
  684.     ; increase item 'last', add mode '$2-' to the hashtable with item name that 'last' has
  685.     hinc -m $1 last | hadd $+(-m,%e) $1 $hget($1,last) $2-
  686.   }
  687.  
  688.   ; propertie is next and hash table '$1' exists, increase item 'first'
  689.   elseif ($isid) && ($prop == next) && ($hget($1)) { hinc -m $1 first
  690.  
  691.     ; 'first' is smaller or equal to 'last', set vars
  692.     if ($hget($1,first) <= $hget($1,last)) {
  693.       var %next = $hget($1,$hget($1,first)), %number = $hget($1,first)
  694.       var %mode = $gettok(%next,1,32), %param = $gettok(%next,2,32)
  695.  
  696.       ; mode is a usermode, parameter matches *!*@*, set var
  697.       if ($right(%mode,1) isin $pushmode.prefix) && (*!*@* iswm %param) {
  698.         var %x = $ial(%param,0)
  699.         while (%x) { var %nick = $ial(%param,%x).nick
  700.  
  701.           ; the tag is there, remove it, set var, stop loop
  702.           if ($wildtok($ial(%nick).mark,$+($1,.,%number),1,32)) {
  703.             .ialmark %nick $remove($ial(%nick).mark,$ifmatch)
  704.             var %next = %mode %nick | break
  705.           }
  706.           dec %x
  707.         }
  708.  
  709.         ; no matches found, clear var
  710.         if (%x == 0) { var %next = $null }
  711.       }
  712.  
  713.       ; delete this item from the hashtable
  714.       hdel $1 $hget($1,first)
  715.  
  716.       ; this is the last item, free the hash table
  717.       if ($hget($1,first) >= $hget($1,last)) { hfree $1 }
  718.       return %next
  719.     }
  720.   }
  721.  
  722.   ; called as identifier ($alias) and propertie is size ($alias().size)
  723.   ; decrease number of items with 1, (1 item in queue, and last is there)
  724.   elseif ($isid) && ($prop == size) { return $iif($calc($hget($1,0).item -1) >= 0,$ifmatch,0) }
  725.  
  726.   ; called as identifier ($alias) and propertie is clear ($alias().clear), free hashtables that match $1
  727.   elseif ($isid) && ($prop == clear) { hfree -w $1 }
  728. }
  729.  
  730. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ALIAS PUSHMODE.TEMPBAN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  731. alias -l pushmode.tempban {
  732.   var %x = 1
  733.  
  734.   ; loop through the channels
  735.   while (%x <= $chan(0)) {
  736.  
  737.     ; loop as long as a match is found, items with values 0 or lower
  738.     while ($hfind($+($cid,.pushmode.,$hash($chan(%x),32),.bans),/^[0-]/,1,r).data) {
  739.  
  740.       ; ibl is not filled, or the ban is set, use pushmode to remove the ban
  741.       if (!$chan(%x).ibl) || ($hfind($+($cid,.pushmode.,$hash($chan(%x),32),.bans),/^[0-]/,1,r).data isban $chan(%x)) {
  742.         pushmode $chan(%x) -b $hfind($+($cid,.pushmode.,$hash($chan(%x),32),.bans),/^[0-]/,1,r).data
  743.       }
  744.  
  745.       ; del the item from the hash table
  746.       hdel $+($cid,.pushmode.,$hash($chan(%x),32),.bans) $hfind($+($cid,.pushmode.,$hash($chan(%x),32),.bans),/^[0-]/,1,r).data
  747.     }
  748.  
  749.     ; check if hash table is empty and the hash table exists, remove hash table
  750.     if ($hget($+($cid,.pushmode.,$hash($chan(%x),32),.bans),0).item == 0) && ($hget($+($cid,.pushmode.,$hash($chan(%x),32),.bans))) {
  751.       hfree $+($cid,.pushmode.,$hash($chan(%x),32),.bans)
  752.     }
  753.     inc %x
  754.   }
  755.  
  756.   ; start the timer
  757.   .timer $+ $cid $+ .pushmode.bans 1 $$pushmode.ban pushmode.tempban
  758. }
  759.  
  760. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DISCONNECT EVENT ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  761. on *:disconnect: { pushmode -c }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement