SRCDS Steam group


PHP reboot
#1
Is there a way to reset a SRCDS by using the php exec or system commands. I would like to setup a web based reset for my clan's server using XAMMP (apache) and php. I think the server will be running on Fedora. Thanks. Smile
Reply
#2
You can use php to connect to the server using RCON protocol. just google php and rcon.
[Image: userbar_wow.jpg]
starting 9/24/2006 if your problem has been solved please edit your first post and add [solved] to the begining of the title. Thanks.
Reply
#3
is this avaiable for source engine?
i was looking for something like this.
Linux IsiX 64 Generic Desktop ValHalla 2.6.33.4 x86_64
Intel Core 2 Duo T8400 4Gb Ram 40G SSD Intel
[Image: b_460x42_C000000-454234-696149-FFFFFF-FFF468-FFF468.png]
DoD 31 Comunity DoD 31 Spanish Comunity
Erste SS Panzer Grendier Division [DOD Clan]
Reply
#4
I'm not sure how different the rcon protocol for source is from hlds, but i know its still possible to have PHP connect to an srcds server via the rcon protocol using sockets.
[Image: userbar_wow.jpg]
starting 9/24/2006 if your problem has been solved please edit your first post and add [solved] to the begining of the title. Thanks.
Reply
#5
Thanks guys, I'll look it up now Smile
Reply
#6
The RCON protocol of source is a real pain in the ass, I've been trying to get it to work for like 3 months, then I gave up. I used to have several php source files which should be working I can try to find thos and post it here.

Stupid thing is that the restart command just shuts down the server, it doesnt actually restart...
Join the Source Dedicated Server Support Group on Steam Community!
Source Dedicated Server (SRCDS)
Free to join, Live support! (When available)

http://forums.srcds.com/viewtopic/5114
Reply
#7
I just found some source code from a french site that worked for me to send a rcon command to my server. Was able to execute _restart from the web and it restarted successfully. I converted the french words into something more readable in english. I've attached the php class file and the example page they had to let you execute rcon commands. Now that I have this at my disposal, I can code something useful for the other admins on my server, especially when I'm not available. =D

class.rcon.css.php
Code:
<?php
/*
    CS:S Rcon PHP Class - code by 1FO|zyzko 01/12/2005
    www.1formatik.com - www.1fogames.com
    --------------------------------------------------
*/
define("SERVERDATA_EXECCOMMAND",2);
define("SERVERDATA_AUTH",3);

class RCon {
    var $Password;
    var $Host;
    var $Port = 27015;
    var $_Sock = null;
    var $_Id = 0;

    function RCon ($Host,$Port,$Password) {
    $this->Password = $Password;
    $this->Host = $Host;
    $this->Port = $Port;
    $this->_Sock = @fsockopen($this->Host,$this->Port, $errno, $errstr, 30) or
        die("Unable to open the port: $errstr ($errno)\n");
    $this->_Set_Timeout($this->_Sock,2,500);
    }
    
    function Auth () {
    $PackID = $this->_Write(SERVERDATA_AUTH,$this->Password);
    
    $ret = $this->_PacketRead();
    if ($ret[1]['id'] == -1) {
        die("Erreur\n");
    }
    }

    function _Set_Timeout(&$res,$s,$m=0) {
    if (version_compare(phpversion(),'4.3.0','<')) {
        return socket_set_timeout($res,$s,$m);
    }
    return stream_set_timeout($res,$s,$m);
    }

    function _Write($cmd, $s1='', $s2='') {
    $id = ++$this->_Id;
    $data = pack("VV",$id,$cmd).$s1.chr(0).$s2.chr(0);
    $data = pack("V",strlen($data)).$data;
    fwrite($this->_Sock,$data,strlen($data));
    return $id;
    }

    function _PacketRead() {
    $retarray = array();
    while ($size = @fread($this->_Sock,4)) {
        $size = unpack('V1Size',$size);
        if ($size["Size"] > 4096) {
        $packet = "\x00\x00\x00\x00\x00\x00\x00\x00".fread($this->_Sock,4096);
        } else {
        $packet = fread($this->_Sock,$size["Size"]);
        }
        array_push($retarray,unpack("V1ID/V1Reponse/a*S1/a*S2",$packet));
    }
    return $retarray;
    }

