1
yakman
Serverspy custom block script hack
  • 2004/8/18 9:50

  • yakman

  • Just popping in

  • Posts: 1

  • Since: 2004/8/15


Hi all, just set up XOOPS with the team module for my clan. Very nice and clean system.
I wanted th share my server spy hack with you as I found it tricky to set server spy up with its usual feeds.
I'm new to oop generally so I have stick to what I know. it works ok for me and makes further customiseation possible.
Please feel free to post improvements to the script :)

// Server spy monitor blcok for XOOPS 2
// remote_file_exists script from the PHP online user manual
// server spy monitor from the server spy xml example, hacked by yakman
// replace xxxxx with your stream number from server spy
// This is designed to fit centre right or centre left as its for 2 servers.
// The map pics url must point to your own source for map pics
// a good place to find them is in the contribs section of the psychostats webby
// you will also need an 'image not found' url
// check the script in operation at http://www.gaming.clanaos.co.uk
function remote_file_exists($url)
{
$head = '';
$url_p = parse_url ($url);

if (isset ($url_p['host']))
{ $host = $url_p['host']; }
else
{
return '1 Invalid URL host';
}

if (isset ($url_p['path']))
{ $path = $url_p['path']; }
else
{ $path = ''; }

$fp = fsockopen ($host, 80, $errno, $errstr, 20);
if (!$fp)
{
return '2 Unable to connect to remote host';
}
else
{
$parse = parse_url($url);
$host = $parse['host'];

fputs($fp, 'HEAD '.$url." HTTP/1.1\r\n");
fputs($fp, 'HOST: '.$host."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
$headers = '';
while (!feof ($fp))
{ $headers .= fgets ($fp, 128); }
}
fclose ($fp);

// for debug
//echo nl2br($headers);

$arr_headers = explode("\n", $headers);
if (isset ($arr_headers[0])) {
if(strpos ($arr_headers[0], '200') !== false)
{ return true; }
if( (strpos ($arr_headers[0], '404') !== false) ||
(strpos ($arr_headers[0], '410') !== false))
{ return false; }
if( (strpos ($arr_headers[0], '301') !== false) ||
(strpos ($arr_headers[0], '302') !== false))
{
preg_match("/Location:\s*(.+)\r/i", $headers, $matches);
if(!isset($matches[1]))
return false;
$nextloc = $matches[1];
return remote_file_exists($nextloc);
}
}
preg_match('/HTTP.*(\d\d\d.*)\r/i', $headers, $matches);
return '3 Status Code not supported'.
(isset($matches[1])?": $matches[1]":'');
}
$smonXML = 'http://www.serverspy.net/bin/smonXml.mpl?mid=xxxxx'; // Replace xxxxx with your own number from Serverspy
$smon = Array();
global $smon;
$smon['PLAYERS'] = Array();
$smon['DETAILS'] = Array();
$smon['RULES'] = Array();
$smon['SERVERSPY'] = Array();
function startElement($parser, $tagName, $attrs) {
global $smon;
if ($tagName == 'PLAYERS'){
$smon['PLAYERS'][$attrs['NAME']] = Array();
$smon['PLAYERS'][$attrs['NAME']]['CONNECTED'] = $attrs['CONNECTED'];
$smon['PLAYERS'][$attrs['NAME']]['KILLS'] = $attrs['KILLS'];

} elseif ($tagName == 'SERVERSPY'){
$smon['SERVERSPY'][$attrs['NAME']] = $attrs['VALUE'];

} elseif ($tagName == 'RULES'){
$smon['RULES'][$attrs['NAME']] = $attrs['VALUE'];

} elseif ($tagName == 'DETAILS'){
$smon['DETAILS'][$attrs['NAME']] = $attrs['VALUE'];
}
// while (list ($key, $val) = each ($attrs)) {
// } // end while
}
function characterData($parser, $data) {
// no wrapped data used
}
function endElement($parser, $tagName) {
// no wrapped data used
}
// Create an XML parser
$xml_parser = xml_parser_create();
// Set the functions to handle opening and closing tags
xml_set_element_handler($xml_parser, "startElement", "endElement");
// Set the function to handle blocks of character data
xml_set_character_data_handler($xml_parser, "characterData");
// Open the XML file for reading
$fp = fopen($smonXML,"r") or die("Error reading ServerSpy.net XML feed. Either the URL is invalid or the XML feed has been updated.");
// Read the XML file 4KB at a time
while ($data = fread($fp, 4096))
// Parse each 4KB chunk with the XML parser created above
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
// Close the XML filef
fclose($fp);

// Free up memory used by the XML parser
xml_parser_free($xml_parser);
echo "

";
// Details
echo "";
echo "";
echo "";
// *************
// url for your map pics filder goes here
// *************
$img = "http://url for map pics folder".$smon['DETAILS']['map'].".jpg";
// *************
// url for your image not found goes here
// *************
if (remote_file_exists ($img)) { } else { $img = "url for no image" height = 150"; }
echo "";
echo "";
// Players
echo "
";
while (list ($key, $val) = each ($smon['PLAYERS'])){
if ($cla == "odd") { $cla="even"; } Else { $cla = "odd"; }
echo "
";
}
echo "
:: ".substr($smon['DETAILS']['name'],0,24)." CS ::
IP:".$smon['DETAILS']['ip']."
Now Playing: ".$smon['DETAILS']['map']."
Players: ".$smon['DETAILS']['currentPlayers']."/".$smon['DETAILS']['maxPlayers']."
Players
".$key."

";
$smonXML = 'http://www.serverspy.net/bin/smonXml.mpl?mid=xxxxx'; // Replace xxxxx with your own number from Serverspy
$smon['PLAYERS'] = Array();
$smon['DETAILS'] = Array();
$smon['RULES'] = Array();
$smon['SERVERSPY'] = Array();
// Create an XML parser
$xml_parser = xml_parser_create();

// Set the functions to handle opening and closing tags
xml_set_element_handler($xml_parser, "startElement", "endElement");

// Set the function to handle blocks of character data
xml_set_character_data_handler($xml_parser, "characterData");

// Open the XML file for reading
$fp = fopen($smonXML,"r") or die("Error reading ServerSpy.net XML feed. Either the URL is invalid or the XML feed has been updated.");

// Read the XML file 4KB at a time
while ($data = fread($fp, 4096))
// Parse each 4KB chunk with the XML parser created above
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
// Close the XML filef
fclose($fp);

// Free up memory used by the XML parser
xml_parser_free($xml_parser);
// Details
echo "";
echo "";
echo "";
// *************
// url for your map pics filder goes here
// *************
$img = "http://url for map pics folder".$smon['DETAILS']['map'].".jpg";
// *************
// url for your image not found goes here
// *************
if (remote_file_exists ($img)) { } else { $img = "url for no image" height = 150"; }
echo "";
echo "";
// Players
echo "
";
while (list ($key, $val) = each ($smon['PLAYERS'])){
if ($cla == "odd") { $cla="even"; } Else { $cla = "odd"; }
echo "
";
}
echo "
:: ".substr($smon['DETAILS']['name'],0,24)." DoD ::
IP:".$smon['DETAILS']['ip']."
Now Playing: ".$smon['DETAILS']['map']."
Players: ".$smon['DETAILS']['currentPlayers']."/".$smon['DETAILS']['maxPlayers']."
Players
".$key."

";

2
evylrat
Re: Serverspy custom block script hack
  • 2004/9/3 11:03

  • evylrat

  • Not too shy to talk

  • Posts: 164

  • Since: 2004/2/25


I'll be trying this out soon! Going to try and setup a spare computer as a game server. Got the XOOPS site ready,
http://games.cheshair.homedns.org (nothing there).

Going to setup teamspeak, and any other goodies to help me and my friends organise online games.

3
jimbofoxman
Re: Serverspy custom block script hack

Anyone ever get this to work? Nothing shows up on mine when I run it.

Login

Who's Online

274 user(s) are online (176 user(s) are browsing Support Forums)


Members: 0


Guests: 274


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits