Posted to tcl by Rothgar at Sun Dec 09 11:47:24 GMT 2007view raw
- proc dcputbotlong {botnick arg} {
- set len [string len $arg];
- set arg "$len $arg"
- if {$len>396} {
- for {set i 0} {$i<$len} {incr i} {
- if {$botnick == "*"} {
- putallbots "DCPBL [string range $arg $i [incr i 395]]"
- } else {
- putbot $botnick "DCPBL [string range $arg $i [incr i 395]]"
- }
- }
- } else {
- if {$botnick == "*"} {
- putallbots "DCPBL [lindex $arg]"
- } else {
- putbot $botnick "DCPBL [lindex $arg]"
- }
- }
- return 1;
- }
-
- proc dcputallbotslong {arg} {
- dcputbotlong "*" $arg;
- return 1;
- }
-
-
-
- proc dcgetbotlong {botnick botnet_command arg} {
- putlog "WTF: $arg";
- upvar #0 putbotlong_buffer($botnick) gblbuffer
- upvar #0 putbotlong_length($botnick) gbllength
- upvar #0 putbotlong_function($botnick) gblfunction
- if {[info exists gblbuffer]} {
- # some more of a multipart message
- if {[string len [append gblbuffer $arg]]>=$gbllength} {
- # multipart complete
- putlog "COMPLETE FULL?";
- putlog "WTF4: $gblbuffer";
- putlog "$gblfunction $botnick DCPBL $gblbuffer";
- $gblfunction $botnick DCPBL $gblbuffer;
- unset gblbuffer;
- unset gbllength;
- unset gblfunction;
- }
- } else {
- # first and possibly only part...
- if {[scan $arg "%i%n" gbllength off]==2} {
- set arg [string range $arg [incr off] end];
- putlog "LEN: $gbllength";
- putlog "WTF2: $arg";
- } else {
- if {[info exists gbllength]} {
- unset gbllength;
- }
-
- putlog "GetBotLong Error from $botnick - expected length at start of first message."
- #unset gblbuffer;
- unset gbllength;
- unset gblfunction;
- }
-
- if {[scan $arg "%s%n" gblfunction off]==2} {
- set arg [string range $arg [incr off] end];
- set gbllength [expr $gbllength - $off];
- putlog "LEN: $gbllength";
- putlog "FUNCTION: $gblfunction";
- putlog "WTF3: $arg";
- } else {
- if {[info exists gbllength]} {
- unset gbllength;
- unset gblfunction;
- }
-
- putlog "GetBotLong Error from $botnick - invalid function specified in first message."
- unset gblbuffer;
- unset gbllength;
- unset gblfunction;
- }
-
- if {[string len $arg] == $gbllength} {
- # single message
- putlog "COMPLETE?";
- unset gbllength;
- $gblfunction $botnick DCPBL $arg;
- } else {
- # multipart - store data and wait for more
- set gblbuffer $arg;
- }
- }
- }
Comments
Posted by Rothgar at Sun Dec 09 11:48:39 GMT 2007 [text] [code]
Need to make DCGetBotLong more threaded? Getting strings mixed up when two commands are executed for example.