Hello.
Im using this php code to parse stats from a COD4 server.
It works great, however i noticed that the players ping and scored seem to be return from the same string variable, and ill be darned if i can figure out how to seperate the 2 values.
im very new to php, but having a try at it. I understand the code, well most. but kinda stumped on how to go about it. Any help is greately appreciated.
Im not sure if I can post my code here, but here goes anyhow:
<?php
/*
cod4server.php
This script connects to a COD4 server, and puts the server information in a table.
Change the variables below to get it working.
You can also address the script as follows to get your own server information:
server.php?server=xxx.xxx.xxx.xxx:port (ie. server.php?server=213.189.21.11:28961)
*/
/*
Version history:
COD4 Server.php by England4eva aka 'e4E.
V 1.0 - Converted to connect to a COD 4 Server, added COD 4 images, map names and gametypes.
MOHAA Server.php by Ghostie (Peter Verboom)
V 1.0 - V 1.12: MOHAA Server Script.
*/
// Server ip and port:
if (!$server) {
$server_ip = "8.12.22.212";
$server_port = "28960";
} else {
$server = explode(":", $server);
$server_ip = $server[0];
$server_port = $server[1];
}
// Do NOT change anything below this line!
// Creating the URL for the connection:
$server_ip = "udp://" . $server_ip;
// Open the connection:
$connect = fsockopen($server_ip, $server_port, $errno, $errstr, 30);
// Set the timeout:
socket_set_timeout ($connect, 1, 000000);
// Get the information from the server, and put it into the $output array:
$send = "\xFF\xFF\xFF\xFFgetstatus\x00";
fputs($connect, $send);
fwrite ($connect, $send);
$output = fread ($connect, 1);
if (! empty ($output)) {
do {
$status_pre = socket_get_status ($connect);
$output = $output . fread ($connect, 1);
$status_post = socket_get_status ($connect);
} while ($status_pre[unread_bytes] != $status_post[unread_bytes]);
};
// Close the connection:
fclose($connect);
// Select the variables from the $output array:
$output = explode ("\\", $output);
$max_index = array_search ("sv_maxclients", $output);
$max_clients = $output[$max_index+1];
$max_index = array_search ("mapname", $output);
$mapname = $output[$max_index+1];
$max_index = array_search ("sv_hostname", $output);
$hostname = $output[$max_index+1];
$max_index = array_search ("g_gametype", $output);
$gametype = $output[$max_index+1];
$last_value = count($output) - 1;
$players_string = $output[$last_value];
$players_string = explode("\"", $players_string);
$get_first_ping = explode("\n", $players_string[0]);
//$players_string[0] = $get_first_ping[1];
$players_string[0] = $get_first_ping[1];
$i = 1;
$players = 0;
while (count($players_string) != $i) {
$i++;
$i++;
$players++;
}
// Create the image url:
/*
if (substr($mapname, 0, 3) == "") {
$picture_src = str_replace("dm/", "", $mapname);
}
*/
$picture_src = "images/" . $mapname . ".jpg";
$mapname = substr($mapname, 3);
$mapname = ucwords($mapname);
// Convert the game type name to something a little more pleasing to the eye
if ($gametype == "sd"){$gametype = "Search & Destroy";}
elseif ($gametype == "dm"){$gametype = "Free For All Deathmatch";}
elseif ($gametype == "dom"){$gametype = "Domination";}
elseif ($gametype == "koth"){$gametype = "Headquarters";}
elseif ($gametype == "sab"){$gametype = "Sabotage";}
elseif ($gametype == "war"){$gametype = "Team Deathmatch";}
// Start the output:
?>
<?=$hostname?>
Gametype:
<?=$gametype?>
|
|
Players:
<?=$players?>
/
<?=$max_clients?>
|
Map:
<?=$mapname?>
|
|
|
Player name: |
Score | Ping: |
<?
$i = 1;
while (count($players_string) != $i) {
$j = $i -1;
?>
<?=$players_string[$i]?>
|
<?=$players_string[$j]?>//////the string variable in question
</td>
</tr>
<?
$i = $i + 2;
}
?>
</table></td>
|
<?
?>
again thank you for any help
Derek.
|