Open Sim Global Calculations BRIGADOON-0011
Provide a php class that provides a series of calculations using global coordinates
Loading...
Searching...
No Matches
load_region_table.php File Reference

Load a Table with Region Information from Open Simulator Config File Regions.ini. More...

Go to the source code of this file.

Functions

 rdOpenDatabase ($Database, $Host, $Username, $Password)
 Open the Support Database for Use.
 rdSaveRegion ($Parameters, $Pdo)
 Save a region to the Region Table.

Variables

 $pdo = rdOpenDatabase($db, $host, $db_username, $db_password)
 $region_data = []
 $source_file = "/opt/ls_opensim/bin/Regions/Regions.ini"
 $lines = file($source_file, FILE_IGNORE_NEW_LINES)
 $array_size = count($lines)

Detailed Description

Load a Table with Region Information from Open Simulator Config File Regions.ini.

Author
River Drifter river.nosp@m.-dri.nosp@m.fter@.nosp@m.auss.nosp@m.iebro.nosp@m.adba.nosp@m.nd.co.nosp@m.m.au
Version
1.0.0
Date
06-January-2026

The creation of this table is an interim step until access to this data becaomes available by a more supported method. Besides providing the data in the Regions.ini file, it also calculates the boundaries of the regions in global coordinates. This allows a simple method of determining which regon any position using global coordinates is in, by just using four comparisons in an SQL query. As in

select lor_name from ls_os_region where x_pos >= lor_edge_left and x_pos <= lor_edge_right and y_pos >= lor_edge_bottom and y_pos <= lor_edge_top;

This script is used to parse an Open Simulator "Regiion.ini" file into a database table. This is a very elemertary script as it assumes that is scanning a standard Regions.ini file where each region in the file is in the standard format below:

[RegionName]
RegionUUID = 2d69924a-8c19-12f0-72e4-345d605b1025
Location = 104,374
SizeX = 512
SizeY = 512
SizeZ = 4000
InternalAddress = 0.0.0.0
InternalPort = 5027
ResolveAddress = False
ExternalHostName = www.internet.address.com
MaptileStaticUUID = 00000000-0000-0000-0000-000000000000
; * Default region landing point used when no teleport coords are specified
DefaultLanding = <128,128,24>

Definition in file load_region_table.php.

Function Documentation

◆ rdOpenDatabase()

rdOpenDatabase ( $Database,
$Host,
$Username,
$Password )

Open the Support Database for Use.

Parameters
$DatabaseThe Name of the Database to Open
$HostThe name of the computer use to conenct to the Database
$UsernameThe username to access the Database
$PasswordThe password to access the database.

If this routine fails, it will case the program to abort and the heartbeat will neither identify itself as being on-line and it will not update the list of destinations.

Definition at line 61 of file load_region_table.php.

62 {
63 // Data Source Name (DSN) string
64 $dsn = "mysql:host=$Host;dbname=$Database;charset=utf8mb4";
65
66 // Set PDO options for better error handling and security
67 $options = [
68 PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // Throw exceptions on errors
69 PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, // Set default fetch mode to associative array
70 PDO::ATTR_EMULATE_PREPARES => true, // Disable emulated prepares for better security
71 ];
72
73 try
74 {
75 // Create a new PDO connection instance
76 $pdo = new PDO($dsn, $Username, $Password, $options);
77 }
78 catch (PDOException $e)
79 {
80 // Catch the exception and display a user-friendly error message
81 // In a production environment, you might log the specific error
82
83 die("FAILURE=DATABASE:Connection failed " . $e->getMessage());
84 }
85
86 return $pdo;
87 }

References $pdo.

◆ rdSaveRegion()

rdSaveRegion ( $Parameters,
$Pdo )

Save a region to the Region Table.

Parameters
$ParametersThe Region Information
$PdoThe Database Driver Instance

Definition at line 96 of file load_region_table.php.

