well iam not that advanced scripter...so i took some stuff i found and combined it pretty much
the main two problems are.
everytime i execute long command lets say like "exec server.cfg" (which executes lots of commands in once)
it crashes the server.
other issue, the query is very slow
i write for example
map cp_badlands
takes it about 30second to change map...sometimes its instant
sometimes its slow like hell
also i added the CheckEmpty stuff...to stop the page from reloading for years first time you open it :X
anyone mind helping and improving this?
thanks =\
(probably posted on the wrong forum, so move it to the correct one please)
PHP Code:
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
<input name="command" type="text"><br>
<input type="submit" value="QUERY RCON COMMAND">
</form>
<?php
$command = $_REQUEST['command'] ;
function getByte(&$string)
{
$data = substr($string, 0, 1);
$string = substr($string, 1);
$data = unpack('Cvalue', $data);
return $data['value'];
}
function getShortUnsigned(&$string)
{
$data = substr($string, 0, 2);
$string = substr($string, 2);
$data = unpack('nvalue', $data);
return $data['value'];
}
function getShortSigned(&$string)
{
$data = substr($string, 0, 2);
$string = substr($string, 2);
$data = unpack('svalue', $data);
return $data['value'];
}
function getLong(&$string)
{
$data = substr($string, 0, 4);
$string = substr($string, 4);
$data = unpack('Vvalue', $data);
return $data['value'];
}
function getFloat(&$string)
{
$data = substr($string, 0, 4);
$string = substr($string, 4);
$array = unpack("fvalue", $data);
return $array['value'];
}
function getString(&$string)
{
$data = "";
$byte = substr($string, 0, 1);
$string = substr($string, 1);
while (ord($byte) != "0")
{
$data .= $byte;
$byte = substr($string, 0, 1);
$string = substr($string, 1);
}
return $data;
}
function checkEmpty($variable)
{
if($variable == NULL || $variable == '' || $variable == "" || $variable == " ")
{
$isempty = true;
}
else
{
$isempty = false;
}
return($isempty);
}
if(!CheckEmpty($command))
{
define('PACKET_SIZE', '1400');
define('SERVERQUERY_INFO', "\xFF\xFF\xFF\xFFTSource Engine Query");
define ('REPLY_INFO', "\x49");
define('SERVERQUERY_GETCHALLENGE', "\xFF\xFF\xFF\xFF\x57");
define ('REPLY_GETCHALLENGE', "\x41");
define('SERVERDATA_AUTH', 3) ;
define ('SERVERDATA_EXECCOMMAND', 2) ;
$_ip = '62.90.138.115' ; // server ip
$_port = '27011'; // server port
$_password = 'aj94ze' ; // your rcon password
$s2 = '';
$requestId = 1;
$socket = fsockopen ('tcp://'.$_ip, $_port, $errno, $errstr, 30) ;
$data = pack("VV", $requestId, SERVERDATA_AUTH).$_password.chr(0).$s2.chr(0);
$data = pack("V",strlen($data)).$data;
fwrite ($socket, $data, strlen($data)) ;
$requestId++ ;
$junk = fread ($socket, PACKET_SIZE) ;
$string = fread ($socket, PACKET_SIZE) ;
$size = getLong($string) ;
$id = getLong ($string) ;
if ($id == -1)
{
die ('Auth failed: bad password !') ;
}
$data = pack ("VV", $requestId, SERVERDATA_EXECCOMMAND).$command.chr(0).$s2.chr(0) ;
$data = pack ("V", strlen ($data)).$data ;
fwrite ($socket, $data, strlen($data)) ;
$requestId++ ;
$i = 0 ;
$text = '' ;
while ($string = fread($socket, 4))
{
$info[$i]['size'] = getLong($string) ;
$string = fread($socket, $info[$i]['size']) ;
$info[$i]['id'] = getLong ($string) ;
$info[$i]['type'] = getLong ($string) ;
$info[$i]['s1'] = getString ($string) ;
$info[$i]['s2'] = getString ($string) ;
$text .= $info[$i]['s1'] ;
$i++ ;
}
$first= strpos ($text, '"', 12) ;
$first++ ;
$last = strpos ($text, '"', $first+2) ;
print "Rcon Respone: " . substr($text, $first, $last-$first) ;
}
?>
the main two problems are.
everytime i execute long command lets say like "exec server.cfg" (which executes lots of commands in once)
it crashes the server.
other issue, the query is very slow
i write for example
map cp_badlands
takes it about 30second to change map...sometimes its instant
sometimes its slow like hell
also i added the CheckEmpty stuff...to stop the page from reloading for years first time you open it :X
anyone mind helping and improving this?
thanks =\
(probably posted on the wrong forum, so move it to the correct one please)