|
Joined: Jun 2004
Posts: 33
Ameglian cow
|
OP
Ameglian cow
Joined: Jun 2004
Posts: 33 |
Hey, ive had some experience with mIRC scripting but none with sockets, i run a server and i need to make a script for my bot that, with a remote, will put the html code into a variable and then parse it searching for multiple lines of text. Any help will be much appreciated.
Thanks Xidus
|
|
|
|
Joined: Jun 2004
Posts: 33
Ameglian cow
|
OP
Ameglian cow
Joined: Jun 2004
Posts: 33 |
Sorry about double post but edit time expired, this is my code so far /xile { /sockopen Xile http://xilero.net 80
on *:sockopen:Xile:{
sockwrite -n $socketname GET /forumlist.php HTTP/1.1
sockwrite -n $socketname Host: xilero.net $+ $crlf $+ $crlf
}
}
ON *:sockread:Xile:{
if ($sockerr) {
echo -a Error.
halt
}
else {
var %temptext
sockread %temptext
if (<table><tr><td><span style="color: black" >XiLeRO Login:</span></td><td><span style="color: red ; font-weight: 700" ><b>Online</b></span>) {
echo XileRO Login: Online
}
if (<table><tr><td><span style="color: black" >XiLeRO Login:</span></td><td><span style="color: red ; font-weight: 700" ><b>Offline</b></span>) {
echo XileRO Login: Offline
}
if (</td></tr><tr><td><span style="color: black" >XiLeRO Char:</span></td><td><span style="color: red ; font-weight: 700" ><b>Online</b></span>) {
echo XileRO Char: Online
}
if (</td></tr><tr><td><span style="color: black" >XiLeRO Char:</span></td><td><span style="color: red ; font-weight: 700" ><b>Offline</b></span>) {
echo XileRO Char: Offline
}
if (</td></tr><tr><td><span style="color: black" >XiLeRO Map:</span></td><td><span style="color: red ; font-weight: 700" ><b>Online</b></span>) {
echo XileRO Map: Online
}
if (</td></tr><tr><td><span style="color: black" >XiLeRO Map:</span></td><td><span style="color: red ; font-weight: 700" ><b>Offline</b></span>) {
echo XileRO Map: Offline
}
}
}
When i do the command /xile i get the errors * /sockwrite: 'GET' no such socket (line 3, aliases1.ini)
-
*:SOCKREAD:XILE:{ Unknown command
-
|
|
|
|
Joined: Nov 2005
Posts: 104
Vogon poet
|
Vogon poet
Joined: Nov 2005
Posts: 104 |
shouldn't the $socketname be $sockname ? That would explain why it's trying to use GET as the socket instead of the actual socket. I've never really used sockets other than for version checking, but it does make sense to me.
|
|
|
|
Joined: Jun 2004
Posts: 33
Ameglian cow
|
OP
Ameglian cow
Joined: Jun 2004
Posts: 33 |
*hits head* whoops, i still get * /sockwrite: 'GET' no such socket (line 3, aliases1.ini)
-
*:SOCKREAD:XILE:{ Unknown command
-
Though :P Thanks
|
|
|
|
Joined: Nov 2005
Posts: 104
Vogon poet
|
Vogon poet
Joined: Nov 2005
Posts: 104 |
lol, I know this isn't prob. the best method.. but $sock(xile).name should work.
|
|
|
|
Joined: Jun 2004
Posts: 33
Ameglian cow
|
OP
Ameglian cow
Joined: Jun 2004
Posts: 33 |
OK, getting somewhere XD now i get: * /sockwrite: 'Xile' not connected (line 3, aliases1.ini)
-
*:SOCKREAD:XILE:{ Unknown command
-
|
|
|
|
Joined: Nov 2005
Posts: 104
Vogon poet
|
Vogon poet
Joined: Nov 2005
Posts: 104 |
yeah. But I'm sure someone that's familiar with sockets will be on soon, and can offer better help. I was just playing around out of boredom. :-\, but the $sock(xile).name kept from showing me any error messages on the sockwrite.
|
|
|
|
Joined: Nov 2005
Posts: 104
Vogon poet
|
Vogon poet
Joined: Nov 2005
Posts: 104 |
I also noticed that you're missing a closing bracket.
/xile { /sockopen Xile http://xilero.net 80
on *:sockopen:Xile:{
should be
/xile { /sockopen Xile http://xilero.net 80 }
on *:sockopen:Xile:{
' Empashis on the closing bracket on the first line.
|
|
|
|
Joined: Jun 2004
Posts: 33
Ameglian cow
|
OP
Ameglian cow
Joined: Jun 2004
Posts: 33 |
when i do that nothing happens at all
Last edited by Xidus; 21/03/06 11:16 PM.
|
|
|
|
Joined: Dec 2002
Posts: 580
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 580 |
drc4, almost had their finger on the problem...  You can not nest events inside an alias, '/' prefixes can only be used in the aliases section to my knowledge, ALL events must be in remotes...
alias xile {
sockopen Xile http://xilero.net 80
}
on *:sockopen:Xile:{
sockwrite -n $socketname GET /forumlist.php HTTP/1.1
sockwrite -n $socketname Host: xilero.net $+ $crlf $+ $crlf
}
Learning mIRC's syntax first might help you...  /help Remote Scripts /help Aliases
|
|
|
|
Joined: Jun 2004
Posts: 33
Ameglian cow
|
OP
Ameglian cow
Joined: Jun 2004
Posts: 33 |
Ahhh, i see  Now how some reason it thinks that the socket hasn't connected * /sockwrite: 'Xile' not connected (line 5, script1.ini)
|
|
|
|
Joined: Dec 2002
Posts: 580
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 580 |
Odd, SockOpen event shouldn't occur unless the socket was opened... Use the command "/socklist" to view open sockets... Try $sockname instead of $socketname... Also check $sockerr is zero as the first line in *:sockread...
if ($sockerr) {
echo -s SockError $sockname $sockerr
return
}
|
|
|
|
Joined: Jun 2004
Posts: 33
Ameglian cow
|
OP
Ameglian cow
Joined: Jun 2004
Posts: 33 |
Ok, when i do /socklist it says there are no sockets open :P The current code is: alias xile {
sockopen Xile http://xilero.net 80
}
on *:sockopen:Xile:{
sockwrite -n $sock(Xile).name GET /home.php HTTP/1.1
sockwrite -n $sock(Xile).name Host: xilero.net $+ $crlf $+ $crlf
}
ON *:sockread:Xile:{
if ($sockerr) {
echo -s SockError $sockname $sockerr
return
}
else {
var %temptext
sockread %temptext
if (<table><tr><td><span style="color: black" >XiLeRO Login:</span></td><td><span style="color: red ; font-weight: 700" ><b>Online</b></span>) {
echo XileRO Login: Online
}
if (<table><tr><td><span style="color: black" >XiLeRO Login:</span></td><td><span style="color: red ; font-weight: 700" ><b>Offline</b></span>) {
echo XileRO Login: Offline
}
if (</td></tr><tr><td><span style="color: black" >XiLeRO Char:</span></td><td><span style="color: red ; font-weight: 700" ><b>Online</b></span>) {
echo XileRO Char: Online
}
if (</td></tr><tr><td><span style="color: black" >XiLeRO Char:</span></td><td><span style="color: red ; font-weight: 700" ><b>Offline</b></span>) {
echo XileRO Char: Offline
}
if (</td></tr><tr><td><span style="color: black" >XiLeRO Map:</span></td><td><span style="color: red ; font-weight: 700" ><b>Online</b></span>) {
echo XileRO Map: Online
}
if (</td></tr><tr><td><span style="color: black" >XiLeRO Map:</span></td><td><span style="color: red ; font-weight: 700" ><b>Offline</b></span>) {
echo XileRO Map: Offline
}
}
*Xidus cry's in a corner
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
alias xile { sockopen Xile http://xilero.net 80 } * Dns resolving http://xilero.net* Dns unable to resolve http://xilero.net- * Dns resolving xilero.net *xilero.net resolved to 72.29.77.223 ok, so we see http isnt working, and the TLD is, so .... alias xile { sockopen Xile xilero.net 80 } on *:sockopen:Xile:{ sockwrite -n Xile GET (What? Where?) /home.php HTTP/1.1 put the full path there and see what happens sockwrite -n Xile Host: xilero.net $+ $crlf $+ $crlf }
|
|
|
|
Joined: Nov 2005
Posts: 104
Vogon poet
|
Vogon poet
Joined: Nov 2005
Posts: 104 |
don't know if there's a reason for it. But when I tried just /sockopen http://www.google.com it would'nt open the socket. but /sockopen google.com opened the socket. So try leaving out the http:// part of the sockopen in the alias.
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
I think sockopen www.google.com 80 might be better with the commercial site, especially if they have different IP addresses for web access than other com access they might have. FEX * Dns resolving google.com google.com resolved to 72.14.207.99 - * Dns resolving www.google.comwww.google.com resolved to 66.102.7.99 though I am not sure in this case if you would or would not be able to access the google info you wanted.
|
|
|
|
Joined: Oct 2005
Posts: 1,671
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,671 |
I got the socket to read using this code:
alias xile {
if ($sock(xile)) sockclose xile
sockopen xile xilero.net 80
}
on *:sockopen:xile:{
sockwrite -n $sockname GET /home.php HTTP/1.1
sockwrite -n $sockname Host: xilero.net $+ $crlf $+ $crlf
}
ON *:sockread:xile:{
if ($sockerr) {
echo -s SockError $sockname $sockerr
return
}
var %t
sockread %t
echo -s > %t
if (*XiLeRO Login:*Online* iswm %t) {
echo 3 -s XileRO Login: Online
}
elseif (*XiLeRO Login:*Offline* iswm %t) {
echo 4 -s XileRO Login: Offline
}
elseif (*XiLeRO Char:*Online* iswm %t) {
echo 3 -s XileRO Char: Online
}
elseif (*XiLeRO Char:*Offline* iswm %t) {
echo 4 -s XileRO Char: Offline
}
elseif (*XiLeRO Map:*Online* iswm %t) {
echo 3 -s XileRO Map: Online
}
elseif (*XiLeRO Map:*Offline* iswm %t) {
echo 4 -s XileRO Map: Offline
}
}
It catches two of the online/offline lines, but for some reason, the socket is getting strange data in the middle of one line which is disrupting the third catch. When I open the webpage in a browser and view the source, I get this bit of code: <table><tr><td><span style="color: black" >XiLeRO Login:</span></td><td><span style="color: green ; font-weight: 700" ><b>Online</b></span>
</td></tr><tr><td><span style="color: black" >XiLeRO Char:</span></td><td><span style="color: green ; font-weight: 700" ><b>Online</b></span>
</td></tr><tr><td><span style="color: black" >XiLeRO Map:</span></td><td><span style="color: green ; font-weight: 700" ><b>Online</b></span> But when I view the exact same page with the mIRC socket, I get this code: <table><tr><td><span style="color: black" >XiLeRO Login:</span></td><td><span style="color: green ; font-weight: 700" ><b>Online</b></span>
</td></tr><tr><td><span style="color: black" >XiLeRO Char:</span></td><td><s
54
pan style="color: green ; font-weight: 700" ><b>Online</b></span>
</td></tr><tr><td>
5e3
<span style="color: black" >XiLeRO Map:</span></td><td><span style="color: green ; font-weight: 700" ><b>Online</b></span>
I have absolutely no idea where the "54" and "5e3" and extra carriage returns are coming from. If anyone knows, please share with the rest of the class. ;P -genius_at_work
|
|
|
|
Joined: Feb 2004
Posts: 2,013
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,013 |
If you change the request to HTTP/1.0 then that weird data should be gone.
The reason is that with the 1.1 request for this site, you'll get the header Transfer-Encoding: chunked, which means your data will be retrieved in chunks. At the end of the chunks (when all data has been retrieved), you'll see a 0 followed by some optional ending headers (footers) and a blank line.
Those weird chars denote the size of the chunk that is being sent in hex. For example the first value I got was "d7e", which converted to the decimal system means $base(d7e,16,10) = 3454, in other words the number of bytes of the chunk. Each chunk will have that hex char possibly followed by a semicolon and extra parameters you can ignore. The line with the hex char will have a crlf following it, so will the data.
Note that putting 1.1 doesn't automatically mean your data will always be received in chunks, it depends on the server, but since 1.0 doesn't support this method afaik, you won't get chunked responses, thus neither those hex chars.
|
|
|
|
Joined: Oct 2005
Posts: 1,671
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,671 |
That's good to know. I'm not too familiar with transfer protocols, so I never would have guessed that was the problem.
-genius_at_work
|
|
|
|
|