SRCDS Steam group


Rcon query with PHP...need some help?
#1
well iam not that advanced scripter...so i took some stuff i found and combined it pretty much
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)
Reply
#2
There are many written RCon classes already, you can find a few in the tutorials section of this forum too, it's really a waste of time to write it yourself. Smile
Join the Source Dedicated Server Support Group on Steam Community!
Source Dedicated Server (SRCDS)
Free to join, Live support! (When available)

*****forums.srcds.com/viewtopic/5114
Reply
#3
Drocona Wrote:There are many written RCon classes already, you can find a few in the tutorials section of this forum too, it's really a waste of time to write it yourself. Smile
well iam way more satisfied when i understand what the script does and able to add stuff to it :O
only thing i wonder is, what is the loop for?
i removed the loop, now it retrieves the Respond way quicker, Instantly.


well never mind
now i have other issue i wanna take care of.
everytime i get rcon respone..lets say i get it like this:
Code:
"sv_password" = "157" ( def. "" ) notify - Server password for entry into multiplayer games

its supposed to come out like this:
Code:
"sv_password" = "157" ( def. "" ) notify - Server password for entry into multiplayer games

with spaces and what not
how can i detect spaces and add them manually? thx Smile
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)