| Autor |
Mesaj |
*Power l Aleksey b.
---[CaPiTaN]---
![---[CaPiTaN]--- ---[CaPiTaN]---](http://support.myforum.ro/images/ranks/CSRanks/Admin.gif)

Data inscrierii: 22/Mar/2007 Mesaje: 197 Localitate: JaPaN/YoKoHaMa |
|
Clasa info servere hlds |
|
Clasa info servere hlds
Code:
<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;
}
?>
Pentru a o utiliza trebuie sa aveti socketurile activate din PHP.ini.
_________________ [url=http://www.gametracker.com/server_info/89.43.237.130:27015/] [/url] |
|
| 19/04/2007 18:32 |
|
 |
|
|
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, 2005 phpBB Group Fa-ti si tu propriul forum GRATUIT, pe www.myforum.ro
|
|