Posted to tcl by randorn at Fri Dec 07 14:32:55 GMT 2007view raw
- bind bot b L gotbotlong
- proc gotbotlong {bot L arg} {
- upvar #0 putbotlong_buffer($bot) buffer
- upvar #0 putbotlong_length($bot) length
- if {[info exists buffer]} {# some more of a multipart message
- if {[string len [append buffer $arg]]>=$length} {
- # multipart complete
- yourProcUsingTheRecievedData $bot $buffer[unset buffer][unset length]
- }
- } else {# first and possibly only part...
- if {[scan $arg "%i%n" length off]!=2} {
- if {[info exists length]} {unset length}
- putlog "gotbotlong Error from $bot - expected length at start of first message."
- } elseif {$length==0} {# single message
- unset length
- yourProcUsingTheRecievedData $bot [string range $arg [incr off] end]
- } else {# multipart - store data and wait for more
- set buffer [string range $arg [incr off] end]
- }
- }
- }
- proc putbotlong {bot arg} {
- if {[set len [string len $arg]]>396} {
- set arg "$len $arg"
- set j [string len $arg]
- for {set i 0} {$i<$j} {incr i} {
- putbot $bot "L [string range $arg $i [incr i 397]]"
- }
- } else {
- putbot $bot "L 0 $arg"
- }
- }
- proc yourProcUsingTheRecievedData {bot arg} {
- putlog "Recieved [string bytelen $arg] bytes from $bot"
- }
Comments
Posted by randorn at Fri Dec 07 14:34:44 GMT 2007 [text] [code]
To prevent errors if a bot gets disconnected from the botnet in the middle of a long message, create a cleanup proc that is invoked when bots link.
Posted by Rothgar at Sat Dec 08 02:49:44 GMT 2007 [text] [code]
Ammended putbotlong function fixed a length issue and created botnick "*" for putallbots: proc putbotlong {botnick arg} { set len [string len $arg]; if {$len>396} { set arg "$len $arg" for {set i 0} {$i<$len} {incr i} { if {$botnick == "*"} { putallbots "PBL [string range $arg $i [incr i 395]]" } else { putbot $botnick "PBL [string range $arg $i [incr i 395]]" } } } else { if {$botnick == "*"} { putallbots "PBL 0 $arg" } else { putbot $botnick "PBL 0 $arg" } } }