Ja BF2 ist deutlich einfacher. Für BF2 verwende ich folgendes:
- Code: Alles auswählen
class RconWI
{
private $socket = false;
function send_rcon($cmd)
{
$response = $this->send($cmd);
return $response;
}
function connect($ip = '127.0.0.1', $port = '4711')
{
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($this->socket === false)
{
return false;
}
$result = socket_connect($this->socket, $ip, $port);
if ($result === false)
{
return false;
}
return true;
}
function close()
{
socket_close($this->socket);
}
function login($pw, $username = false)
{
if(empty($pw))
{
return false;
}
socket_read($this->socket, 2048);
$seed = socket_read($this->socket, 2048);
$seed = str_replace('### Digest seed: ', '', $seed);
$seed = str_replace("\n", '', $seed);
$pw = md5($seed . $pw);
socket_write($this->socket, "\x02login " . $pw . "\n");
return $this->read_socked();
}
function read_socked()
{
$out = $done = false;
while (!$done)
{
$data = socket_read($this->socket, 1024);
$out .= $data;
if(substr_count($data, "\x04"))
{
$done = true;
}
}
return str_replace("\x04", '', $out);
}
function send($cmd)
{
socket_write($this->socket, "\x02" . $cmd . "\n");
return $this->read_socked();
}
}
Dann hätte ich noch GTA SA:MP im Angebot:
- Code: Alles auswählen
class RconWI
{
private $socket = false;
private $pass = '';
private $ip_adr = false;
function connect($ip = '127.0.0.1', $port = '7777')
{
if($this->socket = fsockopen('udp://'.$ip, $port, $iError, $sError, 2))
{
$this->ip_adr = $ip;
return true;
}
}
function close()
{
fclose($this->socket);
}
function login($pw, $username = false)
{
$this->pass = $pw;
}
function send_rcon($command)
{
$iPort = 7777;
$aIPAddr = explode('.', $this->ip_adr);
$sPacket = "";
$sPacket .= "SAMP";
$sPacket .= chr($aIPAddr[0]);
$sPacket .= chr($aIPAddr[1]);
$sPacket .= chr($aIPAddr[2]);
$sPacket .= chr($aIPAddr[3]);
$sPacket .= chr($iPort & 0xFF);
$sPacket .= chr($iPort >> 8 & 0xFF);
$sPacket .= "x";
$sPacket .= chr(strlen($this->pass) & 0xFF);
$sPacket .= chr(strlen($this->pass) >> 8 & 0xFF);
$sPacket .= $this->pass;
$sPacket .= chr(strlen($command) & 0xFF);
$sPacket .= chr(strlen($command) >> 8 & 0xFF);
$sPacket .= $command;
fwrite($this->socket, $sPacket);
$response = array();
if(socket_set_timeout($this->socket, 0, 10000))
{
$out = stream_get_contents($this->socket, -1);
$rpl = preg_replace('(\w+)', '', $out);
$rpl = chunk_split($rpl,1,"|");
$rpl = explode("|",$rpl);
$out = str_replace($rpl, '', $out);
$out = str_replace('SAMPax', "\n", $out);
}
return $out;
}
}
Weitere Server sind noch in Arbeit