• Welcome to Valhalla Legends Archive.
 

Connecting to Battle.net with PHP

Started by Augural Sentinel, December 13, 2005, 08:05 PM

Previous topic - Next topic

Augural Sentinel

I'm trying to make a PHP script that connects to the Battle.net servers to do various actions.  On this page, how would I go about sending all those values?  Right now, I'm just using $end = chr(10).chr(13);

fputs($conn, "0");
fputs($conn, "68XI");
fputs($conn, "PXES");
fputs($conn, chr(205));
fputs($conn, "0");
fputs($conn, "0");
fputs($conn, "0");
fputs($conn, "0");
fputs($conn, "0");
fputs($conn, "USA");
fputs($conn, "United States".$end);


When I use Ethereal, the packet where all this information is sent contains the following:
Quote..8.9...  .....E.
.H..@... .,....?.
.~.....= Z.....P.
..3...68 XIPXES.0
0000USAU nited St
ates..   

StealthBot sends this in a packet:
Quote..8.9...  .....E.
.b..@... ......?.
.~.,.... ....d.P.
..`....P :.....68
XIPXES.. ........
........ .....|US
A.United  States.

StealthBot doesn't even half of the variables listed for SID_AUTH_INFO.  Do I even need to bother sending the 0's?

Also, how do I know Battle.net accepted what I sent it?  All the packets I receive from it are just random characters that don't contain any message from Battle.net telling me whether or not my login was accepted (unless Battle.net sends a hex code and Starcraft itself interprets this ) because I'm not getting a packet with this information.

Joe[x86]

#1
fputs($conn, chr(205));
Much easier to just use hex.
fputs($conn, chr(0xCD));

fputs($conn, "0");
1) Thats a DWORD, not a BYTE.
2) You're inserting that 0x30 bytes too high. It should be 0x0, not 0x30.

fputs($conn, chr(0) . chr(0) . chr(0) . chr(0));

Also, you're going to have one hell of a hard time doing anything without GetDWORD and MakeDWORD, and their WORD counterparts.

You'll never send CRLF (which you have as LFCR) to Battle.net in the binary protocol. Never.

Last but not least, make a packet buffer. You didn't send your sanity byte, packetID, nor packet length.

In short, you violated the protocol about 30 times.

If you need any help, I'm usually sitting in front of my computer except for sleep, getting food (I eat in my room =p), or at school. I'm headed to bed right now, but I think I'm going to have a snow day tomorrow.

EDIT -
Two things I forgot.

1) Null terminate your strings.
fputs($conn, "USA" . chr(0));

2) Don't send CRLF after the packet.
fputs($conn, "United States" . chr(0));
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Augural Sentinel

Quote from: Joe on December 13, 2005, 08:14 PM
fputs($conn, chr(205));
Much easier to just use hex.
fputs($conn, chr(0xCD));
I haven't used chr() in the past, so I wasn't sure if it accepted hex values.

QuoteYou'll never send CRLF (which you have as LFCR) to Battle.net in the binary protocol. Never.
I was basing what I was doing off a opensource bot (made in 1998, as I just found out) and what someone else was doing.

QuoteTwo things I forgot.

1) Null terminate your strings.
fputs($conn, "USA" . chr(0));

2) Don't send CRLF after the packet.
fputs($conn, "United States" . chr(0));
Like I said earlier, I was basing what I was doing off two other clients.  I'm fairly new to using sockets with PHP.  All of the problems seem to be my own ineptness at using sockets with PHP  :-\

Thanks for pointing out all my problems :)

Joe[x86]

Not a problem. If anything sounded harsh, it wasn't meant to be.

As for your CRLF problem, you're probably looking at a telnet bot, which does send that.

I'm pretty sure that chr() will accept hex, because hex is just another part of the PHP language, not a different class of integer or anything.

I'm actually interested in making a PHP bot, but I'll have to do a telnet bot, because I'm don't feel like reinventing the wheel, reimplementing X-SHA-1, checkrevision, etc, in PHP.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Joe[x86]

Augural Sentinel, contact me (information is to the left).
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Kp

Quote from: Joe on December 13, 2005, 08:14 PMYou'll never send CRLF (which you have as LFCR) to Battle.net in the binary protocol. Never.

Not even when setting the contents of profile\description? ;)
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Joe[x86]

I don't think its allowed in descriptions, but it could be.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Augural Sentinel


Joe[x86]

You may have forgotten the protocol byte as well, now that I think about it. When you first connect, send a chr(1).
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Augural Sentinel

Quote from: Joe on December 15, 2005, 01:30 AM
You may have forgotten the protocol byte as well, now that I think about it. When you first connect, send a chr(1).
It appears that I have to send this as a seperate packet.  Are my assumptions correct?  Blizzard made an opensource C++ bot in 1998, and in that, you have to send chr(03) and chr (04) together in one packet to tell the server you want to connect, then you had to put your login information after it in the same packet.  That's why I was trying to send CRLF to the server.

Would I use socket_recv() to accept the ping from Battle.net (and later any other packets)?  I think that this would be much easier with C++'s networking library  :-\

Joe[x86]

Receiving packets is not fun. I'm still struggling with that.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.