aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/GridServer/GridManager.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Grid/GridServer/GridManager.cs1420
1 files changed, 710 insertions, 710 deletions
diff --git a/OpenSim/Grid/GridServer/GridManager.cs b/OpenSim/Grid/GridServer/GridManager.cs
index 64b51b4..22bffa0 100644
--- a/OpenSim/Grid/GridServer/GridManager.cs
+++ b/OpenSim/Grid/GridServer/GridManager.cs
@@ -1,710 +1,710 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Reflection; 31using System.Reflection;
32using System.Xml; 32using System.Xml;
33using libsecondlife; 33using libsecondlife;
34using Nwc.XmlRpc; 34using Nwc.XmlRpc;
35using OpenSim.Framework.Console; 35using OpenSim.Framework.Console;
36using OpenSim.Framework.Data; 36using OpenSim.Framework.Data;
37using OpenSim.Framework.Interfaces; 37using OpenSim.Framework.Interfaces;
38using OpenSim.Framework.Utilities; 38using OpenSim.Framework.Utilities;
39 39
40namespace OpenSim.Grid.GridServer 40namespace OpenSim.Grid.GridServer
41{ 41{
42 class GridManager 42 class GridManager
43 { 43 {
44 Dictionary<string, IGridData> _plugins = new Dictionary<string, IGridData>(); 44 Dictionary<string, IGridData> _plugins = new Dictionary<string, IGridData>();
45 Dictionary<string, ILogData> _logplugins = new Dictionary<string, ILogData>(); 45 Dictionary<string, ILogData> _logplugins = new Dictionary<string, ILogData>();
46 46
47 public GridConfig config; 47 public GridConfig config;
48 48
49 /// <summary> 49 /// <summary>
50 /// Adds a new grid server plugin - grid servers will be requested in the order they were loaded. 50 /// Adds a new grid server plugin - grid servers will be requested in the order they were loaded.
51 /// </summary> 51 /// </summary>
52 /// <param name="FileName">The filename to the grid server plugin DLL</param> 52 /// <param name="FileName">The filename to the grid server plugin DLL</param>
53 public void AddPlugin(string FileName) 53 public void AddPlugin(string FileName)
54 { 54 {
55 MainLog.Instance.Verbose("Storage: Attempting to load " + FileName); 55 MainLog.Instance.Verbose("Storage: Attempting to load " + FileName);
56 Assembly pluginAssembly = Assembly.LoadFrom(FileName); 56 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
57 57
58 MainLog.Instance.Verbose("Storage: Found " + pluginAssembly.GetTypes().Length + " interfaces."); 58 MainLog.Instance.Verbose("Storage: Found " + pluginAssembly.GetTypes().Length + " interfaces.");
59 foreach (Type pluginType in pluginAssembly.GetTypes()) 59 foreach (Type pluginType in pluginAssembly.GetTypes())
60 { 60 {
61 if (!pluginType.IsAbstract) 61 if (!pluginType.IsAbstract)
62 { 62 {
63 // Regions go here 63 // Regions go here
64 Type typeInterface = pluginType.GetInterface("IGridData", true); 64 Type typeInterface = pluginType.GetInterface("IGridData", true);
65 65
66 if (typeInterface != null) 66 if (typeInterface != null)
67 { 67 {
68 IGridData plug = (IGridData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); 68 IGridData plug = (IGridData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
69 plug.Initialise(); 69 plug.Initialise();
70 this._plugins.Add(plug.getName(), plug); 70 this._plugins.Add(plug.getName(), plug);
71 MainLog.Instance.Verbose("Storage: Added IGridData Interface"); 71 MainLog.Instance.Verbose("Storage: Added IGridData Interface");
72 } 72 }
73 73
74 typeInterface = null; 74 typeInterface = null;
75 75
76 // Logs go here 76 // Logs go here
77 typeInterface = pluginType.GetInterface("ILogData", true); 77 typeInterface = pluginType.GetInterface("ILogData", true);
78 78
79 if (typeInterface != null) 79 if (typeInterface != null)
80 { 80 {
81 ILogData plug = (ILogData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); 81 ILogData plug = (ILogData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
82 plug.Initialise(); 82 plug.Initialise();
83 this._logplugins.Add(plug.getName(), plug); 83 this._logplugins.Add(plug.getName(), plug);
84 MainLog.Instance.Verbose( "Storage: Added ILogData Interface"); 84 MainLog.Instance.Verbose( "Storage: Added ILogData Interface");
85 } 85 }
86 86
87 typeInterface = null; 87 typeInterface = null;
88 } 88 }
89 } 89 }
90 90
91 pluginAssembly = null; 91 pluginAssembly = null;
92 } 92 }
93 93
94 /// <summary> 94 /// <summary>
95 /// Logs a piece of information to the database 95 /// Logs a piece of information to the database
96 /// </summary> 96 /// </summary>
97 /// <param name="target">What you were operating on (in grid server, this will likely be the region UUIDs)</param> 97 /// <param name="target">What you were operating on (in grid server, this will likely be the region UUIDs)</param>
98 /// <param name="method">Which method is being called?</param> 98 /// <param name="method">Which method is being called?</param>
99 /// <param name="args">What arguments are being passed?</param> 99 /// <param name="args">What arguments are being passed?</param>
100 /// <param name="priority">How high priority is this? 1 = Max, 6 = Verbose</param> 100 /// <param name="priority">How high priority is this? 1 = Max, 6 = Verbose</param>
101 /// <param name="message">The message to log</param> 101 /// <param name="message">The message to log</param>
102 private void logToDB(string target, string method, string args, int priority, string message) 102 private void logToDB(string target, string method, string args, int priority, string message)
103 { 103 {
104 foreach (KeyValuePair<string, ILogData> kvp in _logplugins) 104 foreach (KeyValuePair<string, ILogData> kvp in _logplugins)
105 { 105 {
106 try 106 try
107 { 107 {
108 kvp.Value.saveLog("Gridserver", target, method, args, priority, message); 108 kvp.Value.saveLog("Gridserver", target, method, args, priority, message);
109 } 109 }
110 catch (Exception) 110 catch (Exception)
111 { 111 {
112 MainLog.Instance.Warn("Storage: unable to write log via " + kvp.Key); 112 MainLog.Instance.Warn("Storage: unable to write log via " + kvp.Key);
113 } 113 }
114 } 114 }
115 } 115 }
116 116
117 /// <summary> 117 /// <summary>
118 /// Returns a region by argument 118 /// Returns a region by argument
119 /// </summary> 119 /// </summary>
120 /// <param name="uuid">A UUID key of the region to return</param> 120 /// <param name="uuid">A UUID key of the region to return</param>
121 /// <returns>A SimProfileData for the region</returns> 121 /// <returns>A SimProfileData for the region</returns>
122 public SimProfileData getRegion(LLUUID uuid) 122 public SimProfileData getRegion(LLUUID uuid)
123 { 123 {
124 foreach(KeyValuePair<string,IGridData> kvp in _plugins) { 124 foreach(KeyValuePair<string,IGridData> kvp in _plugins) {
125 try 125 try
126 { 126 {
127 return kvp.Value.GetProfileByLLUUID(uuid); 127 return kvp.Value.GetProfileByLLUUID(uuid);
128 } 128 }
129 catch (Exception e) 129 catch (Exception e)
130 { 130 {
131 MainLog.Instance.Warn("Message from Storage: " + e.Message); 131 MainLog.Instance.Warn("Message from Storage: " + e.Message);
132 } 132 }
133 } 133 }
134 return null; 134 return null;
135 } 135 }
136 136
137 /// <summary> 137 /// <summary>
138 /// Returns a region by argument 138 /// Returns a region by argument
139 /// </summary> 139 /// </summary>
140 /// <param name="uuid">A regionHandle of the region to return</param> 140 /// <param name="uuid">A regionHandle of the region to return</param>
141 /// <returns>A SimProfileData for the region</returns> 141 /// <returns>A SimProfileData for the region</returns>
142 public SimProfileData getRegion(ulong handle) 142 public SimProfileData getRegion(ulong handle)
143 { 143 {
144 foreach (KeyValuePair<string, IGridData> kvp in _plugins) 144 foreach (KeyValuePair<string, IGridData> kvp in _plugins)
145 { 145 {
146 try 146 try
147 { 147 {
148 return kvp.Value.GetProfileByHandle(handle); 148 return kvp.Value.GetProfileByHandle(handle);
149 } 149 }
150 catch 150 catch
151 { 151 {
152 MainLog.Instance.Warn("Storage: Unable to find region " + handle.ToString() + " via " + kvp.Key); 152 MainLog.Instance.Warn("Storage: Unable to find region " + handle.ToString() + " via " + kvp.Key);
153 } 153 }
154 } 154 }
155 return null; 155 return null;
156 } 156 }
157 157
158 public Dictionary<ulong, SimProfileData> getRegions(uint xmin, uint ymin, uint xmax, uint ymax) 158 public Dictionary<ulong, SimProfileData> getRegions(uint xmin, uint ymin, uint xmax, uint ymax)
159 { 159 {
160 Dictionary<ulong, SimProfileData> regions = new Dictionary<ulong, SimProfileData>(); 160 Dictionary<ulong, SimProfileData> regions = new Dictionary<ulong, SimProfileData>();
161 161
162 SimProfileData[] neighbours; 162 SimProfileData[] neighbours;
163 163
164 foreach (KeyValuePair<string, IGridData> kvp in _plugins) 164 foreach (KeyValuePair<string, IGridData> kvp in _plugins)
165 { 165 {
166 try 166 try
167 { 167 {
168 neighbours = kvp.Value.GetProfilesInRange(xmin, ymin, xmax, ymax); 168 neighbours = kvp.Value.GetProfilesInRange(xmin, ymin, xmax, ymax);
169 foreach (SimProfileData neighbour in neighbours) 169 foreach (SimProfileData neighbour in neighbours)
170 { 170 {
171 regions[neighbour.regionHandle] = neighbour; 171 regions[neighbour.regionHandle] = neighbour;
172 } 172 }
173 } 173 }
174 catch 174 catch
175 { 175 {
176 MainLog.Instance.Warn("Storage: Unable to query regionblock via " + kvp.Key); 176 MainLog.Instance.Warn("Storage: Unable to query regionblock via " + kvp.Key);
177 } 177 }
178 } 178 }
179 179
180 return regions; 180 return regions;
181 } 181 }
182 182
183 183
184 184
185 /// <summary> 185 /// <summary>
186 /// Returns a XML String containing a list of the neighbouring regions 186 /// Returns a XML String containing a list of the neighbouring regions
187 /// </summary> 187 /// </summary>
188 /// <param name="reqhandle">The regionhandle for the center sim</param> 188 /// <param name="reqhandle">The regionhandle for the center sim</param>
189 /// <returns>An XML string containing neighbour entities</returns> 189 /// <returns>An XML string containing neighbour entities</returns>
190 public string GetXMLNeighbours(ulong reqhandle) 190 public string GetXMLNeighbours(ulong reqhandle)
191 { 191 {
192 string response = ""; 192 string response = "";
193 SimProfileData central_region = getRegion(reqhandle); 193 SimProfileData central_region = getRegion(reqhandle);
194 SimProfileData neighbour; 194 SimProfileData neighbour;
195 for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++) 195 for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++)
196 { 196 {
197 if (getRegion(Util.UIntsToLong((uint)((central_region.regionLocX + x) * 256), (uint)(central_region.regionLocY + y) * 256)) != null) 197 if (getRegion(Util.UIntsToLong((uint)((central_region.regionLocX + x) * 256), (uint)(central_region.regionLocY + y) * 256)) != null)
198 { 198 {
199 neighbour = getRegion(Util.UIntsToLong((uint)((central_region.regionLocX + x) * 256), (uint)(central_region.regionLocY + y) * 256)); 199 neighbour = getRegion(Util.UIntsToLong((uint)((central_region.regionLocX + x) * 256), (uint)(central_region.regionLocY + y) * 256));
200 response += "<neighbour>"; 200 response += "<neighbour>";
201 response += "<sim_ip>" + neighbour.serverIP + "</sim_ip>"; 201 response += "<sim_ip>" + neighbour.serverIP + "</sim_ip>";
202 response += "<sim_port>" + neighbour.serverPort.ToString() + "</sim_port>"; 202 response += "<sim_port>" + neighbour.serverPort.ToString() + "</sim_port>";
203 response += "<locx>" + neighbour.regionLocX.ToString() + "</locx>"; 203 response += "<locx>" + neighbour.regionLocX.ToString() + "</locx>";
204 response += "<locy>" + neighbour.regionLocY.ToString() + "</locy>"; 204 response += "<locy>" + neighbour.regionLocY.ToString() + "</locy>";
205 response += "<regionhandle>" + neighbour.regionHandle.ToString() + "</regionhandle>"; 205 response += "<regionhandle>" + neighbour.regionHandle.ToString() + "</regionhandle>";
206 response += "</neighbour>"; 206 response += "</neighbour>";
207 207
208 } 208 }
209 } 209 }
210 return response; 210 return response;
211 } 211 }
212 212
213 /// <summary> 213 /// <summary>
214 /// Performed when a region connects to the grid server initially. 214 /// Performed when a region connects to the grid server initially.
215 /// </summary> 215 /// </summary>
216 /// <param name="request">The XMLRPC Request</param> 216 /// <param name="request">The XMLRPC Request</param>
217 /// <returns>Startup parameters</returns> 217 /// <returns>Startup parameters</returns>
218 public XmlRpcResponse XmlRpcSimulatorLoginMethod(XmlRpcRequest request) 218 public XmlRpcResponse XmlRpcSimulatorLoginMethod(XmlRpcRequest request)
219 { 219 {
220 220
221 XmlRpcResponse response = new XmlRpcResponse(); 221 XmlRpcResponse response = new XmlRpcResponse();
222 Hashtable responseData = new Hashtable(); 222 Hashtable responseData = new Hashtable();
223 response.Value = responseData; 223 response.Value = responseData;
224 224
225 SimProfileData TheSim = null; 225 SimProfileData TheSim = null;
226 Hashtable requestData = (Hashtable)request.Params[0]; 226 Hashtable requestData = (Hashtable)request.Params[0];
227 227
228 if (requestData.ContainsKey("UUID")) 228 if (requestData.ContainsKey("UUID"))
229 { 229 {
230 TheSim = getRegion(new LLUUID((string)requestData["UUID"])); 230 TheSim = getRegion(new LLUUID((string)requestData["UUID"]));
231 231
232 logToDB((new LLUUID((string)requestData["UUID"])).ToStringHyphenated(),"XmlRpcSimulatorLoginMethod","", 5,"Region attempting login with UUID."); 232 logToDB((new LLUUID((string)requestData["UUID"])).ToStringHyphenated(),"XmlRpcSimulatorLoginMethod","", 5,"Region attempting login with UUID.");
233 } 233 }
234 else if (requestData.ContainsKey("region_handle")) 234 else if (requestData.ContainsKey("region_handle"))
235 { 235 {
236 236
237 TheSim = getRegion((ulong)Convert.ToUInt64(requestData["region_handle"])); 237 TheSim = getRegion((ulong)Convert.ToUInt64(requestData["region_handle"]));
238 logToDB((string)requestData["region_handle"], "XmlRpcSimulatorLoginMethod", "", 5, "Region attempting login with regionHandle."); 238 logToDB((string)requestData["region_handle"], "XmlRpcSimulatorLoginMethod", "", 5, "Region attempting login with regionHandle.");
239 } 239 }
240 else 240 else
241 { 241 {
242 responseData["error"] = "No UUID or region_handle passed to grid server - unable to connect you"; 242 responseData["error"] = "No UUID or region_handle passed to grid server - unable to connect you";
243 return response; 243 return response;
244 } 244 }
245 245
246 if (TheSim == null) // Shouldnt this be in the REST Simulator Set method? 246 if (TheSim == null) // Shouldnt this be in the REST Simulator Set method?
247 { 247 {
248 //NEW REGION 248 //NEW REGION
249 TheSim = new SimProfileData(); 249 TheSim = new SimProfileData();
250 250
251 TheSim.regionRecvKey = config.SimRecvKey; 251 TheSim.regionRecvKey = config.SimRecvKey;
252 TheSim.regionSendKey = config.SimSendKey; 252 TheSim.regionSendKey = config.SimSendKey;
253 TheSim.regionSecret = config.SimRecvKey; 253 TheSim.regionSecret = config.SimRecvKey;
254 TheSim.regionDataURI = ""; 254 TheSim.regionDataURI = "";
255 TheSim.regionAssetURI = config.DefaultAssetServer; 255 TheSim.regionAssetURI = config.DefaultAssetServer;
256 TheSim.regionAssetRecvKey = config.AssetRecvKey; 256 TheSim.regionAssetRecvKey = config.AssetRecvKey;
257 TheSim.regionAssetSendKey = config.AssetSendKey; 257 TheSim.regionAssetSendKey = config.AssetSendKey;
258 TheSim.regionUserURI = config.DefaultUserServer; 258 TheSim.regionUserURI = config.DefaultUserServer;
259 TheSim.regionUserSendKey = config.UserSendKey; 259 TheSim.regionUserSendKey = config.UserSendKey;
260 TheSim.regionUserRecvKey = config.UserRecvKey; 260 TheSim.regionUserRecvKey = config.UserRecvKey;
261 261
262 TheSim.serverIP = (string)requestData["sim_ip"]; 262 TheSim.serverIP = (string)requestData["sim_ip"];
263 TheSim.serverPort = Convert.ToUInt32((string)requestData["sim_port"]); 263 TheSim.serverPort = Convert.ToUInt32((string)requestData["sim_port"]);
264 TheSim.httpPort = Convert.ToUInt32((string)requestData["http_port"]); 264 TheSim.httpPort = Convert.ToUInt32((string)requestData["http_port"]);
265 TheSim.remotingPort = Convert.ToUInt32((string)requestData["remoting_port"]); 265 TheSim.remotingPort = Convert.ToUInt32((string)requestData["remoting_port"]);
266 TheSim.regionLocX = Convert.ToUInt32((string)requestData["region_locx"]); 266 TheSim.regionLocX = Convert.ToUInt32((string)requestData["region_locx"]);
267 TheSim.regionLocY = Convert.ToUInt32((string)requestData["region_locy"]); 267 TheSim.regionLocY = Convert.ToUInt32((string)requestData["region_locy"]);
268 TheSim.regionLocZ = 0; 268 TheSim.regionLocZ = 0;
269 TheSim.regionMapTextureID = new LLUUID((string)requestData["map-image-id"]); 269 TheSim.regionMapTextureID = new LLUUID((string)requestData["map-image-id"]);
270 270
271 TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256)); 271 TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256));
272 System.Console.WriteLine("adding region " + TheSim.regionLocX + " , " + TheSim.regionLocY + " , " + TheSim.regionHandle); 272 System.Console.WriteLine("adding region " + TheSim.regionLocX + " , " + TheSim.regionLocY + " , " + TheSim.regionHandle);
273 TheSim.serverURI = "http://" + TheSim.serverIP + ":" + TheSim.serverPort + "/"; 273 TheSim.serverURI = "http://" + TheSim.serverIP + ":" + TheSim.serverPort + "/";
274 TheSim.httpServerURI = "http://" + TheSim.serverIP + ":" + TheSim.httpPort + "/"; 274 TheSim.httpServerURI = "http://" + TheSim.serverIP + ":" + TheSim.httpPort + "/";
275 275
276 Console.WriteLine("NEW SIM: " + TheSim.serverURI); 276 Console.WriteLine("NEW SIM: " + TheSim.serverURI);
277 TheSim.regionName = (string)requestData["sim_name"]; 277 TheSim.regionName = (string)requestData["sim_name"];
278 TheSim.UUID = new LLUUID((string)requestData["UUID"]); 278 TheSim.UUID = new LLUUID((string)requestData["UUID"]);
279 279
280 foreach (KeyValuePair<string, IGridData> kvp in _plugins) 280 foreach (KeyValuePair<string, IGridData> kvp in _plugins)
281 { 281 {
282 try 282 try
283 { 283 {
284 DataResponse insertResponse = kvp.Value.AddProfile(TheSim); 284 DataResponse insertResponse = kvp.Value.AddProfile(TheSim);
285 switch(insertResponse) 285 switch(insertResponse)
286 { 286 {
287 case DataResponse.RESPONSE_OK: 287 case DataResponse.RESPONSE_OK:
288 OpenSim.Framework.Console.MainLog.Instance.Verbose("New sim creation successful: " + TheSim.regionName); 288 OpenSim.Framework.Console.MainLog.Instance.Verbose("New sim creation successful: " + TheSim.regionName);
289 break; 289 break;
290 case DataResponse.RESPONSE_ERROR: 290 case DataResponse.RESPONSE_ERROR:
291 OpenSim.Framework.Console.MainLog.Instance.Warn("New sim creation failed (Error): " + TheSim.regionName); 291 OpenSim.Framework.Console.MainLog.Instance.Warn("New sim creation failed (Error): " + TheSim.regionName);
292 break; 292 break;
293 case DataResponse.RESPONSE_INVALIDCREDENTIALS: 293 case DataResponse.RESPONSE_INVALIDCREDENTIALS:
294 OpenSim.Framework.Console.MainLog.Instance.Warn("New sim creation failed (Invalid Credentials): " + TheSim.regionName); 294 OpenSim.Framework.Console.MainLog.Instance.Warn("New sim creation failed (Invalid Credentials): " + TheSim.regionName);
295 break; 295 break;
296 case DataResponse.RESPONSE_AUTHREQUIRED: 296 case DataResponse.RESPONSE_AUTHREQUIRED:
297 OpenSim.Framework.Console.MainLog.Instance.Warn("New sim creation failed (Authentication Required): " + TheSim.regionName); 297 OpenSim.Framework.Console.MainLog.Instance.Warn("New sim creation failed (Authentication Required): " + TheSim.regionName);
298 break; 298 break;
299 } 299 }
300 300
301 } 301 }
302 catch (Exception e) 302 catch (Exception e)
303 { 303 {
304 OpenSim.Framework.Console.MainLog.Instance.Warn("Storage: Unable to add region " + TheSim.UUID.ToStringHyphenated() + " via " + kvp.Key); 304 OpenSim.Framework.Console.MainLog.Instance.Warn("Storage: Unable to add region " + TheSim.UUID.ToStringHyphenated() + " via " + kvp.Key);
305 OpenSim.Framework.Console.MainLog.Instance.Warn(e.ToString()); 305 OpenSim.Framework.Console.MainLog.Instance.Warn(e.ToString());
306 } 306 }
307 } 307 }
308 308
309 309
310 if (getRegion(TheSim.regionHandle) == null) 310 if (getRegion(TheSim.regionHandle) == null)
311 { 311 {
312 responseData["error"] = "Unable to add new region"; 312 responseData["error"] = "Unable to add new region";
313 return response; 313 return response;
314 } 314 }
315 } 315 }
316 316
317 317
318 ArrayList SimNeighboursData = new ArrayList(); 318 ArrayList SimNeighboursData = new ArrayList();
319 319
320 SimProfileData neighbour; 320 SimProfileData neighbour;
321 Hashtable NeighbourBlock; 321 Hashtable NeighbourBlock;
322 322
323 bool fastMode = false; // Only compatible with MySQL right now 323 bool fastMode = false; // Only compatible with MySQL right now
324 324
325 if (fastMode) 325 if (fastMode)
326 { 326 {
327 Dictionary<ulong, SimProfileData> neighbours = getRegions(TheSim.regionLocX - 1, TheSim.regionLocY - 1, TheSim.regionLocX + 1, TheSim.regionLocY + 1); 327 Dictionary<ulong, SimProfileData> neighbours = getRegions(TheSim.regionLocX - 1, TheSim.regionLocY - 1, TheSim.regionLocX + 1, TheSim.regionLocY + 1);
328 328
329 foreach (KeyValuePair<ulong, SimProfileData> aSim in neighbours) 329 foreach (KeyValuePair<ulong, SimProfileData> aSim in neighbours)
330 { 330 {
331 NeighbourBlock = new Hashtable(); 331 NeighbourBlock = new Hashtable();
332 NeighbourBlock["sim_ip"] = aSim.Value.serverIP.ToString(); 332 NeighbourBlock["sim_ip"] = aSim.Value.serverIP.ToString();
333 NeighbourBlock["sim_port"] = aSim.Value.serverPort.ToString(); 333 NeighbourBlock["sim_port"] = aSim.Value.serverPort.ToString();
334 NeighbourBlock["region_locx"] = aSim.Value.regionLocX.ToString(); 334 NeighbourBlock["region_locx"] = aSim.Value.regionLocX.ToString();
335 NeighbourBlock["region_locy"] = aSim.Value.regionLocY.ToString(); 335 NeighbourBlock["region_locy"] = aSim.Value.regionLocY.ToString();
336 NeighbourBlock["UUID"] = aSim.Value.UUID.ToString(); 336 NeighbourBlock["UUID"] = aSim.Value.UUID.ToString();
337 337
338 if (aSim.Value.UUID != TheSim.UUID) 338 if (aSim.Value.UUID != TheSim.UUID)
339 SimNeighboursData.Add(NeighbourBlock); 339 SimNeighboursData.Add(NeighbourBlock);
340 } 340 }
341 } 341 }
342 else 342 else
343 { 343 {
344 for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++) 344 for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++)
345 { 345 {
346 if (getRegion(Helpers.UIntsToLong((uint)((TheSim.regionLocX + x) * 256), (uint)(TheSim.regionLocY + y) * 256)) != null) 346 if (getRegion(Helpers.UIntsToLong((uint)((TheSim.regionLocX + x) * 256), (uint)(TheSim.regionLocY + y) * 256)) != null)
347 { 347 {
348 neighbour = getRegion(Helpers.UIntsToLong((uint)((TheSim.regionLocX + x) * 256), (uint)(TheSim.regionLocY + y) * 256)); 348 neighbour = getRegion(Helpers.UIntsToLong((uint)((TheSim.regionLocX + x) * 256), (uint)(TheSim.regionLocY + y) * 256));
349 349
350 NeighbourBlock = new Hashtable(); 350 NeighbourBlock = new Hashtable();
351 NeighbourBlock["sim_ip"] = neighbour.serverIP; 351 NeighbourBlock["sim_ip"] = neighbour.serverIP;
352 NeighbourBlock["sim_port"] = neighbour.serverPort.ToString(); 352 NeighbourBlock["sim_port"] = neighbour.serverPort.ToString();
353 NeighbourBlock["region_locx"] = neighbour.regionLocX.ToString(); 353 NeighbourBlock["region_locx"] = neighbour.regionLocX.ToString();
354 NeighbourBlock["region_locy"] = neighbour.regionLocY.ToString(); 354 NeighbourBlock["region_locy"] = neighbour.regionLocY.ToString();
355 NeighbourBlock["UUID"] = neighbour.UUID.ToString(); 355 NeighbourBlock["UUID"] = neighbour.UUID.ToString();
356 356
357 if (neighbour.UUID != TheSim.UUID) SimNeighboursData.Add(NeighbourBlock); 357 if (neighbour.UUID != TheSim.UUID) SimNeighboursData.Add(NeighbourBlock);
358 } 358 }
359 } 359 }
360 } 360 }
361 361
362 responseData["UUID"] = TheSim.UUID.ToString(); 362 responseData["UUID"] = TheSim.UUID.ToString();
363 responseData["region_locx"] = TheSim.regionLocX.ToString(); 363 responseData["region_locx"] = TheSim.regionLocX.ToString();
364 responseData["region_locy"] = TheSim.regionLocY.ToString(); 364 responseData["region_locy"] = TheSim.regionLocY.ToString();
365 responseData["regionname"] = TheSim.regionName; 365 responseData["regionname"] = TheSim.regionName;
366 responseData["estate_id"] = "1"; 366 responseData["estate_id"] = "1";
367 responseData["neighbours"] = SimNeighboursData; 367 responseData["neighbours"] = SimNeighboursData;
368 368
369 responseData["sim_ip"] = TheSim.serverIP; 369 responseData["sim_ip"] = TheSim.serverIP;
370 responseData["sim_port"] = TheSim.serverPort.ToString(); 370 responseData["sim_port"] = TheSim.serverPort.ToString();
371 responseData["asset_url"] = TheSim.regionAssetURI; 371 responseData["asset_url"] = TheSim.regionAssetURI;
372 responseData["asset_sendkey"] = TheSim.regionAssetSendKey; 372 responseData["asset_sendkey"] = TheSim.regionAssetSendKey;
373 responseData["asset_recvkey"] = TheSim.regionAssetRecvKey; 373 responseData["asset_recvkey"] = TheSim.regionAssetRecvKey;
374 responseData["user_url"] = TheSim.regionUserURI; 374 responseData["user_url"] = TheSim.regionUserURI;
375 responseData["user_sendkey"] = TheSim.regionUserSendKey; 375 responseData["user_sendkey"] = TheSim.regionUserSendKey;
376 responseData["user_recvkey"] = TheSim.regionUserRecvKey; 376 responseData["user_recvkey"] = TheSim.regionUserRecvKey;
377 responseData["authkey"] = TheSim.regionSecret; 377 responseData["authkey"] = TheSim.regionSecret;
378 378
379 // New! If set, use as URL to local sim storage (ie http://remotehost/region.yap) 379 // New! If set, use as URL to local sim storage (ie http://remotehost/region.yap)
380 responseData["data_uri"] = TheSim.regionDataURI; 380 responseData["data_uri"] = TheSim.regionDataURI;
381 381
382 382
383 return response; 383 return response;
384 } 384 }
385 385
386 public XmlRpcResponse XmlRpcSimulatorDataRequestMethod(XmlRpcRequest request) 386 public XmlRpcResponse XmlRpcSimulatorDataRequestMethod(XmlRpcRequest request)
387 { 387 {
388 Hashtable requestData = (Hashtable)request.Params[0]; 388 Hashtable requestData = (Hashtable)request.Params[0];
389 Hashtable responseData = new Hashtable(); 389 Hashtable responseData = new Hashtable();
390 SimProfileData simData = null; 390 SimProfileData simData = null;
391 if (requestData.ContainsKey("region_UUID")) 391 if (requestData.ContainsKey("region_UUID"))
392 { 392 {
393 simData = getRegion(new LLUUID((string)requestData["region_UUID"])); 393 simData = getRegion(new LLUUID((string)requestData["region_UUID"]));
394 } 394 }
395 else if (requestData.ContainsKey("region_handle")) 395 else if (requestData.ContainsKey("region_handle"))
396 { 396 {
397 Console.WriteLine("requesting data for region " + (string)requestData["region_handle"]); 397 Console.WriteLine("requesting data for region " + (string)requestData["region_handle"]);
398 simData = getRegion(Convert.ToUInt64((string)requestData["region_handle"])); 398 simData = getRegion(Convert.ToUInt64((string)requestData["region_handle"]));
399 } 399 }
400 400
401 if (simData == null) 401 if (simData == null)
402 { 402 {
403 //Sim does not exist 403 //Sim does not exist
404 Console.WriteLine("region not found"); 404 Console.WriteLine("region not found");
405 responseData["error"] = "Sim does not exist"; 405 responseData["error"] = "Sim does not exist";
406 } 406 }
407 else 407 else
408 { 408 {
409 Console.WriteLine("found region"); 409 Console.WriteLine("found region");
410 responseData["sim_ip"] = simData.serverIP; 410 responseData["sim_ip"] = simData.serverIP;
411 responseData["sim_port"] = simData.serverPort.ToString(); 411 responseData["sim_port"] = simData.serverPort.ToString();
412 responseData["http_port"] = simData.httpPort.ToString(); 412 responseData["http_port"] = simData.httpPort.ToString();
413 responseData["remoting_port"] = simData.remotingPort.ToString(); 413 responseData["remoting_port"] = simData.remotingPort.ToString();
414 responseData["region_locx"] = simData.regionLocX.ToString() ; 414 responseData["region_locx"] = simData.regionLocX.ToString() ;
415 responseData["region_locy"] = simData.regionLocY.ToString(); 415 responseData["region_locy"] = simData.regionLocY.ToString();
416 responseData["region_UUID"] = simData.UUID.UUID.ToString(); 416 responseData["region_UUID"] = simData.UUID.UUID.ToString();
417 responseData["region_name"] = simData.regionName; 417 responseData["region_name"] = simData.regionName;
418 } 418 }
419 419
420 XmlRpcResponse response = new XmlRpcResponse(); 420 XmlRpcResponse response = new XmlRpcResponse();
421 response.Value = responseData; 421 response.Value = responseData;
422 return response; 422 return response;
423 } 423 }
424 424
425 public XmlRpcResponse XmlRpcMapBlockMethod(XmlRpcRequest request) 425 public XmlRpcResponse XmlRpcMapBlockMethod(XmlRpcRequest request)
426 { 426 {
427 int xmin=980, ymin=980, xmax=1020, ymax=1020; 427 int xmin=980, ymin=980, xmax=1020, ymax=1020;
428 428
429 Hashtable requestData = (Hashtable)request.Params[0]; 429 Hashtable requestData = (Hashtable)request.Params[0];
430 if (requestData.ContainsKey("xmin")) 430 if (requestData.ContainsKey("xmin"))
431 { 431 {
432 xmin = (Int32)requestData["xmin"]; 432 xmin = (Int32)requestData["xmin"];
433 } 433 }
434 if (requestData.ContainsKey("ymin")) 434 if (requestData.ContainsKey("ymin"))
435 { 435 {
436 ymin = (Int32)requestData["ymin"]; 436 ymin = (Int32)requestData["ymin"];
437 } 437 }
438 if (requestData.ContainsKey("xmax")) 438 if (requestData.ContainsKey("xmax"))
439 { 439 {
440 xmax = (Int32)requestData["xmax"]; 440 xmax = (Int32)requestData["xmax"];
441 } 441 }
442 if (requestData.ContainsKey("ymax")) 442 if (requestData.ContainsKey("ymax"))
443 { 443 {
444 ymax = (Int32)requestData["ymax"]; 444 ymax = (Int32)requestData["ymax"];
445 } 445 }
446 446
447 XmlRpcResponse response = new XmlRpcResponse(); 447 XmlRpcResponse response = new XmlRpcResponse();
448 Hashtable responseData = new Hashtable(); 448 Hashtable responseData = new Hashtable();
449 response.Value = responseData; 449 response.Value = responseData;
450 IList simProfileList = new ArrayList(); 450 IList simProfileList = new ArrayList();
451 451
452 bool fastMode = false; // MySQL Only 452 bool fastMode = false; // MySQL Only
453 453
454 if (fastMode) 454 if (fastMode)
455 { 455 {
456 Dictionary<ulong, SimProfileData> neighbours = getRegions((uint)xmin, (uint)ymin, (uint)xmax, (uint)ymax); 456 Dictionary<ulong, SimProfileData> neighbours = getRegions((uint)xmin, (uint)ymin, (uint)xmax, (uint)ymax);
457 457
458 foreach (KeyValuePair<ulong, SimProfileData> aSim in neighbours) 458 foreach (KeyValuePair<ulong, SimProfileData> aSim in neighbours)
459 { 459 {
460 Hashtable simProfileBlock = new Hashtable(); 460 Hashtable simProfileBlock = new Hashtable();
461 simProfileBlock["x"] = aSim.Value.regionLocX.ToString(); 461 simProfileBlock["x"] = aSim.Value.regionLocX.ToString();
462 simProfileBlock["y"] = aSim.Value.regionLocY.ToString(); 462 simProfileBlock["y"] = aSim.Value.regionLocY.ToString();
463 System.Console.WriteLine("send neighbour info for " + aSim.Value.regionLocX.ToString() + " , " + aSim.Value.regionLocY.ToString()); 463 System.Console.WriteLine("send neighbour info for " + aSim.Value.regionLocX.ToString() + " , " + aSim.Value.regionLocY.ToString());
464 simProfileBlock["name"] = aSim.Value.regionName; 464 simProfileBlock["name"] = aSim.Value.regionName;
465 simProfileBlock["access"] = 21; 465 simProfileBlock["access"] = 21;
466 simProfileBlock["region-flags"] = 512; 466 simProfileBlock["region-flags"] = 512;
467 simProfileBlock["water-height"] = 0; 467 simProfileBlock["water-height"] = 0;
468 simProfileBlock["agents"] = 1; 468 simProfileBlock["agents"] = 1;
469 simProfileBlock["map-image-id"] = aSim.Value.regionMapTextureID.ToString(); 469 simProfileBlock["map-image-id"] = aSim.Value.regionMapTextureID.ToString();
470 470
471 // For Sugilite compatibility 471 // For Sugilite compatibility
472 simProfileBlock["regionhandle"] = aSim.Value.regionHandle.ToString(); 472 simProfileBlock["regionhandle"] = aSim.Value.regionHandle.ToString();
473 simProfileBlock["sim_ip"] = aSim.Value.serverIP.ToString(); 473 simProfileBlock["sim_ip"] = aSim.Value.serverIP.ToString();
474 simProfileBlock["sim_port"] = aSim.Value.serverPort.ToString(); 474 simProfileBlock["sim_port"] = aSim.Value.serverPort.ToString();
475 simProfileBlock["sim_uri"] = aSim.Value.serverURI.ToString(); 475 simProfileBlock["sim_uri"] = aSim.Value.serverURI.ToString();
476 simProfileBlock["uuid"] = aSim.Value.UUID.ToStringHyphenated(); 476 simProfileBlock["uuid"] = aSim.Value.UUID.ToStringHyphenated();
477 477
478 simProfileList.Add(simProfileBlock); 478 simProfileList.Add(simProfileBlock);
479 } 479 }
480 MainLog.Instance.Verbose("World map request processed, returned " + simProfileList.Count.ToString() + " region(s) in range via FastMode"); 480 MainLog.Instance.Verbose("World map request processed, returned " + simProfileList.Count.ToString() + " region(s) in range via FastMode");
481 } 481 }
482 else 482 else
483 { 483 {
484 SimProfileData simProfile; 484 SimProfileData simProfile;
485 for (int x = xmin; x < xmax+1; x++) 485 for (int x = xmin; x < xmax+1; x++)
486 { 486 {
487 for (int y = ymin; y < ymax+1; y++) 487 for (int y = ymin; y < ymax+1; y++)
488 { 488 {
489 ulong regHandle = Helpers.UIntsToLong((uint)(x * 256), (uint)(y * 256)); 489 ulong regHandle = Helpers.UIntsToLong((uint)(x * 256), (uint)(y * 256));
490 simProfile = getRegion(regHandle); 490 simProfile = getRegion(regHandle);
491 if (simProfile != null) 491 if (simProfile != null)
492 { 492 {
493 Hashtable simProfileBlock = new Hashtable(); 493 Hashtable simProfileBlock = new Hashtable();
494 simProfileBlock["x"] = x; 494 simProfileBlock["x"] = x;
495 simProfileBlock["y"] = y; 495 simProfileBlock["y"] = y;
496 simProfileBlock["name"] = simProfile.regionName; 496 simProfileBlock["name"] = simProfile.regionName;
497 simProfileBlock["access"] = 0; 497 simProfileBlock["access"] = 0;
498 simProfileBlock["region-flags"] = 0; 498 simProfileBlock["region-flags"] = 0;
499 simProfileBlock["water-height"] = 20; 499 simProfileBlock["water-height"] = 20;
500 simProfileBlock["agents"] = 1; 500 simProfileBlock["agents"] = 1;
501 simProfileBlock["map-image-id"] = simProfile.regionMapTextureID.ToStringHyphenated(); 501 simProfileBlock["map-image-id"] = simProfile.regionMapTextureID.ToStringHyphenated();
502 502
503 // For Sugilite compatibility 503 // For Sugilite compatibility
504 simProfileBlock["regionhandle"] = simProfile.regionHandle.ToString(); 504 simProfileBlock["regionhandle"] = simProfile.regionHandle.ToString();
505 simProfileBlock["sim_ip"] = simProfile.serverIP.ToString(); 505 simProfileBlock["sim_ip"] = simProfile.serverIP.ToString();
506 simProfileBlock["sim_port"] = simProfile.serverPort.ToString(); 506 simProfileBlock["sim_port"] = simProfile.serverPort.ToString();
507 simProfileBlock["sim_uri"] = simProfile.serverURI.ToString(); 507 simProfileBlock["sim_uri"] = simProfile.serverURI.ToString();
508 simProfileBlock["uuid"] = simProfile.UUID.ToStringHyphenated(); 508 simProfileBlock["uuid"] = simProfile.UUID.ToStringHyphenated();
509 509
510 simProfileList.Add(simProfileBlock); 510 simProfileList.Add(simProfileBlock);
511 } 511 }
512 } 512 }
513 } 513 }
514 MainLog.Instance.Verbose("World map request processed, returned " + simProfileList.Count.ToString() + " region(s) in range via Standard Mode"); 514 MainLog.Instance.Verbose("World map request processed, returned " + simProfileList.Count.ToString() + " region(s) in range via Standard Mode");
515 } 515 }
516 516
517 responseData["sim-profiles"] = simProfileList; 517 responseData["sim-profiles"] = simProfileList;
518 518
519 return response; 519 return response;
520 } 520 }
521 521
522 522
523 523
524 /// <summary> 524 /// <summary>
525 /// Performs a REST Get Operation 525 /// Performs a REST Get Operation
526 /// </summary> 526 /// </summary>
527 /// <param name="request"></param> 527 /// <param name="request"></param>
528 /// <param name="path"></param> 528 /// <param name="path"></param>
529 /// <param name="param"></param> 529 /// <param name="param"></param>
530 /// <returns></returns> 530 /// <returns></returns>
531 public string RestGetRegionMethod(string request, string path, string param) 531 public string RestGetRegionMethod(string request, string path, string param)
532 { 532 {
533 return RestGetSimMethod("", "/sims/", param); 533 return RestGetSimMethod("", "/sims/", param);
534 } 534 }
535 535
536 /// <summary> 536 /// <summary>
537 /// Performs a REST Set Operation 537 /// Performs a REST Set Operation
538 /// </summary> 538 /// </summary>
539 /// <param name="request"></param> 539 /// <param name="request"></param>
540 /// <param name="path"></param> 540 /// <param name="path"></param>
541 /// <param name="param"></param> 541 /// <param name="param"></param>
542 /// <returns></returns> 542 /// <returns></returns>
543 public string RestSetRegionMethod(string request, string path, string param) 543 public string RestSetRegionMethod(string request, string path, string param)
544 { 544 {
545 return RestSetSimMethod("", "/sims/", param); 545 return RestSetSimMethod("", "/sims/", param);
546 } 546 }
547 547
548 /// <summary> 548 /// <summary>
549 /// Returns information about a sim via a REST Request 549 /// Returns information about a sim via a REST Request
550 /// </summary> 550 /// </summary>
551 /// <param name="request"></param> 551 /// <param name="request"></param>
552 /// <param name="path"></param> 552 /// <param name="path"></param>
553 /// <param name="param"></param> 553 /// <param name="param"></param>
554 /// <returns>Information about the sim in XML</returns> 554 /// <returns>Information about the sim in XML</returns>
555 public string RestGetSimMethod(string request, string path, string param) 555 public string RestGetSimMethod(string request, string path, string param)
556 { 556 {
557 string respstring = String.Empty; 557 string respstring = String.Empty;
558 558
559 SimProfileData TheSim; 559 SimProfileData TheSim;
560 LLUUID UUID = new LLUUID(param); 560 LLUUID UUID = new LLUUID(param);
561 TheSim = getRegion(UUID); 561 TheSim = getRegion(UUID);
562 562
563 if (!(TheSim == null)) 563 if (!(TheSim == null))
564 { 564 {
565 respstring = "<Root>"; 565 respstring = "<Root>";
566 respstring += "<authkey>" + TheSim.regionSendKey + "</authkey>"; 566 respstring += "<authkey>" + TheSim.regionSendKey + "</authkey>";
567 respstring += "<sim>"; 567 respstring += "<sim>";
568 respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>"; 568 respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>";
569 respstring += "<regionname>" + TheSim.regionName + "</regionname>"; 569 respstring += "<regionname>" + TheSim.regionName + "</regionname>";
570 respstring += "<sim_ip>" + TheSim.serverIP + "</sim_ip>"; 570 respstring += "<sim_ip>" + TheSim.serverIP + "</sim_ip>";
571 respstring += "<sim_port>" + TheSim.serverPort.ToString() + "</sim_port>"; 571 respstring += "<sim_port>" + TheSim.serverPort.ToString() + "</sim_port>";
572 respstring += "<region_locx>" + TheSim.regionLocX.ToString() + "</region_locx>"; 572 respstring += "<region_locx>" + TheSim.regionLocX.ToString() + "</region_locx>";
573 respstring += "<region_locy>" + TheSim.regionLocY.ToString() + "</region_locy>"; 573 respstring += "<region_locy>" + TheSim.regionLocY.ToString() + "</region_locy>";
574 respstring += "<estate_id>1</estate_id>"; 574 respstring += "<estate_id>1</estate_id>";
575 respstring += "</sim>"; 575 respstring += "</sim>";
576 respstring += "</Root>"; 576 respstring += "</Root>";
577 } 577 }
578 578
579 return respstring; 579 return respstring;
580 } 580 }
581 581
582 /// <summary> 582 /// <summary>
583 /// Creates or updates a sim via a REST Method Request 583 /// Creates or updates a sim via a REST Method Request
584 /// BROKEN with SQL Update 584 /// BROKEN with SQL Update
585 /// </summary> 585 /// </summary>
586 /// <param name="request"></param> 586 /// <param name="request"></param>
587 /// <param name="path"></param> 587 /// <param name="path"></param>
588 /// <param name="param"></param> 588 /// <param name="param"></param>
589 /// <returns>"OK" or an error</returns> 589 /// <returns>"OK" or an error</returns>
590 public string RestSetSimMethod(string request, string path, string param) 590 public string RestSetSimMethod(string request, string path, string param)
591 { 591 {
592 Console.WriteLine("Processing region update via REST method"); 592 Console.WriteLine("Processing region update via REST method");
593 SimProfileData TheSim; 593 SimProfileData TheSim;
594 TheSim = getRegion(new LLUUID(param)); 594 TheSim = getRegion(new LLUUID(param));
595 if ((TheSim) == null) 595 if ((TheSim) == null)
596 { 596 {
597 TheSim = new SimProfileData(); 597 TheSim = new SimProfileData();
598 LLUUID UUID = new LLUUID(param); 598 LLUUID UUID = new LLUUID(param);
599 TheSim.UUID = UUID; 599 TheSim.UUID = UUID;
600 TheSim.regionRecvKey = config.SimRecvKey; 600 TheSim.regionRecvKey = config.SimRecvKey;
601 } 601 }
602 602
603 XmlDocument doc = new XmlDocument(); 603 XmlDocument doc = new XmlDocument();
604 doc.LoadXml(request); 604 doc.LoadXml(request);
605 XmlNode rootnode = doc.FirstChild; 605 XmlNode rootnode = doc.FirstChild;
606 XmlNode authkeynode = rootnode.ChildNodes[0]; 606 XmlNode authkeynode = rootnode.ChildNodes[0];
607 if (authkeynode.Name != "authkey") 607 if (authkeynode.Name != "authkey")
608 { 608 {
609 return "ERROR! bad XML - expected authkey tag"; 609 return "ERROR! bad XML - expected authkey tag";
610 } 610 }
611 611
612 XmlNode simnode = rootnode.ChildNodes[1]; 612 XmlNode simnode = rootnode.ChildNodes[1];
613 if (simnode.Name != "sim") 613 if (simnode.Name != "sim")
614 { 614 {
615 return "ERROR! bad XML - expected sim tag"; 615 return "ERROR! bad XML - expected sim tag";
616 } 616 }
617 617
618 //TheSim.regionSendKey = Cfg; 618 //TheSim.regionSendKey = Cfg;
619 TheSim.regionRecvKey = config.SimRecvKey; 619 TheSim.regionRecvKey = config.SimRecvKey;
620 TheSim.regionSendKey = config.SimSendKey; 620 TheSim.regionSendKey = config.SimSendKey;
621 TheSim.regionSecret = config.SimRecvKey; 621 TheSim.regionSecret = config.SimRecvKey;
622 TheSim.regionDataURI = ""; 622 TheSim.regionDataURI = "";
623 TheSim.regionAssetURI = config.DefaultAssetServer; 623 TheSim.regionAssetURI = config.DefaultAssetServer;
624 TheSim.regionAssetRecvKey = config.AssetRecvKey; 624 TheSim.regionAssetRecvKey = config.AssetRecvKey;
625 TheSim.regionAssetSendKey = config.AssetSendKey; 625 TheSim.regionAssetSendKey = config.AssetSendKey;
626 TheSim.regionUserURI = config.DefaultUserServer; 626 TheSim.regionUserURI = config.DefaultUserServer;
627 TheSim.regionUserSendKey = config.UserSendKey; 627 TheSim.regionUserSendKey = config.UserSendKey;
628 TheSim.regionUserRecvKey = config.UserRecvKey; 628 TheSim.regionUserRecvKey = config.UserRecvKey;
629 629
630 630
631 for (int i = 0; i < simnode.ChildNodes.Count; i++) 631 for (int i = 0; i < simnode.ChildNodes.Count; i++)
632 { 632 {
633 switch (simnode.ChildNodes[i].Name) 633 switch (simnode.ChildNodes[i].Name)
634 { 634 {
635 case "regionname": 635 case "regionname":
636 TheSim.regionName = simnode.ChildNodes[i].InnerText; 636 TheSim.regionName = simnode.ChildNodes[i].InnerText;
637 break; 637 break;
638 638
639 case "sim_ip": 639 case "sim_ip":
640 TheSim.serverIP = simnode.ChildNodes[i].InnerText; 640 TheSim.serverIP = simnode.ChildNodes[i].InnerText;
641 break; 641 break;
642 642
643 case "sim_port": 643 case "sim_port":
644 TheSim.serverPort = Convert.ToUInt32(simnode.ChildNodes[i].InnerText); 644 TheSim.serverPort = Convert.ToUInt32(simnode.ChildNodes[i].InnerText);
645 break; 645 break;
646 646
647 case "region_locx": 647 case "region_locx":
648 TheSim.regionLocX = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText); 648 TheSim.regionLocX = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
649 TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256)); 649 TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256));
650 break; 650 break;
651 651
652 case "region_locy": 652 case "region_locy":
653 TheSim.regionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText); 653 TheSim.regionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
654 TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256)); 654 TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256));
655 break; 655 break;
656 } 656 }
657 } 657 }
658 658
659 TheSim.serverURI = "http://" + TheSim.serverIP + ":" + TheSim.serverPort + "/"; 659 TheSim.serverURI = "http://" + TheSim.serverIP + ":" + TheSim.serverPort + "/";
660 660
661 bool requirePublic = false; 661 bool requirePublic = false;
662 bool requireValid = true; 662 bool requireValid = true;
663 663
664 if (requirePublic && (TheSim.serverIP.StartsWith("172.16") || TheSim.serverIP.StartsWith("192.168") || TheSim.serverIP.StartsWith("10.") || TheSim.serverIP.StartsWith("0.") || TheSim.serverIP.StartsWith("255."))) 664 if (requirePublic && (TheSim.serverIP.StartsWith("172.16") || TheSim.serverIP.StartsWith("192.168") || TheSim.serverIP.StartsWith("10.") || TheSim.serverIP.StartsWith("0.") || TheSim.serverIP.StartsWith("255.")))
665 { 665 {
666 return "ERROR! Servers must register with public addresses."; 666 return "ERROR! Servers must register with public addresses.";
667 } 667 }
668 668
669 if (requireValid && (TheSim.serverIP.StartsWith("0."))) 669 if (requireValid && (TheSim.serverIP.StartsWith("0.")))
670 { 670 {
671 return "ERROR! 0.*.*.* Addresses are invalid, please check your server config and try again"; 671 return "ERROR! 0.*.*.* Addresses are invalid, please check your server config and try again";
672 } 672 }
673 673
674 674
675 try 675 try
676 { 676 {
677 MainLog.Instance.Verbose("Updating / adding via " + _plugins.Count + " storage provider(s) registered."); 677 MainLog.Instance.Verbose("Updating / adding via " + _plugins.Count + " storage provider(s) registered.");
678 foreach (KeyValuePair<string, IGridData> kvp in _plugins) 678 foreach (KeyValuePair<string, IGridData> kvp in _plugins)
679 { 679 {
680 try 680 try
681 { 681 {
682 //Check reservations 682 //Check reservations
683 ReservationData reserveData = kvp.Value.GetReservationAtPoint(TheSim.regionLocX, TheSim.regionLocY); 683 ReservationData reserveData = kvp.Value.GetReservationAtPoint(TheSim.regionLocX, TheSim.regionLocY);
684 if ((reserveData != null && reserveData.gridRecvKey == TheSim.regionRecvKey) || (reserveData == null && authkeynode.InnerText != TheSim.regionRecvKey)) 684 if ((reserveData != null && reserveData.gridRecvKey == TheSim.regionRecvKey) || (reserveData == null && authkeynode.InnerText != TheSim.regionRecvKey))
685 { 685 {
686 kvp.Value.AddProfile(TheSim); 686 kvp.Value.AddProfile(TheSim);
687 MainLog.Instance.Verbose("New sim added to grid (" + TheSim.regionName + ")"); 687 MainLog.Instance.Verbose("New sim added to grid (" + TheSim.regionName + ")");
688 logToDB(TheSim.UUID.ToStringHyphenated(), "RestSetSimMethod", "", 5, "Region successfully updated and connected to grid."); 688 logToDB(TheSim.UUID.ToStringHyphenated(), "RestSetSimMethod", "", 5, "Region successfully updated and connected to grid.");
689 } 689 }
690 else 690 else
691 { 691 {
692 MainLog.Instance.Warn("Unable to update region (RestSetSimMethod): Incorrect reservation auth key.");// Wanted: " + reserveData.gridRecvKey + ", Got: " + TheSim.regionRecvKey + "."); 692 MainLog.Instance.Warn("Unable to update region (RestSetSimMethod): Incorrect reservation auth key.");// Wanted: " + reserveData.gridRecvKey + ", Got: " + TheSim.regionRecvKey + ".");
693 return "Unable to update region (RestSetSimMethod): Incorrect auth key."; 693 return "Unable to update region (RestSetSimMethod): Incorrect auth key.";
694 } 694 }
695 } 695 }
696 catch (Exception e) 696 catch (Exception e)
697 { 697 {
698 MainLog.Instance.Verbose("getRegionPlugin Handle " + kvp.Key + " unable to add new sim: " + e.ToString()); 698 MainLog.Instance.Verbose("getRegionPlugin Handle " + kvp.Key + " unable to add new sim: " + e.ToString());
699 } 699 }
700 } 700 }
701 return "OK"; 701 return "OK";
702 } 702 }
703 catch (Exception e) 703 catch (Exception e)
704 { 704 {
705 return "ERROR! Could not save to database! (" + e.ToString() + ")"; 705 return "ERROR! Could not save to database! (" + e.ToString() + ")";
706 } 706 }
707 } 707 }
708 708
709 } 709 }
710} 710}