Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kungfooman/6d80bad9243de035f3e48e644664de62 to your computer and use it in GitHub Desktop.
Save kungfooman/6d80bad9243de035f3e48e644664de62 to your computer and use it in GitHub Desktop.
hlsw/servers.php
<?php
function handle_mysql_error()
{
die(mysql_error());
}
mysql_connect("127.0.0.1:3306", "username", "password") OR handle_mysql_error();
mysql_select_db("tracker") OR handle_mysql_error();
?>
<html>
<head>
<title><?=@htmlspecialchars($_GET["query"])?></title>
<meta http-equiv="refresh" content="5; URL=?query=<?=@htmlspecialchars($_GET["query"])?>&resource=<?=@htmlspecialchars($_GET["resource"])?>">
</head>
<style>
#hlsw {
width: 100%;
font-family: Verdana;
font-size: 12px;
font-weight: bold;
}
#hlsw .map {
color: red;
}
a {
text-decoration: none;
}
.colorcode_0 { font-weight: bold; color: #000000; /*background-color: red; opacity:0.8; */ }
.colorcode_1 { font-weight: bold; color: #DA0120; }
.colorcode_2 { font-weight: bold; color: #00B906; }
.colorcode_3 { font-weight: bold; color: #E8FF19; text-shadow: 1px 1px 2px black, -1px -1px 2px black; }
.colorcode_4 { font-weight: bold; color: #170BDB; }
.colorcode_5 { font-weight: bold; color: #23C2C6; }
.colorcode_6 { font-weight: bold; color: #E201DB; }
.colorcode_7 { font-weight: bold; color: white; /*#FFFFFF;*/ /*background-color: #ccc;*/ text-shadow: 1px 1px 2px black, -1px -1px 2px black; }
.colorcode_8 { font-weight: bold; color: #0AFF95; }
.colorcode_9 { font-weight: bold; color: #757575; }
</style>
<body>
<?php
if (isset($_get["search"]) && $_get["search"]!="0")
{
?>
<form action="" method="get">
<p><input name="query" value="<?=@htmlspecialchars($_GET["query"])?>"></p>
<p><input type=submit value="Search"></p>
</form>
<?php
}
?>
<?php
$where = "";
if (isset($_GET["query"]))
{
$query = $_GET["query"];
$parts = explode(" ", $query);
$ports = 0;
$lastip = "";
foreach ($parts as $part)
{
$parts2 = explode(".", $part);
if (
count($parts2) == 4 &&
is_numeric($parts2[0]) &&
is_numeric($parts2[1]) &&
is_numeric($parts2[2]) &&
is_numeric($parts2[3]) &&
$parts2[0] >= 0 && $parts2[0] <= 255 &&
$parts2[1] >= 0 && $parts2[1] <= 255 &&
$parts2[2] >= 0 && $parts2[2] <= 255 &&
$parts2[3] >= 0 && $parts2[3] <= 255
)
{
$where .= " OR ip = '$part'";
$lastip = $part;
}
$parts2 = explode("=", $part);
if (
count($parts2) == 2 &&
$parts2[0] == "port" &&
is_numeric($parts2[1]) &&
$parts2[1] >= 0 && $parts2[1] <= 66000
)
{
if ( ! $ports)
$where = " || (ip='$lastip' && port IN (" . intval($parts2[1]) ;
else
$where .= ", " . intval($parts2[1]);
$ports = 1;
}
$parts2 = explode("!=", $part);
if (
count($parts2) == 2 &&
$parts2[0] == "port" &&
is_numeric($parts2[1]) &&
$parts2[1] >= 0 && $parts2[1] <= 66000
)
{
$where = " || (ip='$lastip' && port not in (" . intval($parts2[1]) . "))";
continue;
}
//echo $part . "|";
}
if ($ports)
$where .= "))";
//echo $where;
}
?>
<?php
if ($where == "")
die();
function color_name($name)
{
// double color codes are just usefull ingame, so replace them with normal
$name = str_replace("^^00", "^0", $name);
$name = str_replace("^^11", "^1", $name);
$name = str_replace("^^22", "^2", $name);
$name = str_replace("^^33", "^3", $name);
$name = str_replace("^^44", "^4", $name);
$name = str_replace("^^55", "^5", $name);
$name = str_replace("^^66", "^6", $name);
$name = str_replace("^^77", "^7", $name);
$name = str_replace("^^88", "^8", $name);
$name = str_replace("^^99", "^9", $name);
$name = '<font class="colorcode_7">' . $name; // white by default
$name = str_replace('^0', '</font><font class="colorcode_0">', $name);
$name = str_replace('^1', '</font><font class="colorcode_1">', $name);
$name = str_replace('^2', '</font><font class="colorcode_2">', $name);
$name = str_replace('^3', '</font><font class="colorcode_3">', $name);
$name = str_replace('^4', '</font><font class="colorcode_4">', $name);
$name = str_replace('^5', '</font><font class="colorcode_5">', $name);
$name = str_replace('^6', '</font><font class="colorcode_6">', $name);
$name = str_replace('^7', '</font><font class="colorcode_7">', $name);
$name = str_replace('^8', '</font><font class="colorcode_8">', $name);
$name = str_replace('^9', '</font><font class="colorcode_9">', $name);
return $name;
}
?>
<table id="hlsw">
<?php
$sql = "
SELECT *
FROM servers
WHERE 0
$where
AND (protocol = 115 || protocol = 117 || protocol = 118)
AND unix_timestamp() - last_actualize < 60
ORDER BY gametype
";
$query = mysql_query($sql);
//echo "<pre>$sql</pre>";
$resource = "http%3A//85.25.109.177/TeufeL_design&graph=0";
if (isset($_GET["resource"]))
$resource = htmlspecialchars($_GET["resource"]);
while ($row = mysql_fetch_assoc($query))
{
$country = "<img src=/images/flags/" . strtolower($row["country"]) . ".png>";
// vorher war es target=server
$hostname = "<a target=\"_self\" href=\"http://tracker.killtube.org/server.php?ip=".$row["ip"]."&port=".$row["port"]."&resource=$resource\">".color_name($row["hostname"]) . "</a>";
$gameinfo = "CoD2 - " . $row["fs_game"] . "(". $row["gametype"] .")";
$map = $row["map"];
$playerinfo = ($row["players"]>0?"<font color=#00cc19>":"") . $row["players"] . "/" . $row["max_players"];
$average_ping = $row["average_ping"];
?>
<tr>
<td><?=$country?>
<td><a href=""><?=$hostname?></a>
<td><?=$gameinfo?>
<td class="map"><?=$map?>
<td><?=$playerinfo?>
<td><?=$average_ping?>
<?php
}
?>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment