• Welcome to Valhalla Legends Archive.
 

PHP Help with Battle.net

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

Previous topic - Next topic

Kp

Quote from: UnderCover on November 20, 2003, 04:06 PM
is this the right way for getting data forma  socket or is there a better way?

this way cuts off data :(

Then obviously, it is not the right way.

Quote from: UnderCover on November 20, 2003, 04:06 PM
I have to have them twice becuase once lets bnet know that i want to login and the next time tells bnet my login stuff.

This is incorrect.  Unless your language has fundamental flaws in its socket suite (which I find to be astronomically unlikely), you're doing something wrong and have convinced yourself that this is the fix.  I would not be greatly surprised to see that the result of your "fix" is that the first thing your client does upon logging on is to announce its name and password in channel.  The use of the second ^C might be saving you from this - it's been ages since I've used chat and I don't care enough to go find out if you're releasing your password.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

UnderCover


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


does anyone know an alternate way to connect and retrieve data from the socket with php?

Kp

Quote from: UnderCover on November 20, 2003, 06:11 PM
does anyone know an alternate way to connect and retrieve data from the socket with php?

Have you checked a reference manual or PHP tutorial?  That question seems awfully basic.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

UnderCover

yea i have php.net and it gives me fread fgets but its basically the same ican't seem to find a ocmmand that doesn't cut off my data...

MyndFyre

#34
.net hrm?  maybe I'll just give you my .net class library to get you to shut up.

EDIT: I'm sorry, that was really harsh, and if Kp can be so patient with this guy, then I really ought to try too.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

UnderCover

sorry im not trying ot be fdifficult its jsut went to the guid at http://www.php.net and it helped a little, it jsut didn't work for wut i was trying to do :(

Arta

Tips for not being a pain in the arse (in all seriousness):

- READ the replies to your questions THOROUGHLY.
- If you don't understand the first time, read them again.
- Make a sincere attempt to use the advice given to you before asking more questions.
- Spellcheck your posts, or be more careful when typing them. If you're bad at communicating people will be less inclined to help you.
- Think about your questions before you ask them. Do you really think that truncating (cutting off) your data is a feature of fgets()? If not, what possible use would it be to try a different function? The fault is plainly with your code, therefore, look more carefully. Try to break down the problem so it's easier to grasp.

You have picked a fairly hard thing to write for what I assume is your first (or one of your first) PHP scripts. You might want to try learning on some simpler things and coming back to this later.

UnderCover

#37
how come using this php script it keeps cutting off data?


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

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

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

while($data2 = fread($server, 1024)) {
$cut = explode("\n", $data2);
$i = 0;
$count = count($cut);
while($i < $count) {
$i++;
$cut2 = "<li>$cut[$i]</li>";
echo $cut2;
}
}


here is wut i get from it



2010 NAME lSAl-Bot#2
1007 CHANNEL "Public Chat 1"
1001 USER Stevmules 0010 [CHAT]
1001 USER Andakro 0010 [CHAT]
1001 USER LoRd]VeGiTo[#2 0010 [CHAT]
1001 USER fattim@Azeroth 0000 [WAR3]
1001 USER rabitebot 0010 [CHAT]
1001 USER Tulak 0000 [D2XP]
1001 USER akira_@Azeroth 0000 [WAR3]
1001 USER Bannage#2 0010 [CHAT]
1001 USER Minkus 0000 [SEXP]
1001 USER dbabel 0010 [CHAT]
1001 USER Brood[L2K] 0010 [CHAT]
1001 USER SA_2 0010 [CHAT]
1001 USER Dantes_dance 0000 [D2XP]
1001 USER Trav580 0



1001 USER DisturbedKnot@Azeroth 0000 [W3XP]
1001 USER lSAl-Bot#2 0010 [CHAT]
1018 INFO "Welcome to Battle.net!"
1018 INFO "This server is hosted by AT&T."
1018 INFO "There are currently 639 users in Chat, and 291724 users playing 104523 games on Battle.net."
1019 ERROR "Chatting with this game is restricted to the channels listed in the channel menu."
1018 INFO "Last logon: Sat Nov 22 3:44 PM"



Grok

Because you are not checking if the data is followed by a newline \n character before putting the last bit into the final array element.

TCP sent you the data in chunks, and you cannot assume it is an entire line of chat.  The first chunk was about 502(?) bytes.  Your code is processing the last element as if it were completed.

Explode should only be used up to and including the final \n character in the text stream.  Anything after the final \n, put that in your inbuffer and to wait for more text.

UnderCover

Quote from: Grok on November 22, 2003, 10:42 AM
Because you are not checking if the data is followed by a newline \n character before putting the last bit into the final array element.


So instead of \n for explode would " " work (Space)?

Kp

Quote from: UnderCover on November 22, 2003, 10:52 AM
So instead of \n for explode would " " work (Space)?

It would definitely work, but I expect it will produce even less desirable results than your current method (which, as Grok said, is flawed).  Perhaps you should simply try these things instead of asking?
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

UnderCover

wut way would you recommend so i can get the easiest results?

right now my way causes the script to time out :)

Kp

Quote from: UnderCover on November 22, 2003, 11:14 AM
wut way would you recommend so i can get the easiest results?

Do exactly what Grok said.  His solution is correct and should be pretty straightforward even for you to implement.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

UnderCover

Grok said to store anything after the \n.

How would i get the results after \n?

Kp

Quote from: UnderCover on November 22, 2003, 11:23 AM
Grok said to store anything after the \n.

How would i get the results after \n?

That's a language specific question, and it's specific to a language few (if any) of the people in this thread know.  Look at the documentation for explode, it might tell you.  Failing that, ask a PHP guru how to handle retrieving the final fragment of an explode.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

|