I am trying to query an application that I developed via php.
Here is what I am confused on:
-The socket on the app is using a command that sends just text. It does not use a file stream or anything like that. Will php accept this?
-I have connected to the application using the following code I modified from a game server query script:
function file:
Code: Select all
<?
function getnull ($src) {
$data = "";
$out = "";
while($data != "\0") {
$data = fread($src, 1);
$out .= $data;
}
return substr($out, 0, -1);
}
function hlsend ($udp, $str) {
fwrite($udp, "${str}");
fread($udp, 4);
}
function server($addr){
if(strstr($addr,"/")){$addr = substr($addr, 0, strpos($addr, "/"));}
return $addr;
}
list($addr,$port)= explode (':', $server_ip);
$fp = @fsockopen("tcp://".server($addr), $port, $errno, $errstr);
if(!$fp) {
$hl["st"] = 0;
} else {
hlsend($fp, "\\version\\");
$testme= fread($fp, 1);
// $hl["version"] = getnull($fp);
// $oar = array();
// if (!$fp){
// echo $errstr;
// $oar["st"] = 0;
// } else {
// $oar["st"] = 1;
// $oar["na"] = $hl["version"];
// $oar["cp"] = $hl["current_players"];
// $oar["mp"] = $hl["max_players"];
// $oar["ga"] = $hl["description"];
// $oar["sv"] = $server_ip;
// unset($oar);
}
fclose($fp);
?>Code: Select all
<?
// first we make sure that server ip is set:
$server_ip = "24.105.221.206:6000";
// then we include the file required (as long as server ip is set)
if($server_ip == "" || !empty($server_ip)) {
require("ncss.php");
}
//if($hl["st"] == 0) {
// echo "server is offline";
//} else {
// do whatever if the server is online
//echo "server: ".$hl['sv']."<br>";
echo ($testme);
// list players:
// if ($hl["cp"] > 0) {
// for ($i = 0; $i < $hl["cp"]; $i++) {
// echo $hp[$i]["name"]." - ";
// echo "<b>".$hp[$i]["frags"]."</b> - ";
// echo $hp[$i]["time"]."<br>";
// }
// } else {
// echo "<b>no</b> players online\n";
// }
?>Now, due to the logging that I put in the app, I can see that it connects, and that it sends the query command "\version\", but how can I get it to display what is sent? Note that each command will return a simple text value, not an array of values.