User:Fly-man-/Webbased Regions

From OpenSimulator

< User:Fly-man-
Revision as of 09:46, 15 February 2009 by Fly-man- (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

How to create a region server that uses the Web to get his regions:


1: Create a database called regionxml

CREATE DATABASE regionxml

2: Create 2 tables that hold all the information for the regionserver and regions themselves

CREATE TABLE regionservers (
  `IP` varchar(20) NOT NULL,
  `ServerID` int(1) NOT NULL,
  PRIMARY KEY  (`IP`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `xmlregions` (
  `sim_UUID` varchar(50) NOT NULL,
  `sim_name` varchar(255) NOT NULL,
  `sim_location_x` int(6) NOT NULL,
  `sim_location_y` int(6) NOT NULL,
  `internal_ip_address` varchar(20) NOT NULL default '0.0.0.0',
  `regionserver` int(1) NOT NULL,
  `master_avatar_uuid` varchar(50) NOT NULL default '00000000-0000-0000-0000-000000000000',
  `master_avatar_first` varchar(255) NOT NULL,
  `master_avatar_last` varchar(255) NOT NULL,
  `master_avatar_pass` varchar(255) NOT NULL,
  `lastmap_uuid` varchar(50) NOT NULL,
  `lastmap_refresh` int(11) NOT NULL,
  PRIMARY KEY  (`sim_UUID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

3: Fill in your region server and give them a number

INSERT INTO `regionservers` VALUES ('<IP>', <number>);

4: Fill the xmlregion table with the region info you need

INSERT INTO `xmlregions` VALUES ('<UUID>', '<region name>', <X>, <Y>, '0.0.0.0', <regionserver>, '00000000-0000-0000-0000-000000000000', 
'<master_first>', '<master_last>', '<master_password>', '', 0);

5: Use these settings in your OpenSim.ini to get the region to poll the Grid server for regions:

; Determine where OpenSimulator looks for the files which tell it which regions to server
; Defaults to "filesystem" if this setting isn't present
; region_info_source = "filesystem"
region_info_source = "web"

; Determines where the region XML files are stored if you are loading these from the filesystem.  
; Defaults to bin/Regions in your OpenSimulator installation directory
; regionload_regionsdir="C:\somewhere\xmlfiles\"

; Determines the page from which regions xml is retrieved if you are loading these from the web
; The XML here has the same format as it does on the filesystem (including the <Root> tag), 
; except that everything is also enclosed in a <Regions> tag.
regionload_webserver_url = "http://grid/opensim/regions.php";

The region.php file looks like this:

<?
include("database.inc.php");

// Setup the database connection
mysql_connect($host,$username,$password);
mysql_select_db($database);

// Getting the region server credits
$external = ($_SERVER['HTTP_X_FORWARDED_FOR']) ?  $_SERVER['HTTP_X_FORWARDED_FOR'] :  $_SERVER['REMOTE_ADDR'];

$requestregion = "SELECT ServerID from regionservers where IP = '$external'";

$trapregion = mysql_query($requestregion);

while ($regions = mysql_fetch_row($trapregion))
{
 $region = $regions[0];
}

// Getting all region info for the calling server
$sql = "SELECT sim_UUID,sim_name,sim_location_x,sim_location_y,master_avatar_uuid,
        master_avatar_first,master_avatar_last,master_avatar_pass,
        lastmap_uuid,lastmap_refresh FROM
        $table WHERE regionserver = $region";

$result = mysql_query($sql);

// Set the Start for the XML
echo "<Regions>\r\n";

// Additional port info set here
$port = 9000;

// Fill the XML with the region from the database
while ($row = mysql_fetch_row($result))
{
    echo "<Root>\r\n";
    echo '<Config sim_UUID="'.$row[0].'" sim_name="'.$row[1].'" sim_location_x="'.$row[2].'" sim_location_y="'.$row[3].'" internal_ip_address="0.0.0.0" internal_ip_port="'.$port.'" external_host_name="'.$external.'" master_avatar_uuid="'.$row[4].'" master_avatar_first="'.$row[5].'" master_avatar_last="'.$row[6].'" master_avatar_pass="'.$row[7].'"/>';
    echo "\r\n";
    echo "</Root>\r\n";
    $port = $port + 1;
}
echo "</Regions>";
?>
Personal tools
General
About This Wiki