Klickst du hier: -Klick-deeg.at^ said:Wenns möglich ist auch n TS2 info
<?php
class serverinfo
{
var $ip;
var $port;
var $fp;
var $timeout;
var $serverData;
var $playerData;
function serverinfo($ip, $port, $timeout = 3)
{
$this->ip = $ip;
$this->port = $port;
$this->fp = fsockopen("udp://" . $ip, $port);
$this->timeout = $timeout;
}
function getServerData()
{
$this->writeData($this->getQuery("A2S_INFO"));
$this->getData("byte");
$this->getString();
$this->serverData['hostname'] = $this->getString();
$this->serverData['map'] = $this->getString();
$this->getString();
$this->serverData['mod'] = $this->getString();
$this->serverData['players'] = $this->getData("byte");
$this->serverData['maxplayers'] = $this->getData("byte");
$this->getData("byte");
$this->serverData['servertype'] = (chr($this->getData("byte")) == "d") ? "Dedicated" : "Listen";
$this->serverData['server_os'] = (chr($this->getData("byte")) == "w") ? "Windows" : "Linux";
$this->serverData['password'] = $this->getData("byte");
$this->getData("byte");
$this->getString();
$this->getString();
$this->getString();
$this->getData("long");
$this->getData("long");
$this->getData("byte");
$this->getData("byte");
$this->serverData['vac'] = $this->getData("byte");
$this->getData("byte");
}
function getPlayerData()
{
$this->writeData($this->getQuery("A2S_PLAYER"));
fread($this->fp, 4);
$this->getData("byte");
$count = $this->getData("byte");
for($i = 0; $i < $count; $i++)
{
$this->playerData[$i]['id'] = $this->getData("byte");
$this->playerData[$i]['name'] = $this->getString();
$this->playerData[$i]['frags'] = $this->getData("long");
$this->playerData[$i]['time'] = round($this->getData("float"));
}
}
function getQuery($queryType)
{
switch($queryType)
{
case "A2S_SERVERQUERY_GETCHALLENGE":
return "\xFF\xFF\xFF\xFF\x57";
break;
case "A2S_INFO":
return "\xFF\xFF\xFF\xFFTSource Engine Query\x00";
break;
case "A2S_PLAYER":
return sprintf("\xFF\xFF\xFF\xFFU%s", $this->getChallenge());
break;
}
}
function getChallenge()
{
$this->writeData($this->getQuery("A2S_SERVERQUERY_GETCHALLENGE"));
return substr(fread($this->fp, 16), 5, 9);
}
function getData($type)
{
switch($type)
{
case "long":
$data = unpack("L", fread($this->fp, 4));
return $data[1];
break;
case "byte":
return ord(fread($this->fp, 1));
break;
case "char":
return fread($this->fp, 1);
break;
case "float":
$data = unpack("f", fread($this->fp, 4));
return $data[1];
break;
}
}
function getString()
{
$string = '';
$loop = TRUE;
while($loop)
{
$_fp = $this->getData("char");
if( ord($_fp) != 0 )
{
$string .= $_fp;
}
else { $loop = FALSE; }
}
return $string;
}
function writeData($input)
{
if( !$this->fp )
{
exit("Error: Couldn't connect to server.");
}
else {
fwrite($this->fp, $input);
socket_set_timeout($this->fp, $this->timeout);
}
}
function setTimeFormat($format, $input)
{
$hours = floor($input / 3600);
$input = $input % 3600;
$minutes = floor($input / 60);
$input = $input % 60;
$seconds = round($input);
return sprintf($format, $hours, $minutes, $seconds);
}
function sortPlayers($sort = "time", $type = "desc")
{
if(isset($this->playerData[0][$sort]))
{
for($i = 0; $i < count($this->playerData); $i++)
{
$temp[] = $this->playerData[$i][$sort];
}
switch($sort)
{
case "name":
uasort($temp, "strcasecmp");
break;
default:
if($type == "desc") {
arsort($temp);
}
elseif($type == "asc") {
asort($temp);
}
break;
}
foreach($temp as $key => $value)
{
$keys[] = $key;
}
foreach($keys AS $k => $v)
{
$tempvar[$k]['id'] = $this->playerData[$v]['id'];
$tempvar[$k]['name'] = $this->playerData[$v]['name'];
$tempvar[$k]['frags'] = $this->playerData[$v]['frags'];
$tempvar[$k]['time'] = $this->playerData[$v]['time'];
}
$this->playerData = $tempvar;
}
}
}
?>
<?php require("class.hl.php"); ?>
<html>
<head>
<title>Half-life Serverinfo</title>
<style type="text/css">
<!--
body, table {
border: 1;
border-color: #CCCCCC;
font-family: Verdana;
font-size: 10px;
color: #000000;
}
a { text-decoration: none; color: #666666; }
a:hover { color: #333333; }
-->
</style>
</head>
</html>
<body>
<?php
// En array med IP till olika servrar
$ip_port = array(
1 => "dust2.gamers.nu:27017",
"dust2d.gamers.nu:27015",
"dust2.gamers.nu:27019"
);
$rand = rand(1, count($ip_port)); // Slumpar fram ett ip ifrån arrayen $ip_port
$getip_port = explode(":", $ip_port[$rand]); // Delar på IP och Port
$ip = (empty($_POST["ip"])) ? $getip_port[0] : $_POST["ip"];
$port = (empty($_POST["port"])) ? $getip_port[1] : $_POST["port"];
$s = &new serverinfo($ip, $port); // Skapar en referens till klassen
$s->getServerData();
$s->getPlayerData();
?>
<form name="serverinfo" method="post" action="./">
<input name="servername" style="width: 300px;" value="<?php echo $s->serverData['hostname']; ?>">
<input name="ip" style="width: 200px;" value="<?php echo $ip; ?>">
<input name="port" style="width: 50px;" value="<?php echo $port; ?>">
<input name="check" type="submit" value="submit">
</form>
<hr align="center" noshade color="#000000" size="1">
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="125" height="15" align="left">Spel:</td>
<td width="100" height="15" align="left"><?php echo $s->serverData['mod']; ?></td>
<td width="1" rowspan="8" align="left" bgcolor="#000000"></td>
<td rowspan="8" align="center" valign="top">
<table width="550" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20">##</td>
<td width="200">Spelarnamn:</td>
<td width="50">Frags:</td>
<td width="230">Tid i spelet:</td>
</tr>
<?php
#$s->sortPlayers("frags");
for($i = 0; $i < count($s->playerData); $i++)
{
echo "<tr>";
printf("<td>%02d</td>", $s->playerData[$i]['id']);
printf("<td>%s</td>", htmlentities($s->playerData[$i]['name']));
printf("<td>%s</td>", $s->playerData[$i]['frags']);
printf("<td>%s</td>", $s->setTimeformat("%02d:%02d:%02d", $s->playerData[$i]['time']));
echo "</tr>\n";
}
$dif = (count($s->playerData) < $s->serverData['players']) ? ($s->serverData['players'] - count($s->playerData)) : 0;
// Skriver ut de spelare som fortfarande håller på att ansluta till servern
for($j = 0; $j < $dif; $j++)
{
echo "<tr>";
echo "<td>?</td>";
echo "<td>?</td>";
echo "<td>?</td>";
echo "<td>?</td>";
echo "</tr>";
}
?>
</table>
</td>
</tr>
<tr>
<td width="125" height="15" align="left">Spelare:</td>
<td width="100" height="15" align="left"><?php echo $s->serverData['players'] . "/" . $s->serverData['maxplayers']; ?></td>
</tr>
<tr>
<td width="125" height="15" align="left">Bana:</td>
<td width="100" height="15" align="left"><?php echo $s->serverData['map']; ?></td>
</tr>
<tr>
<td width="125" height="15" align="left">Typ:</td>
<td width="100" height="15" align="left"><?php echo $s->serverData['servertype']; ?></td>
</tr>
<tr>
<td width="125" height="15" align="left">Operativsystem:</td>
<td width="100" height="15" align="left"><?php echo $s->serverData['server_os']; ?></td>
</tr>
<tr>
<td width="125" height="15" align="left">L&senord:</td>
<td width="100" height="15" align="left"><?php echo ($s->serverData['password'] == 1) ? "Ja" : "Nej"; ?></td>
</tr>
<tr>
<td width="125" height="15" align="left">VAC:</td>
<td width="100" height="15" align="left"><?php echo ($s->serverData['vac'] == 1) ? "Ja" : "Nej"; ?></td>
</tr>
<tr>
<td colspan="2" align="left">&</td>
</tr>
</table>
<hr align="center" noshade color="#000000" size="1">
Half-life serverinfo, version 3. Copyright & <a href="mailto: benjii@underline.se">xsp</a>.<br>
</body>
</html>
$ip_port = array(
1 => "dust2.gamers.nu:27017",
"dust2d.gamers.nu:27015",
"dust2.gamers.nu:27019"
);
We use essential cookies to make this site work, and optional cookies to enhance your experience.