PDA

View Full Version : Need help with PHP UDP status script



STAUFFi
21st March 2013, 20:38
(config.php)


<?php
$ip = "85.190.142.9";
$port = "28960";
$bgcolor = "#272526";
$textcolor = "#FFFFFF";
$links = "#272526";
$linkstext = "#FFFFFF";
$rechts = "#272526";
$rechtstext ="#FFFFFF";
?>
(index.php)

<?
include("config.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Serverstatus</title>
<style type="text/css">
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
.status_error {
font-weight: bold;
color: red;
}
th {
text-align: left;
background-color: <?=$links?>;
color: <?=$linkstext?>;
}
td {
text-align: left;
background-color: <?=$rechts?>;
color: <?=$rechtstext?>;
}
img {
border: 1px solid <?=$rechtstext?>;
}
</style>
</head>
<body bgcolor="<?=$bgcolor?>" text="<?=$textcolor?>">
<?php
$timeout = 0.5; //Timeout in Sekunden
$html = <<<HEREDOC
<table border="0" cellspacing="2" cellpadding="0">
<tr>
<th width="120"><left>Spiel:</left></th>
<td>{gamename}</td>
</tr>
<tr>
<th>Servername:</th>
<td>{sv_hostname}</td>
</tr>
<tr>
<th>Server IP:</th>
<td>{ip}:{port}</td>
</tr>
<tr>
<th>Serverversion:</th>
<td>{shortversion}</td>
</tr>
<tr>
<th>Map:</th>
<td>{mapname}</td>
</tr>
<tr>
<th></th>
<td><img src="data/maps/{mapname}.jpg"></td>
</tr>
<tr>
<th>Spieltyp:</th>
<td>{g_gametype}</td>
</tr>
<tr>
<th>Spieler:</th>
<td>{currentplayers}/{sv_maxclients}</td>
</tr>
<tr>
<th>Passwort:</b></th>
<td>{pswrd}</td>
</tr>
<tr>
<th>PunkBuster:</th>
<td>{sv_punkbuster}</td>
</tr>
<tr>
<th>Mod:</th>
<td>{fs_game}</td>
</tr>
</table>
HEREDOC;

/* CONFIG END */

$con = fsockopen("udp://$ip", $port, $errno, $errstr, 3);

if (!$con) {
echo "<b class='status_error'>Server offline</b>\n";
}
else {
fwrite($con, "\xFF\xFF\xFF\xFFgetstatus\x00");
stream_set_timeout($con, (int) $timeout, ($timeout - ((int) $timeout)) * 100000);
$start = microtime(true);
$s = "";
do {
$s .= substr(fread($con, 9999), 10);
$info = stream_get_meta_data($con);
if (!isset($end)) {
$end = microtime(true);
}
}
while(!$info["timed_out"]) ;


if (empty($s)) {
echo "<b class='status_error'>The Serverbanner ist in Bau gerade!</b>\n";
}
else {
$ping = round(($end - $start) * 1000) . " ms";

list($dummy, $dvarslist, $playerlist) = explode("\n", $s, 3);

$dvarslist = explode("\\", $dvarslist);
$dvars = array();
for ($i = 1; $i < count($dvarslist); $i += 2) {
$dvars[$dvarslist[$i]] = htmlentities(trimcolor($dvarslist[$i + 1]));
}

$playerlist = explode("\n", $playerlist);
array_pop($playerlist);
$players = array();
foreach ($playerlist as $value) {
list($score, $pingp, $name) = explode(" ", $value, 3);
$players[] = array(
"name" => htmlspecialchars(trimcolor(substr($name, 1, -1))),
"score" => $score,
"ping" => $pingp
);
}

$dvars["mapname"] = getmap($dvars["mapname"]);
$dvars["g_gametype"] = getgametype($dvars["g_gametype"]);
$dvars["fs_game"] = getmods($dvars["fs_game"]);
$dvars["sv_punkbuster"] = getpb($dvars["sv_punkbuster"]);
$dvars["pswrd"] = getpw($dvars["pswrd"]);


$playerlist = "";
foreach ($players as $value) {
$playerlist .= "<tr><td>$value[name]</td><td>$value[score]</td><td>$value[ping]</td></tr>\n";
}

$search[] = "{playerlist}";
$replace[] = $playerlist;
$search[] = "{ping}";
$replace[] = $ping;
$search[] = "{ip}";
$replace[] = $ip;
$search[] = "{port}";
$replace[] = $port;
$search[] = "{currentplayers}";
$replace[] = count($players);

foreach ($dvars as $key => $value) {
$search[] = "{" . $key ."}";
$replace[] = $value;
}

echo str_replace($search, $replace, $html);
}
}


function trimcolor($name) {
return preg_replace('|\^.|', '', $name);
}

function getmap($short) {
$maps = array(

// Call of Duty 2
"mp_toujane" => "Toujane",


// Call of Duty 4: Modern Warfare Maps
"mp_backlot" => "Backlot",
"mp_bloc" => "Bloc",
"mp_bog" => "Bog",
"mp_cargoship" => "Wet Work",
"mp_citystreets" => "District",
"mp_convoy" => "Ambush",
"mp_countdown" => "Countdown",
"mp_crash" => "Crash",
"mp_crash_snow" => "Winter Crash",
"mp_crossfire" => "Crossfire",
"mp_farm" => "Downpour",
"mp_overgrown" => "Overgrown",
"mp_pipeline" => "Pipeline",
"mp_showdown" => "Showdown",
"mp_strike" => "Strike",
"mp_vacant" => "Vacant",
"mp_shipment" => "Shipment",
"mp_broadcast" => "Broadcast",
"mp_carentan" => "Chinatown",
"mp_creek" => "Creek",
"mp_killhouse" => "Killhouse"

);
if (array_key_exists($short, $maps)) {
return $maps[$short];
}
return $short;
}
function getgametype($short) {
$gametypes = array(
"dm" => "Deathmatch",
"tdm" => "TeamDeathmatch",
"sd" => "Suchen und Zerstören",
"koth" => "Hauptquatier",
"ctf" => "Capture the Flag",
);
if (array_key_exists($short, $gametypes)) {
return $gametypes[$short];
}
return $short;
}
function getmods($short) {
$mods = array(
"" => "Kein Mod",
"mods/pam4" => "Pam4",
"mods/promod_version3" => "Promod Version 3",
);
if (array_key_exists($short, $mods)) {
return $mods[$short];
}
return $short;
}
function getpb($short) {
$pb = array(
"1" => "An",
"0" => "Aus",
);
if (array_key_exists($short, $pb)) {
return $pb[$short];
}
return $short;
}
function getpw($short) {
$pw = array(
"1" => "Ja",
"0" => "Nein",
);
if (array_key_exists($short, $pw)) {
return $pw[$short];
}
return $short;
}
?>
</body>
</html>
All times coming Server offline pls help

kung foo man
21st March 2013, 21:12
Do:



$con = fsockopen("udp://$ip", $port, $errno, $errstr, 3);
echo $errno . " " . $errstr;

Tally
21st March 2013, 23:27
Sorry, but how is this Call of Duty scripting?

kung foo man
21st March 2013, 23:40
Ups, moved to PHP-Forum and renamed to something meaningful.

Degraded to normal User also (was Moderator), since:
- can't do meaningful titles
- using wrong forums
- did nothing for K~Portal (was Mod in that forum).

Jeplaa
22nd March 2013, 13:52
hey STAUFFi,

I noticed that you've got:


<?
include("config.php");
?>

just wrong php-tags:


<?php
include("config.php");
?>

STAUFFi
22nd March 2013, 18:06
hey STAUFFi,

I noticed that you've got:


<?
include("config.php");
?>

just wrong php-tags:


<?php
include("config.php");
?>

http://germanstauffits.de/statusscript/ :(
Dont work ^^

kung foo man
22nd March 2013, 18:58
Still to do:



$con = fsockopen("udp://$ip", $port, $errno, $errstr, 3);
echo $errno . " " . $errstr;

STAUFFi
22nd March 2013, 19:55
Still to do:



$con = fsockopen("udp://$ip", $port, $errno, $errstr, 3);
echo $errno . " " . $errstr;

dont work to;(

kung foo man
22nd March 2013, 23:18
I guess your php-hoster disallowed "fsockopen", because the script is running fine on my server (besides one warning).

Jeplaa
23rd March 2013, 06:20
I guess your php-hoster disallowed "fsockopen", because the script is running fine on my server (besides one warning).

Yep, localhost (WAMP server) running it and no problems, but when I throw the files on the webpage then pops up Server Offline.

STAUFFi
23rd March 2013, 11:20
Yep, localhost (WAMP server) running it and no problems, but when I throw the files on the webpage then pops up Server Offline.
you can show me
how to make it on a wampserver?

kung foo man
23rd March 2013, 12:10
Just install this: http://www.apachefriends.org/de/xampp-windows.html

STAUFFi
23rd March 2013, 19:40
So other problem how to lock the pic?
203
When i press "Grafik anzeigen" switch my internet to the pfad data/hindergrund.jpg but i dont want it :P
Pls help

kung foo man
23rd March 2013, 20:32
Just fix the HTML the way you want it ^^