• Welcome to Valhalla Legends Archive.
 

PHP Help with Battle.net

Started by UnderCover, November 16, 2003, 06:51 PM

Previous topic - Next topic

UnderCover

Hi I was wondering I can connect to battle.net but im not sure wut the string code is to send a request like...



<?

$ip = "useast.battle.net";
$port = "6112";

$server = fsockopen("udp://".$ip, $port , $errno, $errstr , 1);
$SocStatus = socket_get_status($server);
$timeout = "5";
socket_set_timeout($server, $timeout);

fputs($server, "\xff\xff\xff\xffconnecting?");
fread($server, 5);
$SocStatus = socket_get_status($server);
$infostats = fread($server, $SocStatus['unread_bytes']);

echo $infostats;

?>



Where it says fput its a code then anything you want...

Arta

#1
You should be using TCP, not UDP, and assuming you want to make  CHAT connection, you should be sending:


"\x03\x04USERNAME\r\nPASSWORD\r\n"


I'm not sure the idea is workable though. You'll be able to connect, but what then? If you just want to query people's records and stuff it'll work fine - I wrote a PHP script to do that some time ago - but if you want actual chat I'm not quite sure if that's workable. I seem to remember reading about a set of PHP scripts that connect and, AFAIK, are able to chat on IRC, so you might want to check that out.

UnderCover

#2
Why TCP and not UDP?

UPDATED:

Also when using sockets how do you know wut the code is to enter text...


"\x03\x04USERNAME\r\nPASSWORD\r\n"


like that code?  How do you find it out?

Spht

#3
Quote from: UnderCover on November 16, 2003, 07:53 PM
Why TCP and not UDP?

Because the Battle.net chat server you're connecting to uses TCP.

Spht

#4
Quote from: UnderCover on November 16, 2003, 07:53 PM
UPDATED:

Also when using sockets how do you know wut the code is to enter text...


"\x03\x04USERNAME\r\nPASSWORD\r\n"


like that code?  How do you find it out?

Blizzard documented this a long time ago -- how to use the Telnet chat server interface.

\x03 substitutes for sending Ctrl-C (to specify connection of chat protocol) through Telnet interface, while \x04 substitutes for sending Ctrl-D (to turn off message echoing). Username & password follow which are return-prompted.

UnderCover

#5
How do you know the codes for other sockets too (such as irc, game servers, etc) would you have to look at them and figure them out?

Also wuts the /r and /n mean?

Kp

Quote from: UnderCover on November 16, 2003, 08:42 PM
How do you know the codes for other sockets too (such as irc, game servers, etc) would you have to look at them and figure them out?

Unless you implicitly know all protocols, yes. :)

Quote from: UnderCover on November 16, 2003, 08:42 PM
Also wuts the /r and /n mean?

That's context dependent.  What program are you looking at?
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

UnderCover

#7
Quote from: Kp on November 16, 2003, 08:51 PM
That's context dependent.  What program are you looking at?

PHP   i was also wondering how do you figure out the 0x and code like ctrl c was ??? code

Kp

Quote from: UnderCover on November 16, 2003, 08:54 PM
PHP   i was also wondering how do you figure out the 0x and code like ctrl c was ??? code
Check the PHP documentation for what the /r and /n switches do to its processor.  I don't use PHP, so I don't have the manual on hand.

Your question makes no sense.  Try writing in proper sentences with punctuation and we'll have a better time understanding.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

UnderCover

Quote from: Kp on November 16, 2003, 11:00 PM
Your question makes no sense.  Try writing in proper sentences with punctuation and we'll have a better time understanding.

Hehe.   Sorry...

UnderCover

Could anyone tell me why i always get this error when trying to connect?

onnection from [24.61.140.141] Enter your account name and password. Use 'anonymous' if you only want to issue queries. sername: Password:

Also it cuts of the first word for some reason :( ?


$ip = "useast.battle.net";
$port = "6112";

$server = fsockopen("tcp://".$ip, $port , $errno, $errstr , 1);
$SocStatus = socket_get_status($server);
$timeout = "5";

$username = "########";
//Cloaked Name :)
$password = "########";
//Cloaked Password :)

fputs($server, "\x03\x04$username\r\n");
fread($server, 1);
$SocStatus = socket_get_status($server);
$info = fread($server, $SocStatus['unread_bytes']);

fputs($server, "\x03\x04$username\r\n\x03\x04$password\r\n");
fread($server, 1);
$SocStatus = socket_get_status($server);
$info2 = fread($server, $SocStatus['unread_bytes']);

echo $info;

echo $info2;

Skywing

Though I do not know PHP, I would imagine that your problem is due to your initial fread call on the socket handle (where you discard the data read).

UnderCover

i didn't mean to post 2 :)

Also when i try to change fread from 1 to 0 it doesn't display at all.
How do i fix this?

UnderCover

I was wondering is there a way to make a php script connect to BNLS so you can access private channels?

iago

Quotefputs($server, "\x03\x04$username\r\n\x03\x04$password\r\n");

Correct me if I'm wrong, but you don't need to be sending 03 04 twice; only send if once.  It should look like this:
fputs($server, "\x03\x04$username\r\n$password\r\n");

Or, if you are too lazy to be doing local echoing:
fputs($server, "\x03$username\r\n$password\r\n");
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*