123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830 |
- # 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.
- 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 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
- # 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.014unique-users"
- set mnet_max_history 8
- set mnet(reached) "0"
- set mnet(reached_channels) "0"
- 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]
-
- 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} {
- putlog "::cims:: put_bot: + a message delivered to $botnetnick."
-
- 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
- }
- } 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 [::putils::kill_spaces [join [lindex $rec_data 2]]]
- #set rec_nickname [::putils::kill_spaces clean_txt [join [lrange [split $rec_data] 4 end]]]
- set rec_channel [::putils::kill_spaces [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
- 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!
- ::cims::put_bot $rec_botnick "mnet_answer $network $name $rec_channel $users $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 STRING in rec_data! convert into list!
- set rec_data [split $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]]
- # 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 mnet
- 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. :)
- ::putils::put_nick $nick "::cims:: Not allowed to send messages. Reason: $reason"
- 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
- }
- proc ::cims::reply_timeout {name chan} {
- 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}]
- # 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 drfte 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"
- ::putils::put_local_msg ${chan} "::cims:: Message sent to $chan_cnt channels, reaching $user_cnt unique users."
- }
- ### public reachable commands
- proc ::cims::history_frequency {nick mask hand chan text} {
- # proc triggered by specified $prefix_history
- variable mnet
- 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 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.
- putlog "mnet_history: $com triggered by $nick in $chan"
- if {[info exists mnet_histories($network,$name)] == 1} {
- set list_length [llength $mnet_histories($network,$name)]
- if {$list_length >= 1} {
- set msg "::cims:: last $mnet_max_history messages of $network $name:"
- ::putils::put_nick $nick $msg
-
- set x_count 0
- foreach {msg} $mnet_histories($network,$name) {
- incr x_count
- set backwards_x [expr $list_length - $x_count]
- set msg [lindex $mnet_histories($network,$name) $backwards_x]
- ::putils::put_nick $nick "($x_count/$list_length) $msg"
-
- }
- }
- } else {
- ::putils::put_nick $nick "::cims:: no accumulated history for $network $name"
- }
- }
- proc ::cims::enable_frequency {nick mask hand chan text} {
- # proc triggered by specified $prefix_enable
- variable mnet
- 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 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.
- putlog "mnet_freq_status: before $mnet_freqs_onoff($name,$chan)"
- set mnet_freqs_onoff($name,$chan) 1
- putlog "mnet_freq_status: now $mnet_freqs_onoff($name,$chan)"
- ::putils::put_local_msg $chan "::cims:: $name _output_ enabled for $chan"
- }
- proc ::cims::disable_frequency {nick mask hand chan text} {
- # proc triggered by specified $prefix_enable
- variable mnet
- 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 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.
-
- putlog "mnet_freq_status: before $mnet_freqs_onoff($name,$chan)"
- set mnet_freqs_onoff($name,$chan) 0
- putlog "mnet_freq_status: now $mnet_freqs_onoff($name,$chan)"
-
- ::putils::put_local_msg $chan "::cims:: $name _output_ disabled for $chan"
-
- }
- proc ::cims::toggle_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
- 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 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.
-
- putlog "mnet_freq_status: toggle $mnet_freqs_onoff($name,$chan)"
- if {$mnet_freqs_onoff($name,$chan) == 1} {
- set mnet_freqs_onoff($name,$chan) 0
- ::putils::put_local_msg $chan "::cims:: toggling ${name} _output_, now disabled for ${chan}"
- } else {
- set mnet_freqs_onoff($name,$chan) 1
- ::putils::put_local_msg $chan "::cims:: toggling ${name} _output_, now enabled for ${chan}"
- }
- putlog "mnet_freq_status: toggle now $mnet_freqs_onoff($name,$chan)"
-
- # frequency toggled .. :)
-
- }
- #::cims::enable_color
- proc ::cims::enable_color {nick mask hand chan text} {
- # proc triggered by specified $prefix_enable
- variable mnet
- 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 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.
- if {$mnet_colors_optional($network) != 1} {
- return 0
- }
- putlog "mnet_color_status: before $mnet_colors_onoff($name,$chan)"
- set mnet_colors_onoff($name,$chan) 1
- putlog "mnet_color_status: now $mnet_colors_onoff($name,$chan)"
-
- ::putils::put_local_msg $chan "::cims:: $name _coloroutput_ enabled for $chan"
- }
- #::cims::disable_color
- proc ::cims::disable_color {nick mask hand chan text} {
- # proc triggered by specified $prefix_enable
- variable mnet
- 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 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.
- if {$mnet_colors_optional($network) != 1} {
- return 0
- }
- putlog "mnet_color_status: before $mnet_colors_onoff($name,$chan)"
- set mnet_colors_onoff($name,$chan) 0
- putlog "mnet_color_status: now $mnet_colors_onoff($name,$chan)"
-
- ::putils::put_local_msg $chan "::cims:: $name _coloroutput_ disabled for $chan"
- }
- #::cims::toggle_color
- proc ::cims::toggle_color {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
- 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.
- if {$mnet_colors_optional($network) != 1} {
- return 0
- }
-
- putlog "mnet_color_status: toggle $mnet_colors_onoff($name,$chan)"
- if {$mnet_colors_onoff($name,$chan) == 1} {
- set mnet_colors_onoff($name,$chan) 0
- ::putils::put_local_msg $chan "::cims:: toggling ${name} _coloroutput_, now disabled for ${chan}"
- } else {
- set mnet_colors_onoff($name,$chan) 1
- ::putils::put_local_msg $chan "::cims:: toggling ${name} _coloroutput_, now enabled for ${chan}"
- }
- putlog "mnet_color_status: toggle now $mnet_colors_onoff($name,$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::messaging_public {nick mask hand chan text} {
- # proc triggered by specified $prefix and calling the following (internal) one
- variable mnet
- variable mnet_channels
- variable mnet_bots
- variable mnet_networks_by_prefix
- variable mnet_colors
- variable mnet_freqs
- variable mnet_freqs_onoff
- variable mnet_delay
- variable mnet_histories
- variable mnet_reached_users
- variable mnet_reached_userlist
- variable mnet_reached_chans
- 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 name [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 $name $prefix $nick $mask $chan]
- if {$allowed == 0} {
- return 0
- }
- # now generally allowed.
- # is user banned from sending??
- set user_allowed [::cims::allowed_user $network $name $prefix $nick $mask $chan]
- if {$user_allowed == 0} {
- return 0
- }
- # user has not been matched against banlist. So he's allowed here.
-
-
- # cleaning given strings...
- set text [::cims::clean_txt $text]
- # check here if we have some text or not.. :)
- if {$text == "" || $text == "{}"} {
-
- # output some help:
- putlog "::cims:: = gave him some help"
- ::putils::put_local_msg $chan $help
- } else {
- # ok, now send! (if timer allows it)
-
- ### 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".
- # NO break.. for debug :)) arf
- return 0
- }
- # 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]
- ### end spamprotection
-
- ## HE IS SENDING NOW!
-
- set mnet(reached) "0"
- set mnet(reached_channels) "0"
- # reset stats .. because he is just freshly sending
- set mnet_reached_users($name,$chan) "0"
- set mnet_reached_userlist($name,$chan) ""
- set mnet_reached_chans($name,$chan) "0"
- ::cims::history_queue $network,$name $nick $chan $text
-
- # send them first, we await a reply!
- set proper_botnick [::cims::proper_botnick ${botnet-nick}]
- # putlog "{botnet-nick} huar: $proper_botnick"
- # single sends TO ALL REMOTE BOTS with their remote CHANNELS...
- # let's see which mode for sending is used...
- 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: $name: $text"
- # safe put_bot function..
- ::cims::put_bot $_botnick "mnet_receive $network $name $nick $chan $text"
-
- }
- }
-
- # SEND TO ALL OWN CHANNELS...
- # send to all own channels, except to the channel the message originating from:
- 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($name,$_ownchan) == 1} {
-
- # userstats local
- set mnet_reached_users($name,$chan) [::cims::chanstat_users $_ownchan $mnet_reached_users($name,$chan)]
- set mnet_reached_userlist($name,$chan) [::cims::chanstat_userlist $_ownchan $mnet_reached_userlist($name,$chan)]
-
- putlog "::cims:: * Localcounting up $_ownchan users: $mnet_reached_users($name,$chan)"
-
- # channel count local
- incr mnet_reached_chans($name,$chan)
-
- ::cims::put_local_netmessage $network $name $_ownchan $nick $chan $text
- } else {
- putlog "::cims:: + $_ownchan has disabled $name output"
- }
- } else {
- putlog "::cims:: + Can't send a local message to '$_ownchan' since I am not there."
- }
- }
- }
-
- # wait here some more! (10 seconds with utimer)
- utimer 5 "::cims::reply_timeout $name $chan"
- # 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".
-
- }
- }
- ### 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 "name: $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
- # $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
- putlog "debug:: $mnet_http_config"
- # 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]} {
- 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
- }
- }
|