cims.tcl 51 KB

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