Server Detector

From: Ron Hiler (rhiler_at_spam.be.gone.rjcyberware.com)
Date: 11/29/03


Date: Sat, 29 Nov 2003 14:27:16 -0800

Hi guys,

I've written a small bit of PHP code who's purpose is to detect my game
server. If the game server is running, I want to display the Launcher and
Client population (two parts of the game program).

So here is what I wrote, minus the address and port :)

<?php
if(($sock = socket_create (AF_INET, SOCK_DGRAM, 0)) < 0)
  {
  echo "socket_create() failed: reason: " . socket_strerror($sock) . "<BR>";
  }
else
  {
  $server='xxx.xxx.xxx.xxx';
  $port=yyyy;
  $send=sprintf('%c%c%c%c',24, 0, 0, 0);
  $x=socket_sendto($sock,$send,strlen($send)-1,0,$server,$port);

  $bar = array($sock);
  $select_result = socket_select($bar, $b=null, $c=null, 3);
  if ($select_result == true)
    {
    $y=socket_recvfrom($sock,&$recvbuf,1024,0,&$from,&$port);
    $LauncherPopulation = sprintf('%d', $recvbuf[0]);
    $ClientPopulation = sprintf('%d', $recvbuf[4]);
    echo "<CENTER>The Sovereignty Server<BR>";
    echo "is UP</CENTER><BR>";
    ?>
    <CENTER><img src="GreenGem.png" border="0"></CENTER>
    <?php
    echo $recvbuf . $y . "<BR>";
    echo "Launcher Population:" . $LauncherPopulation . "<BR>";
    echo "Client Population:" . $ClientPopulation . "<BR><BR>";
    }
  else
    {
    echo "<CENTER>The Sovereignty Server<BR>";
    echo "is DOWN</CENTER><BR>";
    ?>
    <CENTER><img src="RedGem.png" border="0"></CENTER>
    <?php
    }
  }
socket_close($sock);
?>

This works to some extent. If the server is not running, I get a timeout
after 3 seconds and the red gem graphic is shown. If it is running the
server responds and I get the green gem graphic. The server sends back two
integers for the population

The problem is the $LauncherPopulation and $ClientPopulation values. They
always come up 0 even when there are player in game. The result of the
socket_recvfrom call ($y) is 8, which is the proper size for two integers,
and I know for sure that the server is sending the correct values. But for
some reason, my buffer doesn't appear to be set with them.

What am I doing wrong?

Ron

-- 
Creation is an act of sheer will
www.rjcyberware.com
Home of "Manifest Destiny" and "Sovereignty"


Relevant Pages

  • Re: PHP Instalation problems. Browser doesnt know what to do
    ... This is loaded and run as a local server (for class ... PHP 5.2.0 from php-5.2.0-win32-installer.msi ... # configuration directives that give the server its instructions. ...
    (comp.lang.php)
  • Re: PHP Instalation problems. Browser doesnt know what to do
    ... This is loaded and run as a local server (for class ... PHP 5.2.0 from php-5.2.0-win32-installer.msi ... # configuration directives that give the server its instructions. ...
    (comp.lang.php)
  • Re: write with cURL
    ... execute permissions. ... This is assuming that the PHP script runs ... of potential security risks from other users on the same server. ... Apache as the global web server user and thus needs world write ...
    (alt.php)
  • mysqli error?
    ... I'm just setting up my php enviroment and I typed in a simple script ... # configuration directives that give the server its instructions. ...
    (comp.lang.php)
  • Re: write with cURL
    ... execute permissions. ... This is assuming that the PHP script runs ... of potential security risks from other users on the same server. ... web server itself is part of the group. ...
    (alt.php)