Posted to tcl by Rothgar at Tue Dec 11 09:52:08 GMT 2007view raw
- # Constants
- set ::constants [list]
- # Constant Handling
- if {[info procs "proc"] == ""} {
- rename proc _proc
- _proc const {name value} {
- global constants;
- lappend constants $name $value;
- }
- _proc proc {name argpat body} {
- global constants;
- _proc $name $argpat [string map $constants $body];
- }
- }
- const PUTBOT_MAX_LEN 400;
- proc dcputbotlong {botnick arg} {
- set dcpbl_function "DCPBL"
- set len [string length $arg];
- set arg "$len $arg";
- set maxlen [expr PUTBOT_MAX_LEN - [string length $dcpbl_function] - 1];
- putlog "LENGTH: $len";
- putlog "MAXLEN: $maxlen";
- if {$len>$maxlen} {
- for {set i 0} {$i<$len} {incr i} {
- if {$botnick == "*"} {
- putallbots "$dcpbl_function [string range $arg $i [incr $maxlen]]"
- } else {
- putbot $botnick "$dcpbl_function [string range $arg $i [incr $maxlen]]"
- }
- }
- } else {
- if {$botnick == "*"} {
- putallbots "$dcpbl_function [lindex $arg]"
- } else {
- putbot $botnick "$dcpbl_function [lindex $arg]"
- }
- }
- return 1;
- }
- proc dcputallbotslong {arg} {
- dcputbotlong "*" $arg;
- return 1;
- }
- # Constants
- set ::constants [list]
- # Constant Handling
- if {[info procs "proc"] == ""} {
- rename proc _proc
- _proc const {name value} {
- global constants;
- lappend constants $name $value;
- }
- _proc proc {name argpat body} {
- global constants;
- _proc $name $argpat [string map $constants $body];
- }
- }
- const PUTBOT_MAX_LEN 400;
- bind bot - DCPBL dcgetbotlong;
- 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 gbllength 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.";
- return 1;
- }
- if {[scan $arg "%s%n" gblfunction off]==2 && [info proc $gblfunction] == $gblfunction} {
- set arg [string range $arg [incr off] end];
- set gbllength [expr $gbllength - $off];
- putlog "FUNCTION: $gblfunction";
- putlog "WTF3: $arg";
- } else {
- if {[info exists gbllength]} {
- unset gbllength;
- }
- if {[info exists gblfunction]} {
- unset gblfunction;
- }
- putlog "GetBotLong Error from $botnick - invalid function specified in first message.";
- return 1;
- }
- if {$gbllength <= PUTBOT_MAX_LEN} {
- # single message
- putlog "COMPLETE?";
- unset gbllength;
- $gblfunction $botnick DCPBL $arg;
- } else {
- # multipart - store data and wait for more
- set gblbuffer $arg;
- }
- }
- }
- TEST COMMAND:
- dcputallbotslong "RAWR 1111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222";