Clasa info servere hlds

 
Creaza un subiect nou   Raspunde la subiect    Pagina de start a forumului TutorialeGaming - Speram sa va placa forumul! :: Tutoriale PHP
Subiectul anterior :: Subiectul urmator  
Autor Mesaj
KaDaVrU
Founder
Founder
KaDaVrU

Data inscrierii: 26/Mai/2008
Mesaje: 128
Localitate: Baia Mare

MesajTrimis: 07/06/2008 11:40    Titlul subiectului: Clasa info servere hlds Raspunde cu citat (quote)

Cod:
<class>port = $portin; } else { $this->port = "27015"; }
     $this->ip = $ipin;
     $this->command = "\377\377\377\377infostring\0";
     // infostring can be replaced with players too, but it returns some strange things.. so...
  }
function connect() {

  if($this->ip != NULL) {
  // Open a connection to the server
  $this->fp = fsockopen("udp://".$this->ip, $this->port, $errno, $errstr);

  //Send the request to the server.
  fwrite($this->fp, $this->command);

  //Remove the junk headers sent back
  $JunkHead = fread($this->fp,24);

  // Check to see if the server is running
  $CheckStatus = socket_get_status($this->fp);
  if($CheckStatus["unread_bytes"] == 0){
     $this->err = "Unable to connect to the server, ensure the IP and port is correct and that the server is running."; $this->errno = 2;
    }
   } else { $this->err = "There hasn't been entered any IP"; $this->errno = 1; }
  }
  function process() {
   if(!$errno) {
    // Read through the returned data and put in variable
    $do = 1;
    $HLServerStats= "";
    while($do) {
    $str = fread($this->fp,1);
    $HLServerStats.= $str;
    $status = socket_get_status($this->fp);
    if($status["unread_bytes"] == 0) {$do = 0;}
    }
    //Close the connection
    fclose($this->fp);

    // Explode the packet into an array.
    $HLServerStats = explode("\\", $HLServerStats);

    // Count the amount of keys in the array.
    $count = count($HLServerStats);

    // The amount of keys in the array MUST be an even number
    if($count % 2 == 0)
    {
    // Loop though all the keys and put them in the $ServerData array with the key values.
    $i = 0;
    while($count != $i)
    {
    $ServerData[$HLServerStats[$i]] = $HLServerStats[$i+1];
    $i = $i + 2;
     }
    $this->data=$ServerData;
    }
   }
  }
}
/*

--------------------------------------------------------------------------------
Returned Values
--------------------------------------------------------------------------------
Returned data from the code will return some commonly used information about the server. Here is a list of keys you can use use and a description of what they are:
address - IP Address of the server
players - Number of players currently playing
max - Max number of players that can connect
gamedir - Directory of the mod being played (IE: tfc)
map - Current map being played
type - Type of server: d for dedicated, l for listen.
os - OS the server is running on: w for Windows, l for Linux.

Now, if you're going to use the data in a webpage, the data is all stored in the data array which is contained in the object. You can now use the following code snippet, simply changing "VALUENAME" to the key of the value you wish to display. simply use
*/
$server = new server("86.55.132.198", "27015");
$asd=$server->connect();
$server->process();
if(!$server->errno) {
echo $server->data['map'];
} else {
echo "An error no. ".$server->errno." has been encountered: ".$server->err;
}
?>

_________________
Dute tAre viNo lenT,Pentru mIne na-I Tal3nt :P
Sus
Vezi profilul utilizatorului Trimite mesaj privat Trimite un mesaj
Afiseaza mesajele pentru a le previzualiza:   
Creaza un subiect nou   Raspunde la subiect    Pagina de start a forumului TutorialeGaming - Speram sa va placa forumul! :: Tutoriale PHP Ora este GMT + 2 ore
Pagina 1 din 1

 
Mergi direct la:  
Nu puteti crea un subiect nou in acest forum
Nu puteti raspunde in subiectele acestui forum
Nu puteti modifica mesajele proprii din acest forum
Nu puteti sterge mesajele proprii din acest forum
Nu puteti vota in chestionarele din acest forum




Powered by phpBB © 2001, 2002 phpBB Group
Fa-ti si tu propriul forum GRATUIT, pe www.myforum.ro
Charcoal2 Theme © Zarron Media