97{
98 $sql_query = "INSERT INTO ls_os_support.ls_os_region (";
99
100 $sql_query .= " lor_name, lor_location_x, lor_location_y, lor_size_x, lor_size_y, lor_size_z,";
101 $sql_query .= " lor_uuid, lor_map_uuid, lor_edge_upper, lor_edge_lower, lor_edge_left, lor_edge_right";
102
103 $sql_query .= ")VALUES(";
104
105 $sql_query .= " :lor_name, :lor_location_x, :lor_location_y, :lor_size_x, :lor_size_y, :lor_size_z,";
106 $sql_query .= " :lor_uuid, :lor_map_uuid, :lor_edge_upper, :lor_edge_lower, :lor_edge_left, :lor_edge_right";
107
108 $sql_query .= ");";
109
110 try
111 {
112 $stmt = $Pdo->prepare($sql_query);
113 $stmt->execute($Parameters);
114 }
115 catch (Exception $e)
116 {
117 echo("FAILURE=EXTRACT:".$e->getMessage()."\n");
118 }
119
120}
121
122
123/***************************************************************************************************
124 * PROGRAM ENTRY
125 ***************************************************************************************************/
126
127// Connect to the Support Database
128$pdo = rdOpenDatabase($db, $host, $db_username, $db_password);
129
130$region_data = [];
131
132// Set the Source File for the Conversion and Check it exists. Die if it doesn't exist
133$source_file = "/opt/ls_opensim/bin/Regions/Regions.ini";
134
135// Read the Source File into an Array
136$lines = file($source_file, FILE_IGNORE_NEW_LINES);
137$array_size = count($lines);
138
139// Step through the Array Line by Line
140for ($index = 0; $index < $array_size; $index++)
141{
142 //Only Process Lines that aren't blank or a comment
143 $line = $lines[$index];
144 if (!(($line == "") || ($line[0] == ";")))
145 {
146 //NOTE: The key names in the array match the names used for character substituitions in
147 // the SQL insertion command.
148
149 // Process a new Region. If a line starts with a '[' character, it is a new region
150 if ($line[0] == "[")
151 {
152 // Clear out the Region Buffer Array
153 $region_data = [];
154
155 // Extract the Region name
156 $region_data['lor_name'] = substr($line, 1, -1);
157 }
158
159 // If it isn't Region Start, add Infor into the Buffer Array
160 else
161 {
162 // Split the String by the = character
163 $key_value_array = explode("=", $line);
164 $key = trim($key_value_array[0]); $value = trim($key_value_array[1]);
165
166 // Extract the Relevant Items
167 switch($key)
168 {
169 // Extract the UUID of the Array. This UUID can be used to link the Region Name
170 // to data in the OpenSim tables
171 case "RegionUUID":
172 $region_data['lor_uuid'] = $value;
173 break;
174
175 // Get the Bottom Left Corner of the Region.
176 case "Location":
177 $location_array = explode(",", $value);
178 $region_data['lor_location_x'] = $location_array[0];
179 $region_data['lor_location_y'] = $location_array[1];
180 break;
181
182 // Get the X size of the Region in Metres
183 case "SizeX":
184 $region_data['lor_size_x'] = $value;
185 break;
186
187 // get the Y Size of the Region in Metres
188 case "SizeY":
189 $region_data['lor_size_y'] = $value;
190 break;
191
192 // Get the Z Sizeo f the Region
193 case "SizeZ":
194 $region_data['lor_size_z'] = $value;
195 break;
196
197 // Get the UUID of a Static Map Tile
198 case "MaptileStaticUUID":
199 $region_data['lor_map_uuid'] = $value;
200 break;
201
202 // The Default landing Position is not store in the Region Table, but it does indicate that this
203 // is the end of the Entry for the Region. Once the end is reached, the boundaries of the Region in
204 // global units are calculated. This allows for easy testing to determine which Region in which a
205 // global position is located. It also makes conversion between global and local positions easier.
206 case "DefaultLanding":
207 $region_data['lor_edge_lower'] = (float)$region_data['lor_location_y'] * 256.0;
208 $region_data['lor_edge_upper'] = (float)$region_data['lor_edge_lower'] + (float)$region_data['lor_size_y'];
209 $region_data['lor_edge_left'] = (float)$region_data['lor_location_x'] * 256.0;
210 $region_data['lor_edge_right'] = (float)$region_data['lor_edge_left'] + (float)$region_data['lor_size_x'];
211
212 // Save the Region to the Table
214 break;
215 }
216 }
217 }
218}
rdOpenDatabase($Database, $Host, $Username, $Password)
Open the Support Database for Use.
rdSaveRegion($Parameters, $Pdo)
Save a region to the Region Table.

Variable Documentation

◆ $array_size

$array_size = count($lines)

Definition at line 137 of file load_region_table.php.

◆ $lines

$lines = file($source_file, FILE_IGNORE_NEW_LINES)

Definition at line 136 of file load_region_table.php.

◆ $pdo

◆ $region_data

$region_data = []

Definition at line 130 of file load_region_table.php.

◆ $source_file

$source_file = "/opt/ls_opensim/bin/Regions/Regions.ini"

Definition at line 133 of file load_region_table.php.