Halihalo ihr,
Heute sah ich von ( ich glaube ) Gamemonitor.de Serverviewer für Samp und habe mich gleich an einen rangesetzt:
Code
<?php
header("Content-Type: image/jpg");
$ip = '127.0.0.1';
$port = 7777;
require
$server = new gtasampapi($ip,$port);
$infos = $server->getInfo();
$im = imagecreatefromjpeg("background.jpg");
$tc = imagecolorallocate ($im, 0, 0, 0);
if(!$server->isOnline())
{
$text = 'Server offline';
imageString($im, 2, 5, 3, $text, $tc);
ImageJPEG($im);
imagedestroy ($im);
}
$text = $infos['hostname'] .' ( '. $ip .':'. $port .' )';
imageString($im, 2, 5, 3, $text, $tc);
$text = 'Version: '. $infos['gamemode'];
imageString($im, 2, 25, 3, $text, $tc);
$text = 'Spieler: '. $infos['players'] .' / '. $infos['maxplayers'];
imageString($im, 2, 45, 3, $text, $tc);
if(!is_array($players) || count($players) == 0)
{
$text = 'Keiner online';
imageString($im, 2, 65, 3, $text, $tc);
}
else
{
$i = 45;
foreach($players as $value) //for($i = 0; $i < count($players);$i++)
{
$i += 20;
$text = $value['nickname'] .' ( Level: '. $value['Score'] .' )';
imageString($im, 2, $i, 3, $text, $tc);
}
}
ImageJPEG($im);
imagedestroy ($im);
class gtasampapi
{
private $rSocket = false;
private $aServer = array();
public function __construct($sServer, $iPort = 7777)
{
$this->aServer[0] = $sServer;
$this->aServer[1] = $iPort;
$this->rSocket = fsockopen('udp://'.$this->aServer[0], $this->aServer[1], $iError, $sError, 2);
if(!$this->rSocket)
{
$this->aServer[4] = false;
return;
}
socket_set_timeout($this->rSocket, 2);
$sPacket = 'SAMP';
$sPacket .= chr(strtok($this->aServer[0], '.'));
$sPacket .= chr(strtok('.'));
$sPacket .= chr(strtok('.'));
$sPacket .= chr(strtok('.'));
$sPacket .= chr($this->aServer[1] & 0xFF);
$sPacket .= chr($this->aServer[1] >> 8 & 0xFF);
$sPacket .= 'p4150';
fwrite($this->rSocket, $sPacket);
if(fread($this->rSocket, 15))
{
$this->aServer[4] = true;
}
else
{
$this->aServer[4] = false;
}
}
public function __destruct()
{
@fclose($this->rSocket);
}
public function isOnline()
{
return isset($this->aServer[4]) ? $this->aServer[4] : false;
}
public function getInfo()
{
@fwrite($this->rSocket, $this->createPacket('i'));
fread($this->rSocket, 11);
$aDetails['password'] = (integer) ord(fread($this->rSocket, 1));
$aDetails['players'] = (integer) $this->toInteger(fread($this->rSocket, 2));
$aDetails['maxplayers'] = (integer) $this->toInteger(fread($this->rSocket, 2));
$iStrlen = ord(fread($this->rSocket, 4));
if(!$iStrlen) return -1;
$aDetails['hostname'] = (string) fread($this->rSocket, $iStrlen);
$iStrlen = ord(fread($this->rSocket, 4));
$aDetails['gamemode'] = (string) fread($this->rSocket, $iStrlen);
$iStrlen = ord(fread($this->rSocket, 4));
$aDetails['mapname'] = (string) fread($this->rSocket, $iStrlen);
return $aDetails;
}
public function getBasicPlayers()
{
@fwrite($this->rSocket, $this->createPacket('c'));
fread($this->rSocket, 11);
$iPlayerCount = ord(fread($this->rSocket, 2));
$aDetails = array();
if($iPlayerCount > 0)
{
for($iIndex = 0; $iIndex < $iPlayerCount; ++$iIndex)
{
$iStrlen = ord(fread($this->rSocket, 1));
$aDetails[] = array
(
"nickname" => (string) fread($this->rSocket, $iStrlen),
"score" => (integer) $this->toInteger(fread($this->rSocket, 4)),
);
}
}
return $aDetails;
}
public function getDetailedPlayers()
{
@fwrite($this->rSocket, $this->createPacket('d'));
fread($this->rSocket, 11);
$iPlayerCount = ord(fread($this->rSocket, 2));
$aDetails = array();
for($iIndex = 0; $iIndex < $iPlayerCount; ++$iIndex)
{
$aPlayer['playerid'] = (integer) ord(fread($this->rSocket, 1));
$iStrlen = ord(fread($this->rSocket, 1));
$aPlayer['nickname'] = (string) fread($this->rSocket, $iStrlen);
$aPlayer['score'] = (integer) $this->toInteger(fread($this->rSocket, 4));
$aPlayer['ping'] = (integer) $this->toInteger(fread($this->rSocket, 4));
$aDetails[] = $aPlayer;
unset($aPlayer);
}
return $aDetails;
}
public function getRules()
{
@fwrite($this->rSocket, $this->createPacket('r'));
fread($this->rSocket, 11);
$iRuleCount = ord(fread($this->rSocket, 2));
$aReturn = array();
for($iIndex = 0; $iIndex < $iRuleCount; ++$iIndex)
{
$iStrlen = ord(fread($this->rSocket, 1));
$sRulename = (string) fread($this->rSocket, $iStrlen);
$iStrlen = ord(fread($this->rSocket, 1));
$aDetails[$sRulename] = (string) fread($this->rSocket, $iStrlen);
}
return $aDetails;
}
private function toInteger($sData)
{
$iInteger = 0;
$iInteger += (ord($sData[0]));
if(isset($sData[1]))
{
$iInteger += (ord($sData[1]) << 8);
}
if(isset($sData[2]))
{
$iInteger += (ord($sData[2]) << 16);
}
if(isset($sData[3]))
{
$iInteger += (ord($sData[3]) << 24);
}
if($iInteger >= 4294967294)
{
$iInteger -= 4294967296;
}
return $iInteger;
}
private function createPacket($sPayload)
{
$sPacket = 'SAMP';
$sPacket .= chr(strtok($this->aServer[0], '.'));
$sPacket .= chr(strtok('.'));
$sPacket .= chr(strtok('.'));
$sPacket .= chr(strtok('.'));
$sPacket .= chr($this->aServer[1] & 0xFF);
$sPacket .= chr($this->aServer[1] >> 8 & 0xFF);
$sPacket .= $sPayload;
return $sPacket;
}
}
?>
Alles anzeigen
Das untere mit gtasampapi habe ich aus dem Internet von i-einer PHP-Socket website, müsste ich googlen.
Und das Bild sieht bei mir so aus:
entspreich also 100% der Internetadresse über die ich das Bild aufrufe
Die Grafik "backgroundcolor.jpg" könnte ich auch posten, wäre aber platzverschwendeung, da sie einfach nur weiß ist ( falls es einen unterschid macht: x = 88px y = 500px oder andersrum )
Hoffe jmd kann mir helfen,
Tion
// Edit:
In meinem Admin - CotrolPanel funktioniert die Socketverbindung einwandfrei, an der kanns also nicht liegen, ahe sie nur sicherheitshalber mit reingetan