mnet.tcl 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640
  1. # MNET (Message Network) - Networked Broadcasting of Messages over IRC for Communities
  2. # Copyright (C) 2004 Paul-Dieter Klumpp
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. set configs_file "scripts/mnet_conf.tcl"
  18. #your notes:
  19. # - Requirements:
  20. # -> eggdrop bot version >= 1.6.17
  21. # -> using TCL version >= 8.3
  22. # -> TCLLib version >= 1.6
  23. # -> TCLXML version >= 2.6
  24. #my notes:
  25. # ?- aliasing of channels!
  26. # ?- alternative configs! backupconf..
  27. # ?- xml:dom!
  28. # ?- better http get implementation!
  29. # ?- korrekte Statistiken der User usw?
  30. # ?- wordbanning?
  31. # Now, hands away pls :) except you know what you are doing.
  32. ######
  33. #package prefer stable
  34. # we need a nice tcl version
  35. package require Tcl 8.3
  36. # it's an eggdrop script, right? :)
  37. package require eggdrop 1.6
  38. # we need the tclxml package.. at least 2.6 i think
  39. package require xml
  40. # tclxml needs uri of tcllib.. at least 1.1 i think
  41. package require uri
  42. ############ XML CONFIGURATION PARSING FOLLOWS!! WTF! :) #########
  43. global mnet_networks mnet_bots mnet_channels mnet_freqs mnet_bans \
  44. mnet_colors mnet_colors_optional \
  45. mnet_reached_users mnet_reached_chans \
  46. mnet_http_config mnet_local_config \
  47. mnet_histories \
  48. mnet_netconfig_timer \
  49. currentNetworkDesc currentNetworkSig \
  50. startNetworkInstance \
  51. currentBot currentOwner \
  52. startBotInstance \
  53. currentFreqName currentFreqPrefix currentFreqHelpmsg currentFreqDesc \
  54. startFrequencyInstance \
  55. botnet-nick
  56. # list
  57. set mnet_local_config ""
  58. unset mnet_local_config
  59. # list
  60. set mnet_http_config ""
  61. unset mnet_http_config
  62. set mnet_cfg_reload_interval 0
  63. # list
  64. #set mnet_freqs_onoff "lala lala"
  65. #unset mnet_freqs_onoff
  66. proc mnet:clean_netconfig {} {
  67. global mnet_bots mnet_channels mnet_freqs mnet_bans mnet_colors mnet_networks
  68. # secure deletion of all config-arrays..
  69. if {[array exists mnet_bots]} {
  70. array unset mnet_bots
  71. }
  72. if {[array exists mnet_channels]} {
  73. array unset mnet_channels
  74. }
  75. if {[array exists mnet_freqs]} {
  76. array unset mnet_freqs
  77. }
  78. if {[array exists mnet_bans]} {
  79. array unset mnet_bans
  80. }
  81. #if {[array exists mnet_freqs_onoff]} {
  82. # array unset mnet_freqs_onoff
  83. #}
  84. if {[array exists mnet_colors]} {
  85. array unset mnet_colors
  86. }
  87. if {[array exists mnet_colors_optional]} {
  88. array unset mnet_colors_optional
  89. }
  90. # list
  91. set mnet_networks ""
  92. unset mnet_networks
  93. # list
  94. set mnet_freqs "lala lala"
  95. unset mnet_freqs
  96. set mnet_bans "lala lala"
  97. unset mnet_bans
  98. # list FIXME (this kills the history upon every .mnet_reload ... :( .. not good)
  99. if {[array exists mnet_histories]} {
  100. array unset mnet_histories
  101. }
  102. set mnet_histories ""
  103. unset mnet_histories
  104. }
  105. set p [xml::parser \
  106. -elementstartcommand xmlElementStart \
  107. -elementendcommand xmlElementEnd \
  108. -defaultcommand xmlDefaultCmd \
  109. -characterdatacommand xmlCdata \
  110. ]
  111. # -errorcommand xmlHandleError
  112. proc mnet:initvars {} {
  113. global currentNetworkDesc currentNetworkSig \
  114. startNetworkInstance \
  115. currentBot currentOwner \
  116. startBotInstance \
  117. startFrequencyInstance \
  118. mnet_networks mnet_freqs mnet_bans mnet_networks_by_prefix \
  119. botnet-nick
  120. set currentNetwork ""
  121. set currentSig ""
  122. set startNetworkInstance ""
  123. set currentBot ""
  124. set currentOwner ""
  125. set startBotInstance ""
  126. set startFrequencyInstance ""
  127. }
  128. mnet:initvars
  129. proc xmlElementStart {tagname attlist args} {
  130. global mnet_networks mnet_bots mnet_channels mnet_freqs mnet_bans \
  131. mnet_colors mnet_colors_optional \
  132. mnet_freqs_onoff \
  133. currentNetworkDesc currentNetworkSig \
  134. startNetworkInstance \
  135. currentBot currentOwner \
  136. startBotInstance \
  137. currentFreqName currentFreqPrefix currentFreqHelpmsg currentFreqDesc \
  138. startFrequencyInstance \
  139. botnet-nick
  140. set proper_botnick [mnet:proper_botnick ${botnet-nick}]
  141. # putlog "mnet: attr: '$attlist' arg: '$args'"
  142. # getting NETWORK NAME
  143. if {"$tagname" == "mnet"} {
  144. set currentNetworkDesc ""
  145. set currentNetworkSig ""
  146. foreach {key value} $attlist {
  147. if {"$key" == "sig"} {
  148. set currentNetworkSig $value
  149. }
  150. if {"$key" == "desc"} {
  151. set currentNetworkDesc $value
  152. }
  153. if {"$currentNetworkSig" != ""} {
  154. if {"$currentNetworkDesc" != ""} {
  155. putlog "yo: $currentNetworkSig $currentNetworkDesc"
  156. lappend mnet_networks "$currentNetworkSig" "$currentNetworkDesc"
  157. set startNetworkInstance 1
  158. }
  159. }
  160. }
  161. }
  162. # getting botinfos...
  163. if {"$startNetworkInstance" == "1"} {
  164. if {"$tagname" == "bot"} {
  165. set currentBot ""
  166. set currentOwner ""
  167. foreach {key value} $attlist {
  168. if {"$key" == "nick"} {
  169. set currentBot [mnet:proper_botnick $value]
  170. }
  171. if {"$key" == "owner"} {
  172. set currentOwner $value
  173. }
  174. }
  175. if {"$currentBot" != ""} {
  176. if {"$currentOwner" != ""} {
  177. # currentbot auf 9 zeichen runter.. lowercase
  178. # botnick ebenso
  179. lappend mnet_bots($currentNetworkSig) "$currentBot"
  180. putlog "mnet: cfg: reached botcfg for: $currentBot - and my name is: $proper_botnick"
  181. if {"$currentBot" == "$proper_botnick"} {
  182. putlog "mnet: Oh yes, I, ${botnet-nick}, am listed for the network $currentNetworkSig by using '$currentBot'!"
  183. set startBotInstance 1
  184. }
  185. }
  186. }
  187. }
  188. # end of $tagname == "bot"
  189. if {"$startBotInstance" == "1"} {
  190. if {"$tagname" == "ch"} {
  191. foreach {key value} $attlist {
  192. if {"$key" == "name"} {
  193. putlog "test: ${value}"
  194. lappend mnet_channels($currentNetworkSig,$currentBot) [mnet:proper_channelname ${value}]
  195. putlog "mnet: cfg: my channels for $currentNetworkSig $mnet_channels($currentNetworkSig,$currentBot)"
  196. }
  197. }
  198. }
  199. # end of $tagname == "ch"
  200. }
  201. # end of a bot...
  202. if {"$tagname" == "frequency"} {
  203. set currentFreqName ""
  204. set currentFreqPrefix ""
  205. set currentFreqHelpmsg ""
  206. set currentFreqDesc ""
  207. set currentDelay "120"
  208. foreach {key value} $attlist {
  209. if {"$key" == "name"} {
  210. set currentFreqName $value
  211. }
  212. if {"$key" == "prefix"} {
  213. set currentFreqPrefix $value
  214. }
  215. if {"$key" == "helpmsg"} {
  216. set currentFreqHelpmsg $value
  217. }
  218. if {"$key" == "desc"} {
  219. set currentFreqDesc $value
  220. }
  221. if {"$key" == "delay"} {
  222. set currentDelay $value
  223. }
  224. }
  225. if {"$currentFreqName" != ""} {
  226. if {"$currentFreqPrefix" != ""} {
  227. if {"$currentFreqHelpmsg" != ""} {
  228. if {"$currentFreqDesc" != ""} {
  229. putlog "mnet: i, ${botnet-nick}, serve the frequency: $currentFreqName ($currentFreqPrefix) of $currentNetworkSig!"
  230. set startFrequencyInstance 1
  231. lappend mnet_freqs($currentNetworkSig) "$currentNetworkSig" "$currentFreqName" "$currentFreqPrefix" "$currentFreqHelpmsg" "$currentFreqDesc" "$currentDelay"
  232. }
  233. }
  234. }
  235. }
  236. # end of: alle attribs vorhanden fr eine valide frequenz
  237. }
  238. # end of $tagname == "frequency"
  239. # in element Frequency, there are bans as children.
  240. if {"$startFrequencyInstance" == "1"} {
  241. if {"$tagname" == "ban"} {
  242. set currentBanHostmask ""
  243. set currentBanReason ""
  244. foreach {key value} $attlist {
  245. if {"$key" == "hostmask"} {
  246. set currentBanHostmask $value
  247. }
  248. if {"$key" == "reason"} {
  249. set currentBanReason $value
  250. }
  251. }
  252. if {"$currentBanHostmask" != ""} {
  253. if {"$currentBanReason" != ""} {
  254. putlog "mnet: adding ban to frequency: $currentNetworkSig, $currentFreqPrefix, $currentBanHostmask, reason: $currentBanReason"
  255. lappend mnet_bans($currentNetworkSig,$currentFreqPrefix) "$currentBanHostmask" "$currentBanReason"
  256. }
  257. }
  258. }
  259. }
  260. if {"$tagname" == "color"} {
  261. set currentColor ""
  262. set currentColorOptional ""
  263. foreach {key value} $attlist {
  264. if {"$key" == "id"} {
  265. set currentColor $value
  266. putlog "mnet: gone into colors! $value"
  267. }
  268. if {"$key" == "optional"} {
  269. set currentColorOptional $value
  270. putlog "mnet: color optional? $value"
  271. }
  272. }
  273. if {"$currentColor" != ""} {
  274. set mnet_colors($currentNetworkSig) $currentColor
  275. putlog "mnet: the color-id for $currentNetworkSig is: $currentColor"
  276. } else {
  277. # make NO color if no color-id or tag has been given:
  278. set mnet_colors($currentNetworkSig) none
  279. }
  280. if {"$currentColorOptional" != ""} {
  281. set mnet_colors_optional($currentNetworkSig) $currentColorOptional
  282. putlog "mnet: the color is optional: $currentColorOptional"
  283. } else {
  284. set mnet_colors_optional($currentNetworkSig) 0
  285. putlog "mnet: the color is NOT optional and will be forced."
  286. }
  287. }
  288. }
  289. }
  290. proc xmlElementEnd {tagname} {
  291. global mnet_networks mnet_bots mnet_channels \
  292. currentNetworkDesc currentNetworkSig \
  293. startNetworkInstance \
  294. startBotInstance \
  295. startFrequencyInstance \
  296. currentBot currentOwner
  297. if {"$tagname" == "mnet"} {
  298. set startNetworkInstance 0
  299. set currentNetworkDesc ""
  300. set currentNetworkSig ""
  301. }
  302. if {"$tagname" == "bot"} {
  303. set startBotInstance 0
  304. }
  305. if {"$tagname" == "frequency"} {
  306. set startFrequencyInstance 0
  307. }
  308. }
  309. proc xmlCdata {data} {
  310. # putlog "mnet: data found: $data"
  311. return 1
  312. }
  313. proc xmlHandleError {errorcode errormsg} {
  314. putlog "mnet: some error occured: errcode $errorcode: $errormsg"
  315. }
  316. proc xmlDefaultCmd {data} {
  317. putlog "mnet: i don't know this element: $data"
  318. return 1
  319. }
  320. ##################################################################
  321. ## some internal variables for messaging and stuff :) not your business after all.
  322. set mnet(version) "mnet 1.011escape"
  323. set mnet_max_history 8
  324. set mnet(reached) "0"
  325. set mnet(reached_channels) "0"
  326. set mnet_reached_users(dummy) "0"
  327. set mnet_reached_chans(dummy) "0"
  328. ##
  329. proc mnet:get_data {n} {
  330. if {[string range $n 0 0] == "\{"} {
  331. set n "\\$n"
  332. }
  333. return $n
  334. }
  335. proc mnet:proper_botnick {botnick} {
  336. set temp [string tolower $botnick]
  337. # abfrage ob zu lang, dann fixen
  338. # putlog "mnet: $botnick lowercase: $temp"
  339. if {[string length $botnick] > 9} {
  340. set temp [string range $temp 0 8 ]
  341. # putlog "mnet: botnickname $botnick too long: capping to: $temp"
  342. }
  343. return $temp
  344. }
  345. proc mnet:proper_channelname {channelname} {
  346. # channel names ARE NOT and SHOULD NOT BE CASE SENSITIVE!
  347. set temp [string tolower $channelname]
  348. set temp [mnet:umlauts $temp]
  349. # putlog "mnet: $channelname lowercase: $temp"
  350. return $temp
  351. }
  352. proc mnet:put_local_netmessage {network name chan rec_nickname rec_channel rec_text} {
  353. global mnet_colors mnet_colors_optional mnet_colors_onoff
  354. # validating incoming vars..
  355. set chan [mnet:proper_channelname $chan]
  356. if {$mnet_colors($network) == "none"} {
  357. # if no color id was found...
  358. set color_string ""
  359. } else {
  360. # if there was a color id...
  361. if {$mnet_colors_optional($network) == 1} {
  362. # check for the channel if activated..
  363. if {$mnet_colors_onoff($name,$chan) == 1} {
  364. set color_string "\003$mnet_colors($network)"
  365. set bold_string "\002"
  366. set bold_string_end "\002"
  367. } else {
  368. set color_string ""
  369. set bold_string ""
  370. set bold_string_end ""
  371. }
  372. } else {
  373. # if not optional then force colors.. whatever :)
  374. set color_string "\003$mnet_colors($network)"
  375. set bold_string "\002"
  376. set bold_string_end "\002"
  377. }
  378. }
  379. putserv "PRIVMSG $chan :${bold_string}${name}${bold_string_end} ${color_string}${rec_nickname} - ${rec_channel} : ${rec_text}"
  380. putlog "mnet: + local message from $rec_nickname @ $rec_channel to $chan : $rec_text"
  381. }
  382. proc mnet:put_local_msg {chan text} {
  383. global mnet_colors mnet_freqs_onoff
  384. putserv "PRIVMSG $chan :$text"
  385. putlog "mnet: + normal message: ${chan} => '$text'"
  386. }
  387. proc get_httpfile {host file port} {
  388. global botnet-nick
  389. if {[catch {set sock [socket $host $port] } sockerror]} {
  390. putlog "mnet: error: $sockerror"
  391. return 0
  392. } else {
  393. puts $sock "GET $file HTTP/1.0"
  394. puts $sock "User-Agent: Mozilla/5.0 (compatible; ${botnet-nick}; mnet.tcl)"
  395. puts $sock "Host: $host"
  396. puts $sock "Connection: close"
  397. puts $sock ""
  398. flush $sock
  399. set header_done 0
  400. set data ""
  401. # get some strings out of the http stream.. better write them in a var.. normally.
  402. while {[eof $sock] != 1} {
  403. set bl [gets $sock]
  404. # putlog "test: $bl"
  405. if {[string match "" $bl]} {
  406. set header_done 1
  407. }
  408. if {$header_done == 1} {
  409. set data "$data\n$bl"
  410. }
  411. }
  412. close $sock
  413. return $data
  414. }
  415. }
  416. proc get_localfile {file} {
  417. global botnet-nick
  418. set data ""
  419. if {[file isfile "$file"] == 1} {
  420. set fh [open "$file" "r"]
  421. while {![eof $fh]} {
  422. set line [gets $fh]
  423. append data $line
  424. }
  425. return $data
  426. } else {
  427. putlog "mnet: Local configfile $file not found. Ignoring."
  428. }
  429. }
  430. proc mnet:put_nick {nick msg} {
  431. putserv "NOTICE $nick :$msg"
  432. }
  433. proc mnet:dummy {} {
  434. return 0
  435. }
  436. #not used..
  437. proc mnet:kill_delaytimer {prefix chan} {
  438. global mnet_delay
  439. set mnet_delay($prefix,$chan) 0
  440. putlog "Sending in $chan allowed again, since the timer expired"
  441. }
  442. proc mnet:put_bot {botnetnick data} {
  443. set testlink [islinked $botnetnick]
  444. if {$testlink == 1} {
  445. putlog "mnet: put_bot: + a message delivered to $botnetnick."
  446. putbot $botnetnick $data
  447. } else {
  448. putlog "mnet: put_bot: + a message couldn't be delivered. Bot $botnetnick is not linked"
  449. }
  450. }
  451. proc mnet:chanstat_users {chan users} {
  452. set ch_users [chanlist $chan]
  453. set ch_users_count [llength $ch_users]
  454. set users [expr $users + $ch_users_count]
  455. return $users
  456. }
  457. proc mnet:history_queue {bucket nickname channel rec_text} {
  458. #mnet:history_queue $network,$name "$timestamp $rec_nickname $rec_channel $rec_text"
  459. global mnet_histories mnet_max_history
  460. #putlog "mnet: HISTORY $nickname $channel $rec_text"
  461. set timestamp [clock format [clock seconds] -format "%H:%M:%S"]
  462. #putlog "tstamp: $timestamp"
  463. # no clean:text needed .. already done sometime before.
  464. set input_history "$timestamp / $nickname - $channel : $rec_text"
  465. # putlog "tst: $timestamp nick: $nickname chan: $channel txt: $rec_text"
  466. set list_length 0
  467. if {[info exists mnet_histories($bucket)] == 1} {
  468. set list_length [llength $mnet_histories($bucket)]
  469. putlog "listlength of mnet_histories($bucket) before: $list_length"
  470. }
  471. if {$list_length >= $mnet_max_history} {
  472. # $mnet_max_history 10 - 9
  473. # 5= 1 4
  474. #10= 1 9
  475. # wenn man von 10 auf 5 wechselt: 6 9
  476. set mnet_histories($bucket) [lrange $mnet_histories($bucket) [expr $list_length - $mnet_max_history + 1] [expr $list_length - 1]]
  477. # putlog "grosser oder gleich 10: str: $input"
  478. }
  479. lappend mnet_histories($bucket) $input_history
  480. #set list_length [llength $mnet_histories($bucket)]
  481. #putlog "listlength of mnet_histories($bucket) now: $list_length"
  482. # define your own logging
  483. if {[info procs mnet:history_logger] == "mnet:history_logger"} {
  484. mnet:history_logger $bucket $nickname $channel $rec_text
  485. } else {
  486. putlog "mnet: procedure mnet:history_logger hasn't been defined. Do it, if you want logging."
  487. }
  488. }
  489. ## procs which are executed remotely follow:
  490. proc mnet:receive_message {rec_botnick cmd rec_data} {
  491. global mnet mnet_channels mnet_freqs_onoff mnet_bots \
  492. mnet_histories \
  493. botnet-nick
  494. #putlog "rec_data string: '$rec_data'"
  495. # escape it to be a list FIRST.. and for output later, let the list JOIN together to a string again!
  496. set rec_data [split $rec_data]
  497. #putlog "rec_data list: '$rec_data'"
  498. set tmp_network [join [lindex $rec_data 0]]
  499. set tmp_name [join [lindex $rec_data 1]]
  500. #putlog "tmp_net: '$tmp_network'"
  501. #putlog "tmp_nam: '$tmp_name'"
  502. set network [mnet:kill_spaces $tmp_network]
  503. #putlog "network: '$network'"
  504. set name [mnet:kill_spaces $tmp_name]
  505. #putlog "name: '$name'"
  506. set rec_nickname [mnet:kill_spaces [join [lindex $rec_data 2]]]
  507. #set rec_nickname [mnet:kill_spaces clean_txt [join [lrange [split $rec_data] 4 end]]]
  508. set rec_channel [mnet:kill_spaces [join [lindex $rec_data 3]]]
  509. #set rec_text [mnet:clean_txt [join [lrange [split $rec_data] 4 end]]]
  510. set rec_text [join [lrange $rec_data 4 end]]
  511. #putlog "rec_text: '$rec_text'"
  512. set allowed [mnet:allowed_netbot $network ${rec_botnick}]
  513. if {$allowed == 0} {
  514. return 0
  515. }
  516. # now the bot is declared as a known bot.
  517. set proper_botnick [mnet:proper_botnick ${botnet-nick}]
  518. putlog "mnet: + Relaying Message from: $rec_nickname @ $rec_botnick @ $rec_channel: $rec_text"
  519. set users 0
  520. set count_channels 0
  521. mnet:history_queue $network,$name $rec_nickname $rec_channel $rec_text
  522. foreach {chan} $mnet_channels($network,$proper_botnick) {
  523. if {[mnet:botonchannel $chan] == "1"} {
  524. # erster disable/enable check
  525. if {$mnet_freqs_onoff($name,$chan) == 1} {
  526. incr count_channels
  527. set users [mnet:chanstat_users $chan $users]
  528. putlog "mnet: * Remote counting $chan users: $users"
  529. mnet:put_local_netmessage $network $name $chan $rec_nickname $rec_channel $rec_text
  530. } else {
  531. putlog "mnet: + $chan has disabled $name output"
  532. }
  533. } else {
  534. putlog "mnet: + Can't relay a message to '$chan' since I am not there."
  535. }
  536. }
  537. # ANSWER! SEND!
  538. mnet:put_bot $rec_botnick "mnet_answer $network $name $rec_channel $users $count_channels"
  539. return 0
  540. }
  541. proc mnet:receive_answer {rec_botnick cmd rec_data} {
  542. global mnet mnet_reached_users mnet_reached_chans
  543. # we receive a STRING in rec_data! convert into list!
  544. set rec_data [split $rec_data]
  545. # work with list (lindex, lrange) and put together to a STRING again with JOIN.
  546. set network [join [lindex $rec_data 0]]
  547. set name [join [lindex $rec_data 1]]
  548. set chan [join [lindex $rec_data 2]]
  549. set rec_usercount [join [lindex $rec_data 3]]
  550. set rec_chancount [join [lindex $rec_data 4]]
  551. # set rec_text [lrange $rec_data 2 end]
  552. # get this bots results to our global variable:
  553. # FIXME: make simple userstats more accurate by sending nicknames back..
  554. # done: userstats should be counted in a correct variablename .. according to network and frequency
  555. # if you don't pay attention to it, a conflict between two broadcasts counting users may appear.
  556. # $mnet_reached_chans($name,$chan) <- $mnet_reached_users($name,$chan)
  557. set mnet_reached_users($name,$chan) [expr $mnet_reached_users($name,$chan) + $rec_usercount]
  558. set mnet_reached_chans($name,$chan) [expr $mnet_reached_chans($name,$chan) + $rec_chancount]
  559. putlog "mnet: * $rec_botnick told me he sent its message to $rec_usercount people in $rec_chancount channels for $network frequency $name!"
  560. #putlog "mnet: * Users reached since $name call: $mnet_reached_users($name,$chan) in channels: $mnet_reached_chans($name,$chan)"
  561. }
  562. proc mnet:clean_braces {text} {
  563. regsub -all "{" $text "" text
  564. regsub -all "}" $text "" text
  565. return $text
  566. }
  567. proc mnet:kill_spaces {text} {
  568. regsub -all "\\s+" $text "" text
  569. return $text
  570. }
  571. proc mnet:clean_txt {text} {
  572. # putlog "filter_A: ${text}"
  573. # regsub -all "\\" $text "\\\\" text
  574. # fixes many whitespace between words down to one space between words
  575. regsub -all "\\s+" $text " " text
  576. # filtering out all colorcodes (works well)
  577. regsub -all "\003\[0-9\]\{1,2\},\[0-9\]\{1,2\}" $text "" text
  578. regsub -all "\003\[0-9\]\{1,2\}" $text "" text
  579. regsub -all "\003" $text "" text
  580. # filtering out BOLD text
  581. regsub -all "\002" $text "" text
  582. # underline gets filtered too. (since +c on quakenet would suppress it ...)
  583. regsub -all "\037" $text "" text
  584. # replacing like !!!!!!!!!!!!! with !!!!! (5 letters)
  585. # s/(.?)\1{4,}/\1\1\1\1\1/g;
  586. # - max 5 same chars in a row
  587. regsub -all -nocase -expanded {(.)\1\1\1\1+} $text {\1\1\1\1\1} text
  588. # putlog "test: $text"
  589. set text [string trim $text]
  590. # putlog "filter_B: ${text}"
  591. return $text
  592. }
  593. proc mnet:umlauts {text} {
  594. # A REAL STRANGE BUG WORKAROUND WITH UMLAUTS
  595. regsub -all "Ä" ${text} "Ä" text
  596. regsub -all "Ü" ${text} "Ü" text
  597. regsub -all "Ö" ${text} "Ö" text
  598. regsub -all "ä" ${text} "ä" text
  599. regsub -all "ü" ${text} "ü" text
  600. regsub -all "ö" ${text} "ö" text
  601. return ${text}
  602. }
  603. proc mnet:botonchannel {chan} {
  604. # safe "bot-knows-the-channel-and-is-in-there"-function
  605. if {[validchan $chan] == 1 && [botonchan $chan] == 1} {
  606. return 1
  607. } else {
  608. return 0
  609. }
  610. }
  611. # allowcheck for public commands..
  612. proc mnet:allowed_channel {network name prefix nick mask chan} {
  613. global mnet mnet_channels mnet_bots mnet_freqs mnet_networks_by_prefix mnet_colors \
  614. botnick botnet-nick \
  615. lastbind
  616. # validating incoming vars
  617. set chan [mnet:proper_channelname $chan]
  618. putlog "mnet: = a command for ($prefix) triggered by $nick ($mask) in $chan"
  619. # the command must be from a channel of "ownchannels"
  620. putlog "mnet: = trying if $chan is allowed in network: $network"
  621. set found 0
  622. set proper_botnick [mnet:proper_botnick ${botnet-nick}]
  623. foreach _trigger_chan $mnet_channels($network,$proper_botnick) {
  624. #putlog "mnet: = test: $_trigger_chan vs $chan"
  625. if {[string compare -nocase $_trigger_chan $chan] == 0} {
  626. putlog "mnet: = channel: $_trigger_chan is allowed in network: $network"
  627. set found 1
  628. } else {
  629. # putlog "mnet: = not in list: $chan"
  630. }
  631. }
  632. if {$found == 0} {
  633. putlog "mnet: = triggering $prefix of network $network in $chan is not allowed (in my point of view)"
  634. return 0
  635. }
  636. set snd_nick [mnet:get_data $nick]
  637. if {![isop $nick $chan]} {
  638. putlog "mnet: = allowed in $chan, but $nick is no op"
  639. mnet:put_nick $nick "Sorry $nick, you need to be op."
  640. return 0
  641. }
  642. if {$nick == $botnick} {
  643. # no recursion :)
  644. return 0
  645. }
  646. # got through all checks .. so it's an OK channel
  647. return 1
  648. }
  649. # checks if the user is allowed, returns 1 if OK.
  650. # checks against the xml config of the banned ones.
  651. proc mnet:allowed_user {network name prefix nick mask chan} {
  652. global mnet mnet_channels mnet_bots mnet_bans mnet_networks_by_prefix mnet_colors \
  653. botnick botnet-nick \
  654. lastbind
  655. # validating incoming vars
  656. set chan [mnet:proper_channelname $chan]
  657. # does mnet_bans even exist? it's optional after all.
  658. if {[info exists mnet_bans($network,$prefix)] == 1} {
  659. putlog "mnet: = a command for ($prefix) triggered by $nick ($mask) in $chan"
  660. # the command must be from a channel of "ownchannels"
  661. putlog "mnet: = trying if $nick ($mask) banned from frequency: $network,$prefix"
  662. set found 0
  663. foreach {hostmask reason} $mnet_bans($network,$prefix) {
  664. if {[string match [string tolower $hostmask] [string tolower $mask]]} {
  665. putlog "mnet: = allowed_user: $nick ($mask) is not allowed in network ($network) by hostmask ($hostmask) for reason: $reason"
  666. set found 1
  667. } else {
  668. # putlog "mnet: = not in list: $chan"
  669. }
  670. }
  671. if {$found == 1} {
  672. # tell the user his ban. :)
  673. mnet:put_nick $nick "mnet: Not allowed to send messages. Reason: $reason"
  674. return 0
  675. }
  676. }
  677. # got through all checks .. so user is not in banlist
  678. return 1
  679. }
  680. # allowcheck for bots sending netmessages
  681. proc mnet:allowed_netbot {network netbot} {
  682. global mnet mnet_bots \
  683. botnick botnet-nick \
  684. lastbind
  685. putlog "mnet: = a netbot $netbot sending message... allowed?"
  686. # the command must be from a channel of "ownchannels"
  687. set found 0
  688. set proper_botnick [mnet:proper_botnick ${botnet-nick}]
  689. set proper_netbot [mnet:proper_botnick $netbot]
  690. foreach {_netbotnick} $mnet_bots($network) {
  691. if {$_netbotnick == $proper_netbot} {
  692. putlog "mnet: = netbot: $proper_netbot is allowed in network: $network"
  693. set found 1
  694. } else {
  695. # putlog "mnet: = netbot: ...."
  696. }
  697. }
  698. if {$found == 0} {
  699. putlog "mnet: = $proper_netbot of network $network sent me something - but it is not allowed in my network: $network"
  700. return 0
  701. }
  702. if {$netbot == ${botnet-nick}} {
  703. # if myself (for some reason) then don't do anything... no recursion :)
  704. return 0
  705. }
  706. # got through all checks .. so it's an OK netbot for a given network
  707. return 1
  708. }
  709. proc mnet:reply_timeout {name chan} {
  710. global mnet mnet_reached_users mnet_reached_chans
  711. # clean $name and $chan
  712. set name [mnet:kill_spaces $name]
  713. set chan [mnet:kill_spaces $chan]
  714. # easify variables
  715. set users $mnet_reached_users($name,$chan)
  716. set chans $mnet_reached_chans($name,$chan)
  717. #putlog "mnet: HIER $name UND $chan"
  718. # inzwischen drfte auch die antwort gekommen sein.. also jetzt mnet_reached_* auswerten nach timeout..
  719. # make stats channel-dependent
  720. putlog "mnet: * After ALL: Count_Users: $mnet_reached_users($name,$chan) Count_Channels: $mnet_reached_chans($name,$chan)"
  721. # Give me some reply.
  722. mnet:put_local_msg ${chan} "mnet: Message sent to $users users in $chans channels."
  723. }
  724. ### public reachable commands
  725. proc mnet:history_frequency {nick mask hand chan text} {
  726. # proc triggered by specified $prefix_history
  727. global mnet mnet_channels mnet_bots mnet_networks_by_prefix mnet_colors \
  728. mnet_freqs mnet_freqs_onoff \
  729. mnet_histories mnet_max_history \
  730. botnick lastbind
  731. set com $lastbind
  732. # validating incoming vars
  733. set chan [mnet:proper_channelname $chan]
  734. # cutting .prefix_history down to .prefix
  735. set prefix [string range $com 0 [expr [string first _ $com] -1]]
  736. #putlog "mnet: the prefix is $prefix"
  737. set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
  738. set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
  739. set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
  740. set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
  741. putlog "network: $network"
  742. set allowed [mnet:allowed_channel $network $name $prefix $nick $mask $chan]
  743. if {$allowed == 0} {
  744. return 0
  745. }
  746. # now generally allowed.
  747. putlog "mnet_history: $com triggered by $nick in $chan"
  748. if {[info exists mnet_histories($network,$name)] == 1} {
  749. set list_length [llength $mnet_histories($network,$name)]
  750. if {$list_length >= 1} {
  751. set msg "mnet: last $mnet_max_history messages of $network $name:"
  752. mnet:put_nick $nick $msg
  753. set x_count 0
  754. foreach {msg} $mnet_histories($network,$name) {
  755. incr x_count
  756. set backwards_x [expr $list_length - $x_count]
  757. set msg [lindex $mnet_histories($network,$name) $backwards_x]
  758. mnet:put_nick $nick "($x_count/$list_length) $msg"
  759. }
  760. }
  761. } else {
  762. mnet:put_nick $nick "mnet: no accumulated history for $network $name"
  763. }
  764. }
  765. proc mnet:enable_frequency {nick mask hand chan text} {
  766. # proc triggered by specified $prefix_enable
  767. global mnet mnet_channels mnet_bots mnet_networks_by_prefix mnet_colors \
  768. mnet_freqs mnet_freqs_onoff \
  769. botnick lastbind
  770. set com $lastbind
  771. # validating incoming vars
  772. set chan [mnet:proper_channelname $chan]
  773. # cutting .prefix_enable down to .prefix
  774. set prefix [string range $com 0 [expr [string first _ $com] -1]]
  775. #putlog "mnet: the prefix is $prefix"
  776. set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
  777. set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
  778. set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
  779. set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
  780. #putlog "network: $network"
  781. set allowed [mnet:allowed_channel $network $name $prefix $nick $mask $chan]
  782. if {$allowed == 0} {
  783. return 0
  784. }
  785. # now generally allowed.
  786. putlog "mnet_freq_status: before $mnet_freqs_onoff($name,$chan)"
  787. set mnet_freqs_onoff($name,$chan) 1
  788. putlog "mnet_freq_status: now $mnet_freqs_onoff($name,$chan)"
  789. mnet:put_local_msg $chan "mnet: $name _output_ enabled for $chan"
  790. }
  791. proc mnet:disable_frequency {nick mask hand chan text} {
  792. # proc triggered by specified $prefix_enable
  793. global mnet mnet_channels mnet_bots mnet_networks_by_prefix mnet_colors \
  794. mnet_freqs mnet_freqs_onoff \
  795. botnick lastbind
  796. set com $lastbind
  797. # validating incoming vars
  798. set chan [mnet:proper_channelname $chan]
  799. # cutting .prefix_enable down to .prefix
  800. set prefix [string range $com 0 [expr [string first _ $com] -1]]
  801. putlog "mnet: the prefix is $prefix"
  802. set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
  803. set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
  804. set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
  805. set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
  806. #putlog "network: $network"
  807. set allowed [mnet:allowed_channel $network $name $prefix $nick $mask $chan]
  808. if {$allowed == 0} {
  809. return 0
  810. }
  811. # now generally allowed.
  812. putlog "mnet_freq_status: before $mnet_freqs_onoff($name,$chan)"
  813. set mnet_freqs_onoff($name,$chan) 0
  814. putlog "mnet_freq_status: now $mnet_freqs_onoff($name,$chan)"
  815. mnet:put_local_msg $chan "mnet: $name _output_ disabled for $chan"
  816. }
  817. proc mnet:toggle_frequency {nick mask hand chan text} {
  818. # proc triggered by specified $prefix_toggle
  819. global mnet mnet_channels mnet_bots mnet_networks_by_prefix \
  820. mnet_colors \
  821. mnet_freqs mnet_freqs_onoff \
  822. botnick lastbind
  823. set com $lastbind
  824. # validating incoming vars
  825. set chan [mnet:proper_channelname $chan]
  826. # cutting .prefix_enable down to .prefix
  827. set prefix [string range $com 0 [expr [string first _ $com] -1]]
  828. # putlog "mnet: the prefix is $prefix"
  829. set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
  830. set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
  831. set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
  832. set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
  833. # putlog "network: $network"
  834. set allowed [mnet:allowed_channel $network $name $prefix $nick $mask $chan]
  835. if {$allowed == 0} {
  836. return 0
  837. }
  838. # now generally allowed.
  839. putlog "mnet_freq_status: toggle $mnet_freqs_onoff($name,$chan)"
  840. if {$mnet_freqs_onoff($name,$chan) == 1} {
  841. set mnet_freqs_onoff($name,$chan) 0
  842. mnet:put_local_msg $chan "mnet: toggling ${name} _output_, now disabled for ${chan}"
  843. } else {
  844. set mnet_freqs_onoff($name,$chan) 1
  845. mnet:put_local_msg $chan "mnet: toggling ${name} _output_, now enabled for ${chan}"
  846. }
  847. putlog "mnet_freq_status: toggle now $mnet_freqs_onoff($name,$chan)"
  848. # frequency toggled .. :)
  849. }
  850. #mnet:enable_color
  851. proc mnet:enable_color {nick mask hand chan text} {
  852. # proc triggered by specified $prefix_enable
  853. global mnet mnet_channels mnet_bots mnet_networks_by_prefix \
  854. mnet_colors_optional mnet_colors_onoff \
  855. botnick lastbind
  856. set com $lastbind
  857. # validating incoming vars
  858. set chan [mnet:proper_channelname $chan]
  859. # cutting .prefix_enable down to .prefix
  860. set prefix [string range $com 0 [expr [string first _ $com] -1]]
  861. #putlog "mnet: the prefix is $prefix"
  862. set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
  863. set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
  864. set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
  865. set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
  866. #putlog "network: $network"
  867. set allowed [mnet:allowed_channel $network $name $prefix $nick $mask $chan]
  868. if {$allowed == 0} {
  869. return 0
  870. }
  871. # now generally allowed.
  872. if {$mnet_colors_optional($network) != 1} {
  873. return 0
  874. }
  875. putlog "mnet_color_status: before $mnet_colors_onoff($name,$chan)"
  876. set mnet_colors_onoff($name,$chan) 1
  877. putlog "mnet_color_status: now $mnet_colors_onoff($name,$chan)"
  878. mnet:put_local_msg $chan "mnet: $name _coloroutput_ enabled for $chan"
  879. }
  880. #mnet:disable_color
  881. proc mnet:disable_color {nick mask hand chan text} {
  882. # proc triggered by specified $prefix_enable
  883. global mnet mnet_channels mnet_bots mnet_networks_by_prefix \
  884. mnet_colors_optional mnet_colors_onoff \
  885. botnick lastbind
  886. set com $lastbind
  887. # validating incoming vars
  888. set chan [mnet:proper_channelname $chan]
  889. # cutting .prefix_enable down to .prefix
  890. set prefix [string range $com 0 [expr [string first _ $com] -1]]
  891. #putlog "mnet: the prefix is $prefix"
  892. set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
  893. set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
  894. set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
  895. set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
  896. #putlog "network: $network"
  897. set allowed [mnet:allowed_channel $network $name $prefix $nick $mask $chan]
  898. if {$allowed == 0} {
  899. return 0
  900. }
  901. # now generally allowed.
  902. if {$mnet_colors_optional($network) != 1} {
  903. return 0
  904. }
  905. putlog "mnet_color_status: before $mnet_colors_onoff($name,$chan)"
  906. set mnet_colors_onoff($name,$chan) 0
  907. putlog "mnet_color_status: now $mnet_colors_onoff($name,$chan)"
  908. mnet:put_local_msg $chan "mnet: $name _coloroutput_ disabled for $chan"
  909. }
  910. #mnet:toggle_color
  911. proc mnet:toggle_color {nick mask hand chan text} {
  912. # proc triggered by specified $prefix_toggle
  913. global mnet mnet_channels mnet_bots mnet_networks_by_prefix \
  914. mnet_colors_optional mnet_colors_onoff \
  915. botnick lastbind
  916. set com $lastbind
  917. # validating incoming vars
  918. set chan [mnet:proper_channelname $chan]
  919. # cutting .prefix_enable down to .prefix
  920. set prefix [string range $com 0 [expr [string first _ $com] -1]]
  921. # putlog "mnet: the prefix is $prefix"
  922. set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
  923. set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
  924. set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
  925. set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
  926. # putlog "network: $network"
  927. set allowed [mnet:allowed_channel $network $name $prefix $nick $mask $chan]
  928. if {$allowed == 0} {
  929. return 0
  930. }
  931. # now generally allowed.
  932. if {$mnet_colors_optional($network) != 1} {
  933. return 0
  934. }
  935. putlog "mnet_color_status: toggle $mnet_colors_onoff($name,$chan)"
  936. if {$mnet_colors_onoff($name,$chan) == 1} {
  937. set mnet_colors_onoff($name,$chan) 0
  938. mnet:put_local_msg $chan "mnet: toggling ${name} _coloroutput_, now disabled for ${chan}"
  939. } else {
  940. set mnet_colors_onoff($name,$chan) 1
  941. mnet:put_local_msg $chan "mnet: toggling ${name} _coloroutput_, now enabled for ${chan}"
  942. }
  943. putlog "mnet_color_status: toggle now $mnet_colors_onoff($name,$chan)"
  944. # color for a channel toggled .. :)
  945. }
  946. #mnet:toggle_color
  947. proc mnet:status_frequency {nick mask hand chan text} {
  948. # proc triggered by specified $prefix_toggle
  949. global mnet mnet_channels mnet_bots mnet_networks_by_prefix \
  950. mnet_colors_optional mnet_colors_onoff \
  951. mnet_freqs_onoff \
  952. mnet_reached_users mnet_reached_chans \
  953. botnick lastbind
  954. set com $lastbind
  955. # validating incoming vars
  956. set chan [mnet:proper_channelname $chan]
  957. # cutting .prefix_enable down to .prefix
  958. set prefix [string range $com 0 [expr [string first _ $com] -1]]
  959. # putlog "mnet: the prefix is $prefix"
  960. set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
  961. set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
  962. set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
  963. set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
  964. # putlog "network: $network"
  965. set allowed [mnet:allowed_channel $network $name $prefix $nick $mask $chan]
  966. if {$allowed == 0} {
  967. return 0
  968. }
  969. # now generally allowed.
  970. ## get status for this frequency.
  971. set status_message "$chan $name: "
  972. if {$mnet_freqs_onoff($name,$chan) == 1} {
  973. append status_message "frequency output is on. "
  974. } else {
  975. append status_message "frequency output is off. "
  976. }
  977. if {$mnet_colors_optional($network) == 1} {
  978. if {$mnet_colors_onoff($name,$chan) == 1} {
  979. append status_message "colors are turned on. "
  980. } else {
  981. append status_message "colors are turned off. "
  982. }
  983. } else {
  984. append status_message "message-colors are forced. "
  985. }
  986. if {[info exists mnet_reached_users($name,$chan)]} {
  987. if {[info exists mnet_reached_chans($name,$chan)]} {
  988. append status_message "Your last message reached about $mnet_reached_users($name,$chan) users and $mnet_reached_chans($name,$chan) channels. "
  989. }
  990. }
  991. mnet:put_local_msg $chan "$status_message"
  992. }
  993. # checks timers of channels ... if not found, then ok with "0" secs left.. if found then return $secsleft
  994. proc mnet:check_spam_protection {prefix chan} {
  995. global mnet_delay
  996. # validating incoming vars
  997. set chan [mnet:proper_channelname $chan]
  998. # check for pending timers.. spam-protection
  999. set timerlist [utimers]
  1000. set secondsLeft 0
  1001. if {![info exists mnet_delay($prefix,$chan)]} {
  1002. set mnet_delay($prefix,$chan) 0
  1003. } else {
  1004. foreach {timerinfo} $timerlist {
  1005. set secsleft [join [lindex $timerinfo 0]]
  1006. set timer_id [join [lindex $timerinfo 2]]
  1007. # putlog "sec: $secsleft tid: $timer_id"
  1008. # putlog "checking timer ($timer_id) against mdelay-id: $mnet_delay($prefix,$chan)"
  1009. if {$timer_id == $mnet_delay($prefix,$chan)} {
  1010. return $secsleft
  1011. }
  1012. }
  1013. }
  1014. return 0
  1015. }
  1016. proc mnet:messaging_public {nick mask hand chan text} {
  1017. # proc triggered by specified $prefix and calling the following (internal) one
  1018. global mnet mnet_channels mnet_bots mnet_networks_by_prefix mnet_colors \
  1019. mnet_freqs mnet_freqs_onoff mnet_delay \
  1020. mnet_histories \
  1021. mnet_reached_users mnet_reached_chans \
  1022. botnet-nick lastbind
  1023. # validating incoming vars
  1024. set chan [mnet:proper_channelname $chan]
  1025. set prefix $lastbind
  1026. # $mnet_networks_by_prefix($prefix) is already a list! Don't split it! But work with lindex and lrange on it! later: JOIN it to a string.
  1027. set my_network_entry $mnet_networks_by_prefix($prefix)
  1028. set network [join [lindex $my_network_entry 0]]
  1029. set name [join [lindex $my_network_entry 1]]
  1030. set help [join [lindex $my_network_entry 2]]
  1031. set desc [join [lindex $my_network_entry 3]]
  1032. set delay [join [lindex $my_network_entry 4]]
  1033. set allowed [mnet:allowed_channel $network $name $prefix $nick $mask $chan]
  1034. if {$allowed == 0} {
  1035. return 0
  1036. }
  1037. # now generally allowed.
  1038. # is user banned from sending??
  1039. set user_allowed [mnet:allowed_user $network $name $prefix $nick $mask $chan]
  1040. if {$user_allowed == 0} {
  1041. return 0
  1042. }
  1043. # user has not been matched against banlist. So he's allowed here.
  1044. # cleaning given strings...
  1045. set text [mnet:clean_txt $text]
  1046. # check here if we have some text or not.. :)
  1047. if {$text == "" || $text == "{}"} {
  1048. # output some help:
  1049. putlog "mnet: = gave him some help"
  1050. mnet:put_local_msg $chan $help
  1051. } else {
  1052. # ok, now send! (if timer allows it)
  1053. ### spamprotection
  1054. # returns the seconds that are left for this channel .. or 0 if no seconds left.
  1055. set secsleft [mnet:check_spam_protection $prefix $chan]
  1056. if {$secsleft > 0} {
  1057. putlog "mnet: The timer of $prefix for $chan is still running. The guy has to wait ($secsleft/$delay) more seconds. I tell him."
  1058. mnet:put_nick $nick "Sorry $nick, usage of $prefix only every $delay seconds. $secsleft seconds for $chan remaining."
  1059. # now BREAK "messaging_public".
  1060. # NO break.. for debug :)) arf
  1061. return 0
  1062. }
  1063. # if we went through the timer check ... so it doesn't exist anymore then we set a new one:
  1064. # set a timer-id to check for again, if it's allowed or not .. delay
  1065. set mnet_delay($prefix,$chan) [utimer $delay mnet:dummy]
  1066. ### end spamprotection
  1067. ## HE IS SENDING NOW!
  1068. set mnet(reached) "0"
  1069. set mnet(reached_channels) "0"
  1070. # reset stats .. because he is just freshly sending
  1071. set mnet_reached_users($name,$chan) "0"
  1072. set mnet_reached_chans($name,$chan) "0"
  1073. mnet:history_queue $network,$name $nick $chan $text
  1074. # send them first, we await a reply!
  1075. set proper_botnick [mnet:proper_botnick ${botnet-nick}]
  1076. # putlog "{botnet-nick} huar: $proper_botnick"
  1077. # single sends TO ALL REMOTE BOTS with their remote CHANNELS...
  1078. # let's see which mode for sending is used...
  1079. foreach _botnick $mnet_bots($network) {
  1080. if {$_botnick == $proper_botnick} {
  1081. } else { # if not myself!
  1082. putlog "mnet: send: + I am about to send a message to $_botnick for $network: $name: $text"
  1083. # safe put_bot function..
  1084. mnet:put_bot $_botnick "mnet_receive $network $name $nick $chan $text"
  1085. }
  1086. }
  1087. # SEND TO ALL OWN CHANNELS...
  1088. # send to all own channels, except to the channel the message originating from:
  1089. foreach _ownchan $mnet_channels($network,$proper_botnick) {
  1090. if {$_ownchan == $chan} {
  1091. } else { # if not own channel!
  1092. if {[mnet:botonchannel $_ownchan] == "1"} {
  1093. putlog "mnet: = i am on $_ownchan"
  1094. # second enable/disable check
  1095. if {$mnet_freqs_onoff($name,$_ownchan) == 1} {
  1096. # userstats local
  1097. # set mnet(reached) [mnet:chanstat_users $_ownchan $mnet(reached)]
  1098. set mnet_reached_users($name,$chan) [mnet:chanstat_users $_ownchan $mnet_reached_users($name,$chan)]
  1099. putlog "mnet: * Localcounting up $_ownchan users: $mnet_reached_users($name,$chan)"
  1100. # channel count local
  1101. incr mnet_reached_chans($name,$chan)
  1102. mnet:put_local_netmessage $network $name $_ownchan $nick $chan $text
  1103. } else {
  1104. putlog "mnet: + $_ownchan has disabled $name output"
  1105. }
  1106. } else {
  1107. putlog "mnet: + Can't send a local message to '$_ownchan' since I am not there."
  1108. }
  1109. }
  1110. }
  1111. # wait here some more! (10 seconds with utimer)
  1112. utimer 5 "mnet:reply_timeout $name $chan"
  1113. # notice: better would be to go into the "reply" when all known bots already answered..
  1114. # then, if a bot is missing, but it was a known bot, just use a timeout with about 5-10 seconds..
  1115. # if the bot still didn't answer, then just go into "reply".
  1116. }
  1117. }
  1118. ### END public reachable commands
  1119. proc mnet:binds {} {
  1120. global currentNetworkDesc currentNetworkSig \
  1121. startNetworkInstance \
  1122. currentBot currentOwner \
  1123. startBotInstance \
  1124. mnet_networks mnet_freqs mnet_networks_by_prefix mnet_channels \
  1125. mnet_freqs_onoff mnet_colors_onoff \
  1126. botnet-nick
  1127. set proper_botnick [mnet:proper_botnick ${botnet-nick}]
  1128. # binding of irc commands ... only works well if a config was loaded..
  1129. foreach {network desc} $mnet_networks {
  1130. # putlog "test: network is $network"
  1131. # putlog "test: networkdesc is $desc"
  1132. foreach {network name prefix help desc msgdelay} $mnet_freqs($network) {
  1133. putlog "network: $network"
  1134. putlog "name: $name"
  1135. putlog "prefix: $prefix"
  1136. putlog "help: $help"
  1137. putlog "desc: $desc"
  1138. putlog "msgdelay: $msgdelay"
  1139. set mnet_networks_by_prefix($prefix) "{$network} {$name} {$help} {$desc} {$msgdelay}"
  1140. # setting variables on init.
  1141. foreach {channel} $mnet_channels($network,$proper_botnick) {
  1142. # catch like php isset() - but catch returns 0 if OK!
  1143. set channel [mnet:proper_channelname $channel]
  1144. if {[catch {set mnet_freqs_onoff($name,$channel)}] == 1} {
  1145. set mnet_freqs_onoff($name,$channel) 1
  1146. putlog "mnet: initially enabling $name for channel: $channel"
  1147. } else {
  1148. putlog "mnet: $name for $channel is already on output: $mnet_freqs_onoff($name,$channel)"
  1149. }
  1150. # catch like php isset() - but catch returns 0 if OK!
  1151. if {[catch {set mnet_colors_onoff($name,$channel)}] == 1} {
  1152. set mnet_colors_onoff($name,$channel) 0
  1153. putlog "mnet: initially disabling colors for $name for channel (if not forced): $channel"
  1154. } else {
  1155. putlog "mnet: coloroutput of $name for $channel is already on (if not forced): $mnet_colors_onoff($name,$channel)"
  1156. }
  1157. }
  1158. bind pub - ${prefix} mnet:messaging_public
  1159. # $network $name $prefix $help $desc
  1160. bind pub - ${prefix}_enable mnet:enable_frequency
  1161. bind pub - ${prefix}_disable mnet:disable_frequency
  1162. bind pub - ${prefix}_toggle mnet:toggle_frequency
  1163. bind pub - ${prefix}_enable_colors mnet:enable_color
  1164. bind pub - ${prefix}_disable_colors mnet:disable_color
  1165. bind pub - ${prefix}_toggle_colors mnet:toggle_color
  1166. # with typos..
  1167. bind pub - ${prefix}_enable_color mnet:enable_color
  1168. bind pub - ${prefix}_disable_color mnet:disable_color
  1169. bind pub - ${prefix}_toggle_color mnet:toggle_color
  1170. bind pub - ${prefix}_history mnet:history_frequency
  1171. bind pub - ${prefix}_status mnet:status_frequency
  1172. bind pub - .mnet_status mnet:dummy
  1173. # FIXME: make some more commands available to have control over the messages
  1174. # - "_stats"?
  1175. }
  1176. }
  1177. }
  1178. bind bot - mnet_receive mnet:receive_message
  1179. bind bot - mnet_answer mnet:receive_answer
  1180. bind dcc m mnet_reload mnet:dcc_configload
  1181. proc mnet:conf_parsing {} {
  1182. global mnet_config mnet_num_configs p
  1183. for {set y 1} {$y <= $mnet_num_configs} {incr y} {
  1184. set configfile $mnet_config($y)
  1185. # putlog "HRM?: $configfile"
  1186. $p parse "$configfile"
  1187. }
  1188. }
  1189. proc mnet:dcc_configload {dummy1 dummy2 dummy3} {
  1190. # wrapper command for mnet:netconfigload
  1191. putlog "mnet: = reloading configs..."
  1192. mnet:clean_netconfig
  1193. mnet:netconfigload
  1194. }
  1195. proc mnet:netconfigload {} {
  1196. global mnet_http_config mnet_local_config mnet_config mnet_num_configs
  1197. # possible methods to load a config are: get_httpfile and get_localfile
  1198. # get_httpfile
  1199. # get_localfile RELATIVE_PATH_AND_FILE
  1200. set x 0
  1201. if {[info exists mnet_http_config]} {
  1202. foreach {host httpfile port} $mnet_http_config {
  1203. # FIXME config validating.. is the file received correctly? or do
  1204. # we only have a 404 error message there? ... bad thing still.
  1205. incr x
  1206. set mnet_config($x) [get_httpfile $host $httpfile $port]
  1207. }
  1208. }
  1209. if {[info exists mnet_local_config]} {
  1210. foreach {localfile} $mnet_local_config {
  1211. # FIXME config validating.. could we open the file?
  1212. # is the file a correct config?
  1213. incr x
  1214. set mnet_config($x) [get_localfile $localfile]
  1215. }
  1216. }
  1217. # $x is now at its highest count.
  1218. set mnet_num_configs $x
  1219. if {$x > 0} {
  1220. utimer 5 mnet:conf_parsing
  1221. utimer 10 mnet:binds
  1222. } else {
  1223. putlog "mnet: no configurations loaded."
  1224. }
  1225. }
  1226. # looping this one
  1227. proc mnet:interval_conf {} {
  1228. global mnet_cfg_reload_interval mnet_configtimer_set mnet_netconfig_timer
  1229. # putlog "mnet: interval conf! $mnet_configtimer_set huh?"
  1230. if {$mnet_configtimer_set == 1} {
  1231. putlog "mnet: starting intervalled configload ($mnet_cfg_reload_interval minutes)"
  1232. mnet:clean_netconfig
  1233. mnet:netconfigload
  1234. set mnet_netconfig_timer [timer $mnet_cfg_reload_interval mnet:interval_conf]
  1235. } else {
  1236. putlog "mnet: was about to make a automatic configload again, but it has been disabled recently."
  1237. }
  1238. }
  1239. ############# CONFIG SECTION ##############
  1240. ### the real config section is supposed to be here...
  1241. if {[info exists configs_file]} {
  1242. if {[file isfile "$configs_file"] == 1} {
  1243. source $configs_file
  1244. putlog "mnet: configs file '$configs_file' loaded."
  1245. }
  1246. }
  1247. ############# CONFIG SHOULD NOW BE LOADED ONTO THE VARIABLES ##############
  1248. # pls hands away again: starting up just defined configs ...
  1249. putlog "mnet: = Messaging Network ($mnet(version)) loaded"
  1250. putlog "mnet: = as master, reload current net-configs with .mnet_reload"
  1251. putlog "mnet: = do .rehash and .mnet_reload if you defined a new net-config."
  1252. if {$mnet_cfg_reload_interval >= 90} {
  1253. if {![info exists mnet_netconfig_timer]} {
  1254. set mnet_configtimer_set 1
  1255. mnet:interval_conf
  1256. # this one loops
  1257. }
  1258. } else {
  1259. if {[info exists mnet_netconfig_timer]} {
  1260. set mnet_configtimer_set 0
  1261. killtimer $mnet_netconfig_timer
  1262. unset mnet_netconfig_timer
  1263. }
  1264. set mnet_cfg_reload_interval 0
  1265. mnet:clean_netconfig
  1266. mnet:netconfigload
  1267. }