Code: Select all
namespace eval steam {
variable search "!steamid"
variable flag "-|-"
variable hostname "czleague.org"
variable urlstring "/index.php?div=&action=steamidsearch&submit=1"
variable urldivision "/index.php?div=&action=viewuser&id="
proc steam_search {nick host hand chan arg} {
variable hostname
if {[regexp {^[\x20]{0,100}([0-9]{1,100})[\x20]{0,100}$} $arg -> id]} {
if {[catch {socket -async $hostname 80} s]} {
putserv "NOTICE $nick :Sorry couldn't connect to the webserver."
} else {
fileevent $s writable [list [namespace current]::steam_callback $s $nick $chan $id]
}
} else {
putserv "NOTICE $nick :Invalid steam id."
}
}
proc steam_callback {s nick chan sid} {
variable urlstring; variable hostname
if {[string equal {} [fconfigure $s -error]]} {
fconfigure $s -translation crlf
flush $s
puts $s "POST $urlstring HTTP/1.1"
puts $s "Host: $hostname"
puts $s "Connection: Close"
puts $s "User-Agent: ofloo.net scripts"
puts $s "Content-Type: application/x-www-form-urlencoded"
puts $s "Content-Length: [expr 8 + [string bytelength $sid]]"
puts $s "Referer: ${hostname}${urlstring}\n"
puts $s "steamid=$sid"
flush $s
set switch 0
while {![eof $s]} {
gets $s x
if {[regexp -nocase {<td valign="top"><a href="index.php\?div=&action=viewuser&id=([0-9]{1,100})&PHPSESSID=[0-9a-f]{32}">View</a></td>} $x -> id]} {
break
}
}
} else {
putserv "NOTICE $nick :Sorry couldn't connect to the webserver."
}
close $s
if {[info exists id]} {
if {[catch {socket -async $hostname 80} s]} {
putserv "NOTICE $nick :Sorry couldn't connect to the webserver."
} else {
fileevent $s writable [list [namespace current]::division_callback $s $nick $chan $sid $id]
}
} else {
putserv "NOTICE $nick :No results found for ${sid}."
}
}
proc division_callback {s nick chan sid id} {
variable urldivision; variable hostname
if {[string equal {} [fconfigure $s -error]]} {
puts $s "GET ${urldivision}${id} HTTP/1.1"
puts $s "Host: $hostname"
puts $s "Connection: Close"
puts $s "User-Agent: ofloo.net scripts"
puts $s "\n\r"
flush $s
while {![eof $s]} {
gets $s x
regexp -nocase {<b>Name:</b> (.*?)<br />} $x -> name
regexp -nocase {<b>Alias:</b> (.*?)<br />} $x -> alias
regexp -nocase {<b>SteamID:</b> ([0-9]{1,100}:[0-9]{1,100}:[0-9]{1,100})<br />} $x -> steamid
if {[regexp -nocase {<b>Team:</b> <a href="(index.php\?div=czli&action=viewteam&id=[0-9]{1,100}&PHPSESSID=[0-9a-f]{32})">(.*?)</a><br /><br />} $x -> turl team]} {
set div "invite"
break
}
if {[regexp -nocase {<b>Team:</b> <a href="(index.php\?div=czlo&action=viewteam&id=[0-9]{1,100}&PHPSESSID=[0-9a-f]{32})">(.*?)</a><br /><br />} $x -> turl team]} {
set div "open"
break
}
if {[regexp -nocase {<b>Team:</b> <a href="(index.php\?div=czlm&action=viewteam&id=[0-9]{1,100}&PHPSESSID=[0-9a-f]{32})">(.*?)</a><br /><br />} $x -> turl team]} {
set div "main"
break
}
}
if {[info exists name] && [info exists alias] && [info exists steamid] && [info exists team]} {
putserv "NOTICE $nick :CZL\($steamid\) Name: $name Alias: $alias Team: $team\($div\) MoreInfo: http://$hostname/$turl"
} else {
putserv "NOTICE $nick :Sorry $nick no results for ${sid}."
}
} else {
putserv "NOTICE $nick :Sorry couldn't connect to the webserver."
}
close $s
}
bind pub $flag $search [namespace current]::steam_search
}