BT.SecureMode.tcl 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ########################### SECUREMODE TCL ##########################
  6. #########################################################################
  7. ## ##
  8. ## BlackTools : http://blacktools.tclscripts.net ##
  9. ## Bugs report : http://www.tclscripts.net/ ##
  10. ## Online Help : irc://irc.undernet.org/tcl-help ##
  11. ## #TCL-HELP / UnderNet ##
  12. ## You can ask in english or romanian ##
  13. ## ##
  14. #########################################################################
  15. proc securemode:findexcept {chan host} {
  16. global black
  17. set found_it 0
  18. set file [open $black(add_file) "r"]
  19. set w [read -nonewline $file]
  20. close $file
  21. set data [split $w "\n"]
  22. foreach line $data {
  23. set read_chan [lindex [split $line] 0]
  24. set enc_chan [encoding convertfrom utf-8 $read_chan]
  25. if {[string equal -nocase $enc_chan $chan]} {
  26. set read_type [lindex [split $line] 1]
  27. if {[string equal -nocase $read_type "SECUREMODE-EXCEPT"]} {
  28. set read_host [lindex [split $line] 3]
  29. set real_read_host [string map [list \[ {\[} \] {\]} \? {\?} \\ {\\}] $read_host]
  30. if {[string match -nocase $host $real_read_host] || [string match -nocase $real_read_host $host]} {
  31. set found_it 1
  32. }
  33. }
  34. }
  35. }
  36. return $found_it
  37. }
  38. proc securemode:kickremove {nick host hand chan kicked reason} {
  39. global black
  40. set host [getchanhost $kicked $chan]
  41. if {[setting:get $chan securemode]} {
  42. set chanmode [getchanmode $chan]
  43. if {[string match -nocase "*D*" $chanmode] && [string match -nocase "*m*" $chanmode]} {
  44. if {[info exists black(secure:$chan:allowlist)]} {
  45. if {[lsearch -exact [string tolower $black(secure:$chan:allowlist)] [string tolower $host]] > -1} {
  46. set position [lsearch -exact [string tolower $black(secure:$chan:allowlist)] [string tolower $host]]
  47. set black(secure:$chan:allowlist) [lreplace $black(secure:$chan:allowlist) $position $position]
  48. }
  49. if {[info exists black(secure:$chan:list)]} {
  50. if {[lsearch -exact [string tolower $black(secure:$chan:list)] [string tolower $kicked]] > -1} {
  51. set position [lsearch -exact [string tolower $black(secure:$chan:list)] [string tolower $kicked]]
  52. set black(secure:$chan:list) [lreplace $black(secure:$chan:list) $position $position]
  53. }
  54. }
  55. }
  56. }
  57. }
  58. }
  59. proc secured:allowlist:reset {minute hour day month year} {
  60. global black
  61. foreach chan [channels] {
  62. if {[validchan $chan]} {
  63. if {[info exists black(secure:$chan:allowlist)]} {
  64. unset black(secure:$chan:allowlist)
  65. }
  66. }
  67. }
  68. }
  69. proc securemode:timer {} {
  70. global black botnick
  71. set channels ""
  72. set secure_act 0
  73. foreach chan [channels] {
  74. if {[setting:get $chan securemode]} {
  75. lappend channels $chan
  76. if {[onchan $botnick $chan]} {
  77. set chanmode [getchanmode $chan]
  78. if {[string match -nocase "*D*" $chanmode] && [string match -nocase "*m*" $chanmode]} {
  79. set secure_act 1
  80. }
  81. }
  82. }
  83. }
  84. if {$channels == ""} {
  85. return
  86. }
  87. if {$secure_act == "1"} {
  88. securemode:act $channels 0
  89. }
  90. utimer 30 [list securemode:timer]
  91. }
  92. proc securemode:reply {nick host hand chan mod who} {
  93. global black
  94. if {[setting:get $chan securemode]} {
  95. set getlang [string tolower [setting:get $chan lang]]
  96. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  97. if {[string match "*+D*" $mod]} {
  98. set replace(%chan%) $chan
  99. set text [black:color:set "" $black(say.$getlang.securemode.10)]
  100. set reply [join $text]
  101. putserv "PRIVMSG $chan :[string map [array get replace] $reply]"
  102. }
  103. if {[string match "*-D*" $mod]} {
  104. set replace(%chan%) $chan
  105. set text2 [black:color:set "" $black(say.$getlang.securemode.11)]
  106. set reply2 [join $text2]
  107. putserv "PRIVMSG $chan :[string map [array get replace] $reply2]"
  108. }
  109. }
  110. }
  111. proc securemode:act {channels counter} {
  112. global black
  113. if {$channels == ""} {
  114. return
  115. }
  116. set chan [lindex $channels $counter]
  117. set cc [expr $counter + 1]
  118. if {$chan != ""} {
  119. securemode:raw $chan
  120. } else {
  121. return
  122. }
  123. utimer 5 [list securemode:act $channels $cc]
  124. }
  125. proc securemode:raw {chan} {
  126. global black
  127. putquick "NAMES -d $chan"
  128. set ::securechan $chan
  129. bind RAW - 355 get:nameslist
  130. bind RAW - 366 end:nameslist
  131. }
  132. proc get:nameslist {from keyword arguments} {
  133. global black
  134. set found_it 0
  135. set chan $::securechan
  136. set split_arg [split $arguments ":"]
  137. set names [lindex $split_arg 1]
  138. if {[info exists black(secure:$chan:list)]} {
  139. foreach entry $black(secure:$chan:list) {
  140. if {[lsearch -exact [string tolower [split $names]] [string tolower $entry]] < 0} {
  141. set position [lsearch -exact [string tolower $black(secure:$chan:list)] [string tolower $entry]]
  142. set black(secure:$chan:list) [lreplace $black(secure:$chan:list) $position $position]
  143. if {[info exists black(securecode:$entry:$chan)]} {
  144. unset black(securecode:$entry:$chan)
  145. }
  146. }
  147. }
  148. }
  149. if {[info exists black(secure:$chan:list)]} {
  150. if {[llength $black(secure:$chan:list)] == "0"} {
  151. unset black(secure:$chan:list)
  152. }
  153. }
  154. secure:gethost $names $chan 0
  155. }
  156. proc end:nameslist {from keyword arguments} {
  157. global black
  158. check:if:bind "get:nameslist" "355"
  159. check:if:bind "end:nameslist" "366"
  160. }
  161. proc secure:gethost {names chan counter} {
  162. global black
  163. set name [lindex [split $names] $counter]
  164. set cc [expr $counter + 1]
  165. if {$name != ""} {
  166. securemode:gethost:raw $name $chan
  167. } else {
  168. return
  169. }
  170. utimer 3 [list secure:gethost $names $chan $cc]
  171. }
  172. proc securemode:gethost:raw {name chan} {
  173. global black
  174. putserv "USERHOST :$name"
  175. set ::shchan $chan
  176. set ::shnick $name
  177. bind RAW - 302 get:securemode:host
  178. }
  179. proc get:securemode:host {from keyword arguments} {
  180. global black botnick
  181. set is_allowed 0
  182. set has_access 0
  183. set securemode_activ 0
  184. set hosts [lindex [split $arguments] 1]
  185. set hostname [lindex [split $hosts "="] 1]
  186. regsub {^[-+]} $hostname "" mask
  187. set nick $::shnick
  188. set except_mask "$nick!$mask"
  189. set chan $::shchan
  190. if {[setting:get $chan securemode]} {
  191. set chanmode [getchanmode $chan]
  192. if {[string match -nocase "*D*" $chanmode] && [string match -nocase "*m*" $chanmode]} {
  193. set securemode_activ 1
  194. }
  195. }
  196. if {$securemode_activ == "0"} {
  197. return
  198. }
  199. set replace(%botnick%) $botnick
  200. set replace(%chan%) $chan
  201. set lang [setting:get $chan lang]
  202. if {$lang == ""} { set lang [string tolower $black(default_lang)] }
  203. set getaccess [finduser $except_mask]
  204. if {[matchattr $getaccess $black(exceptflags) $chan]} {
  205. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  206. putserv "PRIVMSG $black(chanserv) :voice $chan $nick"
  207. } else {
  208. putserv "MODE $chan +v $nick"
  209. }
  210. return
  211. }
  212. if {[securemode:findexcept $chan $except_mask] == "1"} {
  213. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  214. putserv "PRIVMSG $black(chanserv) :voice $chan $nick"
  215. } else {
  216. putserv "MODE $chan +v $nick"
  217. }
  218. return
  219. }
  220. if {[info exists black(secure:$chan:allowlist)]} {
  221. if {[setting:get $chan strictsecured] == "" || [setting:get $chan strictsecured] == "0"} {
  222. if {[lsearch -exact [string tolower $black(secure:$chan:allowlist)] [string tolower $mask]] > -1} {
  223. set is_allowed 1
  224. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  225. putserv "PRIVMSG $black(chanserv) :voice $chan $nick"
  226. } else {
  227. putserv "MODE $chan +v $nick"
  228. }
  229. }
  230. if {$is_allowed == "1"} {
  231. return
  232. }
  233. }
  234. }
  235. if {[info exists black(secure:$chan:list)]} {
  236. if {[lsearch -exact [string tolower $black(secure:$chan:list)] [string tolower $nick]] < 0} {
  237. set black(securecode:$nick:$chan) [string toupper [bot:setcode]]
  238. set replace(%msg.1%) $black(securecode:$nick:$chan)
  239. set text [black:color:set "" $black(say.$lang.securemode.1)]
  240. set reply [join $text]
  241. set message [string map [array get replace] $reply]
  242. putserv "PRIVMSG $nick :$message"
  243. lappend black(secure:$chan:list) $nick
  244. }
  245. } else {
  246. set black(securecode:$nick:$chan) [string toupper [bot:setcode]]
  247. set replace(%msg.1%) $black(securecode:$nick:$chan)
  248. set text [black:color:set "" $black(say.$lang.securemode.1)]
  249. set reply [join $text]
  250. set message [string map [array get replace] $reply]
  251. putserv "PRIVMSG $nick :$message"
  252. lappend black(secure:$chan:list) $nick
  253. }
  254. check:if:bind "get:securemode:host" "302"
  255. }
  256. ##############
  257. #########################################################################
  258. ## END ##
  259. #########################################################################