cims.tcl 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  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) "cims!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. set data ""
  454. if {[file isfile "$file"] == 1} {
  455. set fh [open "$file" "r"]
  456. while {![eof $fh]} {
  457. set line [gets $fh]
  458. append data $line
  459. }
  460. return $data
  461. } else {
  462. putlog "::cims:: Local configfile $file not found. Ignoring."
  463. }
  464. }
  465. #::cims::write_arraytofile "scripts/cims/$botnick.cims" "mnet_freqs_onoff"
  466. proc ::cims::write_arraytofile {file arrayname} {
  467. variable $arrayname
  468. set array_string [array get $arrayname]
  469. #putlog "array_string: $array_string"
  470. set fh [open "$file" "w"]
  471. puts $fh $array_string
  472. close $fh
  473. }
  474. #::cims::read_arrayfromfile "scripts/cims/$botnick.cims" "mnet_freqs_onoff"
  475. proc ::cims::read_arrayfromfile {file arrayname} {
  476. variable $arrayname
  477. set fh [open "$file" "r"]
  478. array set $arrayname [gets $fh]
  479. close $fh
  480. }
  481. proc ::cims::dummy {} {
  482. return 0
  483. }
  484. #not used..
  485. proc ::cims::kill_delaytimer {prefix chan} {
  486. variable mnet_delay
  487. set mnet_delay($prefix,$chan) 0
  488. putlog "Sending in $chan allowed again, since the timer expired"
  489. }
  490. proc ::cims::put_bot {botnetnick data} {
  491. set testlink [islinked $botnetnick]
  492. if {$testlink == 1} {
  493. putlog "::cims:: put_bot: + a message delivered to $botnetnick."
  494. putbot $botnetnick $data
  495. } else {
  496. putlog "::cims:: put_bot: + a message couldn't be delivered. Bot $botnetnick is not linked"
  497. }
  498. }
  499. proc ::cims::chanstat_users {chan users} {
  500. set ch_users [chanlist $chan]
  501. set ch_users_count [llength $ch_users]
  502. set users [expr $users + $ch_users_count]
  503. return $users
  504. }
  505. proc ::cims::history_queue {bucket nickname channel rec_text} {
  506. #::cims::history_queue $network,$name "$timestamp $rec_nickname $rec_channel $rec_text"
  507. variable mnet_histories
  508. variable mnet_max_history
  509. #putlog "::cims:: HISTORY $nickname $channel $rec_text"
  510. set timestamp [clock format [clock seconds] -format "%H:%M:%S"]
  511. #putlog "tstamp: $timestamp"
  512. # no clean:text needed .. already done sometime before.
  513. set input_history "$timestamp / $nickname - $channel : $rec_text"
  514. # putlog "tst: $timestamp nick: $nickname chan: $channel txt: $rec_text"
  515. set list_length 0
  516. if {[info exists mnet_histories($bucket)] == 1} {
  517. set list_length [llength $mnet_histories($bucket)]
  518. putlog "listlength of mnet_histories($bucket) before: $list_length"
  519. }
  520. if {$list_length >= $mnet_max_history} {
  521. # $mnet_max_history 10 - 9
  522. # 5= 1 4
  523. #10= 1 9
  524. # wenn man von 10 auf 5 wechselt: 6 9
  525. set mnet_histories($bucket) [lrange $mnet_histories($bucket) [expr $list_length - $mnet_max_history + 1] [expr $list_length - 1]]
  526. # putlog "grosser oder gleich 10: str: $input"
  527. }
  528. lappend mnet_histories($bucket) $input_history
  529. #set list_length [llength $mnet_histories($bucket)]
  530. #putlog "listlength of mnet_histories($bucket) now: $list_length"
  531. # define your own logging
  532. if {[info procs ::cims::history_logger] == "::cims::history_logger"} {
  533. ::cims::history_logger $bucket $nickname $channel $rec_text
  534. } else {
  535. putlog "::cims:: procedure ::cims::history_logger hasn't been defined. Do it, if you want logging."
  536. }
  537. }
  538. ## procs which are executed remotely follow:
  539. proc ::cims::receive_message {rec_botnick cmd rec_data} {
  540. variable mnet
  541. variable mnet_channels
  542. variable mnet_freqs_onoff
  543. variable mnet_bots
  544. variable mnet_histories
  545. global botnet-nick
  546. #putlog "rec_data string: '$rec_data'"
  547. # escape it to be a list FIRST.. and for output later, let the list JOIN together to a string again!
  548. set rec_data [split $rec_data]
  549. #putlog "rec_data list: '$rec_data'"
  550. set tmp_network [join [lindex $rec_data 0]]
  551. set tmp_name [join [lindex $rec_data 1]]
  552. #putlog "tmp_net: '$tmp_network'"
  553. #putlog "tmp_nam: '$tmp_name'"
  554. set network [::putils::kill_spaces $tmp_network]
  555. #putlog "network: '$network'"
  556. set name [::putils::kill_spaces $tmp_name]
  557. #putlog "name: '$name'"
  558. set rec_nickname [::putils::kill_spaces [join [lindex $rec_data 2]]]
  559. #set rec_nickname [::putils::kill_spaces clean_txt [join [lrange [split $rec_data] 4 end]]]
  560. set rec_channel [::putils::kill_spaces [join [lindex $rec_data 3]]]
  561. #set rec_text [::cims::clean_txt [join [lrange [split $rec_data] 4 end]]]
  562. set rec_text [join [lrange $rec_data 4 end]]
  563. #putlog "rec_text: '$rec_text'"
  564. set allowed [::cims::allowed_netbot $network ${rec_botnick}]
  565. if {$allowed == 0} {
  566. return 0
  567. }
  568. # now the bot is declared as a known bot.
  569. set proper_botnick [::cims::proper_botnick ${botnet-nick}]
  570. putlog "::cims:: + Relaying Message from: $rec_nickname @ $rec_botnick @ $rec_channel: $rec_text"
  571. set users 0
  572. set count_channels 0
  573. ::cims::history_queue $network,$name $rec_nickname $rec_channel $rec_text
  574. foreach {chan} $mnet_channels($network,$proper_botnick) {
  575. if {[::cims::botonchannel $chan] == "1"} {
  576. # erster disable/enable check
  577. if {$mnet_freqs_onoff($name,$chan) == 1} {
  578. incr count_channels
  579. set users [::cims::chanstat_users $chan $users]
  580. putlog "::cims:: * Remote counting $chan users: $users"
  581. ::cims::put_local_netmessage $network $name $chan $rec_nickname $rec_channel $rec_text
  582. } else {
  583. putlog "::cims:: + $chan has disabled $name output"
  584. }
  585. } else {
  586. putlog "::cims:: + Can't relay a message to '$chan' since I am not there."
  587. }
  588. }
  589. # ANSWER! SEND!
  590. ::cims::put_bot $rec_botnick "mnet_answer $network $name $rec_channel $users $count_channels"
  591. return 0
  592. }
  593. proc ::cims::receive_answer {rec_botnick cmd rec_data} {
  594. variable mnet
  595. variable mnet_reached_users
  596. variable mnet_reached_chans
  597. # we receive a STRING in rec_data! convert into list!
  598. set rec_data [split $rec_data]
  599. # work with list (lindex, lrange) and put together to a STRING again with JOIN.
  600. set network [join [lindex $rec_data 0]]
  601. set name [join [lindex $rec_data 1]]
  602. set chan [join [lindex $rec_data 2]]
  603. set rec_usercount [join [lindex $rec_data 3]]
  604. set rec_chancount [join [lindex $rec_data 4]]
  605. # set rec_text [lrange $rec_data 2 end]
  606. # get this bots results to our namespaced variable:
  607. # FIXME: make simple userstats more accurate by sending nicknames back..
  608. # done: userstats should be counted in a correct variablename .. according to network and frequency
  609. # if you don't pay attention to it, a conflict between two broadcasts counting users may appear.
  610. # $mnet_reached_chans($name,$chan) <- $mnet_reached_users($name,$chan)
  611. set mnet_reached_users($name,$chan) [expr $mnet_reached_users($name,$chan) + $rec_usercount]
  612. set mnet_reached_chans($name,$chan) [expr $mnet_reached_chans($name,$chan) + $rec_chancount]
  613. putlog "::cims:: * $rec_botnick told me he sent its message to $rec_usercount people in $rec_chancount channels for $network frequency $name!"
  614. #putlog "::cims:: * Users reached since $name call: $mnet_reached_users($name,$chan) in channels: $mnet_reached_chans($name,$chan)"
  615. }
  616. proc ::cims::clean_txt {text} {
  617. # putlog "filter_A: ${text}"
  618. # regsub -all "\\" $text "\\\\" text
  619. # fixes many whitespace between words down to one space between words
  620. regsub -all "\\s+" $text " " text
  621. # filtering out all colorcodes (works well)
  622. regsub -all "\003\[0-9\]\{1,2\},\[0-9\]\{1,2\}" $text "" text
  623. regsub -all "\003\[0-9\]\{1,2\}" $text "" text
  624. regsub -all "\003" $text "" text
  625. # filtering out BOLD text
  626. regsub -all "\002" $text "" text
  627. # underline gets filtered too. (since +c on quakenet would suppress it ...)
  628. regsub -all "\037" $text "" text
  629. # replacing like !!!!!!!!!!!!! with !!!!! (5 letters)
  630. # s/(.?)\1{4,}/\1\1\1\1\1/g;
  631. # - max 5 same chars in a row
  632. regsub -all -nocase -expanded {(.)\1\1\1\1+} $text {\1\1\1\1\1} text
  633. # putlog "test: $text"
  634. set text [string trim $text]
  635. # putlog "filter_B: ${text}"
  636. return $text
  637. }
  638. proc ::cims::umlauts {text} {
  639. # A REAL STRANGE BUG WORKAROUND WITH UMLAUTS
  640. regsub -all "Ä" ${text} "Ä" text
  641. regsub -all "Ü" ${text} "Ü" text
  642. regsub -all "Ö" ${text} "Ö" text
  643. regsub -all "ä" ${text} "ä" text
  644. regsub -all "ü" ${text} "ü" text
  645. regsub -all "ö" ${text} "ö" text
  646. return ${text}
  647. }
  648. proc ::cims::botonchannel {chan} {
  649. # safe "bot-knows-the-channel-and-is-in-there"-function
  650. if {[validchan $chan] == 1 && [botonchan $chan] == 1} {
  651. return 1
  652. } else {
  653. return 0
  654. }
  655. }
  656. # allowcheck for public commands..
  657. proc ::cims::allowed_channel {network name prefix nick mask chan} {
  658. variable mnet
  659. variable mnet_channels
  660. variable mnet_bots
  661. variable mnet_freqs
  662. variable mnet_networks_by_prefix
  663. variable mnet_colors
  664. global botnick botnet-nick lastbind
  665. # validating incoming vars
  666. set chan [::cims::proper_channelname $chan]
  667. putlog "::cims:: = a command for ($prefix) triggered by $nick ($mask) in $chan"
  668. # the command must be from a channel of "ownchannels"
  669. putlog "::cims:: = trying if $chan is allowed in network: $network"
  670. set found 0
  671. set proper_botnick [::cims::proper_botnick ${botnet-nick}]
  672. foreach _trigger_chan $mnet_channels($network,$proper_botnick) {
  673. #putlog "::cims:: = test: $_trigger_chan vs $chan"
  674. if {[string compare -nocase $_trigger_chan $chan] == 0} {
  675. putlog "::cims:: = channel: $_trigger_chan is allowed in network: $network"
  676. set found 1
  677. } else {
  678. # putlog "::cims:: = not in list: $chan"
  679. }
  680. }
  681. if {$found == 0} {
  682. putlog "::cims:: = triggering $prefix of network $network in $chan is not allowed (in my point of view)"
  683. return 0
  684. }
  685. set snd_nick [::cims::get_data $nick]
  686. if {![isop $nick $chan]} {
  687. putlog "::cims:: = allowed in $chan, but $nick is no op"
  688. ::putils::put_nick $nick "Sorry $nick, you need to be op."
  689. return 0
  690. }
  691. if {$nick == $botnick} {
  692. # no recursion :)
  693. return 0
  694. }
  695. # got through all checks .. so it's an OK channel
  696. return 1
  697. }
  698. # checks if the user is allowed, returns 1 if OK.
  699. # checks against the xml config of the banned ones.
  700. proc ::cims::allowed_user {network name prefix nick mask chan} {
  701. variable mnet
  702. variable mnet_channels
  703. variable mnet_bots
  704. variable mnet_bans
  705. variable mnet_networks_by_prefix
  706. variable mnet_colors
  707. global botnick botnet-nick lastbind
  708. # validating incoming vars
  709. set chan [::cims::proper_channelname $chan]
  710. # does mnet_bans even exist? it's optional after all.
  711. if {[info exists mnet_bans($network,$prefix)] == 1} {
  712. putlog "::cims:: = a command for ($prefix) triggered by $nick ($mask) in $chan"
  713. # the command must be from a channel of "ownchannels"
  714. putlog "::cims:: = trying if $nick ($mask) banned from frequency: $network,$prefix"
  715. set found 0
  716. foreach {hostmask reason} $mnet_bans($network,$prefix) {
  717. if {[string match [string tolower $hostmask] [string tolower $mask]]} {
  718. putlog "::cims:: = allowed_user: $nick ($mask) is not allowed in network ($network) by hostmask ($hostmask) for reason: $reason"
  719. set found 1
  720. } else {
  721. # putlog "::cims:: = not in list: $chan"
  722. }
  723. }
  724. if {$found == 1} {
  725. # tell the user his ban. :)
  726. ::putils::put_nick $nick "::cims:: Not allowed to send messages. Reason: $reason"
  727. return 0
  728. }
  729. }
  730. # got through all checks .. so user is not in banlist
  731. return 1
  732. }
  733. # allowcheck for bots sending netmessages
  734. proc ::cims::allowed_netbot {network netbot} {
  735. variable mnet
  736. variable mnet_bots
  737. global botnick botnet-nick lastbind
  738. putlog "::cims:: = a netbot $netbot sending message... allowed?"
  739. # the command must be from a channel of "ownchannels"
  740. set found 0
  741. set proper_botnick [::cims::proper_botnick ${botnet-nick}]
  742. set proper_netbot [::cims::proper_botnick $netbot]
  743. foreach {_netbotnick} $mnet_bots($network) {
  744. if {$_netbotnick == $proper_netbot} {
  745. putlog "::cims:: = netbot: $proper_netbot is allowed in network: $network"
  746. set found 1
  747. } else {
  748. # putlog "::cims:: = netbot: ...."
  749. }
  750. }
  751. if {$found == 0} {
  752. putlog "::cims:: = $proper_netbot of network $network sent me something - but it is not allowed in my network: $network"
  753. return 0
  754. }
  755. if {$netbot == ${botnet-nick}} {
  756. # if myself (for some reason) then don't do anything... no recursion :)
  757. return 0
  758. }
  759. # got through all checks .. so it's an OK netbot for a given network
  760. return 1
  761. }
  762. proc ::cims::reply_timeout {name chan} {
  763. variable mnet
  764. variable mnet_reached_users
  765. variable mnet_reached_chans
  766. # clean $name and $chan
  767. set name [::putils::kill_spaces $name]
  768. set chan [::putils::kill_spaces $chan]
  769. # easify variables
  770. set users $mnet_reached_users($name,$chan)
  771. set chans $mnet_reached_chans($name,$chan)
  772. #putlog "::cims:: HIER $name UND $chan"
  773. # inzwischen drfte auch die antwort gekommen sein.. also jetzt mnet_reached_* auswerten nach timeout..
  774. # make stats channel-dependent
  775. putlog "::cims:: * After ALL: Count_Users: $mnet_reached_users($name,$chan) Count_Channels: $mnet_reached_chans($name,$chan)"
  776. # Give me some reply.
  777. ::putils::put_local_msg ${chan} "::cims:: Message sent to $users users in $chans channels."
  778. }
  779. ### public reachable commands
  780. proc ::cims::history_frequency {nick mask hand chan text} {
  781. # proc triggered by specified $prefix_history
  782. variable mnet
  783. variable mnet_channels
  784. variable mnet_bots
  785. variable mnet_networks_by_prefix
  786. variable mnet_colors
  787. variable mnet_freqs
  788. variable mnet_freqs_onoff
  789. variable mnet_histories
  790. variable mnet_max_history
  791. global botnick lastbind
  792. set com $lastbind
  793. # validating incoming vars
  794. set chan [::cims::proper_channelname $chan]
  795. # cutting .prefix_history down to .prefix
  796. set prefix [string range $com 0 [expr [string first _ $com] -1]]
  797. #putlog "::cims:: the prefix is $prefix"
  798. set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
  799. set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
  800. set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
  801. set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
  802. putlog "network: $network"
  803. set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
  804. if {$allowed == 0} {
  805. return 0
  806. }
  807. # now generally allowed.
  808. putlog "mnet_history: $com triggered by $nick in $chan"
  809. if {[info exists mnet_histories($network,$name)] == 1} {
  810. set list_length [llength $mnet_histories($network,$name)]
  811. if {$list_length >= 1} {
  812. set msg "::cims:: last $mnet_max_history messages of $network $name:"
  813. ::putils::put_nick $nick $msg
  814. set x_count 0
  815. foreach {msg} $mnet_histories($network,$name) {
  816. incr x_count
  817. set backwards_x [expr $list_length - $x_count]
  818. set msg [lindex $mnet_histories($network,$name) $backwards_x]
  819. ::putils::put_nick $nick "($x_count/$list_length) $msg"
  820. }
  821. }
  822. } else {
  823. ::putils::put_nick $nick "::cims:: no accumulated history for $network $name"
  824. }
  825. }
  826. proc ::cims::enable_frequency {nick mask hand chan text} {
  827. # proc triggered by specified $prefix_enable
  828. variable mnet
  829. variable mnet_channels
  830. variable mnet_bots
  831. variable mnet_networks_by_prefix
  832. variable mnet_colors
  833. variable mnet_freqs
  834. variable mnet_freqs_onoff
  835. global botnick lastbind botnet-nick
  836. set com $lastbind
  837. # validating incoming vars
  838. set chan [::cims::proper_channelname $chan]
  839. # cutting .prefix_enable down to .prefix
  840. set prefix [string range $com 0 [expr [string first _ $com] -1]]
  841. #putlog "::cims:: the prefix is $prefix"
  842. set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
  843. set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
  844. set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
  845. set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
  846. #putlog "network: $network"
  847. set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
  848. if {$allowed == 0} {
  849. return 0
  850. }
  851. # now generally allowed.
  852. putlog "mnet_freq_status: before $mnet_freqs_onoff($name,$chan)"
  853. set mnet_freqs_onoff($name,$chan) 1
  854. putlog "mnet_freq_status: now $mnet_freqs_onoff($name,$chan)"
  855. ::putils::put_local_msg $chan "::cims:: $name _output_ enabled for $chan"
  856. }
  857. proc ::cims::disable_frequency {nick mask hand chan text} {
  858. # proc triggered by specified $prefix_enable
  859. variable mnet
  860. variable mnet_channels
  861. variable mnet_bots
  862. variable mnet_networks_by_prefix
  863. variable mnet_colors
  864. variable mnet_freqs
  865. variable mnet_freqs_onoff
  866. global botnick lastbind
  867. set com $lastbind
  868. # validating incoming vars
  869. set chan [::cims::proper_channelname $chan]
  870. # cutting .prefix_enable down to .prefix
  871. set prefix [string range $com 0 [expr [string first _ $com] -1]]
  872. putlog "::cims:: the prefix is $prefix"
  873. set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
  874. set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
  875. set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
  876. set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
  877. #putlog "network: $network"
  878. set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
  879. if {$allowed == 0} {
  880. return 0
  881. }
  882. # now generally allowed.
  883. putlog "mnet_freq_status: before $mnet_freqs_onoff($name,$chan)"
  884. set mnet_freqs_onoff($name,$chan) 0
  885. putlog "mnet_freq_status: now $mnet_freqs_onoff($name,$chan)"
  886. ::putils::put_local_msg $chan "::cims:: $name _output_ disabled for $chan"
  887. }
  888. proc ::cims::toggle_frequency {nick mask hand chan text} {
  889. # proc triggered by specified $prefix_toggle
  890. variable mnet
  891. variable mnet_channels
  892. variable mnet_bots
  893. variable mnet_networks_by_prefix
  894. variable mnet_colors
  895. variable mnet_freqs
  896. variable mnet_freqs_onoff
  897. global botnick lastbind
  898. set com $lastbind
  899. # validating incoming vars
  900. set chan [::cims::proper_channelname $chan]
  901. # cutting .prefix_enable down to .prefix
  902. set prefix [string range $com 0 [expr [string first _ $com] -1]]
  903. # putlog "::cims:: the prefix is $prefix"
  904. set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
  905. set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
  906. set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
  907. set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
  908. # putlog "network: $network"
  909. set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
  910. if {$allowed == 0} {
  911. return 0
  912. }
  913. # now generally allowed.
  914. putlog "mnet_freq_status: toggle $mnet_freqs_onoff($name,$chan)"
  915. if {$mnet_freqs_onoff($name,$chan) == 1} {
  916. set mnet_freqs_onoff($name,$chan) 0
  917. ::putils::put_local_msg $chan "::cims:: toggling ${name} _output_, now disabled for ${chan}"
  918. } else {
  919. set mnet_freqs_onoff($name,$chan) 1
  920. ::putils::put_local_msg $chan "::cims:: toggling ${name} _output_, now enabled for ${chan}"
  921. }
  922. putlog "mnet_freq_status: toggle now $mnet_freqs_onoff($name,$chan)"
  923. # frequency toggled .. :)
  924. }
  925. #::cims::enable_color
  926. proc ::cims::enable_color {nick mask hand chan text} {
  927. # proc triggered by specified $prefix_enable
  928. variable mnet
  929. variable mnet_channels
  930. variable mnet_bots
  931. variable mnet_networks_by_prefix
  932. variable mnet_colors_optional
  933. variable mnet_colors_onoff
  934. global botnick lastbind
  935. set com $lastbind
  936. # validating incoming vars
  937. set chan [::cims::proper_channelname $chan]
  938. # cutting .prefix_enable down to .prefix
  939. set prefix [string range $com 0 [expr [string first _ $com] -1]]
  940. #putlog "::cims:: the prefix is $prefix"
  941. set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
  942. set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
  943. set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
  944. set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
  945. #putlog "network: $network"
  946. set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
  947. if {$allowed == 0} {
  948. return 0
  949. }
  950. # now generally allowed.
  951. if {$mnet_colors_optional($network) != 1} {
  952. return 0
  953. }
  954. putlog "mnet_color_status: before $mnet_colors_onoff($name,$chan)"
  955. set mnet_colors_onoff($name,$chan) 1
  956. putlog "mnet_color_status: now $mnet_colors_onoff($name,$chan)"
  957. ::putils::put_local_msg $chan "::cims:: $name _coloroutput_ enabled for $chan"
  958. }
  959. #::cims::disable_color
  960. proc ::cims::disable_color {nick mask hand chan text} {
  961. # proc triggered by specified $prefix_enable
  962. variable mnet
  963. variable mnet_channels
  964. variable mnet_bots
  965. variable mnet_networks_by_prefix
  966. variable mnet_colors_optional
  967. variable mnet_colors_onoff
  968. global botnick lastbind
  969. set com $lastbind
  970. # validating incoming vars
  971. set chan [::cims::proper_channelname $chan]
  972. # cutting .prefix_enable down to .prefix
  973. set prefix [string range $com 0 [expr [string first _ $com] -1]]
  974. #putlog "::cims:: the prefix is $prefix"
  975. set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
  976. set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
  977. set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
  978. set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
  979. #putlog "network: $network"
  980. set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
  981. if {$allowed == 0} {
  982. return 0
  983. }
  984. # now generally allowed.
  985. if {$mnet_colors_optional($network) != 1} {
  986. return 0
  987. }
  988. putlog "mnet_color_status: before $mnet_colors_onoff($name,$chan)"
  989. set mnet_colors_onoff($name,$chan) 0
  990. putlog "mnet_color_status: now $mnet_colors_onoff($name,$chan)"
  991. ::putils::put_local_msg $chan "::cims:: $name _coloroutput_ disabled for $chan"
  992. }
  993. #::cims::toggle_color
  994. proc ::cims::toggle_color {nick mask hand chan text} {
  995. # proc triggered by specified $prefix_toggle
  996. variable mnet
  997. variable mnet_channels
  998. variable mnet_bots
  999. variable mnet_networks_by_prefix
  1000. variable mnet_colors_optional
  1001. variable mnet_colors_onoff
  1002. global botnick lastbind
  1003. set com $lastbind
  1004. # validating incoming vars
  1005. set chan [::cims::proper_channelname $chan]
  1006. # cutting .prefix_enable down to .prefix
  1007. set prefix [string range $com 0 [expr [string first _ $com] -1]]
  1008. # putlog "::cims:: the prefix is $prefix"
  1009. set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
  1010. set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
  1011. set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
  1012. set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
  1013. # putlog "network: $network"
  1014. set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
  1015. if {$allowed == 0} {
  1016. return 0
  1017. }
  1018. # now generally allowed.
  1019. if {$mnet_colors_optional($network) != 1} {
  1020. return 0
  1021. }
  1022. putlog "mnet_color_status: toggle $mnet_colors_onoff($name,$chan)"
  1023. if {$mnet_colors_onoff($name,$chan) == 1} {
  1024. set mnet_colors_onoff($name,$chan) 0
  1025. ::putils::put_local_msg $chan "::cims:: toggling ${name} _coloroutput_, now disabled for ${chan}"
  1026. } else {
  1027. set mnet_colors_onoff($name,$chan) 1
  1028. ::putils::put_local_msg $chan "::cims:: toggling ${name} _coloroutput_, now enabled for ${chan}"
  1029. }
  1030. putlog "mnet_color_status: toggle now $mnet_colors_onoff($name,$chan)"
  1031. # color for a channel toggled .. :)
  1032. }
  1033. #::cims::toggle_color
  1034. proc ::cims::status_frequency {nick mask hand chan text} {
  1035. # proc triggered by specified $prefix_toggle
  1036. variable mnet
  1037. variable mnet_channels
  1038. variable mnet_bots
  1039. variable mnet_networks_by_prefix
  1040. variable mnet_colors_optional
  1041. variable mnet_colors_onoff
  1042. variable mnet_freqs_onoff
  1043. variable mnet_reached_users
  1044. variable mnet_reached_chans
  1045. global botnick lastbind
  1046. set com $lastbind
  1047. # validating incoming vars
  1048. set chan [::cims::proper_channelname $chan]
  1049. # cutting .prefix_enable down to .prefix
  1050. set prefix [string range $com 0 [expr [string first _ $com] -1]]
  1051. # putlog "::cims:: the prefix is $prefix"
  1052. set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
  1053. set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
  1054. set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
  1055. set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
  1056. # putlog "network: $network"
  1057. set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
  1058. if {$allowed == 0} {
  1059. return 0
  1060. }
  1061. # now generally allowed.
  1062. ## get status for this frequency.
  1063. set status_message "$chan $name: "
  1064. if {$mnet_freqs_onoff($name,$chan) == 1} {
  1065. append status_message "frequency output is on. "
  1066. } else {
  1067. append status_message "frequency output is off. "
  1068. }
  1069. if {$mnet_colors_optional($network) == 1} {
  1070. if {$mnet_colors_onoff($name,$chan) == 1} {
  1071. append status_message "colors are turned on. "
  1072. } else {
  1073. append status_message "colors are turned off. "
  1074. }
  1075. } else {
  1076. append status_message "message-colors are forced. "
  1077. }
  1078. if {[info exists mnet_reached_users($name,$chan)]} {
  1079. if {[info exists mnet_reached_chans($name,$chan)]} {
  1080. append status_message "Your last message reached about $mnet_reached_users($name,$chan) users and $mnet_reached_chans($name,$chan) channels. "
  1081. }
  1082. }
  1083. ::putils::put_local_msg $chan "$status_message"
  1084. }
  1085. # checks timers of channels ... if not found, then ok with "0" secs left.. if found then return $secsleft
  1086. proc ::cims::check_spam_protection {prefix chan} {
  1087. variable mnet_delay
  1088. # validating incoming vars
  1089. set chan [::cims::proper_channelname $chan]
  1090. # check for pending timers.. spam-protection
  1091. set timerlist [utimers]
  1092. set secondsLeft 0
  1093. if {![info exists mnet_delay($prefix,$chan)]} {
  1094. set mnet_delay($prefix,$chan) 0
  1095. } else {
  1096. foreach {timerinfo} $timerlist {
  1097. set secsleft [join [lindex $timerinfo 0]]
  1098. set timer_id [join [lindex $timerinfo 2]]
  1099. # putlog "sec: $secsleft tid: $timer_id"
  1100. # putlog "checking timer ($timer_id) against mdelay-id: $mnet_delay($prefix,$chan)"
  1101. if {$timer_id == $mnet_delay($prefix,$chan)} {
  1102. return $secsleft
  1103. }
  1104. }
  1105. }
  1106. return 0
  1107. }
  1108. proc ::cims::messaging_public {nick mask hand chan text} {
  1109. # proc triggered by specified $prefix and calling the following (internal) one
  1110. variable mnet
  1111. variable mnet_channels
  1112. variable mnet_bots
  1113. variable mnet_networks_by_prefix
  1114. variable mnet_colors
  1115. variable mnet_freqs
  1116. variable mnet_freqs_onoff
  1117. variable mnet_delay
  1118. variable mnet_histories
  1119. variable mnet_reached_users
  1120. variable mnet_reached_chans
  1121. global botnet-nick lastbind
  1122. # validating incoming vars
  1123. set chan [::cims::proper_channelname $chan]
  1124. set prefix $lastbind
  1125. # $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.
  1126. set my_network_entry $mnet_networks_by_prefix($prefix)
  1127. set network [join [lindex $my_network_entry 0]]
  1128. set name [join [lindex $my_network_entry 1]]
  1129. set help [join [lindex $my_network_entry 2]]
  1130. set desc [join [lindex $my_network_entry 3]]
  1131. set delay [join [lindex $my_network_entry 4]]
  1132. set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
  1133. if {$allowed == 0} {
  1134. return 0
  1135. }
  1136. # now generally allowed.
  1137. # is user banned from sending??
  1138. set user_allowed [::cims::allowed_user $network $name $prefix $nick $mask $chan]
  1139. if {$user_allowed == 0} {
  1140. return 0
  1141. }
  1142. # user has not been matched against banlist. So he's allowed here.
  1143. # cleaning given strings...
  1144. set text [::cims::clean_txt $text]
  1145. # check here if we have some text or not.. :)
  1146. if {$text == "" || $text == "{}"} {
  1147. # output some help:
  1148. putlog "::cims:: = gave him some help"
  1149. ::putils::put_local_msg $chan $help
  1150. } else {
  1151. # ok, now send! (if timer allows it)
  1152. ### spamprotection
  1153. # returns the seconds that are left for this channel .. or 0 if no seconds left.
  1154. set secsleft [::cims::check_spam_protection $prefix $chan]
  1155. if {$secsleft > 0} {
  1156. putlog "::cims:: The timer of $prefix for $chan is still running. The guy has to wait ($secsleft/$delay) more seconds. I tell him."
  1157. ::putils::put_nick $nick "Sorry $nick, usage of $prefix only every $delay seconds. $secsleft seconds for $chan remaining."
  1158. # now BREAK "messaging_public".
  1159. # NO break.. for debug :)) arf
  1160. return 0
  1161. }
  1162. # if we went through the timer check ... so it doesn't exist anymore then we set a new one:
  1163. # set a timer-id to check for again, if it's allowed or not .. delay
  1164. set mnet_delay($prefix,$chan) [utimer $delay ::cims::dummy]
  1165. ### end spamprotection
  1166. ## HE IS SENDING NOW!
  1167. set mnet(reached) "0"
  1168. set mnet(reached_channels) "0"
  1169. # reset stats .. because he is just freshly sending
  1170. set mnet_reached_users($name,$chan) "0"
  1171. set mnet_reached_chans($name,$chan) "0"
  1172. ::cims::history_queue $network,$name $nick $chan $text
  1173. # send them first, we await a reply!
  1174. set proper_botnick [::cims::proper_botnick ${botnet-nick}]
  1175. # putlog "{botnet-nick} huar: $proper_botnick"
  1176. # single sends TO ALL REMOTE BOTS with their remote CHANNELS...
  1177. # let's see which mode for sending is used...
  1178. foreach _botnick $mnet_bots($network) {
  1179. if {$_botnick == $proper_botnick} {
  1180. } else { # if not myself!
  1181. putlog "::cims:: send: + I am about to send a message to $_botnick for $network: $name: $text"
  1182. # safe put_bot function..
  1183. ::cims::put_bot $_botnick "mnet_receive $network $name $nick $chan $text"
  1184. }
  1185. }
  1186. # SEND TO ALL OWN CHANNELS...
  1187. # send to all own channels, except to the channel the message originating from:
  1188. foreach _ownchan $mnet_channels($network,$proper_botnick) {
  1189. if {$_ownchan == $chan} {
  1190. } else { # if not own channel!
  1191. if {[::cims::botonchannel $_ownchan] == "1"} {
  1192. putlog "::cims:: = i am on $_ownchan"
  1193. # second enable/disable check
  1194. if {$mnet_freqs_onoff($name,$_ownchan) == 1} {
  1195. # userstats local
  1196. # set mnet(reached) [::cims::chanstat_users $_ownchan $mnet(reached)]
  1197. set mnet_reached_users($name,$chan) [::cims::chanstat_users $_ownchan $mnet_reached_users($name,$chan)]
  1198. putlog "::cims:: * Localcounting up $_ownchan users: $mnet_reached_users($name,$chan)"
  1199. # channel count local
  1200. incr mnet_reached_chans($name,$chan)
  1201. ::cims::put_local_netmessage $network $name $_ownchan $nick $chan $text
  1202. } else {
  1203. putlog "::cims:: + $_ownchan has disabled $name output"
  1204. }
  1205. } else {
  1206. putlog "::cims:: + Can't send a local message to '$_ownchan' since I am not there."
  1207. }
  1208. }
  1209. }
  1210. # wait here some more! (10 seconds with utimer)
  1211. utimer 5 "::cims::reply_timeout $name $chan"
  1212. # notice: better would be to go into the "reply" when all known bots already answered..
  1213. # then, if a bot is missing, but it was a known bot, just use a timeout with about 5-10 seconds..
  1214. # if the bot still didn't answer, then just go into "reply".
  1215. }
  1216. }
  1217. ### END public reachable commands
  1218. proc ::cims::binds {} {
  1219. variable currentNetworkDesc
  1220. variable currentNetworkSig
  1221. variable startNetworkInstance
  1222. variable currentBot
  1223. variable currentOwner
  1224. variable startBotInstance
  1225. variable mnet_networks
  1226. variable mnet_freqs
  1227. variable mnet_networks_by_prefix
  1228. variable mnet_channels
  1229. variable mnet_freqs_onoff
  1230. variable mnet_colors_onoff
  1231. global botnet-nick
  1232. set proper_botnick [::cims::proper_botnick ${botnet-nick}]
  1233. # binding of irc commands ... only works well if a config was loaded..
  1234. foreach {network desc} $mnet_networks {
  1235. # putlog "test: network is $network"
  1236. # putlog "test: networkdesc is $desc"
  1237. foreach {network name prefix help desc msgdelay} $mnet_freqs($network) {
  1238. putlog "network: $network"
  1239. putlog "name: $name"
  1240. putlog "prefix: $prefix"
  1241. putlog "help: $help"
  1242. putlog "desc: $desc"
  1243. putlog "msgdelay: $msgdelay"
  1244. set mnet_networks_by_prefix($prefix) "{$network} {$name} {$help} {$desc} {$msgdelay}"
  1245. # setting variables on init.
  1246. foreach {channel} $mnet_channels($network,$proper_botnick) {
  1247. # catch like php isset() - but catch returns 0 if OK!
  1248. set channel [::cims::proper_channelname $channel]
  1249. if {[catch {set mnet_freqs_onoff($name,$channel)}] == 1} {
  1250. set mnet_freqs_onoff($name,$channel) 1
  1251. putlog "::cims:: initially enabling $name for channel: $channel"
  1252. } else {
  1253. putlog "::cims:: $name for $channel is already on output: $mnet_freqs_onoff($name,$channel)"
  1254. }
  1255. # catch like php isset() - but catch returns 0 if OK!
  1256. if {[catch {set mnet_colors_onoff($name,$channel)}] == 1} {
  1257. set mnet_colors_onoff($name,$channel) 0
  1258. putlog "::cims:: initially disabling colors for $name for channel (if not forced): $channel"
  1259. } else {
  1260. putlog "::cims:: coloroutput of $name for $channel is already on (if not forced): $mnet_colors_onoff($name,$channel)"
  1261. }
  1262. }
  1263. bind pub - ${prefix} ::cims::messaging_public
  1264. # $network $name $prefix $help $desc
  1265. bind pub - ${prefix}_enable ::cims::enable_frequency
  1266. bind pub - ${prefix}_disable ::cims::disable_frequency
  1267. bind pub - ${prefix}_toggle ::cims::toggle_frequency
  1268. bind pub - ${prefix}_enable_colors ::cims::enable_color
  1269. bind pub - ${prefix}_disable_colors ::cims::disable_color
  1270. bind pub - ${prefix}_toggle_colors ::cims::toggle_color
  1271. # with typos..
  1272. bind pub - ${prefix}_enable_color ::cims::enable_color
  1273. bind pub - ${prefix}_disable_color ::cims::disable_color
  1274. bind pub - ${prefix}_toggle_color ::cims::toggle_color
  1275. bind pub - ${prefix}_history ::cims::history_frequency
  1276. bind pub - ${prefix}_status ::cims::status_frequency
  1277. bind pub - .mnet_status ::cims::dummy
  1278. # FIXME: make some more commands available to have control over the messages
  1279. # - "_stats"?
  1280. }
  1281. }
  1282. }
  1283. bind bot - mnet_receive ::cims::receive_message
  1284. bind bot - mnet_answer ::cims::receive_answer
  1285. bind dcc m cims_reload ::cims::dcc_configload
  1286. proc ::cims::conf_parsing {} {
  1287. variable mnet_config
  1288. variable mnet_num_configs
  1289. set parser [xml::parser \
  1290. -elementstartcommand ::cims::xmlElementStart \
  1291. -elementendcommand ::cims::xmlElementEnd \
  1292. -defaultcommand ::cims::xmlDefaultCmd \
  1293. -characterdatacommand ::cims::xmlCdata \
  1294. ]
  1295. # -errorcommand xmlHandleError
  1296. for {set y 1} {$y <= $mnet_num_configs} {incr y} {
  1297. set configfile $mnet_config($y)
  1298. # putlog "HRM?: $configfile"
  1299. $parser parse "$configfile"
  1300. }
  1301. }
  1302. proc ::cims::dcc_configload {dummy1 dummy2 dummy3} {
  1303. # wrapper command for ::cims::netconfigload
  1304. putlog "::cims:: = reloading configs..."
  1305. ::cims::clean_netconfig
  1306. ::cims::netconfigload
  1307. }
  1308. proc ::cims::netconfigload {} {
  1309. variable mnet_http_config
  1310. variable mnet_local_config
  1311. variable mnet_config
  1312. variable mnet_num_configs
  1313. putlog "debug:: $mnet_http_config"
  1314. # possible methods to load a config are: get_httpfile and get_localfile
  1315. # get_httpfile
  1316. # get_localfile RELATIVE_PATH_AND_FILE
  1317. set x 0
  1318. if {[info exists mnet_http_config]} {
  1319. foreach {host httpfile port} $mnet_http_config {
  1320. # FIXME config validating.. is the file received correctly? or do
  1321. # we only have a 404 error message there? ... bad thing still.
  1322. incr x
  1323. set mnet_config($x) [get_httpfile $host $httpfile $port]
  1324. }
  1325. }
  1326. if {[info exists mnet_local_config]} {
  1327. foreach {localfile} $mnet_local_config {
  1328. # FIXME config validating.. could we open the file?
  1329. # is the file a correct config?
  1330. incr x
  1331. set mnet_config($x) [get_localfile $localfile]
  1332. }
  1333. }
  1334. # $x is now at its highest count.
  1335. set mnet_num_configs $x
  1336. if {$x > 0} {
  1337. utimer 5 ::cims::conf_parsing
  1338. utimer 10 ::cims::binds
  1339. } else {
  1340. putlog "::cims:: no configurations loaded."
  1341. }
  1342. }
  1343. # looping this one
  1344. proc ::cims::interval_conf {} {
  1345. variable mnet_cfg_reload_interval
  1346. variable mnet_configtimer_set
  1347. variable mnet_netconfig_timer
  1348. # putlog "::cims:: interval conf! $mnet_configtimer_set huh?"
  1349. if {$mnet_configtimer_set == 1} {
  1350. putlog "::cims:: starting intervalled configload ($mnet_cfg_reload_interval minutes)"
  1351. ::cims::clean_netconfig
  1352. ::cims::netconfigload
  1353. set mnet_netconfig_timer [timer $mnet_cfg_reload_interval ::cims::interval_conf]
  1354. } else {
  1355. putlog "::cims:: was about to make a automatic configload again, but it has been disabled recently."
  1356. }
  1357. }
  1358. namespace eval ::cims {
  1359. ############# CONFIG SECTION ##############
  1360. ### the real config section is supposed to be here...
  1361. if {[info exists configs_file]} {
  1362. if {[file isfile "$configs_file"] == 1} {
  1363. source $configs_file
  1364. putlog "::cims:: configs file '$configs_file' loaded."
  1365. }
  1366. }
  1367. ############# CONFIG SHOULD NOW BE LOADED ONTO THE MANY VARIABLES ##############
  1368. # pls hands away again: starting up just defined configs ...
  1369. putlog "::cims:: = Messaging Network ($mnet(version)) loaded"
  1370. putlog "::cims:: = as master, reload current net-configs with .cims_reload"
  1371. putlog "::cims:: = do .rehash and .cims_reload if you defined a new net-config."
  1372. if {$mnet_cfg_reload_interval >= 90} {
  1373. if {![info exists mnet_netconfig_timer]} {
  1374. set mnet_configtimer_set 1
  1375. ::cims::interval_conf
  1376. # this one loops
  1377. }
  1378. } else {
  1379. if {[info exists mnet_netconfig_timer]} {
  1380. set mnet_configtimer_set 0
  1381. killtimer $mnet_netconfig_timer
  1382. unset mnet_netconfig_timer
  1383. }
  1384. set mnet_cfg_reload_interval 0
  1385. ::cims::clean_netconfig
  1386. ::cims::netconfigload
  1387. }
  1388. }