Willkommen Gast
Du bist nicht angemeldet, um alle Funktionen des Forums zu nutzen musst du dich registrieren und anmelden. Die Registrierung ist natürlich völlig kostenlos und kann jeder Zeit wiederrufen werden.

Aktuelle Zeit: 11. Feb 2012 12:01

BF1942 RCON Protokoll

Das Forum zu allen Gameservern aus der Battlefield Reihe wie z.B. BF1942/BF2/BF2142 und BF Vietnam.


BF1942 RCON Protokoll

Beitragvon Tobi am 22. Jun 2010 12:22

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?
Benutzeravatar
Tobi
Administrator
Administrator
[ Anbieter Profil ]
 
Beiträge: 1555
Registriert: 13. Sep 2004 15:11
Wohnort: Stuttgart

Re: BF1942 RCON Protokoll

Beitragvon Downlord am 28. Jun 2010 07:22

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.
Benutzeravatar
Downlord
Mitglied
Mitglied
 
Beiträge: 64
Registriert: 5. Aug 2008 09:41

Re: BF1942 RCON Protokoll

Beitragvon Tobi am 29. Jun 2010 13:26

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:
Code: Alles auswählen
<?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;
}
?>
Benutzeravatar
Tobi
Administrator
Administrator
[ Anbieter Profil ]
 
Beiträge: 1555
Registriert: 13. Sep 2004 15:11
Wohnort: Stuttgart

Re: BF1942 RCON Protokoll

Beitragvon Downlord am 5. Jul 2010 08:04

Super, Danke. Das heisst wohl, es unterscheidet sich von BF2-rcon? Dann werde ich deinen Code ggf. nach Java in die rconed lib portieren :)
Benutzeravatar
Downlord
Mitglied
Mitglied
 
Beiträge: 64
Registriert: 5. Aug 2008 09:41

Re: BF1942 RCON Protokoll

Beitragvon Tobi am 5. Jul 2010 14:11

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
Benutzeravatar
Tobi
Administrator
Administrator
[ Anbieter Profil ]
 
Beiträge: 1555
Registriert: 13. Sep 2004 15:11
Wohnort: Stuttgart


Zurück zu Battlefield




Ähnliche Beiträge

BF1942 Server startet nicht - Debian64 bit
Forum: Battlefield
Autor: fuuussiiidiel
Antworten: 7
CS:S-GameServer auf HomeServer - RCON funktioniert nicht
Forum: Counter Strike Source
Autor: Pax90
Antworten: 8
Teeworlds Server ohne RCON?!
Forum: Sonstige Gameserver
Autor: ZeroIP
Antworten: 2
Rcon Gameserver Webinterface
Forum: Gameserver Webinterface
Autor: CoB Pitbull
Antworten: 5
KB: MoH Admin / RCON Befehle
Forum: Medal of Honor
Autor: [GSA] Bot
Antworten: 0


Wer ist online?

Mitglieder: Exabot [Bot], Google [Bot]