################################################################################################
### Feb 06 1999 ################################################################################
################################################################################################
####                                                                                        ####
####  ICQ-drop Ver 1.0  ^DaRk^ on EFnet (Darkbringer@Rocketmail.com) (Edited by Xanith)     ####
####       For Eggdrop 1.3.*                                                                ####
####       as always: the code IS sloppy since im teaching myself TCL as i go...            ####
####       learned another 30 or so new commands while making this script heh               ####
####                                                                                        ####
####  This script is simple in theroy (took me forever to make it actually work outside of  ####
####       Theroy though) the bot is able to create a raw socket to ICQ's web server and    ####
####       post to their CGI exactly (almost) as one would to submit a WWPager message.     ####
####       people are able to have the bot send you ICQ messages when youre not on IRC.     ####
####       the possibilities with this script are virtualy limitless depending on what you  ####
####       wish to be notified about. the only requirements are that you run a slightly     ####
####       edited userinfo1.0.tcl <included> (to add the ICQ field in XTRA) and that you    ####
####       and/or any other user on the bot defines their ICQ UIN# with the .icq <UIN#>     ####
####       command.                                                                         ####
################################################################################################

################################################################################################
####                                                                                        ####
####  syntax: /msg <bot> icqsend <recipient> <message>                                      ####
####     DCC: .icqsend <recipient> <message>                                                ####
####                                                                                        ####
################################################################################################

################################################################################################
####                                                                                        ####
####  Extra thanks to Gecko and Noob from #TCL who helped me ALOT with the sockets and      ####
####       regsub commands, and never once losing patients with my constant questions (I    ####
####       really DO know how to add in TCL, i just temporarily forgot)                     ####
####                                                                                        ####
####  Greetz to my bros ReJeCt-, DarKni9hT, _Tenchi_, and Frmbob                            ####
####                                                                                        ####
####  Still much hate to reddog`` who still holds my chan :/                                ####
####                                                                                        ####
################################################################################################
################################################################################################
#
# - If you use/edit/rip/sell my code, at LEAST gimme credit for it -
#
bind dcc - icqsend sendicqdcc
bind msg - icqsend sendicqmsg
#noob and gecko
proc sendicqdcc {hand idx args} {
global botnick
set args [lindex $args 0]
set whom [lindex $args 0]
set msg [lrange $args 1 end]
regsub -all " " $msg + mssg
if {[getuser $whom XTRA ICQ] == "" } {
putdcc $idx "no ICQ # for $whom registered.. (make sure you have the userfile modified to hold an ICQ field"
return 0
}
set icq [getuser $whom XTRA ICQ ] 
set head "$hand ($botnick)"
foreach n [channels] {
if {[getchanhost $hand $n] != ""} { 
set host [getchanhost $hand $n]
set chan $n
}
}
if { $chan == ""} { set host "*!*@*unknown" }

regsub -all " " $head + hed
set body $hed
append body $mssg
set var $body
append var $hand
set chan $host
append var $chan
append var $hand

set l [string length $var]
set ln [expr $l + 41]
go_connect $chan $body $icq $ln $mssg $hed $hand
return 1
}

proc sendicqmsg {hand uhost nick args} {
global botnick
set args [lindex $args 0]
set whom [lindex $args 0]
set msg [lrange $args 1 end]
regsub -all " " $msg + mssg
if {[validuser $whom] == 0 } {
putserv "PRIVMSG $nick :no user by that name, sorry"
}
if {[getuser $whom XTRA ICQ] == "" } {
putserv "PRIVMSG $nick :no ICQ # for $whom registered.. "
return 0
}
set icq [getuser $whom XTRA ICQ ] 
set head "$nick ($botnick)"
set chan $uhost
regsub -all " " $head + hed
set body $hed
append body $mssg
set var $body
append var $hand
append var $chan
append var $botnick
set l [string length $var]
set ln [expr $l + 41]
go_connect $chan $body $icq $ln $mssg $hed $hand
putserv "PRIVMSG $nick :ICQ message sent to $whom"
return 1
}


### sock proc: Gecko's idea (i had thought to use putdcc)
### but this works much better than putdcc
proc go_connect {chan body icq ln mssg hed hand} {
global botnick
global $chan
global $body
global $icq
global $ln 
global $mssg
global $hed
global $hand
if [catch {socket "wwp.icq.com" 80} sockresult] {
putlog "Could not connect:  $sockresult"

return 0
}
putlog "Socket $sockresult was opened"
fconfigure $sockresult -translation auto -buffering line -blocking 0
puts $sockresult "POST /scripts/WWPMsg.dll HTTP/1.1"
puts $sockresult "Accept: application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"
puts $sockresult "Referer: http://nothing.com"
puts $sockresult "Accept-Language: en-u"
puts $sockresult "s"
puts $sockresult "Content-Type: application/x-www-form-urlencoded"
puts $sockresult "Accept-Encoding: gzip, deflate"
puts $sockresult "User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)"
puts $sockresult "Host: x"
puts $sockresult "Content-Length: $ln"
puts $sockresult "Connection: Keep-Alive"
puts $sockresult ""
puts $sockresult "subject=$hed&to=$icq&from=$hand&fromemail=$chan&body=$mssg&x=90&y=50"
close $sockresult
return 1
}
putlog "ICQ-Drop v1.0 - ^DaRk^ on EFnet Loaded (Darkbringer@Rocketmail.com)"