Also ich hab 2 Probleme.
Das 1. Problem ist, dass mir unter PHP5 keine
Fehlermeldungen ausgegeben werden. Anstatt
bleibt die Seite einfach leer.
Mein 2. Problem ist meine GameServer Klasse,
die nicht funktionieren möchte.
Hier der Source:
- Code: Select all
<?php
class GameServer {
public $ip, $port, $data, $status, $conn;
public function __construct($address) {
$this->printLine('TRACE: ' . __METHOD__);
if(preg_match('/:/', $address)) {
$this->printLine('<b>NOTICE:</b> Port given.');
list($this->ip, $this->port) = split(':', $address);
}
else
$this->ip = $address;
}
public function __destruct() {
$this->printLine('TRACE: ' . __METHOD__);
if(fclose($this->conn))
$this->printLine('<b>RUN:</b> Connection closed.');
}
public function __call($method, $args) {
$this->printLine('<i>SCRIPT:</i> The method <u>' . $method . '</u> does not exist.');
}
public function printLine($line) {
print $line . '<br />';
}
}
class Quake3Server extends GameServer {
public $port_default = '27960';
public function __construct($address) {
$this->printLine('TRACE: ' . __METHOD__);
parent::__construct($address);
if(empty($this->port)) {
$this->printLine('<b>NOTICE:</b> No port given; using default.');
$this->port = $port_default;
}
$this->connect();
$this->sendRequest();
}
public function connect() {
$this->printLine('TRACE: ' . __METHOD__);
if($this->conn = fsockopen('udp://' . $this->ip, $this->port, $errno, $errstr))
$this->printLine('<b>RUN:</b> Connection established.');
else
$this->printLine('<b>ERROR:</b> Connection refused.');
}
public function sendRequest() {
$this->printLine('TRACE: ' . __METHOD__);
if($this->conn) {
if(fwrite($this->conn, "\xFF\xFF\xFF\xFFgetStatus\n"))
$this->printLine('<b>RUN:</b> Request sent.');
stream_set_timeout($this->conn, $this->d_timeout);
$this->data = fgetc($this->conn);
$meta = stream_get_meta_data($this->conn);
if($meta['timed_out'])
$this->printLine('<b>RUN:</b> Server timed out.');
else {
if($meta['unread_bytes'] > 0)
if($this->data .= fread($this->conn, $meta['unread_bytes']))
$this->printLine('<b>RUN:</b> Reading data.');
else
$this->printLine('<b>ERROR:</b> No(?) data available.');
}
}
else
$this->printLine('<b>ERROR:</b> Cannot establish connection.');
}
public function getData() {
$this->printLine('TRACE: ' . __METHOD__);
return $this->data;
}
}
$svr1 = new Quake3Server('195.11.243.34:27961');
?>
Die Ausgabe ist folgende:
TRACE: Quake3Server::__construct
TRACE: GameServer::__construct
NOTICE: Port given.
TRACE: Quake3Server::connect
RUN: Connection established.
TRACE: Quake3Server::sendRequest
RUN: Request sent.
RUN: Server timed out.
TRACE: GameServer::__destruct
RUN: Connection closed.
Siehe "RUN: Server timed out."
Wenn ich das ganze ohne OOP mache, dann funktioniert es,
Der Source:
- Code: Select all
<?php
$connection = @fsockopen('udp://' . '195.11.243.34', 27961, $error['number'], $error['string']);
if($connection)
{
fwrite($connection, "\xFF\xFF\xFF\xFFgetStatus\n");
stream_set_timeout($connection, '1');
$data = fgetc($connection);
$status = stream_get_meta_data($connection);
if($status['timed_out'])
$setting['status'] = false;
else
if($status['unread_bytes'] > 0)
$data .= fread($connection, $status['unread_bytes']);
else
$setting['status'] = false;
}
else
{
$setting['status'] = false;
}
@fclose($connection);
print $data;
?>
Die Ausgabe:
ÿÿÿÿstatusResponse \g_maxGameClients\0\g_enableBreath\1\g_needpass\0\capturelimit\0\bot_minplayers\0\sv_allowDownload\1\sv_floodProtect\1\sv_maxPing\0\sv_minPing\0\sv_maxRate\12000\sv_punkbuster\1\sv_maxclients\14\sv_hostname\The Dog [2] Freeze 2\sv_privateClients\2\g_gametype\3\timelimit\20\fraglimit\0\dmflags\0\version\Q3 1.32b linux-i386 Nov 14 2002\protocol\68\mapname\pro-q3dm6\gamename\freeze 0 33 "^1GA^3n^1d^3al^1F^2<^1T^7I^4Q^2" 16 39 "DotS" 30 27 "slm" 25 39 "^1[^7+^1]^7Nosy^1boy" 22 88 "^jJ^gE^jZ" 26 33 "^3[^1PFF^3]^4Garg@mel^7" 22 31 "^4M^1<>^4NK^13^4Y" 12 40 "^4!RaF!^1CoUg4r" 26 60 "^2T^5e^2m^5p" 9 21 "Polyman" 14 31 "P^80^∫" 14 94 "^1Dante"
Hat jemand eine Lösung für mich?