The problem is that when the server is full of players, I can't get all the info from the server. It seems a portion of the data at the end is cut off.
Here's the code
Code: Select all
// This is the server's IP (Forward Observer server for example)
$IP = "69.25.16.150";
//Default query port is 1717
$sock = fsockopen( "udp://" . $IP, 1717);
if($sock != false)
{
//Set time out for socket
socket_set_timeout($sock, 2);
//Write query packet to socket/send query to server
fwrite($sock, "\\info"e;);
//Read response from server - set to 8192 bytes (could probably be less)
$Info = @fread($sock, 8192);
$Info2 = @fread($sock, 8192);
//Close the socket
fclose($sock);
/*
!!!! Comment out the next line to hide the query data, it's for debug only
*/
//print($Info . "<BR><BR>");
}
// Parse \\info\\ query packet and load the contents into an array variable called $Infoarray
$Infoarray = explode(""e;, $Info);
$Infoarray2 = explode(""e;, $Info2);
//meta tag for page to refresh every 30 seconds - THIS IS OPTIONAL
//$result .= "<meta http-equiv=Refresh content=30>";
// Post server info
//Server name from data
// * you could also add in HTML tags to set background color, font size, type-face and color here
$result .= "<BODY><LEFT>" . $Infoarrayї2];
//server IP and host port
$result .= "<BR>IP: " . $IP . ":" . $Infoarrayї8];
//now it's just a matter of determining where in the array the data is that you want to display
$result .= "<BR>Map: " . $Infoarrayї10];
$result .= "<BR>Players: ". $Infoarrayї14]. " / " . $Infoarrayї18];
$result .= "<BR>Round: " . $Infoarrayї38];
$result .= "<BR>Time: " . $Infoarrayї40].'<br><br>'."\n";
foreach($Infoarray as $key => $value) {
$result .= $key.' = '.$value."<br>\n";
}
foreach($Infoarray2 as $key => $value) {
$result .= $key.' = '.$value."<br>\n";
}
$result .= "</BODY>";
// Now display the concatenated string onto the page
print($result);1. I tried increasing the socket time out.
2. I tried increasing the read size.
3. I tried making a second fread call.(which is in the code above)
None of this has fixed the problem. I know that UDP has a maximum datagram size, but I also know that someone else is successfully doing what I want to do, but they aren't forth coming with their solution.
Any ideas would be greatly appreciated.
Eric Stewart