Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

August 19, 2022, 05:52:58 AM

Login with username, password and session length
Members
  • Total Members: 3843
  • Latest: Tricky
Stats
  • Total Posts: 193479
  • Total Topics: 21088
  • Online today: 58
  • Online ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 1
Guests: 51
Total: 52

Author Topic: Psychostats Server Status  (Read 7403 times)

0 Members and 1 Guest are viewing this topic.

Dianoga

  • Guest
Psychostats Server Status
« on: March 02, 2006, 10:50:47 AM »
If you want to get gameserver status and have psychostats setup here is code for you. Just change the first line to your URL.

This probably only works with the default psychostats theme as it is definitely page scraping.

If you want the map images, get them from http://www.joomla-clantools.com/index.php?option=com_docman&task=cat_view&gid=25&Itemid=8 and extract them to a maps folder under your root install.

Example at http://ztkclan.com

Code: [Select]
$timeout = 3;
$host = "stats.ztkclan.com";

$sock = fsockopen($host, 80, $errno, $errstr, $timeout);
if(!$sock){
echo "Unable to get server status";
}else{
$out = "GET /server.php HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n\r\n";

fwrite($sock, $out);
stream_set_blocking($fp, FALSE );
stream_set_timeout($sock, $timeout);
$info = stream_get_meta_data($sock);

while (!feof($sock) && !$info['timed_out']) {
$file .= fgets($sock, 4096);
$info = stream_get_meta_data($sock);
}

fclose($sock);

if(!$info['timed_out']){
$file = substr($file, strpos($file, "Live Server View")+18);
$name = substr($file, 0, strpos($file, "</font>"));

$file = substr($file, strpos($file, "IP</td>"));
$ip = substr($file, strpos($file, "\">")+2, strpos($file, "</td>\n\t\t</tr>")-(strpos($file, "\">")+2)-1);

$file = substr($file, strpos($file, "Map</td>"));
$map = substr($file, strpos($file, "\">")+2, strpos($file, "</td>\n\t\t</tr>")-(strpos($file, "\">")+2));
if(file_exists("maps/" . $map . ".jpg")){
$mapImage = "maps/$map.jpg";
}

$file = substr($file, strpos($file, "Time</td>"));
$time = substr($file, strpos($file, "\">")+2, strpos($file, "</td>\n\t\t</tr>")-(strpos($file, "\">")+2));

$file = substr($file, strpos($file, "Game</td>"));
$game = substr($file, strpos($file, "\">")+2, strpos($file, "</td>\n\t\t</tr>")-(strpos($file, "\">")+2));

$file = substr($file, strpos($file, "Server</td>"));
$server= substr($file, strpos($file, "\">")+2, strpos($file, "</td>\n\t\t</tr>")-(strpos($file, "\">")+2));

$file = substr($file, strpos($file, "Players</td>"));
$players = substr($file, strpos($file, "\">")+2, strpos($file, "</td>\n\t\t</tr>")-(strpos($file, "\">")+2));

$file = substr($file, strpos($file, "Public</td>"));
$public = substr($file, strpos($file, "\">")+2, strpos($file, "</td>\n\t\t</tr>")-(strpos($file, "\">")+2));

$file = substr($file, strpos($file, "Ping</td>"));
$ping = substr($file, strpos($file, "\">")+2, strpos($file, "</td>\n\t\t</tr>")-(strpos($file, "\">")+2));

unset($file);

echo "Players: $players <br />
IP: $ip <br />
Map: $map <br />";
if(isset($mapImage)){
echo "<img src='$mapImage' alt='$map'><br />";
}
}else{
echo "Unable to connect to server";
}
}
« Last Edit: November 20, 2006, 07:34:36 AM by Dianoga »

Dianoga

  • Guest
Re: Psychostats Server Status
« Reply #1 on: July 22, 2006, 11:53:53 AM »
I changed the code a bit to support timeouts. This should prevent your page from timing out when you try and pull stats from a slow host.

Dianoga

  • Guest
Re: Psychostats Server Status
« Reply #2 on: November 20, 2006, 07:36:01 AM »
I updated the code once again. It now actually times out when it should instead of not like it did before.