Kennt jemand eine Beschreibung zum RCON Protokoll vom Battlefield 1942 Server?
Ich kann zwar eine Socket Verbindung aufbauen, aber der Server antwortet mir nur mit "HjŸÃñ·Q=ÊÄ" oder ähnlichem. Ich vermute mal das ich das irgendwie kombiniert mit dem RCON Passwort zurück schicken muss, aber wie? Gibt es irgendwo eine Beschreibung der Protokolls?
-
-
Anscheinend ist leider nur für BF2 etwas zu finden: http://bf2tech.org/index.php/RCon_Protocol
Vielleicht hilfts weiter. Ansonsten hilft wohl nur package-sniffing.. aber das wird schwer. -
Genau so habe ich es auch gelöst. Ich habe einfach ein paar RCON Befehle mit HLSW an den Server geschickt und mit einem Paketsniffer den geschaut was HLSW so macht.
Falls jemand meine RCON Klasse braucht:
PHP
Alles anzeigen<?php if (!defined('IN_SCRIPT')) { exit; } class RconWI { private $socket = false; private $logged_in = 0; 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) { $key = socket_read($this->socket, 2048); $username = _xorcrypt($username, $key) . "\x00"; $password = _xorcrypt($pw, $key) . "\x00"; socket_write($this->socket, pack("L",strlen($username))); socket_write($this->socket, $username); socket_write($this->socket, pack("L",strlen($password))); socket_write($this->socket, $password); $result = socket_read($this->socket, 2048); $this->logged_in = xbyte_to_int($result); } function send($command) { if($this->logged_in == 1) { $comm_tmp = int_to_4byte(2); socket_write($this->socket, $comm_tmp); $comm_tmp = "ConsoleMessage 0"; $len = strlen($comm_tmp) + 1; socket_write($this->socket, int_to_4byte($len)); socket_write($this->socket, $comm_tmp . chr(0)); $len = strlen($command) + 1; socket_write($this->socket, int_to_4byte($len)); socket_write($this->socket, $command . chr(0)); $result = socket_read($this->socket, 2048); $result = socket_read($this->socket, 4048); return $result; } } } function _xorcrypt($string, $key) { for($i = 0; $i < strlen($string); $i++) { $string[$i] = $string[$i]^$key[$i]; } return $string; } function xbyte_to_int($stri_conv) { $val_finale = 0; $len_stri = strlen($stri_conv); for($x = 0; $x < $len_stri; $x++) { $val_finale = $val_finale + (ord(substr($stri_conv, $x, 1)) * pow(256, $x)); } return $val_finale; } function int_to_4byte($numero_conv) { $final_stri = ""; for ($x = 1; $x <= 3; $x++) { $n_val = intval(floor($numero_conv/256)); $n_rest = intval($numero_conv % 256); $final_stri .= chr($n_rest); $numero_conv = $n_val; } $final_stri .= chr($n_val); return $final_stri; } ?>
-
Super, danke. Das heisst wohl, es unterscheidet sich von BF2-rcon? Dann werde ich deinen Code ggf. nach Java in die rconed lib portieren
-
Ja BF2 ist deutlich einfacher. Für BF2 verwende ich folgendes:
PHP
Alles anzeigenclass 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:
PHP
Alles anzeigenclass 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
Jetzt mitmachen!
Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!