Posted to tcl by Rothgar at Sun Dec 09 11:47:24 GMT 2007view raw

  1. proc dcputbotlong {botnick arg} {
  2. set len [string len $arg];
  3. set arg "$len $arg"
  4. if {$len>396} {
  5. for {set i 0} {$i<$len} {incr i} {
  6. if {$botnick == "*"} {
  7. putallbots "DCPBL [string range $arg $i [incr i 395]]"
  8. } else {
  9. putbot $botnick "DCPBL [string range $arg $i [incr i 395]]"
  10. }
  11. }
  12. } else {
  13. if {$botnick == "*"} {
  14. putallbots "DCPBL [lindex $arg]"
  15. } else {
  16. putbot $botnick "DCPBL [lindex $arg]"
  17. }
  18. }
  19. return 1;
  20. }
  21.  
  22. proc dcputallbotslong {arg} {
  23. dcputbotlong "*" $arg;
  24. return 1;
  25. }
  26.  
  27.  
  28.  
  29. proc dcgetbotlong {botnick botnet_command arg} {
  30. putlog "WTF: $arg";
  31. upvar #0 putbotlong_buffer($botnick) gblbuffer
  32. upvar #0 putbotlong_length($botnick) gbllength
  33. upvar #0 putbotlong_function($botnick) gblfunction
  34. if {[info exists gblbuffer]} {
  35. # some more of a multipart message
  36. if {[string len [append gblbuffer $arg]]>=$gbllength} {
  37. # multipart complete
  38. putlog "COMPLETE FULL?";
  39. putlog "WTF4: $gblbuffer";
  40. putlog "$gblfunction $botnick DCPBL $gblbuffer";
  41. $gblfunction $botnick DCPBL $gblbuffer;
  42. unset gblbuffer;
  43. unset gbllength;
  44. unset gblfunction;
  45. }
  46. } else {
  47. # first and possibly only part...
  48. if {[scan $arg "%i%n" gbllength off]==2} {
  49. set arg [string range $arg [incr off] end];
  50. putlog "LEN: $gbllength";
  51. putlog "WTF2: $arg";
  52. } else {
  53. if {[info exists gbllength]} {
  54. unset gbllength;
  55. }
  56.  
  57. putlog "GetBotLong Error from $botnick - expected length at start of first message."
  58. #unset gblbuffer;
  59. unset gbllength;
  60. unset gblfunction;
  61. }
  62.  
  63. if {[scan $arg "%s%n" gblfunction off]==2} {
  64. set arg [string range $arg [incr off] end];
  65. set gbllength [expr $gbllength - $off];
  66. putlog "LEN: $gbllength";
  67. putlog "FUNCTION: $gblfunction";
  68. putlog "WTF3: $arg";
  69. } else {
  70. if {[info exists gbllength]} {
  71. unset gbllength;
  72. unset gblfunction;
  73. }
  74.  
  75. putlog "GetBotLong Error from $botnick - invalid function specified in first message."
  76. unset gblbuffer;
  77. unset gbllength;
  78. unset gblfunction;
  79. }
  80.  
  81. if {[string len $arg] == $gbllength} {
  82. # single message
  83. putlog "COMPLETE?";
  84. unset gbllength;
  85. $gblfunction $botnick DCPBL $arg;
  86. } else {
  87. # multipart - store data and wait for more
  88. set gblbuffer $arg;
  89. }
  90. }
  91. }

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.