( search forums )
Computer too fast for its own good
Soldat Forums - Soldat Talk - Developers Corner
bja888
March 12, 2006, 10:09 am
This one bug has been haunting me since I got the TCP communication working and I wondering if any one had any bright ideas on how to fix.

Should work like this...
- I send the "REFRESH\r\n" then read incoming stream buffer.
- Clear out all built up buffer data to get to the returned "REFRESH\r\n" text.
- Read 1188 byte packet and display info.
- Update loop runs once a second to check the buffer.

Instead it does this...
- I send the "REFRESH\r\n" then read incoming stream buffer.
- Clear out all built up buffer data and do not find the "REFRESH\r\n" anywhere in it.
- The refresh packet is dumped out as ASCII on update loop.


I'm only assuming that the buffer is completely cleared out before the refresh packet could be sent back. So does anyone know a efficient way to pause for a second? At this point I can disable the update while the refresh method is running. I have it stop checking the buffer when nothing is found.

I do not want to....
- Include the REFRESH method in the update check.
- Do a pointless loop just to waist time.

bja888
March 12, 2006, 10:44 am
I just realised (and got out of bed to post it). That cannot be the proublem. Only on the first attempt when I know there is extra info in the buffer does it mess up. I know the proublem is not with the extra information though because when I tell it to loop slower (by giving it a harder task to do on each loop) it catches the REFRESH in the buffer.

Here is a sample of the output...
 Quote:> Soldat Admin Connection Established...
> Succesfully logged in.
> - - - - - - - - - - - REFRESH SENT
> - - - - - - - - - - - Not REFRESH So far so good. It flushes what is not REFRESH data from the buffer.
> Welcome, you are in command of the server now.
> - - - - - - - - - - - Not REFRESH Onece again, flushing usless data
> List of commands available in the Soldat game Manual.
> - - - - - - - - - - - Update This should not be a update...
> REFRESH It was found, but after the buffer ran dry.
> Roach;_z|+>
- - - - - - - - - - - Update
> > random data
- - - - - - - - - - - Update
> > random data
- - - - - - - - - - - Update
> > > > random data
- - - - - - - - - - - Update
> wh};
> D|> random data
- - - - - - - - - - - REFRESH SENT I manually sent the REFRESH command again
> - - - - - - - - - - - Verified Look at that... It worked :)
> - - - - - - - - - - - Update Example that the update works fine
> /kill 3
> - - - - - - - - - - - Update Example that the update works fine
> Roach killed by admin

mar77a
March 12, 2006, 1:25 pm
you have read it all together, until you have your refresh packet complete, here's the PHP code:

[code]$s = fsockopen($_GET[ip], $_GET[port]);

if($s){

$info = array();

fwrite($s, "$_GET[pass]\r\n");

fwrite($s, "REFRESH\r\n");

while(1) {

$data = trim(fgets($s, 1024));

// check if admin password is valid
if(eregi("password", $data)){
printstr("Wrong admin password.", 34985);
break;
exit;
}

if($data == "REFRESH"){

$info = GetSoldatInfo($s); // Function to parse the REFRESH DATA

break;

}else{

echo htmlentities(stripslashes($data));

echo "<br>";

}
[/code]

bja888
March 12, 2006, 7:17 pm
I read the packet later. What I am looking for is "REFRESH" first so I know the packet is accurate.