KaDaVrU Founder


Data inscrierii: 26/Mai/2008 Mesaje: 128 Localitate: Baia Mare
|
Trimis: 07/06/2008 11:40 Titlul subiectului: Clasa info servere hlds |
|
|
| 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 |
|