Posted to tcl by Rothgar at Tue Dec 11 09:52:08 GMT 2007view raw

  1. # Constants
  2. set ::constants [list]
  3.  
  4. # Constant Handling
  5. if {[info procs "proc"] == ""} {
  6. rename proc _proc
  7.  
  8. _proc const {name value} {
  9. global constants;
  10.  
  11. lappend constants $name $value;
  12. }
  13.  
  14. _proc proc {name argpat body} {
  15. global constants;
  16. _proc $name $argpat [string map $constants $body];
  17. }
  18. }
  19.  
  20. const PUTBOT_MAX_LEN 400;
  21.  
  22. proc dcputbotlong {botnick arg} {
  23. set dcpbl_function "DCPBL"
  24. set len [string length $arg];
  25. set arg "$len $arg";
  26.  
  27. set maxlen [expr PUTBOT_MAX_LEN - [string length $dcpbl_function] - 1];
  28. putlog "LENGTH: $len";
  29. putlog "MAXLEN: $maxlen";
  30.  
  31. if {$len>$maxlen} {
  32. for {set i 0} {$i<$len} {incr i} {
  33. if {$botnick == "*"} {
  34. putallbots "$dcpbl_function [string range $arg $i [incr $maxlen]]"
  35. } else {
  36. putbot $botnick "$dcpbl_function [string range $arg $i [incr $maxlen]]"
  37. }
  38. }
  39. } else {
  40. if {$botnick == "*"} {
  41. putallbots "$dcpbl_function [lindex $arg]"
  42. } else {
  43. putbot $botnick "$dcpbl_function [lindex $arg]"
  44. }
  45. }
  46. return 1;
  47. }
  48.  
  49. proc dcputallbotslong {arg} {
  50. dcputbotlong "*" $arg;
  51. return 1;
  52. }
  53.  
  54.  
  55.  
  56. # Constants
  57. set ::constants [list]
  58.  
  59.  
  60. # Constant Handling
  61. if {[info procs "proc"] == ""} {
  62. rename proc _proc
  63.  
  64. _proc const {name value} {
  65. global constants;
  66.  
  67. lappend constants $name $value;
  68. }
  69.  
  70. _proc proc {name argpat body} {
  71. global constants;
  72. _proc $name $argpat [string map $constants $body];
  73. }
  74. }
  75.  
  76.  
  77. const PUTBOT_MAX_LEN 400;
  78.  
  79.  
  80. bind bot - DCPBL dcgetbotlong;
  81.  
  82.  
  83. proc dcgetbotlong {botnick botnet_command arg} {
  84. putlog "WTF: $arg";
  85. upvar #0 putbotlong_buffer($botnick) gblbuffer
  86. upvar #0 putbotlong_length($botnick) gbllength
  87. upvar #0 putbotlong_function($botnick) gblfunction
  88. if {[info exists gblbuffer]} {
  89. # some more of a multipart message
  90. if {[string len [append gblbuffer $arg]]>=$gbllength} {
  91. # multipart complete
  92. putlog "COMPLETE FULL?";
  93. putlog "WTF4: $gblbuffer";
  94. putlog "$gblfunction $botnick DCPBL $gblbuffer";
  95. $gblfunction $botnick DCPBL $gblbuffer[unset gblbuffer gbllength gblfunction];
  96. }
  97. } else {
  98. # first and possibly only part...
  99. if {[scan $arg "%i%n" gbllength off]==2} {
  100. set arg [string range $arg [incr off] end];
  101. putlog "LEN: $gbllength";
  102. putlog "WTF2: $arg";
  103. } else {
  104. if {[info exists gbllength]} {
  105. unset gbllength;
  106. }
  107.  
  108. putlog "GetBotLong Error from $botnick - expected length at start of first message.";
  109. return 1;
  110. }
  111.  
  112. if {[scan $arg "%s%n" gblfunction off]==2 && [info proc $gblfunction] == $gblfunction} {
  113. set arg [string range $arg [incr off] end];
  114. set gbllength [expr $gbllength - $off];
  115. putlog "FUNCTION: $gblfunction";
  116. putlog "WTF3: $arg";
  117. } else {
  118. if {[info exists gbllength]} {
  119. unset gbllength;
  120. }
  121. if {[info exists gblfunction]} {
  122. unset gblfunction;
  123. }
  124.  
  125. putlog "GetBotLong Error from $botnick - invalid function specified in first message.";
  126. return 1;
  127. }
  128.  
  129. if {$gbllength <= PUTBOT_MAX_LEN} {
  130. # single message
  131. putlog "COMPLETE?";
  132. unset gbllength;
  133. $gblfunction $botnick DCPBL $arg;
  134. } else {
  135. # multipart - store data and wait for more
  136. set gblbuffer $arg;
  137. }
  138. }
  139. }
  140.  
  141.  
  142. TEST COMMAND:
  143. dcputallbotslong "RAWR 1111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222";
  144.