Valhalla Legends Forums Archive | Battle.net Bot Development | PHP Help with Battle.net

AuthorMessageTime
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...

[code]

<?

$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;

?>

[/code]

Where it says fput its a code then anything you want...
November 17, 2003, 12:51 AM
Arta
You should be using TCP, not UDP, and assuming you want to make CHAT connection, you should be sending:

[code]
"\x03\x04USERNAME\r\nPASSWORD\r\n"
[/code]

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.
November 17, 2003, 1:51 AM
UnderCover
Why TCP and not UDP?

UPDATED:

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

[code]
"\x03\x04USERNAME\r\nPASSWORD\r\n"
[/code]

like that code? How do you find it out?
November 17, 2003, 1:53 AM
Spht
[quote author=UnderCover link=board=17;threadid=3661;start=0#msg29624 date=1069034033]
Why TCP and not UDP?
[/quote]

Because the Battle.net chat server you're connecting to uses TCP.
November 17, 2003, 2:08 AM
Spht
[quote author=UnderCover link=board=17;threadid=3661;start=0#msg29624 date=1069034033]
UPDATED:

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

[code]
"\x03\x04USERNAME\r\nPASSWORD\r\n"
[/code]

like that code? How do you find it out?
[/quote]

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.
November 17, 2003, 2:11 AM
UnderCover
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?
November 17, 2003, 2:42 AM
Kp
[quote author=UnderCover link=board=17;threadid=3661;start=0#msg29636 date=1069036935]
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?[/quote]

Unless you implicitly know all protocols, yes. :)

[quote author=UnderCover link=board=17;threadid=3661;start=0#msg29636 date=1069036935]
Also wuts the /r and /n mean?[/quote]

That's context dependent. What program are you looking at?
November 17, 2003, 2:51 AM
UnderCover
[quote author=Kp link=board=17;threadid=3661;start=0#msg29637 date=1069037516]
That's context dependent. What program are you looking at?
[/quote]

PHP i was also wondering how do you figure out the 0x and code like ctrl c was ??? code
November 17, 2003, 2:54 AM
Kp
[quote author=UnderCover link=board=17;threadid=3661;start=0#msg29638 date=1069037699]
PHP i was also wondering how do you figure out the 0x and code like ctrl c was ??? code[/quote]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.
November 17, 2003, 5:00 AM
UnderCover
[quote author=Kp link=board=17;threadid=3661;start=0#msg29647 date=1069045223]
Your question makes no sense. Try writing in proper sentences with punctuation and we'll have a better time understanding.
[/quote]

Hehe. Sorry...
November 17, 2003, 11:27 AM
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 :( ?

[code]
$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;
[/code]
November 17, 2003, 11:49 AM
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).
November 17, 2003, 12:55 PM
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?
November 17, 2003, 2:16 PM
UnderCover
I was wondering is there a way to make a php script connect to BNLS so you can access private channels?
November 17, 2003, 5:33 PM
iago
[quote][code]fputs($server, "\x03\x04$username\r\n\x03\x04$password\r\n");[/code][/quote]

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");
November 17, 2003, 6:37 PM
UnderCover
hey thanks but do you know how i can get other lists such as users and stuff??

When I connect to the bnet server can i do normal commands and stuff?

Wut is the type of scripting that gets constant info like instead of reloading the server aall the time how do i get constant access to it and it reports like an irc server into a text box?

UPDATE:

How do you extract the info, I know on the cs server that i have i extracted the ifno through arrays and substr strings but wuts the easiet method of extracting raw info like this?
November 17, 2003, 7:38 PM
Arta
Are you doing anything for yourself?

http://uk.php.net/manual/en/
November 17, 2003, 9:53 PM
UnderCover
lol yeh im trying to extract the records i tihnk i pretty much got it.

On Battle.net wut are those numbers after the person's name
0010 (Chat) do they have any meaning?
November 17, 2003, 10:08 PM
Maddox
[quote author=UnderCover link=board=17;threadid=3661;start=15#msg29759 date=1069106880]
lol yeh im trying to extract the records i tihnk i pretty much got it.

On Battle.net wut are those numbers after the person's name
0010 (Chat) do they have any meaning?
[/quote]

They are a user's flags.
November 17, 2003, 11:58 PM
UnderCover
do you know what some of them mean? Also when I use my php script it shows the users in the channel then when i refresh it changes to show the channel text. Do you know how i can ge tit to show one or the other?

UPDATED:

is there a way i can extract certain data easily rather than tryign to guess the commands? like here is an example when i use the info script here is the respone:

[code]

1018 INFO "Welcome to Battle.net!"
1018 INFO "This server is hosted by AT&T."
1018 INFO "There are currently 696 users in Chat, and 163994 users playing 60920 games on Battle.net."
1019 ERROR "Chatting with this game is restricted to the channels listed in the channel menu."
1018 INFO "Last logon: Tue Nov 18 1:32 AM"

[/code]

before that i get users and a channel

Is there a way i can get it to jsut use the line talk everytime talk appears? or everytime talk appears make it show up a diff color? I have to do all these other werid commands in order to extract it.
November 18, 2003, 12:12 AM
UnderCover
do you think there is a way to change the your ip address with php or use proxies if you get ip banned?
November 18, 2003, 8:22 PM
Myndfyr
[quote author=UserLoser. link=board=17;threadid=3661;start=15#msg29956 date=1069191347]
[quote author=UnderCover link=board=17;threadid=3661;start=15#msg29950 date=1069186921]
do you think there is a way to change the your ip address with php or use proxies if you get ip banned?
[/quote]

I believe you should learn PHP before making a script to connect to Battle.net, or atleast use the link that Arta provided
[/quote]

I wholeheartedly agree.
November 18, 2003, 9:39 PM
UnderCover
Does anyone know a way were i can get this information to be read on one line rather than on seperate lines?

Like is there a code that can count form " to "? Whenever you use " as a field it screws up because of it thinking thats were it will combine data.

Hope this makes since... :)

Count from point " to point "?
[code]
INFO
"There
are
currently
608
users
in
Chat,
and
164865
users
playing
62231
games
on
Battle.net."
[/code]
November 19, 2003, 2:07 AM
Myndfyr
I've never seen that before.

BTW, can you take a hint?
November 19, 2003, 3:31 AM
St0rm.iD
explode() is the call you want

(could doubly be used as a joke :))
November 19, 2003, 9:42 PM
UnderCover
i have always wanted to know

wuts the diffrence between explode() and split()?

i am using split but it seems to work the same as explode
November 19, 2003, 9:44 PM
St0rm.iD
It does. explode() is just a cooler name.
November 19, 2003, 9:45 PM
UnderCover
lol nice

so far i have gotten my script to be able to list users, wut the current channel name is, botname, and battle.net info lines

edit:

does anoyne know how to continue reading from the socket with out reconnecting?

everytime the script reloads it reconnects causing battlen.net to display the same info over and not talk messages.
November 19, 2003, 9:48 PM
Kp
[quote author=UnderCover link=board=17;threadid=3661;start=15#msg30149 date=1069278512]
does anoyne know how to continue reading from the socket with out reconnecting?[/quote]Yes. Stop closing your socket. Instead, stay in a loop reading from it, assembling the inbound data into BNCS-Chat records, and parsing them out when you find a delimiter character (newline). For each record parsed out, pass it to an appropriate handler which understands how to format it for display to the user. For information on how to implement these steps in a particular language, I recommend consulting a manual on that language, or a guidebook for the language if you are unfamiliar.
November 19, 2003, 10:06 PM
UnderCover
is this the right way for getting data forma socket or is there a better way?

this way cuts off data :(

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.

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

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

i only use the $data one the $info is not needed.
November 20, 2003, 10:06 PM
Kp
[quote author=UnderCover link=board=17;threadid=3661;start=30#msg30367 date=1069365973]
is this the right way for getting data forma socket or is there a better way?

this way cuts off data :([/quote]

Then obviously, it is not the right way.

[quote author=UnderCover link=board=17;threadid=3661;start=30#msg30367 date=1069365973]
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.[/quote]

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.
November 20, 2003, 10:51 PM
UnderCover
[code]
fputs($server, "\x03$username\r\n$password\r\n");
fgets($server);
$SocStatus = socket_get_status($server);
$data = fread($server, $SocStatus['unread_bytes']);
[/code]

does anyone know an alternate way to connect and retrieve data from the socket with php?
November 21, 2003, 12:11 AM
Kp
[quote author=UnderCover link=board=17;threadid=3661;start=30#msg30418 date=1069373464]
does anyone know an alternate way to connect and retrieve data from the socket with php?
[/quote]

Have you checked a reference manual or PHP tutorial? That question seems awfully basic.
November 21, 2003, 12:14 AM
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...
November 21, 2003, 12:37 AM
Myndfyr
.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.
November 21, 2003, 12:57 AM
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 :(
November 21, 2003, 1:07 AM
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.
November 21, 2003, 2:59 AM
UnderCover
how come using this php script it keeps cutting off data?

[code]
$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;
}
}
[/code]

here is wut i get from it

[code]

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"

[/code]
November 22, 2003, 3:48 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.
November 22, 2003, 4:42 PM
UnderCover
[quote author=Grok link=board=17;threadid=3661;start=30#msg30689 date=1069519334]
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.

[/quote]

So instead of \n for explode would " " work (Space)?
November 22, 2003, 4:52 PM
Kp
[quote author=UnderCover link=board=17;threadid=3661;start=30#msg30690 date=1069519929]
So instead of \n for explode would " " work (Space)?[/quote]

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?
November 22, 2003, 5:10 PM
UnderCover
wut way would you recommend so i can get the easiest results?

right now my way causes the script to time out :)
November 22, 2003, 5:14 PM
Kp
[quote author=UnderCover link=board=17;threadid=3661;start=30#msg30698 date=1069521266]
wut way would you recommend so i can get the easiest results?[/quote]

Do exactly what Grok said. His solution is correct and should be pretty straightforward even for you to implement.
November 22, 2003, 5:15 PM
UnderCover
Grok said to store anything after the \n.

How would i get the results after \n?
November 22, 2003, 5:23 PM
Kp
[quote author=UnderCover link=board=17;threadid=3661;start=30#msg30700 date=1069521785]
Grok said to store anything after the \n.

How would i get the results after \n?[/quote]

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.
November 22, 2003, 5:28 PM
UnderCover
explode ( string separator, string string [, int limit])


Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string separator. If limit is set, the returned array will contain a maximum of limit elements with the last element containing the rest of string.

thats wut php.net said

so would i put

explode("\n", $data, "not sure wut goes here?");
November 22, 2003, 5:34 PM
Spht
Third parameter looks optional.

If limit is set, the returned array will contain a maximum of limit elements with the last element containing the rest of string.
November 22, 2003, 5:38 PM
UnderCover
yes but im not sure how to stop the cutting of the data.

I couldn't really understand wut grok said...

EDIT:

does anyone know how ot the the ending string of explode?
the way im doing it its causign a lot of cutting to happen....
November 22, 2003, 6:19 PM
Grok
[quote author=UnderCover link=board=17;threadid=3661;start=45#msg30708 date=1069525171]
yes but im not sure how to stop the cutting of the data.

I couldn't really understand wut grok said...
[/quote]

Could you explain your code, as posted? That would go a long way to you understanding what I said. I'm sure of it.
November 22, 2003, 7:06 PM
UnderCover
yeh this code

[code]

<?
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//COPYRIGHT www.saclans.com 2003-2004 ;;
//Written By: -][SA][-UnderCover ;;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

//;;;;;;;;;;;;;;;;;;;;;;
//;;Battle.net Replies;;
//;;USER ;;
//;;NAME ;;
//;;CHANNEL ;;
//;;INFO ;;
//;;ERROR ;;
//;;EMOTE ;;
//;;JOIN ;;
//;;LEAVE ;;
//;;TALK ;;
//;;WHISPER ;;
//;;NULL ;;
//;;;;;;;;;;;;;;;;;;;;;;

$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, 5000)) {
$explode = explode("\n", $data2);
$i = "-1";
$count = count($explode);
while($i <= $count) {
$i++;
$info = "<li>$explode[$i]</li>";
echo $info;
}
}


?>
[/code]

first it connects to bnet, then it sends the login stuff, then it reads from the socket. Im trying tog et it to filter out the data so when it says CHANNEL it would fileter out the channel name and so on.
November 22, 2003, 7:08 PM
Grok
Explain line by line how your loop works.
November 22, 2003, 7:28 PM
UnderCover
[code]<?
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//COPYRIGHT www.saclans.com 2003-2004 ;;
//Written By: -][SA][-UnderCover ;;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

//;;;;;;;;;;;;;;;;;;;;;;
//;;Battle.net Replies;;
//;;USER ;;
//;;NAME ;;
//;;CHANNEL ;;
//;;INFO ;;
//;;ERROR ;;
//;;EMOTE ;;
//;;JOIN ;;
//;;LEAVE ;;
//;;TALK ;;
//;;WHISPER ;;
//;;NULL ;;
//;;;;;;;;;;;;;;;;;;;;;;

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

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

$username = "lSAl-Bot";
$password = "new";

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

// while its gets data from the server
while($data2 = fread($server, 5000)) {
$explode = explode("\n", $data2); ---explode the data
$i = "-1"; give a number
$count = count($explode); count the exploded data
while($i <= $count) { while the number is less than count
$i++; add the number
$info = "<li>$explode[$i]</li>"; show the exploded information 0 , 1, 2 etc
echo $info; show the information
}
}
close loops

?>
[/code]

hope fully this helped
November 22, 2003, 7:30 PM
Grok
No, it didn't. I am not convinced you understand the program. I want you to explain it in terms of the data, not in terms of the function names.

Just document this loop:

[code]
while($data2 = fread($server, 5000)) {
$explode = explode("\n", $data2);
$i = "-1";
$count = count($explode);
while($i <= $count) {
$i++;
$info = "<li>$explode[$i]</li>";
echo $info;
}
}
[/code]
November 22, 2003, 7:38 PM
UnderCover
[code]
while($data2 = fread($server, 5000)) { this talks to the sevrer and retrives data from it
$explode = explode("\n", $data2); this seperates the data by \n
$i = "-1";
$count = count($explode); this counts the seperated data
while($i <= $count) { this takes a number and as long as it is less than the counted data it will stay true
$i++;
$info = "<li>$explode[$i]</li>"; this presents the data by array [1] [2] etc
echo $info; this shows the data
}
}
[/code]

Edit - fixed your format tag.
November 22, 2003, 7:41 PM
UnderCover
spht did you edit my post??

wut did you fix if you edited...

EDIT:

its still cutting of data...

does anyone know wut im doing wrong?
November 23, 2003, 12:29 AM
Spht
[quote author=UnderCover link=board=17;threadid=3661;start=45#msg30768 date=1069547380]
spht did you edit my post??

wut did you fix if you edited...
[/quote]

You should always look at your post after you post something before wandering off. You had a couple empty quote tags at the top, then the code you pasted (which wasn't between code tag), and then empty code tags at end.
November 23, 2003, 1:39 AM
UnderCover
ohh sorry :) but do you know how to get all the data instead of just a segment?
November 23, 2003, 2:08 AM
Arta
Oh for the love of God. You've asked the same question about 4 times now and the same answer has been given in each case.

btw: It's WHAT. W-H-A-T. What.
November 23, 2003, 2:17 AM
UnderCover
lol
November 23, 2003, 3:41 AM
CrAzY
If you dont know what Explode does... it Separates X amonunt of strings by the set string. An example would be " ", a space. $blah = explode(" ", "Hello World");. After this you break apart Hello and World disregaurding the space. Now you can define them into strings :-). $booo = $blah[0];. or $boo is = to Hello.
November 23, 2003, 6:15 AM
UnderCover
i know wut explode does but i can't seem to figure out the fread.

For some reason fread cuts or just doesn't display all then data.

If anyone can help me that would eb great.
November 23, 2003, 2:40 PM
St0rm.iD
[quote author=UnderCover link=board=17;threadid=3661;start=60#msg30887 date=1069598447]
i know wut explode does but i can't seem to figure out the fread.

For some reason fread cuts or just doesn't display all then data.

If anyone can help me that would eb great.
[/quote]

It would help if you actually read what people were saying.
November 23, 2003, 3:15 PM
UnderCover
is this a good loop to get data. I tested it and it worked fine the only problem was that it kept timing out :(

[code]
while ( !feof( $socket ) ) {
$ret = fgets( $socket, 4096 );
echo "<li>$ret</li>";
}
[/code]
November 23, 2003, 4:40 PM
St0rm.iD
Well, if it has a problem, then it isn't.
November 23, 2003, 5:31 PM
Grok
[quote author=St0rm.iD link=board=17;threadid=3661;start=60#msg30908 date=1069608685]
Well, if it has a problem, then it isn't.
[/quote]

And to summarize the last 30 replies,

Your loop, as implemented, has a problem. The problem is:
In case you missed the advance notice .. The problem is:
I'm about to tell you what's wrong ... The problem is:
Here comes a real good clue ... The problem is:
Pay attention now .... The problem is:
Here it is ... The problem is:
The problem is:

If your data contains incomplete data (a line from chat without a newline at the end) your code does not take that into consideration. It puts that last, incomplete line into the final array element which was created by explode(). By then processing that final element as if it were a complete line of chat, you are getting the visible impression of reality -- that TCP breaks up data wherever the hell it wants, and leaves it up to you to make sure the contents are complete.

How to fix? Easy. Only allow explode to operate on your buffer's contents up to the final newline character. Anything after that character you need to put back in the buffer.

After you fix that, you'll realize your program has an additional, major, structural problem.
November 23, 2003, 6:39 PM

Search