cims.tcl 50 KB

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