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
Go to the documentation of this file.
1<?php
41
42// Passwords for the database are stored outside of the webserver accessible directories to improve security.
43// Ensure that passwor file has the correct permission to read, but not be written.
44include '/usr/local/share/brigadoon/apache/os_passwords.php';
45
46 //#############################################################################################################
47 //# OPEN A DATABASE
48 //#############################################################################################################
61 function rdOpenDatabase($Database, $Host, $Username, $Password)
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 }
88
96function rdSaveRegion($Parameters, $Pdo)
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
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);
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}
219
220?>
221
rdOpenDatabase($Database, $Host, $Username, $Password)
Open the Support Database for Use.
rdSaveRegion($Parameters, $Pdo)
Save a region to the Region Table.