opensim-tools – Rev 74
?pathlinks?
#!/usr/bin/php
<?php
/////////////////////////////////////////////////////////////
// Wizardry and Steamworks (c) was.fm - 2014, License: MIT //
// //
// Permission is hereby granted, free of charge, to any //
// person obtaining a copy of this software and associated //
// documentation files (the "Software"), to deal in the //
// Software without restriction, //including without //
// limitation the rights to use, copy, modify, merge, //
// publish, distribute, sublicense, and/or sell copies of //
// the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the //
// following conditions: //
// //
// The above copyright notice and this permission notice //
// shall be included in all copies or substantial portions //
// of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF //
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT //
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS //
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO //
// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE //
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER //
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR //
// THE USE OR OTHER DEALINGS IN THE SOFTWARE. //
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
// CONFIGfURATION //
/////////////////////////////////////////////////////////////
// Hostname or IP of your OpenSim MySQL server.
define("MYSQL_HOSTNAME", "localhost");
// Username of the OpenSim MySQL user.
define("MYSQL_USERNAME", "opensim");
// Password of the OpenSim MySQL user.
define("MYSQL_PASSWORD", "***");
// Name of the OpenSim database on the MySQL server.
define("MYSQL_DATABASE", "opensim");
/////////////////////////////////////////////////////////////
// INTERNALS //
/////////////////////////////////////////////////////////////
require_once('/var/www/lib/wasRemoteAdmin.php');
if(!defined('STDIN')) {
print 'This script is meant to be run on the command line.'."\n";
return 1;
}
$connection_ok = mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD);
if(!$connection_ok) {
print 'Could not connect to the OpenSim database. Please edit the script and make sure the credentials are correct.'."\n";
return 1;
}
$db_selected = mysql_select_db(MYSQL_DATABASE);
if(!$db_selected) {
print 'Could not select the opensim database. Please edit this script and make sure the credentials are correct.'."\n";
return 1;
}
$query = 'SELECT RegionName FROM regions';
$result = mysql_query($query);
$regions = array();
while($row = mysql_fetch_array($result)) {
if(!preg_match('/^http:\/\//', $row[0])) {
array_push($regions, $row[0]);
}
}
$agents = 0;
$req = new wasRemoteAdmin('http://127.0.0.1:10000', 'opensim');
foreach($regions as $region) {
$rep = new SimpleXMLElement($req->admin_get_agents($region, "false"));
foreach($rep->params->param->value->struct->member as $member) {
if($member->name == "regions") {
foreach($member->value->array->data->value->struct->member as $member) {
if($member->name == "agents") {
$agents += count($member->value->array->data->value);
}
}
}
}
}
if($agents == 0) {
$req->admin_console_command("scripts suspend");
return 0;
}
$req->admin_console_command("scripts resume");
return 0;