Export to GitHub

opensimtools - RemoteAdminPHPClass.wiki


How to use ?

For commands and parameters, refer to the RemoteAdmin plugin webpage : http://opensimulator.org/wiki/RemoteAdmin

Example to use this PHP Class :

```

'This message will be broadcast in all regions of the simulator :D'); $myRA->SendCommand('admin_broadcast', $paramaters); // When no parameters are needed for a RemoteAdmin command, no need to specify the second parameter in the SendCommand function. $myRA->SendCommand('admin_shutdown'); ?>

```

Code : RemoteAdmin PHP Class

```

SendCommand('admin_broadcast', array('message' => 'Message to broadcast to all regions')); // $myremoteadmin->SendCommand('admin_shutdown'); // Commands like admin_shutdown don't need params, so you can left the second SendCommand functino param empty ;) // Example for error handling // // include('classes/RemoteAdmin.php'); // $RA = new RemoteAdmin('localhost', 9000, 'secret'); // $retour = $RA->SendCommand('admin_shutdown'); // if ($retour === FALSE) // { // echo 'ERROR'; // } class RemoteAdmin { function RemoteAdmin($sURL, $sPort, $pass) { $this->simulatorURL = $sURL; // String $this->simulatorPort = $sPort; // Integer $this->password = $pass; } function SendCommand($command, $params=array()) { $paramsNames = array_keys($params); $paramsValues = array_values($params); // Building the XML data to pass to RemoteAdmin through XML-RPC ;) $xml = ' ' . htmlspecialchars($command) . ' password ' . htmlspecialchars($this->password) . ' '; if (count($params) != 0) { for ($p = 0; $p ' . htmlspecialchars($paramsNames[$p]) . ''; $xml .= '' . htmlspecialchars($paramsValues[$p]) . ''; } } $xml .= ' '; // // echo $xml; // // Now building headers and sending the data ;) $host = $this->simulatorURL; $port = $this->simulatorPort; $timeout = 5; // Timeout in seconds error_reporting(0); $fp = fsockopen($host, $port, $errno, $errstr, $timeout); if (!$fp) { return FALSE; // If contacting host timeouts or impossible to create the socket, the method returns FALSE } else { fputs($fp, "POST / HTTP/1.1\r\n"); fputs($fp, "Host: $host\r\n"); fputs($fp, "Content-type: text/xml\r\n"); fputs($fp, "Content-length: ". strlen($xml) ."\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $xml); $res = ""; while(!feof($fp)) { $res .= fgets($fp, 128); } fclose($fp); $response = substr($res, strpos($res, "\r\n\r\n"));; // Now parsing the XML response from RemoteAdmin ;) $result = array(); if (preg_match_all('#(.+)(.*)#U', $response, $regs, PREG_SET_ORDER)) { foreach($regs as $key=>$val) { $result[$val[1]] = $val[3]; } } return $result; } } } ?>

```