johnnei
New Member
- Messages
- 20
- Reaction score
- 0
- Points
- 0
Hello,
Here is my code:
Will this code work on X10hosting?
Greatings,
Johnnei
Here is my code:
PHP:
<?php
$server_ip = "udp://CENSORED";
$server_port = "27960";
// Open the connection:
$connect = fsockopen($server_ip, $server_port, $errno, $errstr, 5);
// Set the timeout:
socket_set_timeout ($connect, 5);
// Get the information from the server, and put it into the $output array:
$send = "ÿÿÿÿ" . chr (0x00) . "getstatus";
fputs($connect, $send);
fwrite ($connect, $send);
$output = fread ($connect, 1);
echo "Output: ". $output;
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_gametypestring", $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];
$i = 1;
$players = 0;
while (count($players_string) != $i) {
$i++;
$i++;
$players++;
}
// Create the image url:
if (substr($mapname, 0, 3) == "dm/") {
$picture_src = str_replace("dm/", "", $mapname);
} else {
$picture_src = str_replace("obj/", "", $mapname);
}
$picture_src = "images/" . $picture_src . ".jpg";
// Start the output:
?>
<html>
<head>
<title><?=$hostname?></title>
</head>
<body>
<table width="600" border="0" align="center">
<caption><b><?=$hostname?></b></caption>
<tr>
<td width="256" valign="top">
<table border="0">
<tr>
<td width="256">Game: <?=$gametype?><td>
</tr>
<tr>
<td width="256">Players: <?=$players?>/<?=$max_clients?></td>
</tr>
<tr>
<td width="256">Map: <?=$mapname?></td>
</tr>
<tr>
<td width="256"><img src="<?=$picture_src?>"></td>
</tr>
</table>
</td>
<td valign="top">
<table border="0">
<tr>
<td width="300">Player name:</td>
<td width="44">Ping:</td>
</tr>
<?
$i = 1;
while (count($players_string) != $i) {
$j = $i -1;
?>
<tr>
<td width="300">
<?=$players_string[$i]?>
</td>
<td width="44">
<?=$players_string[$j]?>
</td>
</tr>
<?
$i = $i + 2;
}
?>
</table>
</td>
</tr>
</table>
<center>Stats Version 1.00.01</center>
</body>
</html>
Will this code work on X10hosting?
Greatings,
Johnnei