cims.tcl 48 KB

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