Posted to tcl by randorn at Fri Dec 07 14:32:55 GMT 2007view raw

  1. bind bot b L gotbotlong
  2. proc gotbotlong {bot L arg} {
  3. upvar #0 putbotlong_buffer($bot) buffer
  4. upvar #0 putbotlong_length($bot) length
  5. if {[info exists buffer]} {# some more of a multipart message
  6. if {[string len [append buffer $arg]]>=$length} {
  7. # multipart complete
  8. yourProcUsingTheRecievedData $bot $buffer[unset buffer][unset length]
  9. }
  10. } else {# first and possibly only part...
  11. if {[scan $arg "%i%n" length off]!=2} {
  12. if {[info exists length]} {unset length}
  13. putlog "gotbotlong Error from $bot - expected length at start of first message."
  14. } elseif {$length==0} {# single message
  15. unset length
  16. yourProcUsingTheRecievedData $bot [string range $arg [incr off] end]
  17. } else {# multipart - store data and wait for more
  18. set buffer [string range $arg [incr off] end]
  19. }
  20. }
  21. }
  22. proc putbotlong {bot arg} {
  23. if {[set len [string len $arg]]>396} {
  24. set arg "$len $arg"
  25. set j [string len $arg]
  26. for {set i 0} {$i<$j} {incr i} {
  27. putbot $bot "L [string range $arg $i [incr i 397]]"
  28. }
  29. } else {
  30. putbot $bot "L 0 $arg"
  31. }
  32. }
  33. proc yourProcUsingTheRecievedData {bot arg} {
  34. putlog "Recieved [string bytelen $arg] bytes from $bot"
  35. }

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" } } }