    function Read() {
    $Packets = $this->_PacketRead();    
    foreach($Packets as $pack) {
        if (isset($ret[$pack['ID']])) {
        $ret[$pack['ID']]['S1'] .= $pack['S1'];
        $ret[$pack['ID']]['S2'] .= $pack['S1'];
        } else {
        $ret[$pack['ID']] = array(
                    'Reponse' => $pack['Reponse'],
                    'S1' => $pack['S1'],
                    'S2' =>    $pack['S2'],
                    );
        }
    }
    return $ret;
    }

    function sendCommand($Command) {
    $Command = '"'.trim(str_replace(' ','" "', $Command)).'"';
    $this->_Write(SERVERDATA_EXECCOMMAND,$Command,'');
    }

    function rconCommand($Command) {
    $this->sendcommand($Command);
    $ret = $this->Read();
    return $ret[0]['S1'];
    }
}
?>

rcon.php
Code:
<?php
/*
    CS:S Rcon PHP exemple - code by 1FO|zyzko 01/12/2005
    www.1formatik.com / www.1fogames.com
    --------------------------------------------------
*/
include_once("class.rcon.css.php");

if ( (!isset($_POST["IP"]))&&(!isset($_POST["Port"]))&&(!isset($_POST["Pass"]))&&(!isset($_POST["Rcon"])) )
{
echo "Please complete the following fields.</br>";
echo '<form name="RconForm" method="post" action="./rcon.php">';
echo 'IP : <input type="text" name="IP" value=""></br>';
echo 'Port : <input type="text" name="Port" value=""></br>';
echo 'RCON Password : <input type="password" name="Pass" value=""></br>';
echo 'Command <a href="http://www.hl2world.com/wiki/index.php/CSS_Server_Commands" target="_blank">Rcon</a> : ';
echo '<input type="text" name="Rcon" value=""></br>';
echo '<input type="submit" name="Submit" value="Submit">';
echo '</form>';
}
else
{
$IP = $_POST["IP"];
$Pass = $_POST["Pass"];
$Port = $_POST["Port"];
$Rcon = $_POST["Rcon"];
echo "<div style=\"visibility:hidden\">";
$r = new rcon("$IP",$Port,"$Pass");
$r->Auth();
var_dump($r->rconCommand("$Rcon"));
echo "</div>";
echo "The rcon command \"$Rcon\" was successfully executed on $IP:$Port\n";
echo '<form name="RconForm" method="post" action="./rcon.php">';
echo 'IP : <input type="text" name="IP" value=""></br>';
echo 'Port : <input type="text" name="Port" value=""></br>';
echo 'RCON Password : <input type="password" name="Pass" value=""></br>';
echo 'Command <a href="http://www.hl2world.com/wiki/index.php/CSS_Server_Commands" target="_blank">Rcon</a> : ';
echo '<input type="text" name="Rcon" value=""></br>';
echo '<input type="submit" name="Submit" value="Submit">';
echo '</form>';
}
?>
Reply
#8
great job m8, i will test it and adapt it to my needings.
Linux IsiX 64 Generic Desktop ValHalla 2.6.33.4 x86_64
Intel Core 2 Duo T8400 4Gb Ram 40G SSD Intel
[Image: b_460x42_C000000-454234-696149-FFFFFF-FFF468-FFF468.png]
DoD 31 Comunity DoD 31 Spanish Comunity
Erste SS Panzer Grendier Division [DOD Clan]
Reply
#9
Is there any way on a linux css server to totally restart it? Like rcon quit used to do :/
Reply
#10
configuring a game control panel using webmin.... with start and stop scripts
Linux IsiX 64 Generic Desktop ValHalla 2.6.33.4 x86_64
Intel Core 2 Duo T8400 4Gb Ram 40G SSD Intel
[Image: b_460x42_C000000-454234-696149-FFFFFF-FFF468-FFF468.png]
DoD 31 Comunity DoD 31 Spanish Comunity
Erste SS Panzer Grendier Division [DOD Clan]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)