Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Need help with PHP UDP status script

  1. #1
    Corporal STAUFFi's Avatar
    Join Date
    Aug 2012
    Location
    Germany
    Posts
    269
    Thanks
    106
    Thanked 128 Times in 83 Posts

    Need help with PHP UDP status script

    (config.php)
    Code:
    <?php
    $ip = 	 "85.190.142.9";
    $port =	 "28960";
    $bgcolor = 	 "#272526";
    $textcolor = "#FFFFFF";
    $links = 	 "#272526";
    $linkstext = "#FFFFFF";
    $rechts = 	 "#272526";
    $rechtstext ="#FFFFFF";
    ?>
    (index.php)
    Code:
    <?
    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

  2. #2
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Do:

    PHP Code:
    $con fsockopen("udp://$ip"$port$errno$errstr3);
    echo 
    $errno " " $errstr
    timescale 0.01

  3. The Following User Says Thank You to kung foo man For This Useful Post:

    Jeplaa (22nd March 2013)

  4. #3
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Sorry, but how is this Call of Duty scripting?

  5. #4
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    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).
    timescale 0.01

  6. #5
    Private First Class
    Join Date
    Dec 2012
    Posts
    127
    Thanks
    132
    Thanked 114 Times in 63 Posts
    hey STAUFFi,

    I noticed that you've got:

    PHP Code:
    <?
        include("config.php");
    ?>
    just wrong php-tags:

    PHP Code:
    <?php
        
    include("config.php");
    ?>
    Last edited by Jeplaa; 22nd March 2013 at 15:22.

  7. #6
    Corporal STAUFFi's Avatar
    Join Date
    Aug 2012
    Location
    Germany
    Posts
    269
    Thanks
    106
    Thanked 128 Times in 83 Posts
    Quote Originally Posted by Jeplaa View Post
    hey STAUFFi,

    I noticed that you've got:

    PHP Code:
    <?
        include("config.php");
    ?>
    just wrong php-tags:

    PHP Code:
    <?php
        
    include("config.php");
    ?>
    http://germanstauffits.de/statusscript/
    Dont work ^^

  8. #7
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Still to do:

    PHP Code:
    $con fsockopen("udp://$ip"$port$errno$errstr3);
    echo 
    $errno " " $errstr
    timescale 0.01

  9. #8
    Corporal STAUFFi's Avatar
    Join Date
    Aug 2012
    Location
    Germany
    Posts
    269
    Thanks
    106
    Thanked 128 Times in 83 Posts
    Quote Originally Posted by kung foo man View Post
    Still to do:

    PHP Code:
    $con fsockopen("udp://$ip"$port$errno$errstr3);
    echo 
    $errno " " $errstr
    dont work to;(

  10. #9
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    I guess your php-hoster disallowed "fsockopen", because the script is running fine on my server (besides one warning).
    timescale 0.01

  11. The Following User Says Thank You to kung foo man For This Useful Post:

    Jeplaa (23rd March 2013)

  12. #10
    Private First Class
    Join Date
    Dec 2012
    Posts
    127
    Thanks
    132
    Thanked 114 Times in 63 Posts
    Quote Originally Posted by kung foo man View Post
    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.

  13. The Following User Says Thank You to Jeplaa For This Useful Post:

    kung foo man (23rd March 2013)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •