| HOLOMATCH SERVER MANAGER --- V 0.01
|
|
|
|
[" .
$_SERVER['REMOTE_ADDR'] .
" @ HOLOMATCH1: " .
date("Ymd H:m:s") .
"]# ";
/* unless we have posted information, we should just display the form */
$hIP = "";
$hPort = "";
$cmdType = "";
$hPass = "";
$hCmdArg = "";
$boolPosting = "";
if(isset($_POST['cmdType'])){
$cmdType = $_POST['cmdType'];
}
if(isset($_POST['boolPosting'])){
$boolPosting = $_POST['boolPosting'];
}
if(isset($_POST['hIP'])){
$hIP = $_POST['hIP'];
}
if(isset($_POST['hPort'])){
$hPort = $_POST['hPort'];
}
if(isset($_POST['hPass'])){
$hPass = $_POST['hPass'];
}
if(isset($_POST['hCmdArg'])){
$hCmdArg = $_POST['hCmdArg'];
}
if($boolPosting == "TRUE")
{
/* set a default command type */
if(@$cmdType == "")
{
$pktCmd = "status";
}else{
/* otherwise set it to the requested command from the form */
$pktCmd = $cmdType;
}
/* turn on error reporting for our sockets stuff */
error_reporting(E_ALL);
/* default command string for the q3 and holomatch servers */
$pktSCmd = "rcon ";
/* pad the password string with a space */
$pktPass = $hPass . " ";
/* this is the default port, I haven't let the form change it yet */
$sckPort = 27960;
/* get the IP from the hostname in the form (works for IPs too) */
$sckHname = gethostbyname($hIP);
/* open a socket descriptor */
$socket = socket_create(AF_INET, SOCK_DGRAM, 0);
if($socket < 0 )
{
/* write out a nice error message */
echo $strPrompt .
"create socket failed.. reason:" .
strerror($socket) .
"\n "; /* critical failure, no sense continuing */ return(1); }else{ echo $strPrompt . "create socket SUCCESS!\n "; } echo $strPrompt. "attempting to connect to server: $sckHname..\n "; /* connect to the remote server */ if(($result = socket_connect($socket, $sckHname, $sckPort)) < 0 ) { echo $strPrompt . "connect failed... reason:" . strerror($result) . "\n "; socket_close($socket); /* critical failure, no sense continuing */ return(1); }else{ echo $strPrompt . "connect SUCCESS!\n "; } /******************************************************************* * we need to pad the packet with 4, full-on bytes, then comes the * * rcon command, then the password, then the console command. * * for commands that require arguments, we pad those on later * ******************************************************************/ $out = chr(255) . chr(255) . chr(255) . chr(255) . $pktSCmd . $pktPass . $pktCmd; /************************************************************************ * Some commands require arguments, check and see if the command we are * * passing requires one or not, and if so, append the argument * ***********************************************************************/ switch($pktCmd){ case "say": /* we need to insert a space and the quotation marks around the argument */ $out .= (chr(0x20) . chr(0x22) . $hCmdArg . chr(0x22)); break; case "kick": /* we need to insert a space and the quotation marks around the argument */ $out .= (chr(0x20) . chr(0x22) . $hCmdArg . chr(0x22)); break; default: /* we don't need to do anything for other commands */ break; } //echo "Out: " . $out . "\n "; echo $strPrompt . "sending request.. \n "; /* write the request out to the server */ if((socket_write($socket, $out, strlen($out))) < 0) { echo $strPrompt . "write failed... reason:" . strerror($result) . "\n "; } echo $strPrompt . "sent OK\n "; echo $strPrompt . "reading response..\n "; $in = ''; /* read in 2048 bytes from the port, returning a message if we didn't get anything. */ if(($in = socket_read($socket, 2048, PHP_BINARY_READ)) <= 0) { $in = "No data back from the server, are you sure that machine is running a HOLOMATCH server?"; }else{ /* cut the first 9 characters out of the string (0xFF, 0xFF, 0xFF, 0xFF and "print") */ $in = substr($in, 9); } ?> |
| RESPONSE FROM SERVER: |
|
/* write out one line with the length of data we got (just for fun :-)) */
echo $strPrompt ."INLEN:" . strlen($in) . "\n "; echo $strPrompt ."closing socket... \n "; /* always close sockets !!! */ socket_close($socket); echo $strPrompt . "OK..\n "; } ?> |