12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940 |
- # CIMS: Community IRC Messaging Service
- # CIMS formerly known as MNET (Message Network)
- # Copyright (C) 2004 Paul-Dieter Klumpp
- #
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU General Public License
- # as published by the Free Software Foundation; either version 2
- # of the License, or (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- # vim: expandtab tabstop=2 shiftwidth=2 softtabstop=2 autoindent:
- namespace eval ::cims {
-
- set configs_file "scripts/cims/cims_conf.tcl"
- #your notes:
- # - Requirements:
- # -> eggdrop bot version >= 1.6.17
- # -> using TCL version >= 8.3
- # -> TCLLib version >= 1.6
- # -> TCLXML version >= 2.6
- #my notes:
- # ?- aliasing of channels!
- # ?- alternative configs! backupconf..
- # ?- xml:dom!
- # ?- better http get implementation!
- # ?- korrekte Statistiken der User usw?
- # ?- wordbanning?
- # Now, hands away pls :) except you know what you are doing.
- ######
- #package prefer stable
- # we need a nice tcl version
- package require Tcl 8.3
- # it's an eggdrop script, right? :)
- package require eggdrop 1.6
- # we need the tclxml package.. at least 2.6 i think
- package require xml
- # tclxml needs uri of tcllib.. at least 1.1 i think
- package require uri
- # include my/our little eggdrop utilities and helper library. ;-) Putils!
- if {[file isfile "scripts/cims/putils.tcl"] == 1} {
- source "scripts/cims/putils.tcl"
- }
- ############ XML CONFIGURATION PARSING FOLLOWS!! WTF! :) #########
- variable layout
- variable mnet_networks
- variable mnet_bots
- variable mnet_channels
- variable mnet_freqs
- variable mnet_bans
- variable mnet_colors
- variable mnet_colors_optional
- variable mnet_reached_users
- variable mnet_reached_userlist
- variable mnet_reached_chans
- variable mnet_http_config
- variable mnet_local_config
- variable mnet_histories
- variable mnet_netconfig_timer
- variable currentNetworkDesc
- variable currentNetworkSig
- variable startNetworkInstance
- variable currentBot
- variable currentOwner
- variable startBotInstance
- variable currentFreqName
- variable currentFreqPrefix
- variable currentFreqHelpmsg
- variable currentFreqDesc
- variable startFrequencyInstance
- global botnet-nick
- set layout(local_reply) "::cims:: Message sent to @@chan_cnt@@ channels, reaching @@user_cnt@@ unique users."
- set layout(local_reply) "::cims:: Message sent to @@chan_cnt@@ channels, reaching @@user_cnt@@ unique users."
- set layout(local_reply) "::cims:: Sent to @@chan_cnt@@ channels, @@user_cnt@@ unique users."
- set layout(user_banned) "::cims:: You're not allowed to send messages. Reason: @@reason@@"
- set layout(output_enabled) "::cims:: @@freqname@@ _output_ enabled for @@chan@@"
- set layout(output_disabled) "::cims:: @@freqname@@ _output_ disabled for @@chan@@"
- set layout(output_toggle_enabled) "::cims:: toggling @@freqname@@ _output_, now enabled for @@chan@@"
- set layout(output_toggle_disabled) "::cims:: toggling @@freqname@@ _output_, now disabled for @@chan@@"
- set layout(color_enabled) "::cims:: @@freqname@@ _coloroutput_ enabled for @@chan@@"
- set layout(color_disabled) "::cims:: @@freqname@@ _coloroutput_ disabled for @@chan@@"
- set layout(color_toggle_enabled) "::cims:: toggling @@freqname@@ _coloroutput_, now enabled for @@chan@@"
- set layout(color_toggle_disabled) "::cims:: toggling @@freqname@@ _coloroutput_, now disabled for @@chan@@"
- set layout(history_missing) "::cims:: no accumulated history for @@network@@ @@freqname@@"
- set layout(history_start) "::cims:: last @@mnet_max_history@@ messages of @@network@@ @@freqname@@:"
- set layout(history_message) "(@@x_count@@/@@list_length@@) @@msg@@"
- # list
- set mnet_local_config ""
- unset mnet_local_config
- # list
- set mnet_http_config ""
- unset mnet_http_config
- set mnet_cfg_reload_interval 0
- # list
- #set mnet_freqs_onoff "lala lala"
- #unset mnet_freqs_onoff
- }
- proc ::cims::clean_netconfig {} {
- variable mnet_bots
- variable mnet_channels
- variable mnet_freqs
- variable mnet_bans
- variable mnet_colors
- variable mnet_networks
-
- # secure deletion of all config-arrays..
- if {[array exists mnet_bots]} {
- array unset mnet_bots
- }
- if {[array exists mnet_channels]} {
- array unset mnet_channels
- }
- if {[array exists mnet_freqs]} {
- array unset mnet_freqs
- }
- if {[array exists mnet_bans]} {
- array unset mnet_bans
- }
- #if {[array exists mnet_freqs_onoff]} {
- # array unset mnet_freqs_onoff
- #}
- if {[array exists mnet_colors]} {
- array unset mnet_colors
- }
- if {[array exists mnet_colors_optional]} {
- array unset mnet_colors_optional
- }
- # list
- set mnet_networks ""
- unset mnet_networks
- # list
- set mnet_freqs "lala lala"
- unset mnet_freqs
- set mnet_bans "lala lala"
- unset mnet_bans
- # list FIXME (this kills the history upon every .mnet_reload ... :( .. not good)
- if {[array exists mnet_histories]} {
- array unset mnet_histories
- }
- set mnet_histories ""
- unset mnet_histories
- }
- proc ::cims::initvars {} {
- variable currentNetworkDesc
- variable currentNetworkSig
- variable startNetworkInstance
- variable currentBot
- variable currentOwner
- variable startBotInstance
- variable startFrequencyInstance
- variable mnet_networks
- variable mnet_freqs
- variable mnet_bans
- variable mnet_networks_by_prefix
- global botnet-nick
- set currentNetwork ""
- set currentSig ""
- set startNetworkInstance ""
- set currentBot ""
- set currentOwner ""
- set startBotInstance ""
- set startFrequencyInstance ""
- }
- ::cims::initvars
-
- proc ::cims::xmlElementStart {tagname attlist args} {
- variable mnet_networks
- variable mnet_bots
- variable mnet_channels
- variable mnet_freqs
- variable mnet_bans
- variable mnet_colors
- variable mnet_colors_optional
- variable mnet_freqs_onoff
- variable currentNetworkDesc
- variable currentNetworkSig
- variable startNetworkInstance
- variable currentBot
- variable currentOwner
- variable startBotInstance
- variable currentFreqName
- variable currentFreqPrefix
- variable currentFreqHelpmsg
- variable currentFreqDesc
- variable startFrequencyInstance
- global botnet-nick
-
- set proper_botnick [::cims::proper_botnick ${botnet-nick}]
-
- # putlog "::cims:: attr: '$attlist' arg: '$args'"
- # getting NETWORK NAME
- if {"$tagname" == "mnet"} {
- set currentNetworkDesc ""
- set currentNetworkSig ""
- foreach {key value} $attlist {
- if {"$key" == "sig"} {
- set currentNetworkSig $value
- }
- if {"$key" == "desc"} {
- set currentNetworkDesc $value
- }
- if {"$currentNetworkSig" != ""} {
- if {"$currentNetworkDesc" != ""} {
- putlog "yo: $currentNetworkSig $currentNetworkDesc"
- lappend mnet_networks "$currentNetworkSig" "$currentNetworkDesc"
- set startNetworkInstance 1
- }
- }
- }
- }
- # getting botinfos...
- if {"$startNetworkInstance" == "1"} {
- if {"$tagname" == "bot"} {
- set currentBot ""
- set currentOwner ""
- foreach {key value} $attlist {
- if {"$key" == "nick"} {
- set currentBot [::cims::proper_botnick $value]
- }
- if {"$key" == "owner"} {
- set currentOwner $value
- }
- }
- if {"$currentBot" != ""} {
- if {"$currentOwner" != ""} {
- # currentbot auf 9 zeichen runter.. lowercase
- # botnick ebenso
-
- lappend mnet_bots($currentNetworkSig) "$currentBot"
- putlog "::cims:: cfg: reached botcfg for: $currentBot - and my name is: $proper_botnick"
- if {"$currentBot" == "$proper_botnick"} {
- putlog "::cims:: Oh yes, I, ${botnet-nick}, am listed for the network $currentNetworkSig by using '$currentBot'!"
- set startBotInstance 1
- }
- }
- }
- }
- # end of $tagname == "bot"
- if {"$startBotInstance" == "1"} {
- if {"$tagname" == "ch"} {
- foreach {key value} $attlist {
- if {"$key" == "name"} {
- putlog "test: ${value}"
- lappend mnet_channels($currentNetworkSig,$currentBot) [::cims::proper_channelname ${value}]
- putlog "::cims:: cfg: my channels for $currentNetworkSig $mnet_channels($currentNetworkSig,$currentBot)"
- }
- }
- }
- # end of $tagname == "ch"
- }
- # end of a bot...
- if {"$tagname" == "frequency"} {
- set currentFreqName ""
- set currentFreqPrefix ""
- set currentFreqHelpmsg ""
- set currentFreqDesc ""
- set currentDelay "120"
- foreach {key value} $attlist {
- if {"$key" == "name"} {
- set currentFreqName $value
- }
- if {"$key" == "prefix"} {
- set currentFreqPrefix $value
- }
- if {"$key" == "helpmsg"} {
- set currentFreqHelpmsg $value
- }
- if {"$key" == "desc"} {
- set currentFreqDesc $value
- }
- if {"$key" == "delay"} {
- set currentDelay $value
- }
- }
- if {"$currentFreqName" != ""} {
- if {"$currentFreqPrefix" != ""} {
- if {"$currentFreqHelpmsg" != ""} {
- if {"$currentFreqDesc" != ""} {
-
- putlog "::cims:: i, ${botnet-nick}, serve the frequency: $currentFreqName ($currentFreqPrefix) of $currentNetworkSig!"
- set startFrequencyInstance 1
- lappend mnet_freqs($currentNetworkSig) "$currentNetworkSig" "$currentFreqName" "$currentFreqPrefix" "$currentFreqHelpmsg" "$currentFreqDesc" "$currentDelay"
-
- }
- }
- }
- }
- # end of: alle attribs vorhanden fr eine valide frequenz
- }
- # end of $tagname == "frequency"
- # in element Frequency, there are bans as children.
- if {"$startFrequencyInstance" == "1"} {
- if {"$tagname" == "ban"} {
- set currentBanHostmask ""
- set currentBanReason ""
- foreach {key value} $attlist {
- if {"$key" == "hostmask"} {
- set currentBanHostmask $value
- }
- if {"$key" == "reason"} {
- set currentBanReason $value
- }
- }
- if {"$currentBanHostmask" != ""} {
- if {"$currentBanReason" != ""} {
- putlog "::cims:: adding ban to frequency: $currentNetworkSig, $currentFreqPrefix, $currentBanHostmask, reason: $currentBanReason"
- lappend mnet_bans($currentNetworkSig,$currentFreqPrefix) "$currentBanHostmask" "$currentBanReason"
- }
- }
- }
- }
- if {"$tagname" == "color"} {
- set currentColor ""
- set currentColorOptional ""
- foreach {key value} $attlist {
- if {"$key" == "id"} {
- set currentColor $value
- putlog "::cims:: gone into colors! $value"
- }
- if {"$key" == "optional"} {
- set currentColorOptional $value
- putlog "::cims:: color optional? $value"
- }
- }
-
- if {"$currentColor" != ""} {
- set mnet_colors($currentNetworkSig) $currentColor
- putlog "::cims:: the color-id for $currentNetworkSig is: $currentColor"
- } else {
- # make NO color if no color-id or tag has been given:
- set mnet_colors($currentNetworkSig) none
- }
- if {"$currentColorOptional" != ""} {
- set mnet_colors_optional($currentNetworkSig) $currentColorOptional
- putlog "::cims:: the color is optional: $currentColorOptional"
- } else {
- set mnet_colors_optional($currentNetworkSig) 0
- putlog "::cims:: the color is NOT optional and will be forced."
- }
- }
-
- }
-
- }
- proc ::cims::xmlElementEnd {tagname} {
- variable mnet_networks
- variable mnet_bots
- variable mnet_channels
- variable currentNetworkDesc
- variable currentNetworkSig
- variable startNetworkInstance
- variable startBotInstance
- variable startFrequencyInstance
- variable currentBot
- variable currentOwner
- if {"$tagname" == "mnet"} {
- set startNetworkInstance 0
- set currentNetworkDesc ""
- set currentNetworkSig ""
- }
- if {"$tagname" == "bot"} {
- set startBotInstance 0
- }
- if {"$tagname" == "frequency"} {
- set startFrequencyInstance 0
- }
- }
- proc ::cims::xmlCdata {data} {
- # putlog "::cims:: data found: $data"
- return 1
- }
- proc ::cims::xmlHandleError {errorcode errormsg} {
- putlog "::cims:: some error occured: errcode $errorcode: $errormsg"
- }
- proc ::cims::xmlDefaultCmd {data} {
- putlog "::cims:: i don't know this element: $data"
- return 1
- }
- ##################################################################
- namespace eval ::cims {
- ## some internal variables for messaging and stuff :) not your business after all.
- set mnet(version) "cims!1.16templated_outputs"
- set mnet_max_history 8
- set mnet_reached_users(dummy) "0"
- set mnet_reached_chans(dummy) "0"
- ##
- }
- proc ::cims::get_data {n} {
- if {[string range $n 0 0] == "\{"} {
- set n "\\$n"
- }
- return $n
- }
- proc ::cims::proper_botnick {botnick} {
-
- set temp [string tolower $botnick]
- # abfrage ob zu lang, dann fixen
- # putlog "::cims:: $botnick lowercase: $temp"
- if {[string length $botnick] > 9} {
- set temp [string range $temp 0 8 ]
- # putlog "::cims:: botnickname $botnick too long: capping to: $temp"
- }
- return $temp
- }
- proc ::cims::proper_channelname {channelname} {
- # channel names ARE NOT and SHOULD NOT BE CASE SENSITIVE!
- set temp [string tolower $channelname]
- set temp [::cims::umlauts $temp]
- # putlog "::cims:: $channelname lowercase: $temp"
- return $temp
- }
- proc ::cims::put_local_netmessage {network name chan rec_nickname rec_channel rec_text} {
- variable mnet_colors
- variable mnet_colors_optional
- variable mnet_colors_onoff
-
- # validating incoming vars..
- set chan [::cims::proper_channelname $chan]
- # unescaping vars .. this is an output procedure! remember?
- set rec_nickname [join $rec_nickname]
- set rec_channel [join $rec_channel]
- set rec_text [join $rec_text]
-
- if {$mnet_colors($network) == "none"} {
- # if no color id was found...
- set color_string ""
- } else {
- # if there was a color id...
-
- if {$mnet_colors_optional($network) == 1} {
- # check for the channel if activated..
- if {$mnet_colors_onoff($name,$chan) == 1} {
- set color_string "\003$mnet_colors($network)"
- set bold_string "\002"
- set bold_string_end "\002"
- } else {
- set color_string ""
- set bold_string ""
- set bold_string_end ""
- }
-
- } else {
- # if not optional then force colors.. whatever :)
- set color_string "\003$mnet_colors($network)"
- set bold_string "\002"
- set bold_string_end "\002"
- }
-
- }
- putserv "PRIVMSG $chan :${bold_string}${name}${bold_string_end} ${color_string}${rec_nickname} - ${rec_channel} : ${rec_text}"
- putlog "::cims:: + local message from $rec_nickname @ $rec_channel to $chan : $rec_text"
- }
- proc get_httpfile {host file port} {
- global botnet-nick
- putlog "get_httpfile::debug host: $host file: $file port: $port"
- if {[catch {set sock [socket $host $port] } sockerror]} {
- putlog "get_httpfile:: sockerror: $sockerror"
- return 0
- } else {
- puts $sock "GET $file HTTP/1.0"
- puts $sock "User-Agent: Mozilla/5.0 (compatible; ${botnet-nick}; mnet.tcl)"
- puts $sock "Host: $host"
- puts $sock "Connection: close"
- puts $sock ""
- flush $sock
- set header_done 0
- set data ""
- # get some strings out of the http stream.. better write them in a var.. normally.
- while {[eof $sock] != 1} {
- set bl [gets $sock]
- # putlog "test: $bl"
- if {[string match "" $bl]} {
- set header_done 1
- }
- if {$header_done == 1} {
- set data "$data\n$bl"
- }
- }
- close $sock
- return $data
- }
- }
- proc get_localfile {file} {
- set data ""
- if {[file isfile "$file"] == 1} {
-
- set fh [open "$file" "r"]
- while {![eof $fh]} {
- set line [gets $fh]
- append data $line
- }
- return $data
-
- } else {
- putlog "::cims:: Local configfile $file not found. Ignoring."
- }
- }
- #::cims::write_arraytofile "scripts/cims/$botnick.cims" "mnet_freqs_onoff"
- proc ::cims::write_arraytofile {file arrayname} {
- variable $arrayname
- set array_string [array get $arrayname]
-
- #putlog "array_string: $array_string"
- set fh [open "$file" "w"]
- puts $fh $array_string
- close $fh
- }
- #::cims::read_arrayfromfile "scripts/cims/$botnick.cims" "mnet_freqs_onoff"
- proc ::cims::read_arrayfromfile {file arrayname} {
- variable $arrayname
- set fh [open "$file" "r"]
- array set $arrayname [gets $fh]
- close $fh
- }
- proc ::cims::dummy {} {
- return 0
- }
- #not used..
- proc ::cims::kill_delaytimer {prefix chan} {
- variable mnet_delay
- set mnet_delay($prefix,$chan) 0
- putlog "Sending in $chan allowed again, since the timer expired"
- }
- proc ::cims::put_bot {botnetnick data} {
- set testlink [islinked $botnetnick]
- if {$testlink == 1} {
-
- if {[string length $data] > 335} {
- #::putils::filelog "scripts/cims/cims.log" "alldata put_bot to $botnetnick: $data"
- ::putils::put_bot $botnetnick $data
- } else {
- putbot $botnetnick $data
- }
- putlog "::cims:: put_bot: + a message delivered to $botnetnick."
- } else {
- putlog "::cims:: put_bot: + a message couldn't be delivered. Bot $botnetnick is not linked"
- }
- }
- proc ::cims::chanstat_users {chan users} {
-
- set ch_users [chanlist $chan]
- set ch_users_count [llength $ch_users]
-
- set users [expr $users + $ch_users_count]
- return $users
- }
- # this proc makes ::cims::chanstat_users obsolete! hmm.. but we leave it for some time. compatibility stuff!
- proc ::cims::chanstat_userlist {chan unique_userlist} {
- set ch_userlist [chanlist ${chan}]
- set unique_userlist [lsort -unique [join [concat [split $unique_userlist] [split $ch_userlist]]]]
-
- #putlog "uulist: $unique_userlist"
- return $unique_userlist
- }
- proc ::cims::history_queue {bucket nickname channel rec_text} {
- #::cims::history_queue $network,$name "$timestamp $rec_nickname $rec_channel $rec_text"
- variable mnet_histories
- variable mnet_max_history
-
- #putlog "::cims:: HISTORY $nickname $channel $rec_text"
- set timestamp [clock format [clock seconds] -format "%H:%M:%S"]
- #putlog "tstamp: $timestamp"
- # no clean:text needed .. already done sometime before.
-
- set input_history "$timestamp / $nickname - $channel : $rec_text"
-
- # putlog "tst: $timestamp nick: $nickname chan: $channel txt: $rec_text"
-
- set list_length 0
- if {[info exists mnet_histories($bucket)] == 1} {
- set list_length [llength $mnet_histories($bucket)]
- putlog "listlength of mnet_histories($bucket) before: $list_length"
- }
- if {$list_length >= $mnet_max_history} {
- # $mnet_max_history 10 - 9
- # 5= 1 4
- #10= 1 9
- # wenn man von 10 auf 5 wechselt: 6 9
- set mnet_histories($bucket) [lrange $mnet_histories($bucket) [expr $list_length - $mnet_max_history + 1] [expr $list_length - 1]]
- # putlog "grosser oder gleich 10: str: $input"
- }
- lappend mnet_histories($bucket) $input_history
-
- #set list_length [llength $mnet_histories($bucket)]
- #putlog "listlength of mnet_histories($bucket) now: $list_length"
- # define your own logging
- if {[info procs ::cims::history_logger] == "::cims::history_logger"} {
- ::cims::history_logger $bucket $nickname $channel $rec_text
- } else {
- putlog "::cims:: procedure ::cims::history_logger hasn't been defined. Do it, if you want logging."
- }
-
- }
- ## procs which are executed remotely follow:
- proc ::cims::receive_message {rec_botnick cmd rec_data} {
- variable mnet
- variable mnet_channels
- variable mnet_freqs_onoff
- variable mnet_bots
- variable mnet_histories
- global botnet-nick
- #putlog "rec_data string: '$rec_data'"
- # escape it to be a list FIRST.. and for output later, let the list JOIN together to a string again!
- #set rec_data [split $rec_data]
- putlog "rec_data list: '$rec_data'"
- set tmp_network [join [lindex $rec_data 0]]
- set tmp_name [join [lindex $rec_data 1]]
- #putlog "tmp_net: '$tmp_network'"
- #putlog "tmp_nam: '$tmp_name'"
- set network [::putils::kill_spaces $tmp_network]
- #putlog "network: '$network'"
-
- set name [::putils::kill_spaces $tmp_name]
- #putlog "name: '$name'"
- set rec_nickname [join [lindex $rec_data 2]]
- #putlog "rec_nickname: '$rec_nickname'"
- set rec_channel [join [lindex $rec_data 3]]
-
- #set rec_text [::cims::clean_txt [join [lrange [split $rec_data] 4 end]]]
- set rec_text [join [lrange $rec_data 4 end]]
- #putlog "rec_text: '$rec_text'"
- set allowed [::cims::allowed_netbot $network ${rec_botnick}]
- if {$allowed == 0} {
- return 0
- }
- # now the bot is declared as a known bot.
-
- set proper_botnick [::cims::proper_botnick ${botnet-nick}]
-
- putlog "::cims:: + Relaying Message from: $rec_nickname @ $rec_botnick @ $rec_channel: $rec_text"
-
- set unique_userlist ""
- set users 0
- set count_channels 0
-
- ::cims::history_queue $network,$name $rec_nickname $rec_channel $rec_text
- # plugin... if you want it to do other stuff with a received netbot message as well.
- if {[info procs ::cims::message_from_netbot_to_plugin] == "::cims::message_from_netbot_to_plugin"} {
- ::cims::message_from_netbot_to_plugin $rec_botnick $network $name $rec_channel $rec_nickname $rec_text
- }
- # send message to all local channels, and count stats:
- foreach {chan} $mnet_channels($network,$proper_botnick) {
-
- if {[::cims::botonchannel $chan] == "1"} {
- # erster disable/enable check
- if {$mnet_freqs_onoff($name,$chan) == 1} {
-
- incr count_channels
-
- set users [::cims::chanstat_users $chan $users]
- set unique_userlist [::cims::chanstat_userlist $chan $unique_userlist]
-
- putlog "::cims:: * Remote counting, $chan "
- ::cims::put_local_netmessage $network $name $chan $rec_nickname $rec_channel $rec_text
-
- } else {
- putlog "::cims:: + $chan has disabled $name output"
- }
- } else {
- putlog "::cims:: + Can't relay a message to '$chan' since I am not there."
- }
- }
- # building a fake userlist of 500 people for debugging:
- # for {set x 0} {$x < 500} {incr x} {
- # set unique_userlist [lsort -unique [concat $unique_userlist [::putils::randomRangeString 6]]]
- # }
- #putlog "::cims:: unique_userlist is [llength $unique_userlist] long"
-
- # it is an eggdrop limitation/bug that it is not allowed to send large botnet messages via putbot.
- # it truncates our payload after 388 chars. in fact the payload is 401 chars.
- #
- # we need a workaround! fixme! tcldcc.c:
- #
- #static int tcl_putbot STDVAR
- #{
- #int i;
- #char msg[401];
- #...
- #}
- # ANSWER! SEND THE REPLY of counts to the originating bot.
- #putlog "that ONE LALAL chan: $rec_channel"
- ::cims::put_bot $rec_botnick "mnet_answer [list [list $network] [list $name] $rec_channel [list $users] [list $count_channels] $unique_userlist]"
- return 0
- }
- proc ::cims::receive_answer {rec_botnick cmd rec_data} {
- variable mnet
- variable mnet_reached_users
- variable mnet_reached_userlist
- variable mnet_reached_chans
- global botnet-nick
- set proper_botnick [::cims::proper_botnick ${botnet-nick}]
- set long [string length $rec_data]
- putlog "::cims:: * on receive_answer from $rec_botnick length: $long"
- # we receive a LIST in rec_data! (see above "mnet_anser")
- #putlog "THAT TWO RECDATA: $rec_data"
- # work with list (lindex, lrange) and put together to a STRING again with JOIN.
- set network [join [lindex $rec_data 0]]
- set name [join [lindex $rec_data 1]]
- set chan [join [lindex $rec_data 2]]
- #putlog "THAT TWO: $chan"
- # rec_usercount is obsolete
- set rec_usercount [join [lindex $rec_data 3]]
- set rec_chancount [join [lindex $rec_data 4]]
- set rec_userlist [join [lrange $rec_data 5 end]]
- # override obsolete rec_usercount from above.
- set rec_usercount [llength $rec_userlist]
-
- # get this bots results to our namespaced variable:
- # FIXME: make simple userstats more accurate by sending nicknames back..
- # done: userstats should be counted in a correct variablename .. according to network and frequency
- # if you don't pay attention to it, a conflict between two broadcasts counting users may appear.
- # $mnet_reached_chans($name,$chan) <- $mnet_reached_users($name,$chan)
- set mnet_reached_users($name,$chan) [expr $mnet_reached_users($name,$chan) + $rec_usercount]
- set mnet_reached_chans($name,$chan) [expr $mnet_reached_chans($name,$chan) + $rec_chancount]
- set mnet_reached_userlist($name,$chan) [lsort -unique [join [concat [split $mnet_reached_userlist($name,$chan)] [split $rec_userlist]]]]
- putlog "::cims:: * near end receive_answer from $rec_botnick"
- putlog "::cims:: * $rec_botnick told me he sent its message to $rec_usercount unique people in $rec_chancount channels for $network frequency $name!"
- #putlog "::cims:: * Users reached since $name call: $mnet_reached_users($name,$chan) in channels: $mnet_reached_chans($name,$chan)"
-
- }
- proc ::cims::clean_txt {text} {
- # putlog "filter_A: ${text}"
- # regsub -all "\\" $text "\\\\" text
- # fixes many whitespace between words down to one space between words
- regsub -all "\\s+" $text " " text
-
- # filtering out all colorcodes (works well)
- regsub -all "\003\[0-9\]\{1,2\},\[0-9\]\{1,2\}" $text "" text
- regsub -all "\003\[0-9\]\{1,2\}" $text "" text
- regsub -all "\003" $text "" text
-
- # filtering out BOLD text
- regsub -all "\002" $text "" text
-
- # underline gets filtered too. (since +c on quakenet would suppress it ...)
- regsub -all "\037" $text "" text
-
- # replacing like !!!!!!!!!!!!! with !!!!! (5 letters)
- # s/(.?)\1{4,}/\1\1\1\1\1/g;
- # - max 5 same chars in a row
- regsub -all -nocase -expanded {(.)\1\1\1\1+} $text {\1\1\1\1\1} text
- # putlog "test: $text"
-
- set text [string trim $text]
- # putlog "filter_B: ${text}"
- return $text
- }
- proc ::cims::umlauts {text} {
- # A REAL STRANGE BUG WORKAROUND WITH UMLAUTS
- regsub -all "Ä" ${text} "Ä" text
- regsub -all "Ü" ${text} "Ü" text
- regsub -all "Ö" ${text} "Ö" text
-
- regsub -all "ä" ${text} "ä" text
- regsub -all "ü" ${text} "ü" text
- regsub -all "ö" ${text} "ö" text
-
- return ${text}
- }
- proc ::cims::botonchannel {chan} {
- # safe "bot-knows-the-channel-and-is-in-there"-function
-
- if {[validchan $chan] == 1 && [botonchan $chan] == 1} {
- return 1
- } else {
- return 0
- }
- }
-
- # allowcheck for public commands..
- proc ::cims::allowed_channel {network name prefix nick mask chan} {
- variable mnet
- variable mnet_channels
- variable mnet_bots
- variable mnet_freqs
- variable mnet_networks_by_prefix
- variable mnet_colors
- global botnick botnet-nick lastbind
- # validating incoming vars
- set chan [::cims::proper_channelname $chan]
- putlog "::cims:: = a command for ($prefix) triggered by $nick ($mask) in $chan"
- # the command must be from a channel of "ownchannels"
-
- putlog "::cims:: = trying if $chan is allowed in network: $network"
- set found 0
- set proper_botnick [::cims::proper_botnick ${botnet-nick}]
- foreach _trigger_chan $mnet_channels($network,$proper_botnick) {
- #putlog "::cims:: = test: $_trigger_chan vs $chan"
- if {[string compare -nocase $_trigger_chan $chan] == 0} {
- putlog "::cims:: = channel: $_trigger_chan is allowed in network: $network"
- set found 1
- } else {
- # putlog "::cims:: = not in list: $chan"
- }
- }
- if {$found == 0} {
- putlog "::cims:: = triggering $prefix of network $network in $chan is not allowed (in my point of view)"
- return 0
- }
-
- set snd_nick [::cims::get_data $nick]
- if {![isop $nick $chan]} {
- putlog "::cims:: = allowed in $chan, but $nick is no op"
- ::putils::put_nick $nick "Sorry $nick, you need to be op."
- return 0
- }
- if {$nick == $botnick} {
- # no recursion :)
- return 0
- }
-
-
- # got through all checks .. so it's an OK channel
- return 1
- }
- # checks if the user is allowed, returns 1 if OK.
- # checks against the xml config of the banned ones.
- proc ::cims::allowed_user {network name prefix nick mask chan} {
- variable layout
- variable mnet_channels
- variable mnet_bots
- variable mnet_bans
- variable mnet_networks_by_prefix
- variable mnet_colors
- global botnick botnet-nick lastbind
- # validating incoming vars
- set chan [::cims::proper_channelname $chan]
- # does mnet_bans even exist? it's optional after all.
- if {[info exists mnet_bans($network,$prefix)] == 1} {
- putlog "::cims:: = a command for ($prefix) triggered by $nick ($mask) in $chan"
-
- # the command must be from a channel of "ownchannels"
-
- putlog "::cims:: = trying if $nick ($mask) banned from frequency: $network,$prefix"
- set found 0
- foreach {hostmask reason} $mnet_bans($network,$prefix) {
- if {[string match [string tolower $hostmask] [string tolower $mask]]} {
- putlog "::cims:: = allowed_user: $nick ($mask) is not allowed in network ($network) by hostmask ($hostmask) for reason: $reason"
- set found 1
- } else {
- # putlog "::cims:: = not in list: $chan"
- }
- }
- if {$found == 1} {
- # tell the user his ban. :)
- set output [::cims::sarvar $layout(user_banned)]
- ::putils::put_nick $nick $output
-
- return 0
- }
- }
- # got through all checks .. so user is not in banlist
- return 1
- }
- # allowcheck for bots sending netmessages
- proc ::cims::allowed_netbot {network netbot} {
- variable mnet
- variable mnet_bots
- global botnick botnet-nick lastbind
- putlog "::cims:: = a netbot $netbot sending message... allowed?"
- # the command must be from a channel of "ownchannels"
-
- set found 0
- set proper_botnick [::cims::proper_botnick ${botnet-nick}]
- set proper_netbot [::cims::proper_botnick $netbot]
-
- foreach {_netbotnick} $mnet_bots($network) {
- if {$_netbotnick == $proper_netbot} {
- putlog "::cims:: = netbot: $proper_netbot is allowed in network: $network"
- set found 1
- } else {
- # putlog "::cims:: = netbot: ...."
- }
- }
- if {$found == 0} {
- putlog "::cims:: = $proper_netbot of network $network sent me something - but it is not allowed in my network: $network"
- return 0
- }
-
- if {$netbot == ${botnet-nick}} {
- # if myself (for some reason) then don't do anything... no recursion :)
- return 0
- }
-
-
- # got through all checks .. so it's an OK netbot for a given network
- return 1
- }
- # enter variables into placeholders of that pre-defined string "layout(local_reply)"
- proc ::cims::sarvar {layout_string} {
- set the_list [regexp -inline -all {@@(.+?)@@} $layout_string]
- foreach {thing thong} $the_list {
- #putlog "thing: $thing"
- #putlog "thong: $thong"
-
- # delete upvar link, if it existed.
- #if {[info exists replacer]} {
- # unset replacer
- #}
- # find the variable that is available in the previous context and use this now..
- upvar $thong replacer
- if {[info exists replacer]} {
- if {"$replacer" != ""} {
- #putlog "hum: $replacer"
- regsub -all "$thing" $layout_string "$replacer" layout_string
- }
- }
- }
- return $layout_string
- }
- proc ::cims::timeout_reply_from_local_for_netbots {name chan} {
- variable mnet
- variable mnet_reached_users
- variable mnet_reached_userlist
- variable mnet_reached_chans
- variable layout
- global botnet-nick
- set proper_botnick [::cims::proper_botnick ${botnet-nick}]
- # clean $name and $chan
- set name [::putils::kill_spaces $name]
- #set chan [::putils::kill_spaces $chan]
-
- # easify variables
- set userlist $mnet_reached_userlist($name,$chan)
- set user_cnt [llength $userlist]
- set mnet_reached_users($name,$chan) $user_cnt
- set chan_cnt $mnet_reached_chans($name,$chan)
-
- # inzwischen dürfte auch die antwort gekommen sein.. also jetzt mnet_reached_* auswerten nach timeout..
-
- # make stats channel-dependent
- #putlog "::cims:: * userlist is finally: $userlist "
- putlog "::cims:: * After ALL: Count_Users: $user_cnt Count_Channels: $mnet_reached_chans($name,$chan)"
-
- # Give me some reply.
- ::putils::filelog "scripts/cims/${proper_botnick}.log" "$name from $chan reached $user_cnt users: $userlist"
- # enter variables into placeholders of that pre-defined string "layout(local_reply)"
- set output [::cims::sarvar $layout(local_reply)]
- # plugin before the final answer... if you want it to do other stuff as well.
- if {[info procs ::cims::timeout_reply_from_local_for_netbots_plugin] == "::cims::timeout_reply_from_local_for_netbots_plugin"} {
- ::cims::timeout_reply_from_local_for_netbots_plugin $name $chan
- }
- ::putils::put_local_msg ${chan} $output
- }
- ### public reachable commands
- proc ::cims::history_frequency {nick mask hand chan text} {
- # proc triggered by specified $prefix_history
- variable layout
- variable mnet_channels
- variable mnet_bots
- variable mnet_networks_by_prefix
- variable mnet_colors
- variable mnet_freqs
- variable mnet_freqs_onoff
- variable mnet_histories
- variable mnet_max_history
- global botnick lastbind
- set com $lastbind
- # validating incoming vars
- set chan [::cims::proper_channelname $chan]
-
- # cutting .prefix_history down to .prefix
- set prefix [string range $com 0 [expr [string first _ $com] -1]]
- #putlog "::cims:: the prefix is $prefix"
- set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
- set freqname [join [lindex $mnet_networks_by_prefix($prefix) 1]]
- set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
- set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
- #putlog "network: $network"
- set allowed [::cims::allowed_channel $network $freqname $prefix $nick $mask $chan]
- if {$allowed == 0} {
- return 0
- }
- # now generally allowed.
- putlog "mnet_history: $com triggered by $nick in $chan"
- if {[info exists mnet_histories($network,$freqname)] == 1} {
- set list_length [llength $mnet_histories($network,$freqname)]
- if {$list_length >= 1} {
-
- set msg [::cims::sarvar $layout(history_start)]
- ::putils::put_nick $nick $msg
-
- set x_count 0
- foreach {msg} $mnet_histories($network,$freqname) {
- incr x_count
- set backwards_x [expr $list_length - $x_count]
- set msg [lindex $mnet_histories($network,$freqname) $backwards_x]
- set output [::cims::sarvar $layout(history_message)]
- ::putils::put_nick $nick $output
-
- }
- }
- } else {
- set output [::cims::sarvar $layout(history_missing)]
- ::putils::put_nick $nick $output
- }
- }
- proc ::cims::enable_frequency {nick mask hand chan text} {
- # proc triggered by specified $prefix_enable
- variable layout
- variable mnet_channels
- variable mnet_bots
- variable mnet_networks_by_prefix
- variable mnet_colors
- variable mnet_freqs
- variable mnet_freqs_onoff
- global botnick lastbind botnet-nick
- set com $lastbind
- # validating incoming vars
- set chan [::cims::proper_channelname $chan]
- # cutting .prefix_enable down to .prefix
- set prefix [string range $com 0 [expr [string first _ $com] -1]]
- #putlog "::cims:: the prefix is $prefix"
- set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
- set freqname [join [lindex $mnet_networks_by_prefix($prefix) 1]]
- set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
- set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
- #putlog "network: $network"
- set allowed [::cims::allowed_channel $network $freqname $prefix $nick $mask $chan]
- if {$allowed == 0} {
- return 0
- }
- # now generally allowed.
- putlog "mnet_freq_status: before $mnet_freqs_onoff($freqname,$chan)"
- set mnet_freqs_onoff($freqname,$chan) 1
- putlog "mnet_freq_status: now $mnet_freqs_onoff($freqname,$chan)"
- set output [::cims::sarvar $layout(output_enabled)]
- ::putils::put_local_msg $chan $output
- }
- proc ::cims::disable_frequency {nick mask hand chan text} {
- # proc triggered by specified $prefix_enable
- variable layout
- variable mnet_channels
- variable mnet_bots
- variable mnet_networks_by_prefix
- variable mnet_colors
- variable mnet_freqs
- variable mnet_freqs_onoff
- global botnick lastbind
- set com $lastbind
-
- # validating incoming vars
- set chan [::cims::proper_channelname $chan]
- # cutting .prefix_enable down to .prefix
- set prefix [string range $com 0 [expr [string first _ $com] -1]]
- #putlog "::cims:: the prefix is $prefix"
- set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
- set freqname [join [lindex $mnet_networks_by_prefix($prefix) 1]]
- set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
- set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
- #putlog "network: $network"
- set allowed [::cims::allowed_channel $network $freqname $prefix $nick $mask $chan]
- if {$allowed == 0} {
- return 0
- }
- # now generally allowed.
-
- putlog "mnet_freq_status: before $mnet_freqs_onoff($freqname,$chan)"
- set mnet_freqs_onoff($freqname,$chan) 0
- putlog "mnet_freq_status: now $mnet_freqs_onoff($freqname,$chan)"
- set output [::cims::sarvar $layout(output_disabled)]
- ::putils::put_local_msg $chan $output
-
- }
- proc ::cims::toggle_frequency {nick mask hand chan text} {
- # proc triggered by specified $prefix_toggle
- variable layout
- variable mnet_channels
- variable mnet_bots
- variable mnet_networks_by_prefix
- variable mnet_colors
- variable mnet_freqs
- variable mnet_freqs_onoff
- global botnick lastbind
- set com $lastbind
- # validating incoming vars
- set chan [::cims::proper_channelname $chan]
- # cutting .prefix_enable down to .prefix
- set prefix [string range $com 0 [expr [string first _ $com] -1]]
- # putlog "::cims:: the prefix is $prefix"
- set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
- set freqname [join [lindex $mnet_networks_by_prefix($prefix) 1]]
- set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
- set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
- set allowed [::cims::allowed_channel $network $freqname $prefix $nick $mask $chan]
- if {$allowed == 0} {
- return 0
- }
- # now generally allowed.
- putlog "mnet_freq_status: toggle $mnet_freqs_onoff($freqname,$chan)"
- if {$mnet_freqs_onoff($freqname,$chan) == 1} {
- set mnet_freqs_onoff($freqname,$chan) 0
- set output [::cims::sarvar $layout(output_toggle_disabled)]
- ::putils::put_local_msg $chan $output
- } else {
- set mnet_freqs_onoff($freqname,$chan) 1
- set output [::cims::sarvar $layout(output_toggle_enabled)]
- ::putils::put_local_msg $chan $output
- }
- putlog "mnet_freq_status: toggle now $mnet_freqs_onoff($freqname,$chan)"
-
- # frequency toggled .. :)
-
- }
- #::cims::enable_color
- proc ::cims::enable_color {nick mask hand chan text} {
- # proc triggered by specified $prefix_enable
- variable layout
- variable mnet_channels
- variable mnet_bots
- variable mnet_networks_by_prefix
- variable mnet_colors_optional
- variable mnet_colors_onoff
- global botnick lastbind
- set com $lastbind
-
- # validating incoming vars
- set chan [::cims::proper_channelname $chan]
- # cutting .prefix_enable down to .prefix
- set prefix [string range $com 0 [expr [string first _ $com] -1]]
- #putlog "::cims:: the prefix is $prefix"
- set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
- set freqname [join [lindex $mnet_networks_by_prefix($prefix) 1]]
- set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
- set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
- #putlog "network: $network"
- set allowed [::cims::allowed_channel $network $freqname $prefix $nick $mask $chan]
- if {$allowed == 0} {
- return 0
- }
- # now generally allowed.
- if {$mnet_colors_optional($network) != 1} {
- return 0
- }
- putlog "mnet_color_status: before $mnet_colors_onoff($freqname,$chan)"
- set mnet_colors_onoff($freqname,$chan) 1
- putlog "mnet_color_status: now $mnet_colors_onoff($freqname,$chan)"
- set output [::cims::sarvar $layout(color_enabled)]
- ::putils::put_local_msg $chan $output
- }
- #::cims::disable_color
- proc ::cims::disable_color {nick mask hand chan text} {
- # proc triggered by specified $prefix_enable
- variable layout
- variable mnet_channels
- variable mnet_bots
- variable mnet_networks_by_prefix
- variable mnet_colors_optional
- variable mnet_colors_onoff
- global botnick lastbind
- set com $lastbind
- # validating incoming vars
- set chan [::cims::proper_channelname $chan]
- # cutting .prefix_enable down to .prefix
- set prefix [string range $com 0 [expr [string first _ $com] -1]]
- #putlog "::cims:: the prefix is $prefix"
- set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
- set freqname [join [lindex $mnet_networks_by_prefix($prefix) 1]]
- set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
- set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
- #putlog "network: $network"
- set allowed [::cims::allowed_channel $network $freqname $prefix $nick $mask $chan]
- if {$allowed == 0} {
- return 0
- }
- # now generally allowed.
- if {$mnet_colors_optional($network) != 1} {
- return 0
- }
- putlog "mnet_color_status: before $mnet_colors_onoff($freqname,$chan)"
- set mnet_colors_onoff($freqname,$chan) 0
- putlog "mnet_color_status: now $mnet_colors_onoff($freqname,$chan)"
-
- set output [::cims::sarvar $layout(color_disabled)]
- ::putils::put_local_msg $chan $output
- }
- #::cims::toggle_color
- proc ::cims::toggle_color {nick mask hand chan text} {
- # proc triggered by specified $prefix_toggle
- variable layout
- variable mnet_channels
- variable mnet_bots
- variable mnet_networks_by_prefix
- variable mnet_colors_optional
- variable mnet_colors_onoff
- global botnick lastbind
- set com $lastbind
-
- # validating incoming vars
- set chan [::cims::proper_channelname $chan]
- # cutting .prefix_enable down to .prefix
- set prefix [string range $com 0 [expr [string first _ $com] -1]]
- # putlog "::cims:: the prefix is $prefix"
- set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
- set freqname [join [lindex $mnet_networks_by_prefix($prefix) 1]]
- set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
- set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
- # putlog "network: $network"
- set allowed [::cims::allowed_channel $network $freqname $prefix $nick $mask $chan]
- if {$allowed == 0} {
- return 0
- }
- # now generally allowed.
- if {$mnet_colors_optional($network) != 1} {
- return 0
- }
-
- putlog "mnet_color_status: toggle $mnet_colors_onoff($freqname,$chan)"
- if {$mnet_colors_onoff($freqname,$chan) == 1} {
- set mnet_colors_onoff($freqname,$chan) 0
- set output [::cims::sarvar $layout(color_toggle_disabled)]
- ::putils::put_local_msg $chan $output
- } else {
- set mnet_colors_onoff($freqname,$chan) 1
- set output [::cims::sarvar $layout(color_toggle_enabled)]
- ::putils::put_local_msg $chan $output
- }
- putlog "mnet_color_status: toggle now $mnet_colors_onoff($freqname,$chan)"
-
- # color for a channel toggled .. :)
-
- }
- #::cims::toggle_color
- proc ::cims::status_frequency {nick mask hand chan text} {
- # proc triggered by specified $prefix_toggle
- variable mnet
- variable mnet_channels
- variable mnet_bots
- variable mnet_networks_by_prefix
- variable mnet_colors_optional
- variable mnet_colors_onoff
- variable mnet_freqs_onoff
- variable mnet_reached_users
- variable mnet_reached_chans
- global botnick lastbind
- set com $lastbind
-
- # validating incoming vars
- set chan [::cims::proper_channelname $chan]
- # cutting .prefix_enable down to .prefix
- set prefix [string range $com 0 [expr [string first _ $com] -1]]
- # putlog "::cims:: the prefix is $prefix"
- set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
- set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
- set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
- set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
- # putlog "network: $network"
- set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
- if {$allowed == 0} {
- return 0
- }
- # now generally allowed.
-
- ## get status for this frequency.
- set status_message "$chan $name: "
-
- if {$mnet_freqs_onoff($name,$chan) == 1} {
- append status_message "Frequency output is on. "
- } else {
- append status_message "Frequency output is off. "
- }
- if {$mnet_colors_optional($network) == 1} {
- if {$mnet_colors_onoff($name,$chan) == 1} {
- append status_message "Colors are turned on. "
- } else {
- append status_message "Colors are turned off. "
- }
-
- } else {
- append status_message "Message-colors are forced. "
- }
-
- if {[info exists mnet_reached_users($name,$chan)]} {
- if {[info exists mnet_reached_chans($name,$chan)]} {
- append status_message "Your last message reached $mnet_reached_users($name,$chan) unique users in $mnet_reached_chans($name,$chan) channels. "
- }
- }
-
- ::putils::put_local_msg $chan "$status_message"
- }
- # checks timers of channels ... if not found, then ok with "0" secs left.. if found then return $secsleft
- proc ::cims::check_spam_protection {prefix chan} {
- variable mnet_delay
-
- # validating incoming vars
- set chan [::cims::proper_channelname $chan]
- # check for pending timers.. spam-protection
- set timerlist [utimers]
- set secondsLeft 0
- if {![info exists mnet_delay($prefix,$chan)]} {
- set mnet_delay($prefix,$chan) 0
- } else {
- foreach {timerinfo} $timerlist {
-
- set secsleft [join [lindex $timerinfo 0]]
- set timer_id [join [lindex $timerinfo 2]]
-
- # putlog "sec: $secsleft tid: $timer_id"
- # putlog "checking timer ($timer_id) against mdelay-id: $mnet_delay($prefix,$chan)"
- if {$timer_id == $mnet_delay($prefix,$chan)} {
- return $secsleft
- }
- }
- }
- return 0
- }
- proc ::cims::message_to_own_channels {network freqname chan nick text} {
- variable mnet_channels
- variable mnet_freqs_onoff
- variable mnet_reached_users
- variable mnet_reached_userlist
- variable mnet_reached_chans
- global botnet-nick
- set proper_botnick [::cims::proper_botnick ${botnet-nick}]
- # putlog "{botnet-nick} huar: $proper_botnick"
- foreach _ownchan $mnet_channels($network,$proper_botnick) {
- if {$_ownchan == $chan} {
-
- } else {
- # if not own channel! ...
- if {[::cims::botonchannel $_ownchan] == "1"} {
-
- putlog "::cims:: = i am on $_ownchan"
- # second enable/disable check
- if {$mnet_freqs_onoff($freqname,$_ownchan) == 1} {
-
- # userstats local
- set mnet_reached_users($freqname,$chan) [::cims::chanstat_users $_ownchan $mnet_reached_users($freqname,$chan)]
- set mnet_reached_userlist($freqname,$chan) [::cims::chanstat_userlist $_ownchan $mnet_reached_userlist($freqname,$chan)]
-
- putlog "::cims:: * Localcounting up $_ownchan users: $mnet_reached_users($freqname,$chan)"
-
- # channel count local
- incr mnet_reached_chans($freqname,$chan)
-
- ::cims::put_local_netmessage $network $freqname $_ownchan $nick $chan $text
- } else {
- putlog "::cims:: + $_ownchan has disabled $freqname output"
- }
- } else {
- putlog "::cims:: + Can't send a local message to '$_ownchan' since I am not there."
- }
- }
- }
- }
- proc ::cims::message_to_netbots {network freqname chan nick text} {
- variable mnet_bots
- global botnet-nick
- set proper_botnick [::cims::proper_botnick ${botnet-nick}]
- # putlog "{botnet-nick} huar: $proper_botnick"
- foreach _botnick $mnet_bots($network) {
- if {$_botnick == $proper_botnick} {
-
- } else { # if not myself!
- putlog "::cims:: send: + I am about to send a message to $_botnick for $network: $freqname: $text"
- # safe put_bot function..
- set data "mnet_receive"
- lappend data $network $freqname $nick $chan $text
- putlog "data: $data"
- ::cims::put_bot $_botnick $data
-
- }
- }
- }
- proc ::cims::message_from_local {network freqname source nick text} {
- variable mnet_reached_users
- variable mnet_reached_userlist
- variable mnet_reached_chans
- # reset stats .. because he is just freshly sending
- set mnet_reached_users($freqname,$source) "0"
- set mnet_reached_userlist($freqname,$source) ""
- set mnet_reached_chans($freqname,$source) "0"
- ::cims::history_queue $network,$freqname $nick $source $text
-
- # send them first, we await a reply!
- # single sends TO ALL REMOTE BOTS with their remote CHANNELS...
- # let's see which mode for sending is used...
- ::cims::message_to_netbots $network $freqname $source $nick $text
-
- # SEND TO ALL OWN CHANNELS...
- # send to all own channels, except to the channel the message originating from:
- ::cims::message_to_own_channels $network $freqname $source $nick $text
- # plugin sending... if you want it to do other stuff as well.
- if {[info procs ::cims::message_from_local_plugin] == "::cims::message_from_local_plugin"} {
- ::cims::message_from_local_plugin $network $freqname $source $nick $text
- }
-
- # notice: better would be to go into the "reply" when all known bots already answered..
- # then, if a bot is missing, but it was a known bot, just use a timeout with about 5-10 seconds..
- # if the bot still didn't answer, then just go into "reply".
- }
- proc ::cims::messaging_public_from_bind {nick mask hand chan text} {
- # proc triggered by specified $prefix and calling the following (internal) one
- variable mnet
- variable mnet_networks_by_prefix
- variable mnet_colors
- variable mnet_freqs
- variable mnet_delay
- variable mnet_histories
- global botnet-nick lastbind
-
- # validating incoming vars
- set chan [::cims::proper_channelname $chan]
-
- set prefix $lastbind
- # $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.
- set my_network_entry $mnet_networks_by_prefix($prefix)
- set network [join [lindex $my_network_entry 0]]
- set freqname [join [lindex $my_network_entry 1]]
- set help [join [lindex $my_network_entry 2]]
- set desc [join [lindex $my_network_entry 3]]
- set delay [join [lindex $my_network_entry 4]]
- set allowed [::cims::allowed_channel $network $freqname $prefix $nick $mask $chan]
- if {$allowed == 0} {
- return 0
- }
- # now generally allowed.
- # is user banned from sending??
- set user_allowed [::cims::allowed_user $network $freqname $prefix $nick $mask $chan]
- if {$user_allowed == 0} {
- return 0
- }
- # user has not been matched against banlist. So he's allowed here.
-
- ### spamprotection
- # returns the seconds that are left for this channel .. or 0 if no seconds left.
- set secsleft [::cims::check_spam_protection $prefix $chan]
- if {$secsleft > 0} {
- putlog "::cims:: The timer of $prefix for $chan is still running. The guy has to wait ($secsleft/$delay) more seconds. I tell him."
- ::putils::put_nick $nick "Sorry $nick, usage of $prefix only every $delay seconds. $secsleft seconds for $chan remaining."
- # now BREAK "messaging_public_from_bind".
- # NO break.. for debug :)) arf
- return 0
- }
- ### end spamprotection
- ### text check protection
- # cleaning given strings...
- set text [::cims::clean_txt $text]
- set msglen [string length $text]
- # see if that cleaned text ist ok to send.
- # fixme: put this into a central variable to get from somewhere (http config?)
- set allowed_msglen 230
- if {$msglen == 0} {
- # output some help:
- ::putils::put_local_msg $chan $help
- return 0
- } elseif {$msglen > $allowed_msglen} {
- # output some info:
- ::putils::put_local_msg $chan "Your message is too long, containing $msglen of $allowed_msglen characters."
- return 0
- } elseif {$msglen < 3} {
- # output some info:
- ::putils::put_local_msg $chan "Your message is too short. Minimum 3 characters."
- return 0
- }
- ### end text check protection
- # if we went through the timer check ... so it doesn't exist anymore then we set a new one:
- # set a timer-id to check for again, if it's allowed or not .. delay
- set mnet_delay($prefix,$chan) [utimer $delay ::cims::dummy]
- ## HE IS SENDING NOW!
- ::cims::message_from_local $network $freqname $chan $nick $text
- # wait here some more! (10 seconds with utimer) - to send out a reply to the channel
- utimer 10 "::cims::timeout_reply_from_local_for_netbots $freqname $chan"
- }
- ### END public reachable commands
- proc ::cims::binds {} {
- variable currentNetworkDesc
- variable currentNetworkSig
- variable startNetworkInstance
- variable currentBot
- variable currentOwner
- variable startBotInstance
- variable mnet_networks
- variable mnet_freqs
- variable mnet_networks_by_prefix
- variable mnet_channels
- variable mnet_freqs_onoff
- variable mnet_colors_onoff
- global botnet-nick
-
- set proper_botnick [::cims::proper_botnick ${botnet-nick}]
- # binding of irc commands ... only works well if a config was loaded..
- foreach {network desc} $mnet_networks {
- # putlog "test: network is $network"
- # putlog "test: networkdesc is $desc"
-
- foreach {network name prefix help desc msgdelay} $mnet_freqs($network) {
-
- putlog "network: $network"
- putlog "freqname: $name"
- putlog "prefix: $prefix"
- putlog "help: $help"
- putlog "desc: $desc"
- putlog "msgdelay: $msgdelay"
-
- set mnet_networks_by_prefix($prefix) "{$network} {$name} {$help} {$desc} {$msgdelay}"
-
- # setting variables on init.
- foreach {channel} $mnet_channels($network,$proper_botnick) {
- # catch like php isset() - but catch returns 0 if OK!
- set channel [::cims::proper_channelname $channel]
- if {[catch {set mnet_freqs_onoff($name,$channel)}] == 1} {
- set mnet_freqs_onoff($name,$channel) 1
- putlog "::cims:: initially enabling $name for channel: $channel"
- } else {
- putlog "::cims:: $name for $channel is already on output: $mnet_freqs_onoff($name,$channel)"
- }
-
-
- # catch like php isset() - but catch returns 0 if OK!
- if {[catch {set mnet_colors_onoff($name,$channel)}] == 1} {
- set mnet_colors_onoff($name,$channel) 0
- putlog "::cims:: initially disabling colors for $name for channel (if not forced): $channel"
- } else {
- putlog "::cims:: coloroutput of $name for $channel is already on (if not forced): $mnet_colors_onoff($name,$channel)"
- }
- }
-
-
- bind pub - ${prefix} ::cims::messaging_public_from_bind
- # $network $name $prefix $help $desc
- bind pub - ${prefix}_enable ::cims::enable_frequency
- bind pub - ${prefix}_disable ::cims::disable_frequency
- bind pub - ${prefix}_toggle ::cims::toggle_frequency
- bind pub - ${prefix}_enable_colors ::cims::enable_color
- bind pub - ${prefix}_disable_colors ::cims::disable_color
- bind pub - ${prefix}_toggle_colors ::cims::toggle_color
- # with typos..
- bind pub - ${prefix}_enable_color ::cims::enable_color
- bind pub - ${prefix}_disable_color ::cims::disable_color
- bind pub - ${prefix}_toggle_color ::cims::toggle_color
-
- bind pub - ${prefix}_history ::cims::history_frequency
- bind pub - ${prefix}_status ::cims::status_frequency
-
- bind pub - .mnet_status ::cims::dummy
- # FIXME: make some more commands available to have control over the messages
- # - "_stats"?
-
- }
-
-
- }
- }
- bind bot - mnet_receive ::cims::receive_message
- bind bot - mnet_answer ::cims::receive_answer
- bind dcc m cims_reload ::cims::dcc_configload
- proc ::cims::conf_parsing {} {
- variable mnet_config
- variable mnet_num_configs
- set parser [xml::parser \
- -elementstartcommand ::cims::xmlElementStart \
- -elementendcommand ::cims::xmlElementEnd \
- -defaultcommand ::cims::xmlDefaultCmd \
- -characterdatacommand ::cims::xmlCdata \
- ]
- # -errorcommand xmlHandleError
- for {set y 1} {$y <= $mnet_num_configs} {incr y} {
- set configfile $mnet_config($y)
- # putlog "HRM?: $configfile"
- $parser parse "$configfile"
- }
- }
- proc ::cims::dcc_configload {dummy1 dummy2 dummy3} {
- # wrapper command for ::cims::netconfigload
- putlog "::cims:: = reloading configs..."
- ::cims::clean_netconfig
- ::cims::netconfigload
- }
- proc ::cims::netconfigload {} {
- variable mnet_http_config
- variable mnet_local_config
- variable mnet_config
- variable mnet_num_configs
- # possible methods to load a config are: get_httpfile and get_localfile
- # get_httpfile
- # get_localfile RELATIVE_PATH_AND_FILE
- set x 0
- if {[info exists mnet_http_config]} {
- putlog "debug:: $mnet_http_config"
- foreach {host httpfile port} $mnet_http_config {
- # FIXME config validating.. is the file received correctly? or do
- # we only have a 404 error message there? ... bad thing still.
- incr x
- set mnet_config($x) [get_httpfile $host $httpfile $port]
- }
- }
-
- if {[info exists mnet_local_config]} {
- foreach {localfile} $mnet_local_config {
- # FIXME config validating.. could we open the file?
- # is the file a correct config?
- incr x
- set mnet_config($x) [get_localfile $localfile]
- }
- }
- # $x is now at its highest count.
-
- set mnet_num_configs $x
-
- if {$x > 0} {
- utimer 5 ::cims::conf_parsing
- utimer 10 ::cims::binds
- } else {
- putlog "::cims:: no configurations loaded."
- }
- }
- # looping this one
- proc ::cims::interval_conf {} {
- variable mnet_cfg_reload_interval
- variable mnet_configtimer_set
- variable mnet_netconfig_timer
-
- # putlog "::cims:: interval conf! $mnet_configtimer_set huh?"
-
- if {$mnet_configtimer_set == 1} {
- putlog "::cims:: starting intervalled configload ($mnet_cfg_reload_interval minutes)"
- ::cims::clean_netconfig
- ::cims::netconfigload
- set mnet_netconfig_timer [timer $mnet_cfg_reload_interval ::cims::interval_conf]
- } else {
- putlog "::cims:: was about to make a automatic configload again, but it has been disabled recently."
- }
- }
- namespace eval ::cims {
- ############# CONFIG SECTION ##############
- ### the real config section is supposed to be here...
- if {[info exists configs_file]} {
- if {[file isfile "$configs_file"] == 1} {
- source $configs_file
- putlog "::cims:: configs file '$configs_file' loaded."
- }
- }
- ############# CONFIG SHOULD NOW BE LOADED ONTO THE MANY VARIABLES ##############
- # pls hands away again: starting up just defined configs ...
- putlog "::cims:: = Messaging Network ($mnet(version)) loaded"
- putlog "::cims:: = as master, reload current net-configs with .cims_reload"
- putlog "::cims:: = do .rehash and .cims_reload if you defined a new net-config."
- if {$mnet_cfg_reload_interval >= 90} {
- if {![info exists mnet_netconfig_timer]} {
- set mnet_configtimer_set 1
- ::cims::interval_conf
- # this one loops
- }
- } else {
- if {[info exists mnet_netconfig_timer]} {
- set mnet_configtimer_set 0
- killtimer $mnet_netconfig_timer
- unset mnet_netconfig_timer
- }
- set mnet_cfg_reload_interval 0
- ::cims::clean_netconfig
- ::cims::netconfigload
- }
- }
|