aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-12-07 22:39:12 +0000
committerJustin Clark-Casey (justincc)2011-12-07 22:39:12 +0000
commitfb2f4f158c42ecfea114eb7cefd9074dc001626f (patch)
treec866d0952157474f6702c210845a33b58fe7a019 /OpenSim/ApplicationPlugins
parentRemove unused SceneManager.TryGetAvatarsScene() (diff)
downloadopensim-SC-fb2f4f158c42ecfea114eb7cefd9074dc001626f.zip
opensim-SC-fb2f4f158c42ecfea114eb7cefd9074dc001626f.tar.gz
opensim-SC-fb2f4f158c42ecfea114eb7cefd9074dc001626f.tar.bz2
opensim-SC-fb2f4f158c42ecfea114eb7cefd9074dc001626f.tar.xz
Refactor RemoteAdminPlugin so that every xmlrpc method calls a common block of code to do password checks, etc., instead of copy/pasting this code into every method
Diffstat (limited to 'OpenSim/ApplicationPlugins')
-rw-r--r--OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs3081
1 files changed, 1370 insertions, 1711 deletions
diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
index 1b289a6..1da7c35 100644
--- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
+++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
@@ -124,37 +124,37 @@ namespace OpenSim.ApplicationPlugins.RemoteController
124 m_httpServer = MainServer.GetHttpServer((uint)port,ipaddr); 124 m_httpServer = MainServer.GetHttpServer((uint)port,ipaddr);
125 125
126 Dictionary<string, XmlRpcMethod> availableMethods = new Dictionary<string, XmlRpcMethod>(); 126 Dictionary<string, XmlRpcMethod> availableMethods = new Dictionary<string, XmlRpcMethod>();
127 availableMethods["admin_create_region"] = XmlRpcCreateRegionMethod; 127 availableMethods["admin_create_region"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcCreateRegionMethod);
128 availableMethods["admin_delete_region"] = XmlRpcDeleteRegionMethod; 128 availableMethods["admin_delete_region"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcDeleteRegionMethod);
129 availableMethods["admin_close_region"] = XmlRpcCloseRegionMethod; 129 availableMethods["admin_close_region"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcCloseRegionMethod);
130 availableMethods["admin_modify_region"] = XmlRpcModifyRegionMethod; 130 availableMethods["admin_modify_region"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcModifyRegionMethod);
131 availableMethods["admin_region_query"] = XmlRpcRegionQueryMethod; 131 availableMethods["admin_region_query"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcRegionQueryMethod);
132 availableMethods["admin_shutdown"] = XmlRpcShutdownMethod; 132 availableMethods["admin_shutdown"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcShutdownMethod);
133 availableMethods["admin_broadcast"] = XmlRpcAlertMethod; 133 availableMethods["admin_broadcast"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcAlertMethod);
134 availableMethods["admin_restart"] = XmlRpcRestartMethod; 134 availableMethods["admin_restart"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcRestartMethod);
135 availableMethods["admin_load_heightmap"] = XmlRpcLoadHeightmapMethod; 135 availableMethods["admin_load_heightmap"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcLoadHeightmapMethod);
136 availableMethods["admin_save_heightmap"] = XmlRpcSaveHeightmapMethod; 136 availableMethods["admin_save_heightmap"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcSaveHeightmapMethod);
137 137
138 // Agent management 138 // Agent management
139 availableMethods["admin_teleport_agent"] = XmlRpcTeleportAgentMethod; 139 availableMethods["admin_teleport_agent"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcTeleportAgentMethod);
140 140
141 // User management 141 // User management
142 availableMethods["admin_create_user"] = XmlRpcCreateUserMethod; 142 availableMethods["admin_create_user"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcCreateUserMethod);
143 availableMethods["admin_create_user_email"] = XmlRpcCreateUserMethod; 143 availableMethods["admin_create_user_email"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcCreateUserMethod);
144 availableMethods["admin_exists_user"] = XmlRpcUserExistsMethod; 144 availableMethods["admin_exists_user"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcUserExistsMethod);
145 availableMethods["admin_update_user"] = XmlRpcUpdateUserAccountMethod; 145 availableMethods["admin_update_user"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcUpdateUserAccountMethod);
146 146
147 // Region state management 147 // Region state management
148 availableMethods["admin_load_xml"] = XmlRpcLoadXMLMethod; 148 availableMethods["admin_load_xml"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcLoadXMLMethod);
149 availableMethods["admin_save_xml"] = XmlRpcSaveXMLMethod; 149 availableMethods["admin_save_xml"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcSaveXMLMethod);
150 availableMethods["admin_load_oar"] = XmlRpcLoadOARMethod; 150 availableMethods["admin_load_oar"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcLoadOARMethod);
151 availableMethods["admin_save_oar"] = XmlRpcSaveOARMethod; 151 availableMethods["admin_save_oar"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcSaveOARMethod);
152 152
153 // Estate access list management 153 // Estate access list management
154 availableMethods["admin_acl_clear"] = XmlRpcAccessListClear; 154 availableMethods["admin_acl_clear"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcAccessListClear);
155 availableMethods["admin_acl_add"] = XmlRpcAccessListAdd; 155 availableMethods["admin_acl_add"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcAccessListAdd);
156 availableMethods["admin_acl_remove"] = XmlRpcAccessListRemove; 156 availableMethods["admin_acl_remove"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcAccessListRemove);
157 availableMethods["admin_acl_list"] = XmlRpcAccessListList; 157 availableMethods["admin_acl_list"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcAccessListList);
158 158
159 // Either enable full remote functionality or just selected features 159 // Either enable full remote functionality or just selected features
160 string enabledMethods = m_config.GetString("enabled_methods", "all"); 160 string enabledMethods = m_config.GetString("enabled_methods", "all");
@@ -164,7 +164,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController
164 // If you just leave the option out! 164 // If you just leave the option out!
165 // 165 //
166 if (!String.IsNullOrEmpty(enabledMethods)) 166 if (!String.IsNullOrEmpty(enabledMethods))
167 availableMethods["admin_console_command"] = XmlRpcConsoleCommandMethod; 167 availableMethods["admin_console_command"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcConsoleCommandMethod);
168 168
169 // The assumption here is that simply enabling Remote Admin as before will produce the same 169 // The assumption here is that simply enabling Remote Admin as before will produce the same
170 // behavior - enable all methods unless the whitelist is in place for backward-compatibility. 170 // behavior - enable all methods unless the whitelist is in place for backward-compatibility.
@@ -198,34 +198,67 @@ namespace OpenSim.ApplicationPlugins.RemoteController
198 } 198 }
199 } 199 }
200 200
201 private void FailIfRemoteAdminNotAllowed(string password, string check_ip_address) 201 /// <summary>
202 /// Invoke an XmlRpc method with the standard actions (password check, etc.)
203 /// </summary>
204 /// <param name="method"></param>
205 private XmlRpcResponse InvokeXmlRpcMethod(
206 XmlRpcRequest request, IPEndPoint remoteClient, Action<XmlRpcRequest, XmlRpcResponse, IPEndPoint> method)
207 {
208 XmlRpcResponse response = new XmlRpcResponse();
209 Hashtable responseData = new Hashtable();
210 response.Value = responseData;
211
212 try
213 {
214 Hashtable requestData = (Hashtable) request.Params[0];
215
216 m_log.Info("[RADMIN]: Request to restart Region.");
217 CheckStringParameters(requestData, responseData, new string[] {"password"});
218
219 FailIfRemoteAdminNotAllowed((string)requestData["password"], responseData, remoteClient.Address.ToString());
220
221 method(request, response, remoteClient);
222 }
223 catch (Exception e)
224 {
225 m_log.ErrorFormat(
226 "[RADMIN]: Method {0} failed. Exception {1}{2}", request.MethodName, e.Message, e.StackTrace);
227
228 responseData["success"] = false;
229 responseData["error"] = e.Message;
230 }
231
232 return response;
233 }
234
235 private void FailIfRemoteAdminNotAllowed(string password, Hashtable responseData, string check_ip_address)
202 { 236 {
203 if (m_accessIP.Count > 0 && !m_accessIP.Contains(check_ip_address)) 237 if (m_accessIP.Count > 0 && !m_accessIP.Contains(check_ip_address))
204 { 238 {
205 m_log.WarnFormat("[RADMIN]: Unauthorized acess blocked from IP {0}", check_ip_address); 239 m_log.WarnFormat("[RADMIN]: Unauthorized access blocked from IP {0}", check_ip_address);
240 responseData["accepted"] = false;
206 throw new Exception("not authorized"); 241 throw new Exception("not authorized");
207 } 242 }
208 243
209 if (m_requiredPassword != String.Empty && password != m_requiredPassword) 244 if (m_requiredPassword != String.Empty && password != m_requiredPassword)
210 { 245 {
211 m_log.WarnFormat("[RADMIN]: Wrong password, blocked access from IP {0}", check_ip_address); 246 m_log.WarnFormat("[RADMIN]: Wrong password, blocked access from IP {0}", check_ip_address);
247 responseData["accepted"] = false;
212 throw new Exception("wrong password"); 248 throw new Exception("wrong password");
213 } 249 }
214 } 250 }
215 251
216 public XmlRpcResponse XmlRpcRestartMethod(XmlRpcRequest request, IPEndPoint remoteClient) 252 private void XmlRpcRestartMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
217 { 253 {
218 XmlRpcResponse response = new XmlRpcResponse(); 254 Hashtable responseData = (Hashtable)response.Value;
219 Hashtable responseData = new Hashtable(); 255 Hashtable requestData = (Hashtable)request.Params[0];
220 256
221 try 257 try
222 { 258 {
223 Hashtable requestData = (Hashtable) request.Params[0];
224
225 m_log.Info("[RADMIN]: Request to restart Region."); 259 m_log.Info("[RADMIN]: Request to restart Region.");
226 CheckStringParameters(request, new string[] {"password", "regionID"});
227 260
228 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString()); 261 CheckStringParameters(requestData, responseData, new string[] {"regionID"});
229 262
230 UUID regionID = new UUID((string) requestData["regionID"]); 263 UUID regionID = new UUID((string) requestData["regionID"]);
231 264
@@ -246,231 +279,151 @@ namespace OpenSim.ApplicationPlugins.RemoteController
246 restartModule.ScheduleRestart(UUID.Zero, "Region will restart in {0}", times.ToArray(), true); 279 restartModule.ScheduleRestart(UUID.Zero, "Region will restart in {0}", times.ToArray(), true);
247 responseData["success"] = true; 280 responseData["success"] = true;
248 } 281 }
249
250 response.Value = responseData;
251 } 282 }
252 catch (Exception e) 283 catch (Exception e)
253 { 284 {
254 m_log.ErrorFormat("[RADMIN]: Restart region: failed: {0} {1}", e.Message, e.StackTrace); 285// m_log.ErrorFormat("[RADMIN]: Restart region: failed: {0} {1}", e.Message, e.StackTrace);
255 responseData["accepted"] = false;
256 responseData["success"] = false;
257 responseData["rebooting"] = false; 286 responseData["rebooting"] = false;
258 responseData["error"] = e.Message; 287
259 response.Value = responseData; 288 throw e;
260 } 289 }
261 290
262 m_log.Info("[RADMIN]: Restart Region request complete"); 291 m_log.Info("[RADMIN]: Restart Region request complete");
263 return response;
264 } 292 }
265 293
266 public XmlRpcResponse XmlRpcAlertMethod(XmlRpcRequest request, IPEndPoint remoteClient) 294 private void XmlRpcAlertMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
267 { 295 {
268 XmlRpcResponse response = new XmlRpcResponse();
269 Hashtable responseData = new Hashtable();
270
271 m_log.Info("[RADMIN]: Alert request started"); 296 m_log.Info("[RADMIN]: Alert request started");
272 297
273 try 298 Hashtable responseData = (Hashtable)response.Value;
274 { 299 Hashtable requestData = (Hashtable)request.Params[0];
275 Hashtable requestData = (Hashtable) request.Params[0];
276
277 CheckStringParameters(request, new string[] {"password", "message"});
278
279 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
280 300
281 string message = (string) requestData["message"]; 301 string message = (string) requestData["message"];
282 m_log.InfoFormat("[RADMIN]: Broadcasting: {0}", message); 302 m_log.InfoFormat("[RADMIN]: Broadcasting: {0}", message);
283 303
284 responseData["accepted"] = true; 304 responseData["accepted"] = true;
285 responseData["success"] = true; 305 responseData["success"] = true;
286 response.Value = responseData;
287 306
288 m_application.SceneManager.ForEachScene( 307 m_application.SceneManager.ForEachScene(
289 delegate(Scene scene) 308 delegate(Scene scene)
290 { 309 {
291 IDialogModule dialogModule = scene.RequestModuleInterface<IDialogModule>(); 310 IDialogModule dialogModule = scene.RequestModuleInterface<IDialogModule>();
292 if (dialogModule != null) 311 if (dialogModule != null)
293 dialogModule.SendGeneralAlert(message); 312 dialogModule.SendGeneralAlert(message);
294 }); 313 });
295 }
296 catch (Exception e)
297 {
298 m_log.ErrorFormat("[RADMIN]: Broadcasting: failed: {0}", e.Message, e.StackTrace);
299
300 responseData["accepted"] = false;
301 responseData["success"] = false;
302 responseData["error"] = e.Message;
303 response.Value = responseData;
304 }
305 314
306 m_log.Info("[RADMIN]: Alert request complete"); 315 m_log.Info("[RADMIN]: Alert request complete");
307 return response;
308 } 316 }
309 317
310 public XmlRpcResponse XmlRpcLoadHeightmapMethod(XmlRpcRequest request, IPEndPoint remoteClient) 318 private void XmlRpcLoadHeightmapMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
311 { 319 {
312 XmlRpcResponse response = new XmlRpcResponse();
313 Hashtable responseData = new Hashtable();
314
315 m_log.Info("[RADMIN]: Load height maps request started"); 320 m_log.Info("[RADMIN]: Load height maps request started");
316 321
317 try 322 Hashtable responseData = (Hashtable)response.Value;
318 { 323 Hashtable requestData = (Hashtable)request.Params[0];
319 Hashtable requestData = (Hashtable) request.Params[0];
320
321 m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}", request);
322 // foreach (string k in requestData.Keys)
323 // {
324 // m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}: >{1}< {2}",
325 // k, (string)requestData[k], ((string)requestData[k]).Length);
326 // }
327
328 CheckStringParameters(request, new string[] {"password", "filename", "regionid"});
329 324
330 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString()); 325// m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}", request);
326 // foreach (string k in requestData.Keys)
327 // {
328 // m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}: >{1}< {2}",
329 // k, (string)requestData[k], ((string)requestData[k]).Length);
330 // }
331 331
332 string file = (string) requestData["filename"]; 332 CheckStringParameters(requestData, responseData, new string[] {"filename", "regionid"});
333 UUID regionID = (UUID) (string) requestData["regionid"];
334 m_log.InfoFormat("[RADMIN]: Terrain Loading: {0}", file);
335
336 responseData["accepted"] = true;
337 333
338 LoadHeightmap(file, regionID); 334 string file = (string) requestData["filename"];
335 UUID regionID = (UUID) (string) requestData["regionid"];
336 m_log.InfoFormat("[RADMIN]: Terrain Loading: {0}", file);
339 337
340 responseData["success"] = false; 338 responseData["accepted"] = true;
341 339
342 response.Value = responseData; 340 LoadHeightmap(file, regionID);
343 }
344 catch (Exception e)
345 {
346 m_log.ErrorFormat("[RADMIN]: Terrain Loading: failed: {0} {1}", e.Message, e.StackTrace);
347 341
348 responseData["success"] = false; 342 responseData["success"] = false;
349 responseData["error"] = e.Message;
350 }
351 343
352 m_log.Info("[RADMIN]: Load height maps request complete"); 344 m_log.Info("[RADMIN]: Load height maps request complete");
353
354 return response;
355 } 345 }
356 346
357 public XmlRpcResponse XmlRpcSaveHeightmapMethod(XmlRpcRequest request, IPEndPoint remoteClient) 347 private void XmlRpcSaveHeightmapMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
358 { 348 {
359 XmlRpcResponse response = new XmlRpcResponse();
360 Hashtable responseData = new Hashtable();
361
362 m_log.Info("[RADMIN]: Save height maps request started"); 349 m_log.Info("[RADMIN]: Save height maps request started");
363 350
364 try 351 Hashtable responseData = (Hashtable)response.Value;
365 { 352 Hashtable requestData = (Hashtable)request.Params[0];
366 Hashtable requestData = (Hashtable)request.Params[0];
367
368 m_log.DebugFormat("[RADMIN]: Save Terrain: XmlRpc {0}", request.ToString());
369 353
370 CheckStringParameters(request, new string[] { "password", "filename", "regionid" }); 354// m_log.DebugFormat("[RADMIN]: Save Terrain: XmlRpc {0}", request.ToString());
371 355
372 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString()); 356 CheckStringParameters(requestData, responseData, new string[] { "filename", "regionid" });
373 357
374 string file = (string)requestData["filename"]; 358 string file = (string)requestData["filename"];
375 UUID regionID = (UUID)(string)requestData["regionid"]; 359 UUID regionID = (UUID)(string)requestData["regionid"];
376 m_log.InfoFormat("[RADMIN]: Terrain Saving: {0}", file); 360 m_log.InfoFormat("[RADMIN]: Terrain Saving: {0}", file);
377 361
378 responseData["accepted"] = true; 362 responseData["accepted"] = true;
379
380 Scene region = null;
381 363
382 if (!m_application.SceneManager.TryGetScene(regionID, out region)) 364 Scene region = null;
383 throw new Exception("1: unable to get a scene with that name");
384 365
385 ITerrainModule terrainModule = region.RequestModuleInterface<ITerrainModule>(); 366 if (!m_application.SceneManager.TryGetScene(regionID, out region))
386 if (null == terrainModule) throw new Exception("terrain module not available"); 367 throw new Exception("1: unable to get a scene with that name");
387 368
388 terrainModule.SaveToFile(file); 369 ITerrainModule terrainModule = region.RequestModuleInterface<ITerrainModule>();
370 if (null == terrainModule) throw new Exception("terrain module not available");
389 371
390 responseData["success"] = false; 372 terrainModule.SaveToFile(file);
391 373
392 response.Value = responseData; 374 responseData["success"] = false;
393 }
394 catch (Exception e)
395 {
396 m_log.ErrorFormat("[RADMIN]: Terrain Saving: failed: {0}", e.Message);
397 m_log.DebugFormat("[RADMIN]: Terrain Saving: failed: {0}", e.ToString());
398
399 responseData["success"] = false;
400 responseData["error"] = e.Message;
401
402 }
403 375
404 m_log.Info("[RADMIN]: Save height maps request complete"); 376 m_log.Info("[RADMIN]: Save height maps request complete");
405
406 return response;
407 } 377 }
408 378
409 public XmlRpcResponse XmlRpcShutdownMethod(XmlRpcRequest request, IPEndPoint remoteClient) 379 private void XmlRpcShutdownMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
410 { 380 {
411 m_log.Info("[RADMIN]: Received Shutdown Administrator Request"); 381 m_log.Info("[RADMIN]: Received Shutdown Administrator Request");
412 382
413 XmlRpcResponse response = new XmlRpcResponse(); 383 Hashtable responseData = (Hashtable)response.Value;
414 Hashtable responseData = new Hashtable(); 384 Hashtable requestData = (Hashtable)request.Params[0];
415
416 try
417 {
418 Hashtable requestData = (Hashtable) request.Params[0];
419
420 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
421 385
422 responseData["accepted"] = true; 386 responseData["accepted"] = true;
423 response.Value = responseData; 387 response.Value = responseData;
424
425 int timeout = 2000;
426 string message;
427 388
428 if (requestData.ContainsKey("shutdown") 389 int timeout = 2000;
429 && ((string) requestData["shutdown"] == "delayed") 390 string message;
430 && requestData.ContainsKey("milliseconds"))
431 {
432 timeout = Int32.Parse(requestData["milliseconds"].ToString());
433 391
434 message 392 if (requestData.ContainsKey("shutdown")
435 = "Region is going down in " + ((int) (timeout/1000)).ToString() 393 && ((string) requestData["shutdown"] == "delayed")
436 + " second(s). Please save what you are doing and log out."; 394 && requestData.ContainsKey("milliseconds"))
437 } 395 {
438 else 396 timeout = Int32.Parse(requestData["milliseconds"].ToString());
439 {
440 message = "Region is going down now.";
441 }
442
443 m_application.SceneManager.ForEachScene(
444 delegate(Scene scene)
445 {
446 IDialogModule dialogModule = scene.RequestModuleInterface<IDialogModule>();
447 if (dialogModule != null)
448 dialogModule.SendGeneralAlert(message);
449 });
450
451 // Perform shutdown
452 System.Timers.Timer shutdownTimer = new System.Timers.Timer(timeout); // Wait before firing
453 shutdownTimer.AutoReset = false;
454 shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed);
455 lock (shutdownTimer)
456 {
457 shutdownTimer.Start();
458 }
459 397
460 responseData["success"] = true; 398 message
399 = "Region is going down in " + ((int) (timeout/1000)).ToString()
400 + " second(s). Please save what you are doing and log out.";
461 } 401 }
462 catch (Exception e) 402 else
463 { 403 {
464 m_log.ErrorFormat("[RADMIN]: Shutdown: failed: {0} {1}", e.Message, e.StackTrace); 404 message = "Region is going down now.";
405 }
465 406
466 responseData["accepted"] = false; 407 m_application.SceneManager.ForEachScene(
467 responseData["error"] = e.Message; 408 delegate(Scene scene)
409 {
410 IDialogModule dialogModule = scene.RequestModuleInterface<IDialogModule>();
411 if (dialogModule != null)
412 dialogModule.SendGeneralAlert(message);
413 });
468 414
469 response.Value = responseData; 415 // Perform shutdown
416 System.Timers.Timer shutdownTimer = new System.Timers.Timer(timeout); // Wait before firing
417 shutdownTimer.AutoReset = false;
418 shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed);
419 lock (shutdownTimer)
420 {
421 shutdownTimer.Start();
470 } 422 }
423
424 responseData["success"] = true;
471 425
472 m_log.Info("[RADMIN]: Shutdown Administrator Request complete"); 426 m_log.Info("[RADMIN]: Shutdown Administrator Request complete");
473 return response;
474 } 427 }
475 428
476 private void shutdownTimer_Elapsed(object sender, ElapsedEventArgs e) 429 private void shutdownTimer_Elapsed(object sender, ElapsedEventArgs e)
@@ -541,12 +494,12 @@ namespace OpenSim.ApplicationPlugins.RemoteController
541 /// <description>name of the newly created region</description></item> 494 /// <description>name of the newly created region</description></item>
542 /// </list> 495 /// </list>
543 /// </remarks> 496 /// </remarks>
544 public XmlRpcResponse XmlRpcCreateRegionMethod(XmlRpcRequest request, IPEndPoint remoteClient) 497 private void XmlRpcCreateRegionMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
545 { 498 {
546 m_log.Info("[RADMIN]: CreateRegion: new request"); 499 m_log.Info("[RADMIN]: CreateRegion: new request");
547 500
548 XmlRpcResponse response = new XmlRpcResponse(); 501 Hashtable responseData = (Hashtable)response.Value;
549 Hashtable responseData = new Hashtable(); 502 Hashtable requestData = (Hashtable)request.Params[0];
550 503
551 lock (m_requestLock) 504 lock (m_requestLock)
552 { 505 {
@@ -554,255 +507,235 @@ namespace OpenSim.ApplicationPlugins.RemoteController
554 bool m_enableVoiceForNewRegions = m_config.GetBoolean("create_region_enable_voice", false); 507 bool m_enableVoiceForNewRegions = m_config.GetBoolean("create_region_enable_voice", false);
555 bool m_publicAccess = m_config.GetBoolean("create_region_public", true); 508 bool m_publicAccess = m_config.GetBoolean("create_region_public", true);
556 509
557 try 510 CheckStringParameters(requestData, responseData, new string[]
511 {
512 "region_name",
513 "listen_ip", "external_address",
514 "estate_name"
515 });
516 CheckIntegerParams(requestData, responseData, new string[] {"region_x", "region_y", "listen_port"});
517
518 // check whether we still have space left (iff we are using limits)
519 if (m_regionLimit != 0 && m_application.SceneManager.Scenes.Count >= m_regionLimit)
520 throw new Exception(String.Format("cannot instantiate new region, server capacity {0} already reached; delete regions first",
521 m_regionLimit));
522 // extract or generate region ID now
523 Scene scene = null;
524 UUID regionID = UUID.Zero;
525 if (requestData.ContainsKey("region_id") &&
526 !String.IsNullOrEmpty((string) requestData["region_id"]))
558 { 527 {
559 Hashtable requestData = (Hashtable) request.Params[0]; 528 regionID = (UUID) (string) requestData["region_id"];
560 529 if (m_application.SceneManager.TryGetScene(regionID, out scene))
561 CheckStringParameters(request, new string[] 530 throw new Exception(
562 { 531 String.Format("region UUID already in use by region {0}, UUID {1}, <{2},{3}>",
563 "password", 532 scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
564 "region_name", 533 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
565 "listen_ip", "external_address", 534 }
566 "estate_name" 535 else
567 }); 536 {
568 CheckIntegerParams(request, new string[] {"region_x", "region_y", "listen_port"}); 537 regionID = UUID.Random();
569 538 m_log.DebugFormat("[RADMIN] CreateRegion: new region UUID {0}", regionID);
570 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString()); 539 }
571 540
572 // check whether we still have space left (iff we are using limits) 541 // create volatile or persistent region info
573 if (m_regionLimit != 0 && m_application.SceneManager.Scenes.Count >= m_regionLimit) 542 RegionInfo region = new RegionInfo();
574 throw new Exception(String.Format("cannot instantiate new region, server capacity {0} already reached; delete regions first", 543
575 m_regionLimit)); 544 region.RegionID = regionID;
576 // extract or generate region ID now 545 region.originRegionID = regionID;
577 Scene scene = null; 546 region.RegionName = (string) requestData["region_name"];
578 UUID regionID = UUID.Zero; 547 region.RegionLocX = Convert.ToUInt32(requestData["region_x"]);
579 if (requestData.ContainsKey("region_id") && 548 region.RegionLocY = Convert.ToUInt32(requestData["region_y"]);
580 !String.IsNullOrEmpty((string) requestData["region_id"])) 549
550 // check for collisions: region name, region UUID,
551 // region location
552 if (m_application.SceneManager.TryGetScene(region.RegionName, out scene))
553 throw new Exception(
554 String.Format("region name already in use by region {0}, UUID {1}, <{2},{3}>",
555 scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
556 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
557
558 if (m_application.SceneManager.TryGetScene(region.RegionLocX, region.RegionLocY, out scene))
559 throw new Exception(
560 String.Format("region location <{0},{1}> already in use by region {2}, UUID {3}, <{4},{5}>",
561 region.RegionLocX, region.RegionLocY,
562 scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
563 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
564
565 region.InternalEndPoint =
566 new IPEndPoint(IPAddress.Parse((string) requestData["listen_ip"]), 0);
567
568 region.InternalEndPoint.Port = Convert.ToInt32(requestData["listen_port"]);
569 if (0 == region.InternalEndPoint.Port) throw new Exception("listen_port is 0");
570 if (m_application.SceneManager.TryGetScene(region.InternalEndPoint, out scene))
571 throw new Exception(
572 String.Format(
573 "region internal IP {0} and port {1} already in use by region {2}, UUID {3}, <{4},{5}>",
574 region.InternalEndPoint.Address,
575 region.InternalEndPoint.Port,
576 scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
577 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
578
579 region.ExternalHostName = (string) requestData["external_address"];
580
581 bool persist = Convert.ToBoolean((string) requestData["persist"]);
582 if (persist)
583 {
584 // default place for region configuration files is in the
585 // Regions directory of the config dir (aka /bin)
586 string regionConfigPath = Path.Combine(Util.configDir(), "Regions");
587 try
581 { 588 {
582 regionID = (UUID) (string) requestData["region_id"]; 589 // OpenSim.ini can specify a different regions dir
583 if (m_application.SceneManager.TryGetScene(regionID, out scene)) 590 IConfig startupConfig = (IConfig) m_configSource.Configs["Startup"];
584 throw new Exception( 591 regionConfigPath = startupConfig.GetString("regionload_regionsdir", regionConfigPath).Trim();
585 String.Format("region UUID already in use by region {0}, UUID {1}, <{2},{3}>",
586 scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
587 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
588 } 592 }
589 else 593 catch (Exception)
590 { 594 {
591 regionID = UUID.Random(); 595 // No INI setting recorded.
592 m_log.DebugFormat("[RADMIN] CreateRegion: new region UUID {0}", regionID);
593 } 596 }
594 597
595 // create volatile or persistent region info 598 string regionIniPath;
596 RegionInfo region = new RegionInfo(); 599
597 600 if (requestData.Contains("region_file"))
598 region.RegionID = regionID;
599 region.originRegionID = regionID;
600 region.RegionName = (string) requestData["region_name"];
601 region.RegionLocX = Convert.ToUInt32(requestData["region_x"]);
602 region.RegionLocY = Convert.ToUInt32(requestData["region_y"]);
603
604 // check for collisions: region name, region UUID,
605 // region location
606 if (m_application.SceneManager.TryGetScene(region.RegionName, out scene))
607 throw new Exception(
608 String.Format("region name already in use by region {0}, UUID {1}, <{2},{3}>",
609 scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
610 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
611
612 if (m_application.SceneManager.TryGetScene(region.RegionLocX, region.RegionLocY, out scene))
613 throw new Exception(
614 String.Format("region location <{0},{1}> already in use by region {2}, UUID {3}, <{4},{5}>",
615 region.RegionLocX, region.RegionLocY,
616 scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
617 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
618
619 region.InternalEndPoint =
620 new IPEndPoint(IPAddress.Parse((string) requestData["listen_ip"]), 0);
621
622 region.InternalEndPoint.Port = Convert.ToInt32(requestData["listen_port"]);
623 if (0 == region.InternalEndPoint.Port) throw new Exception("listen_port is 0");
624 if (m_application.SceneManager.TryGetScene(region.InternalEndPoint, out scene))
625 throw new Exception(
626 String.Format(
627 "region internal IP {0} and port {1} already in use by region {2}, UUID {3}, <{4},{5}>",
628 region.InternalEndPoint.Address,
629 region.InternalEndPoint.Port,
630 scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
631 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
632
633 region.ExternalHostName = (string) requestData["external_address"];
634
635 bool persist = Convert.ToBoolean((string) requestData["persist"]);
636 if (persist)
637 { 601 {
638 // default place for region configuration files is in the 602 // Make sure that the file to be created is in a subdirectory of the region storage directory.
639 // Regions directory of the config dir (aka /bin) 603 string requestedFilePath = Path.Combine(regionConfigPath, (string) requestData["region_file"]);
640 string regionConfigPath = Path.Combine(Util.configDir(), "Regions"); 604 string requestedDirectory = Path.GetDirectoryName(Path.GetFullPath(requestedFilePath));
641 try 605 if (requestedDirectory.StartsWith(Path.GetFullPath(regionConfigPath)))
642 { 606 regionIniPath = requestedFilePath;
643 // OpenSim.ini can specify a different regions dir
644 IConfig startupConfig = (IConfig) m_configSource.Configs["Startup"];
645 regionConfigPath = startupConfig.GetString("regionload_regionsdir", regionConfigPath).Trim();
646 }
647 catch (Exception)
648 {
649 // No INI setting recorded.
650 }
651
652 string regionIniPath;
653
654 if (requestData.Contains("region_file"))
655 {
656 // Make sure that the file to be created is in a subdirectory of the region storage directory.
657 string requestedFilePath = Path.Combine(regionConfigPath, (string) requestData["region_file"]);
658 string requestedDirectory = Path.GetDirectoryName(Path.GetFullPath(requestedFilePath));
659 if (requestedDirectory.StartsWith(Path.GetFullPath(regionConfigPath)))
660 regionIniPath = requestedFilePath;
661 else
662 throw new Exception("Invalid location for region file.");
663 }
664 else 607 else
665 { 608 throw new Exception("Invalid location for region file.");
666 regionIniPath = Path.Combine(regionConfigPath,
667 String.Format(
668 m_config.GetString("region_file_template",
669 "{0}x{1}-{2}.ini"),
670 region.RegionLocX.ToString(),
671 region.RegionLocY.ToString(),
672 regionID.ToString(),
673 region.InternalEndPoint.Port.ToString(),
674 region.RegionName.Replace(" ", "_").Replace(":", "_").
675 Replace("/", "_")));
676 }
677
678 m_log.DebugFormat("[RADMIN] CreateRegion: persisting region {0} to {1}",
679 region.RegionID, regionIniPath);
680 region.SaveRegionToFile("dynamic region", regionIniPath);
681 } 609 }
682 else 610 else
683 { 611 {
684 region.Persistent = false; 612 regionIniPath = Path.Combine(regionConfigPath,
613 String.Format(
614 m_config.GetString("region_file_template",
615 "{0}x{1}-{2}.ini"),
616 region.RegionLocX.ToString(),
617 region.RegionLocY.ToString(),
618 regionID.ToString(),
619 region.InternalEndPoint.Port.ToString(),
620 region.RegionName.Replace(" ", "_").Replace(":", "_").
621 Replace("/", "_")));
685 } 622 }
686
687 // Set the estate
688 623
689 // Check for an existing estate 624 m_log.DebugFormat("[RADMIN] CreateRegion: persisting region {0} to {1}",
690 List<int> estateIDs = m_application.EstateDataService.GetEstates((string) requestData["estate_name"]); 625 region.RegionID, regionIniPath);
691 if (estateIDs.Count < 1) 626 region.SaveRegionToFile("dynamic region", regionIniPath);
627 }
628 else
629 {
630 region.Persistent = false;
631 }
632
633 // Set the estate
634
635 // Check for an existing estate
636 List<int> estateIDs = m_application.EstateDataService.GetEstates((string) requestData["estate_name"]);
637 if (estateIDs.Count < 1)
638 {
639 UUID userID = UUID.Zero;
640 if (requestData.ContainsKey("estate_owner_uuid"))
692 { 641 {
693 UUID userID = UUID.Zero; 642 // ok, client wants us to use an explicit UUID
694 if (requestData.ContainsKey("estate_owner_uuid")) 643 // regardless of what the avatar name provided
695 { 644 userID = new UUID((string) requestData["estate_owner_uuid"]);
696 // ok, client wants us to use an explicit UUID
697 // regardless of what the avatar name provided
698 userID = new UUID((string) requestData["estate_owner_uuid"]);
699
700 // Check that the specified user exists
701 Scene currentOrFirst = m_application.SceneManager.CurrentOrFirstScene;
702 IUserAccountService accountService = currentOrFirst.UserAccountService;
703 UserAccount user = accountService.GetUserAccount(currentOrFirst.RegionInfo.ScopeID, userID);
704
705 if (user == null)
706 throw new Exception("Specified user was not found.");
707 }
708 else if (requestData.ContainsKey("estate_owner_first") & requestData.ContainsKey("estate_owner_last"))
709 {
710 // We need to look up the UUID for the avatar with the provided name.
711 string ownerFirst = (string) requestData["estate_owner_first"];
712 string ownerLast = (string) requestData["estate_owner_last"];
713
714 Scene currentOrFirst = m_application.SceneManager.CurrentOrFirstScene;
715 IUserAccountService accountService = currentOrFirst.UserAccountService;
716 UserAccount user = accountService.GetUserAccount(currentOrFirst.RegionInfo.ScopeID,
717 ownerFirst, ownerLast);
718
719 // Check that the specified user exists
720 if (user == null)
721 throw new Exception("Specified user was not found.");
722
723 userID = user.PrincipalID;
724 }
725 else
726 {
727 throw new Exception("Estate owner details not provided.");
728 }
729 645
730 // Create a new estate with the name provided 646 // Check that the specified user exists
731 region.EstateSettings = m_application.EstateDataService.CreateNewEstate(); 647 Scene currentOrFirst = m_application.SceneManager.CurrentOrFirstScene;
732 648 IUserAccountService accountService = currentOrFirst.UserAccountService;
733 region.EstateSettings.EstateName = (string) requestData["estate_name"]; 649 UserAccount user = accountService.GetUserAccount(currentOrFirst.RegionInfo.ScopeID, userID);
734 region.EstateSettings.EstateOwner = userID; 650
735 // Persistence does not seem to effect the need to save a new estate 651 if (user == null)
736 region.EstateSettings.Save(); 652 throw new Exception("Specified user was not found.");
737 653 }
738 if (!m_application.EstateDataService.LinkRegion(region.RegionID, (int) region.EstateSettings.EstateID)) 654 else if (requestData.ContainsKey("estate_owner_first") & requestData.ContainsKey("estate_owner_last"))
739 throw new Exception("Failed to join estate."); 655 {
656 // We need to look up the UUID for the avatar with the provided name.
657 string ownerFirst = (string) requestData["estate_owner_first"];
658 string ownerLast = (string) requestData["estate_owner_last"];
659
660 Scene currentOrFirst = m_application.SceneManager.CurrentOrFirstScene;
661 IUserAccountService accountService = currentOrFirst.UserAccountService;
662 UserAccount user = accountService.GetUserAccount(currentOrFirst.RegionInfo.ScopeID,
663 ownerFirst, ownerLast);
664
665 // Check that the specified user exists
666 if (user == null)
667 throw new Exception("Specified user was not found.");
668
669 userID = user.PrincipalID;
740 } 670 }
741 else 671 else
742 { 672 {
743 int estateID = estateIDs[0]; 673 throw new Exception("Estate owner details not provided.");
744
745 region.EstateSettings = m_application.EstateDataService.LoadEstateSettings(region.RegionID, false);
746
747 if (region.EstateSettings.EstateID != estateID)
748 {
749 // The region is already part of an estate, but not the one we want.
750 region.EstateSettings = m_application.EstateDataService.LoadEstateSettings(estateID);
751
752 if (!m_application.EstateDataService.LinkRegion(region.RegionID, estateID))
753 throw new Exception("Failed to join estate.");
754 }
755 } 674 }
756 675
757 // Create the region and perform any initial initialization 676 // Create a new estate with the name provided
677 region.EstateSettings = m_application.EstateDataService.CreateNewEstate();
678
679 region.EstateSettings.EstateName = (string) requestData["estate_name"];
680 region.EstateSettings.EstateOwner = userID;
681 // Persistence does not seem to effect the need to save a new estate
682 region.EstateSettings.Save();
758 683
759 IScene newScene; 684 if (!m_application.EstateDataService.LinkRegion(region.RegionID, (int) region.EstateSettings.EstateID))
760 m_application.CreateRegion(region, out newScene); 685 throw new Exception("Failed to join estate.");
686 }
687 else
688 {
689 int estateID = estateIDs[0];
761 690
762 // If an access specification was provided, use it. 691 region.EstateSettings = m_application.EstateDataService.LoadEstateSettings(region.RegionID, false);
763 // Otherwise accept the default.
764 newScene.RegionInfo.EstateSettings.PublicAccess = GetBoolean(requestData, "public", m_publicAccess);
765 newScene.RegionInfo.EstateSettings.Save();
766 692
767 // enable voice on newly created region if 693 if (region.EstateSettings.EstateID != estateID)
768 // requested by either the XmlRpc request or the
769 // configuration
770 if (GetBoolean(requestData, "enable_voice", m_enableVoiceForNewRegions))
771 { 694 {
772 List<ILandObject> parcels = ((Scene)newScene).LandChannel.AllParcels(); 695 // The region is already part of an estate, but not the one we want.
696 region.EstateSettings = m_application.EstateDataService.LoadEstateSettings(estateID);
773 697
774 foreach (ILandObject parcel in parcels) 698 if (!m_application.EstateDataService.LinkRegion(region.RegionID, estateID))
775 { 699 throw new Exception("Failed to join estate.");
776 parcel.LandData.Flags |= (uint) ParcelFlags.AllowVoiceChat;
777 parcel.LandData.Flags |= (uint) ParcelFlags.UseEstateVoiceChan;
778 ((Scene)newScene).LandChannel.UpdateLandObject(parcel.LandData.LocalID, parcel.LandData);
779 }
780 } 700 }
701 }
702
703 // Create the region and perform any initial initialization
781 704
782 //Load Heightmap if specified to new region 705 IScene newScene;
783 if (requestData.Contains("heightmap_file")) 706 m_application.CreateRegion(region, out newScene);
784 {
785 LoadHeightmap((string)requestData["heightmap_file"], region.RegionID);
786 }
787 707
788 responseData["success"] = true; 708 // If an access specification was provided, use it.
789 responseData["region_name"] = region.RegionName; 709 // Otherwise accept the default.
790 responseData["region_uuid"] = region.RegionID.ToString(); 710 newScene.RegionInfo.EstateSettings.PublicAccess = GetBoolean(requestData, "public", m_publicAccess);
711 newScene.RegionInfo.EstateSettings.Save();
791 712
792 response.Value = responseData; 713 // enable voice on newly created region if
793 } 714 // requested by either the XmlRpc request or the
794 catch (Exception e) 715 // configuration
716 if (GetBoolean(requestData, "enable_voice", m_enableVoiceForNewRegions))
795 { 717 {
796 m_log.ErrorFormat("[RADMIN] CreateRegion: failed {0} {1}", e.Message, e.StackTrace); 718 List<ILandObject> parcels = ((Scene)newScene).LandChannel.AllParcels();
797 719
798 responseData["success"] = false; 720 foreach (ILandObject parcel in parcels)
799 responseData["error"] = e.Message; 721 {
722 parcel.LandData.Flags |= (uint) ParcelFlags.AllowVoiceChat;
723 parcel.LandData.Flags |= (uint) ParcelFlags.UseEstateVoiceChan;
724 ((Scene)newScene).LandChannel.UpdateLandObject(parcel.LandData.LocalID, parcel.LandData);
725 }
726 }
800 727
801 response.Value = responseData; 728 //Load Heightmap if specified to new region
729 if (requestData.Contains("heightmap_file"))
730 {
731 LoadHeightmap((string)requestData["heightmap_file"], region.RegionID);
802 } 732 }
803 733
734 responseData["success"] = true;
735 responseData["region_name"] = region.RegionName;
736 responseData["region_uuid"] = region.RegionID.ToString();
737
804 m_log.Info("[RADMIN]: CreateRegion: request complete"); 738 m_log.Info("[RADMIN]: CreateRegion: request complete");
805 return response;
806 } 739 }
807 } 740 }
808 741
@@ -832,46 +765,28 @@ namespace OpenSim.ApplicationPlugins.RemoteController
832 /// <description>error message if success is false</description></item> 765 /// <description>error message if success is false</description></item>
833 /// </list> 766 /// </list>
834 /// </remarks> 767 /// </remarks>
835 public XmlRpcResponse XmlRpcDeleteRegionMethod(XmlRpcRequest request, IPEndPoint remoteClient) 768 private void XmlRpcDeleteRegionMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
836 { 769 {
837 m_log.Info("[RADMIN]: DeleteRegion: new request"); 770 m_log.Info("[RADMIN]: DeleteRegion: new request");
838 771
839 XmlRpcResponse response = new XmlRpcResponse(); 772 Hashtable responseData = (Hashtable)response.Value;
840 Hashtable responseData = new Hashtable(); 773 Hashtable requestData = (Hashtable)request.Params[0];
841 774
842 lock (m_requestLock) 775 lock (m_requestLock)
843 { 776 {
844 try 777 CheckStringParameters(requestData, responseData, new string[] {"region_name"});
845 {
846 Hashtable requestData = (Hashtable) request.Params[0];
847 CheckStringParameters(request, new string[] {"password", "region_name"});
848
849 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
850
851 Scene scene = null;
852 string regionName = (string) requestData["region_name"];
853 if (!m_application.SceneManager.TryGetScene(regionName, out scene))
854 throw new Exception(String.Format("region \"{0}\" does not exist", regionName));
855
856 m_application.RemoveRegion(scene, true);
857 778
858 responseData["success"] = true; 779 Scene scene = null;
859 responseData["region_name"] = regionName; 780 string regionName = (string) requestData["region_name"];
860 781 if (!m_application.SceneManager.TryGetScene(regionName, out scene))
861 response.Value = responseData; 782 throw new Exception(String.Format("region \"{0}\" does not exist", regionName));
862 }
863 catch (Exception e)
864 {
865 m_log.ErrorFormat("[RADMIN] DeleteRegion: failed {0} {1}", e.Message, e.StackTrace);
866 783
867 responseData["success"] = false; 784 m_application.RemoveRegion(scene, true);
868 responseData["error"] = e.Message;
869 785
870 response.Value = responseData; 786 responseData["success"] = true;
871 } 787 responseData["region_name"] = regionName;
872 788
873 m_log.Info("[RADMIN]: DeleteRegion: request complete"); 789 m_log.Info("[RADMIN]: DeleteRegion: request complete");
874 return response;
875 } 790 }
876 } 791 }
877 792
@@ -903,69 +818,52 @@ namespace OpenSim.ApplicationPlugins.RemoteController
903 /// <description>error message if success is false</description></item> 818 /// <description>error message if success is false</description></item>
904 /// </list> 819 /// </list>
905 /// </remarks> 820 /// </remarks>
906 public XmlRpcResponse XmlRpcCloseRegionMethod(XmlRpcRequest request, IPEndPoint remoteClient) 821 private void XmlRpcCloseRegionMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
907 { 822 {
908 m_log.Info("[RADMIN]: CloseRegion: new request"); 823 m_log.Info("[RADMIN]: CloseRegion: new request");
909 824
910 XmlRpcResponse response = new XmlRpcResponse(); 825 Hashtable responseData = (Hashtable)response.Value;
911 Hashtable responseData = new Hashtable(); 826 Hashtable requestData = (Hashtable)request.Params[0];
912 Scene scene = null; 827 Scene scene = null;
913 828
914 lock (m_requestLock) 829 lock (m_requestLock)
915 { 830 {
916 try 831 if (requestData.ContainsKey("region_id") &&
832 !String.IsNullOrEmpty((string) requestData["region_id"]))
917 { 833 {
918 Hashtable requestData = (Hashtable) request.Params[0]; 834 // Region specified by UUID
919 CheckStringParameters(request, new string[] {"password"}); 835 UUID regionID = (UUID) (string) requestData["region_id"];
836 if (!m_application.SceneManager.TryGetScene(regionID, out scene))
837 throw new Exception(String.Format("region \"{0}\" does not exist", regionID));
920 838
921 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString()); 839 m_application.CloseRegion(scene);
922 840
923 if (requestData.ContainsKey("region_id") && 841 responseData["success"] = true;
924 !String.IsNullOrEmpty((string) requestData["region_id"])) 842 responseData["region_id"] = regionID;
925 {
926 // Region specified by UUID
927 UUID regionID = (UUID) (string) requestData["region_id"];
928 if (!m_application.SceneManager.TryGetScene(regionID, out scene))
929 throw new Exception(String.Format("region \"{0}\" does not exist", regionID));
930
931 m_application.CloseRegion(scene);
932
933 responseData["success"] = true;
934 responseData["region_id"] = regionID;
935
936 response.Value = responseData;
937 }
938 else if (requestData.ContainsKey("region_name") &&
939 !String.IsNullOrEmpty((string) requestData["region_name"]))
940 {
941 // Region specified by name
942 843
943 string regionName = (string) requestData["region_name"]; 844 response.Value = responseData;
944 if (!m_application.SceneManager.TryGetScene(regionName, out scene)) 845 }
945 throw new Exception(String.Format("region \"{0}\" does not exist", regionName)); 846 else if (
847 requestData.ContainsKey("region_name")
848 && !String.IsNullOrEmpty((string) requestData["region_name"]))
849 {
850 // Region specified by name
946 851
947 m_application.CloseRegion(scene); 852 string regionName = (string) requestData["region_name"];
853 if (!m_application.SceneManager.TryGetScene(regionName, out scene))
854 throw new Exception(String.Format("region \"{0}\" does not exist", regionName));
948 855
949 responseData["success"] = true; 856 m_application.CloseRegion(scene);
950 responseData["region_name"] = regionName;
951 857
952 response.Value = responseData; 858 responseData["success"] = true;
953 } 859 responseData["region_name"] = regionName;
954 else
955 throw new Exception("no region specified");
956 } 860 }
957 catch (Exception e) 861 else
958 { 862 {
959 m_log.ErrorFormat("[RADMIN]: CloseRegion: failed {0} {1}", e.Message, e.StackTrace); 863 throw new Exception("no region specified");
960
961 responseData["success"] = false;
962 responseData["error"] = e.Message;
963
964 response.Value = responseData;
965 } 864 }
966 865
967 m_log.Info("[RADMIN]: CloseRegion: request complete"); 866 m_log.Info("[RADMIN]: CloseRegion: request complete");
968 return response;
969 } 867 }
970 } 868 }
971 869
@@ -1001,70 +899,53 @@ namespace OpenSim.ApplicationPlugins.RemoteController
1001 /// <description>error message if success is false</description></item> 899 /// <description>error message if success is false</description></item>
1002 /// </list> 900 /// </list>
1003 /// </remarks> 901 /// </remarks>
1004 public XmlRpcResponse XmlRpcModifyRegionMethod(XmlRpcRequest request, IPEndPoint remoteClient) 902 private void XmlRpcModifyRegionMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
1005 { 903 {
1006 m_log.Info("[RADMIN]: ModifyRegion: new request"); 904 m_log.Info("[RADMIN]: ModifyRegion: new request");
1007 XmlRpcResponse response = new XmlRpcResponse(); 905
1008 Hashtable responseData = new Hashtable(); 906 Hashtable responseData = (Hashtable)response.Value;
907 Hashtable requestData = (Hashtable)request.Params[0];
1009 908
1010 lock (m_requestLock) 909 lock (m_requestLock)
1011 { 910 {
1012 try 911 CheckStringParameters(requestData, responseData, new string[] {"region_name"});
1013 {
1014 Hashtable requestData = (Hashtable) request.Params[0];
1015 CheckStringParameters(request, new string[] {"password", "region_name"});
1016 912
1017 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString()); 913 Scene scene = null;
914 string regionName = (string) requestData["region_name"];
915 if (!m_application.SceneManager.TryGetScene(regionName, out scene))
916 throw new Exception(String.Format("region \"{0}\" does not exist", regionName));
1018 917
1019 Scene scene = null; 918 // Modify access
1020 string regionName = (string) requestData["region_name"]; 919 scene.RegionInfo.EstateSettings.PublicAccess =
1021 if (!m_application.SceneManager.TryGetScene(regionName, out scene)) 920 GetBoolean(requestData,"public", scene.RegionInfo.EstateSettings.PublicAccess);
1022 throw new Exception(String.Format("region \"{0}\" does not exist", regionName)); 921 if (scene.RegionInfo.Persistent)
922 scene.RegionInfo.EstateSettings.Save();
1023 923
1024 // Modify access 924 if (requestData.ContainsKey("enable_voice"))
1025 scene.RegionInfo.EstateSettings.PublicAccess = 925 {
1026 GetBoolean(requestData,"public", scene.RegionInfo.EstateSettings.PublicAccess); 926 bool enableVoice = GetBoolean(requestData, "enable_voice", true);
1027 if (scene.RegionInfo.Persistent) 927 List<ILandObject> parcels = ((Scene)scene).LandChannel.AllParcels();
1028 scene.RegionInfo.EstateSettings.Save();
1029 928
1030 if (requestData.ContainsKey("enable_voice")) 929 foreach (ILandObject parcel in parcels)
1031 { 930 {
1032 bool enableVoice = GetBoolean(requestData, "enable_voice", true); 931 if (enableVoice)
1033 List<ILandObject> parcels = ((Scene)scene).LandChannel.AllParcels();
1034
1035 foreach (ILandObject parcel in parcels)
1036 { 932 {
1037 if (enableVoice) 933 parcel.LandData.Flags |= (uint)ParcelFlags.AllowVoiceChat;
1038 { 934 parcel.LandData.Flags |= (uint)ParcelFlags.UseEstateVoiceChan;
1039 parcel.LandData.Flags |= (uint)ParcelFlags.AllowVoiceChat; 935 }
1040 parcel.LandData.Flags |= (uint)ParcelFlags.UseEstateVoiceChan; 936 else
1041 } 937 {
1042 else 938 parcel.LandData.Flags &= ~(uint)ParcelFlags.AllowVoiceChat;
1043 { 939 parcel.LandData.Flags &= ~(uint)ParcelFlags.UseEstateVoiceChan;
1044 parcel.LandData.Flags &= ~(uint)ParcelFlags.AllowVoiceChat;
1045 parcel.LandData.Flags &= ~(uint)ParcelFlags.UseEstateVoiceChan;
1046 }
1047 scene.LandChannel.UpdateLandObject(parcel.LandData.LocalID, parcel.LandData);
1048 } 940 }
941 scene.LandChannel.UpdateLandObject(parcel.LandData.LocalID, parcel.LandData);
1049 } 942 }
1050
1051 responseData["success"] = true;
1052 responseData["region_name"] = regionName;
1053
1054 response.Value = responseData;
1055 } 943 }
1056 catch (Exception e)
1057 {
1058 m_log.ErrorFormat("[RADMIN] ModifyRegion: failed {0} {1}", e.Message, e.StackTrace);
1059
1060 responseData["success"] = false;
1061 responseData["error"] = e.Message;
1062 944
1063 response.Value = responseData; 945 responseData["success"] = true;
1064 } 946 responseData["region_name"] = regionName;
1065 947
1066 m_log.Info("[RADMIN]: ModifyRegion: request complete"); 948 m_log.Info("[RADMIN]: ModifyRegion: request complete");
1067 return response;
1068 } 949 }
1069 } 950 }
1070 951
@@ -1106,28 +987,24 @@ namespace OpenSim.ApplicationPlugins.RemoteController
1106 /// </description></item> 987 /// </description></item>
1107 /// </list> 988 /// </list>
1108 /// </remarks> 989 /// </remarks>
1109 public XmlRpcResponse XmlRpcCreateUserMethod(XmlRpcRequest request, IPEndPoint remoteClient) 990 private void XmlRpcCreateUserMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
1110 { 991 {
1111 m_log.Info("[RADMIN]: CreateUser: new request"); 992 m_log.Info("[RADMIN]: CreateUser: new request");
1112 993
1113 XmlRpcResponse response = new XmlRpcResponse(); 994 Hashtable responseData = (Hashtable)response.Value;
1114 Hashtable responseData = new Hashtable(); 995 Hashtable requestData = (Hashtable)request.Params[0];
1115 996
1116 lock (m_requestLock) 997 lock (m_requestLock)
1117 { 998 {
1118 try 999 try
1119 { 1000 {
1120 Hashtable requestData = (Hashtable) request.Params[0];
1121
1122 // check completeness 1001 // check completeness
1123 CheckStringParameters(request, new string[] 1002 CheckStringParameters(requestData, responseData, new string[]
1124 { 1003 {
1125 "password", "user_firstname", 1004 "user_firstname",
1126 "user_lastname", "user_password", 1005 "user_lastname", "user_password",
1127 }); 1006 });
1128 CheckIntegerParams(request, new string[] {"start_region_x", "start_region_y"}); 1007 CheckIntegerParams(requestData, responseData, new string[] {"start_region_x", "start_region_y"});
1129
1130 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
1131 1008
1132 // do the job 1009 // do the job
1133 string firstName = (string) requestData["user_firstname"]; 1010 string firstName = (string) requestData["user_firstname"];
@@ -1154,9 +1031,12 @@ namespace OpenSim.ApplicationPlugins.RemoteController
1154 1031
1155 GridRegion home = scene.GridService.GetRegionByPosition(scopeID, 1032 GridRegion home = scene.GridService.GetRegionByPosition(scopeID,
1156 (int)(regionXLocation * Constants.RegionSize), (int)(regionYLocation * Constants.RegionSize)); 1033 (int)(regionXLocation * Constants.RegionSize), (int)(regionYLocation * Constants.RegionSize));
1157 if (null == home) { 1034 if (null == home)
1035 {
1158 m_log.WarnFormat("[RADMIN]: Unable to set home region for newly created user account {0} {1}", firstName, lastName); 1036 m_log.WarnFormat("[RADMIN]: Unable to set home region for newly created user account {0} {1}", firstName, lastName);
1159 } else { 1037 }
1038 else
1039 {
1160 scene.GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0)); 1040 scene.GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
1161 m_log.DebugFormat("[RADMIN]: Set home region {0} for updated user account {1} {2}", home.RegionID, firstName, lastName); 1041 m_log.DebugFormat("[RADMIN]: Set home region {0} for updated user account {1} {2}", home.RegionID, firstName, lastName);
1162 } 1042 }
@@ -1168,22 +1048,16 @@ namespace OpenSim.ApplicationPlugins.RemoteController
1168 responseData["success"] = true; 1048 responseData["success"] = true;
1169 responseData["avatar_uuid"] = account.PrincipalID.ToString(); 1049 responseData["avatar_uuid"] = account.PrincipalID.ToString();
1170 1050
1171 response.Value = responseData;
1172
1173 m_log.InfoFormat("[RADMIN]: CreateUser: User {0} {1} created, UUID {2}", firstName, lastName, account.PrincipalID); 1051 m_log.InfoFormat("[RADMIN]: CreateUser: User {0} {1} created, UUID {2}", firstName, lastName, account.PrincipalID);
1174 } 1052 }
1175 catch (Exception e) 1053 catch (Exception e)
1176 { 1054 {
1177 m_log.ErrorFormat("[RADMIN]: CreateUser: failed: {0} {1}", e.Message, e.StackTrace);
1178
1179 responseData["success"] = false;
1180 responseData["avatar_uuid"] = UUID.Zero.ToString(); 1055 responseData["avatar_uuid"] = UUID.Zero.ToString();
1181 responseData["error"] = e.Message;
1182 1056
1183 response.Value = responseData; 1057 throw e;
1184 } 1058 }
1059
1185 m_log.Info("[RADMIN]: CreateUser: request complete"); 1060 m_log.Info("[RADMIN]: CreateUser: request complete");
1186 return response;
1187 } 1061 }
1188 } 1062 }
1189 1063
@@ -1219,62 +1093,43 @@ namespace OpenSim.ApplicationPlugins.RemoteController
1219 /// <description>error message if success is false</description></item> 1093 /// <description>error message if success is false</description></item>
1220 /// </list> 1094 /// </list>
1221 /// </remarks> 1095 /// </remarks>
1222 public XmlRpcResponse XmlRpcUserExistsMethod(XmlRpcRequest request, IPEndPoint remoteClient) 1096 private void XmlRpcUserExistsMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
1223 { 1097 {
1224 m_log.Info("[RADMIN]: UserExists: new request"); 1098 m_log.Info("[RADMIN]: UserExists: new request");
1225 1099
1226 XmlRpcResponse response = new XmlRpcResponse(); 1100 Hashtable responseData = (Hashtable)response.Value;
1227 Hashtable responseData = new Hashtable(); 1101 Hashtable requestData = (Hashtable)request.Params[0];
1228
1229 try
1230 {
1231 Hashtable requestData = (Hashtable) request.Params[0];
1232
1233 // check completeness
1234 CheckStringParameters(request, new string[] {"password", "user_firstname", "user_lastname"});
1235
1236 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
1237
1238 string firstName = (string) requestData["user_firstname"];
1239 string lastName = (string) requestData["user_lastname"];
1240 1102
1241 responseData["user_firstname"] = firstName; 1103 // check completeness
1242 responseData["user_lastname"] = lastName; 1104 CheckStringParameters(requestData, responseData, new string[] {"user_firstname", "user_lastname"});
1243 1105
1244 UUID scopeID = m_application.SceneManager.CurrentOrFirstScene.RegionInfo.ScopeID; 1106 string firstName = (string) requestData["user_firstname"];
1107 string lastName = (string) requestData["user_lastname"];
1245 1108
1246 UserAccount account = m_application.SceneManager.CurrentOrFirstScene.UserAccountService.GetUserAccount(scopeID, firstName, lastName); 1109 responseData["user_firstname"] = firstName;
1110 responseData["user_lastname"] = lastName;
1247 1111
1248 if (null == account) 1112 UUID scopeID = m_application.SceneManager.CurrentOrFirstScene.RegionInfo.ScopeID;
1249 {
1250 responseData["success"] = false;
1251 responseData["lastlogin"] = 0;
1252 }
1253 else
1254 {
1255 GridUserInfo userInfo = m_application.SceneManager.CurrentOrFirstScene.GridUserService.GetGridUserInfo(account.PrincipalID.ToString());
1256 if (userInfo != null)
1257 responseData["lastlogin"] = userInfo.Login;
1258 else
1259 responseData["lastlogin"] = 0;
1260 1113
1261 responseData["success"] = true; 1114 UserAccount account = m_application.SceneManager.CurrentOrFirstScene.UserAccountService.GetUserAccount(scopeID, firstName, lastName);
1262 }
1263 1115
1264 response.Value = responseData; 1116 if (null == account)
1265 }
1266 catch (Exception e)
1267 { 1117 {
1268 m_log.ErrorFormat("[RADMIN]: UserExists: failed: {0} {1}", e.Message, e.StackTrace);
1269
1270 responseData["success"] = false; 1118 responseData["success"] = false;
1271 responseData["error"] = e.Message; 1119 responseData["lastlogin"] = 0;
1120 }
1121 else
1122 {
1123 GridUserInfo userInfo = m_application.SceneManager.CurrentOrFirstScene.GridUserService.GetGridUserInfo(account.PrincipalID.ToString());
1124 if (userInfo != null)
1125 responseData["lastlogin"] = userInfo.Login;
1126 else
1127 responseData["lastlogin"] = 0;
1272 1128
1273 response.Value = responseData; 1129 responseData["success"] = true;
1274 } 1130 }
1275 1131
1276 m_log.Info("[RADMIN]: UserExists: request complete"); 1132 m_log.Info("[RADMIN]: UserExists: request complete");
1277 return response;
1278 } 1133 }
1279 1134
1280 /// <summary> 1135 /// <summary>
@@ -1319,27 +1174,23 @@ namespace OpenSim.ApplicationPlugins.RemoteController
1319 /// </description></item> 1174 /// </description></item>
1320 /// </list> 1175 /// </list>
1321 /// </remarks> 1176 /// </remarks>
1322 public XmlRpcResponse XmlRpcUpdateUserAccountMethod(XmlRpcRequest request, IPEndPoint remoteClient) 1177 private void XmlRpcUpdateUserAccountMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
1323 { 1178 {
1324 m_log.Info("[RADMIN]: UpdateUserAccount: new request"); 1179 m_log.Info("[RADMIN]: UpdateUserAccount: new request");
1325 m_log.Warn("[RADMIN]: This method needs update for 0.7"); 1180 m_log.Warn("[RADMIN]: This method needs update for 0.7");
1326 1181
1327 XmlRpcResponse response = new XmlRpcResponse(); 1182 Hashtable responseData = (Hashtable)response.Value;
1328 Hashtable responseData = new Hashtable(); 1183 Hashtable requestData = (Hashtable)request.Params[0];
1329 1184
1330 lock (m_requestLock) 1185 lock (m_requestLock)
1331 { 1186 {
1332 try 1187 try
1333 { 1188 {
1334 Hashtable requestData = (Hashtable) request.Params[0];
1335
1336 // check completeness 1189 // check completeness
1337 CheckStringParameters(request, new string[] { 1190 CheckStringParameters(requestData, responseData, new string[] {
1338 "password", "user_firstname", 1191 "user_firstname",
1339 "user_lastname"}); 1192 "user_lastname"});
1340 1193
1341 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
1342
1343 // do the job 1194 // do the job
1344 string firstName = (string) requestData["user_firstname"]; 1195 string firstName = (string) requestData["user_firstname"];
1345 string lastName = (string) requestData["user_lastname"]; 1196 string lastName = (string) requestData["user_lastname"];
@@ -1425,29 +1276,936 @@ namespace OpenSim.ApplicationPlugins.RemoteController
1425 responseData["success"] = true; 1276 responseData["success"] = true;
1426 responseData["avatar_uuid"] = account.PrincipalID.ToString(); 1277 responseData["avatar_uuid"] = account.PrincipalID.ToString();
1427 1278
1428 response.Value = responseData;
1429
1430 m_log.InfoFormat("[RADMIN]: UpdateUserAccount: account for user {0} {1} updated, UUID {2}", 1279 m_log.InfoFormat("[RADMIN]: UpdateUserAccount: account for user {0} {1} updated, UUID {2}",
1431 firstName, lastName, 1280 firstName, lastName,
1432 account.PrincipalID); 1281 account.PrincipalID);
1433 } 1282 }
1434 catch (Exception e) 1283 catch (Exception e)
1435 { 1284 {
1436 m_log.ErrorFormat("[RADMIN] UpdateUserAccount: failed: {0} {1}", e.Message, e.StackTrace);
1437
1438 responseData["success"] = false;
1439 responseData["avatar_uuid"] = UUID.Zero.ToString(); 1285 responseData["avatar_uuid"] = UUID.Zero.ToString();
1440 responseData["error"] = e.Message;
1441 1286
1442 response.Value = responseData; 1287 throw e;
1443 } 1288 }
1444 1289
1445 m_log.Info("[RADMIN]: UpdateUserAccount: request complete"); 1290 m_log.Info("[RADMIN]: UpdateUserAccount: request complete");
1446 return response;
1447 } 1291 }
1448 } 1292 }
1449 1293
1450 /// <summary> 1294 /// <summary>
1295 /// Load an OAR file into a region..
1296 /// <summary>
1297 /// <param name="request">incoming XML RPC request</param>
1298 /// <remarks>
1299 /// XmlRpcLoadOARMethod takes the following XMLRPC
1300 /// parameters
1301 /// <list type="table">
1302 /// <listheader><term>parameter name</term><description>description</description></listheader>
1303 /// <item><term>password</term>
1304 /// <description>admin password as set in OpenSim.ini</description></item>
1305 /// <item><term>filename</term>
1306 /// <description>file name of the OAR file</description></item>
1307 /// <item><term>region_uuid</term>
1308 /// <description>UUID of the region</description></item>
1309 /// <item><term>region_name</term>
1310 /// <description>region name</description></item>
1311 /// <item><term>merge</term>
1312 /// <description>true if oar should be merged</description></item>
1313 /// <item><term>skip-assets</term>
1314 /// <description>true if assets should be skiped</description></item>
1315 /// </list>
1316 ///
1317 /// <code>region_uuid</code> takes precedence over
1318 /// <code>region_name</code> if both are present; one of both
1319 /// must be present.
1320 ///
1321 /// XmlRpcLoadOARMethod returns
1322 /// <list type="table">
1323 /// <listheader><term>name</term><description>description</description></listheader>
1324 /// <item><term>success</term>
1325 /// <description>true or false</description></item>
1326 /// <item><term>error</term>
1327 /// <description>error message if success is false</description></item>
1328 /// </list>
1329 /// </remarks>
1330 private void XmlRpcLoadOARMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
1331 {
1332 m_log.Info("[RADMIN]: Received Load OAR Administrator Request");
1333
1334 Hashtable responseData = (Hashtable)response.Value;
1335 Hashtable requestData = (Hashtable)request.Params[0];
1336
1337 lock (m_requestLock)
1338 {
1339 try
1340 {
1341 CheckStringParameters(requestData, responseData, new string[] {"filename"});
1342
1343 string filename = (string) requestData["filename"];
1344 Scene scene = null;
1345 if (requestData.Contains("region_uuid"))
1346 {
1347 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
1348 if (!m_application.SceneManager.TryGetScene(region_uuid, out scene))
1349 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
1350 }
1351 else if (requestData.Contains("region_name"))
1352 {
1353 string region_name = (string) requestData["region_name"];
1354 if (!m_application.SceneManager.TryGetScene(region_name, out scene))
1355 throw new Exception(String.Format("failed to switch to region {0}", region_name));
1356 }
1357 else throw new Exception("neither region_name nor region_uuid given");
1358
1359 bool mergeOar = false;
1360 bool skipAssets = false;
1361
1362 if ((string)requestData["merge"] == "true")
1363 {
1364 mergeOar = true;
1365 }
1366 if ((string)requestData["skip-assets"] == "true")
1367 {
1368 skipAssets = true;
1369 }
1370
1371 IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
1372 if (archiver != null)
1373 archiver.DearchiveRegion(filename, mergeOar, skipAssets, Guid.Empty);
1374 else
1375 throw new Exception("Archiver module not present for scene");
1376
1377 responseData["loaded"] = true;
1378 }
1379 catch (Exception e)
1380 {
1381 responseData["loaded"] = false;
1382
1383 throw e;
1384 }
1385
1386 m_log.Info("[RADMIN]: Load OAR Administrator Request complete");
1387 }
1388 }
1389
1390 /// <summary>
1391 /// Save a region to an OAR file
1392 /// <summary>
1393 /// <param name="request">incoming XML RPC request</param>
1394 /// <remarks>
1395 /// XmlRpcSaveOARMethod takes the following XMLRPC
1396 /// parameters
1397 /// <list type="table">
1398 /// <listheader><term>parameter name</term><description>description</description></listheader>
1399 /// <item><term>password</term>
1400 /// <description>admin password as set in OpenSim.ini</description></item>
1401 /// <item><term>filename</term>
1402 /// <description>file name for the OAR file</description></item>
1403 /// <item><term>region_uuid</term>
1404 /// <description>UUID of the region</description></item>
1405 /// <item><term>region_name</term>
1406 /// <description>region name</description></item>
1407 /// <item><term>profile</term>
1408 /// <description>profile url</description></item>
1409 /// <item><term>noassets</term>
1410 /// <description>true if no assets should be saved</description></item>
1411 /// <item><term>perm</term>
1412 /// <description>C and/or T</description></item>
1413 /// </list>
1414 ///
1415 /// <code>region_uuid</code> takes precedence over
1416 /// <code>region_name</code> if both are present; one of both
1417 /// must be present.
1418 ///
1419 /// XmlRpcLoadOARMethod returns
1420 /// <list type="table">
1421 /// <listheader><term>name</term><description>description</description></listheader>
1422 /// <item><term>success</term>
1423 /// <description>true or false</description></item>
1424 /// <item><term>error</term>
1425 /// <description>error message if success is false</description></item>
1426 /// </list>
1427 /// </remarks>
1428 private void XmlRpcSaveOARMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
1429 {
1430 m_log.Info("[RADMIN]: Received Save OAR Administrator Request");
1431
1432 Hashtable responseData = (Hashtable)response.Value;
1433 Hashtable requestData = (Hashtable)request.Params[0];
1434
1435 try
1436 {
1437 CheckStringParameters(requestData, responseData, new string[] {"filename"});
1438
1439 string filename = (string)requestData["filename"];
1440 Scene scene = null;
1441 if (requestData.Contains("region_uuid"))
1442 {
1443 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
1444 if (!m_application.SceneManager.TryGetScene(region_uuid, out scene))
1445 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
1446 }
1447 else if (requestData.Contains("region_name"))
1448 {
1449 string region_name = (string) requestData["region_name"];
1450 if (!m_application.SceneManager.TryGetScene(region_name, out scene))
1451 throw new Exception(String.Format("failed to switch to region {0}", region_name));
1452 }
1453 else throw new Exception("neither region_name nor region_uuid given");
1454
1455 Dictionary<string, object> options = new Dictionary<string, object>();
1456
1457 //if (requestData.Contains("version"))
1458 //{
1459 // options["version"] = (string)requestData["version"];
1460 //}
1461
1462 if (requestData.Contains("profile"))
1463 {
1464 options["profile"] = (string)requestData["profile"];
1465 }
1466
1467 if (requestData["noassets"] == "true")
1468 {
1469 options["noassets"] = (string)requestData["noassets"] ;
1470 }
1471
1472 if (requestData.Contains("perm"))
1473 {
1474 options["checkPermissions"] = (string)requestData["perm"];
1475 }
1476
1477 IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
1478
1479 if (archiver != null)
1480 {
1481 scene.EventManager.OnOarFileSaved += RemoteAdminOarSaveCompleted;
1482 archiver.ArchiveRegion(filename, options);
1483
1484 lock (m_saveOarLock)
1485 Monitor.Wait(m_saveOarLock,5000);
1486
1487 scene.EventManager.OnOarFileSaved -= RemoteAdminOarSaveCompleted;
1488 }
1489 else
1490 {
1491 throw new Exception("Archiver module not present for scene");
1492 }
1493
1494 responseData["saved"] = true;
1495 }
1496 catch (Exception e)
1497 {
1498 responseData["saved"] = false;
1499
1500 throw e;
1501 }
1502
1503 m_log.Info("[RADMIN]: Save OAR Administrator Request complete");
1504 }
1505
1506 private void RemoteAdminOarSaveCompleted(Guid uuid, string name)
1507 {
1508 m_log.DebugFormat("[RADMIN]: File processing complete for {0}", name);
1509 lock (m_saveOarLock)
1510 Monitor.Pulse(m_saveOarLock);
1511 }
1512
1513 private void XmlRpcLoadXMLMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
1514 {
1515 m_log.Info("[RADMIN]: Received Load XML Administrator Request");
1516
1517 Hashtable responseData = (Hashtable)response.Value;
1518 Hashtable requestData = (Hashtable)request.Params[0];
1519
1520 lock (m_requestLock)
1521 {
1522 try
1523 {
1524 CheckStringParameters(requestData, responseData, new string[] {"filename"});
1525
1526 string filename = (string) requestData["filename"];
1527 if (requestData.Contains("region_uuid"))
1528 {
1529 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
1530 if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
1531 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
1532
1533 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
1534 }
1535 else if (requestData.Contains("region_name"))
1536 {
1537 string region_name = (string) requestData["region_name"];
1538 if (!m_application.SceneManager.TrySetCurrentScene(region_name))
1539 throw new Exception(String.Format("failed to switch to region {0}", region_name));
1540
1541 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
1542 }
1543 else throw new Exception("neither region_name nor region_uuid given");
1544
1545 responseData["switched"] = true;
1546
1547 string xml_version = "1";
1548 if (requestData.Contains("xml_version"))
1549 {
1550 xml_version = (string) requestData["xml_version"];
1551 }
1552
1553 switch (xml_version)
1554 {
1555 case "1":
1556 m_application.SceneManager.LoadCurrentSceneFromXml(filename, true, new Vector3(0, 0, 0));
1557 break;
1558
1559 case "2":
1560 m_application.SceneManager.LoadCurrentSceneFromXml2(filename);
1561 break;
1562
1563 default:
1564 throw new Exception(String.Format("unknown Xml{0} format", xml_version));
1565 }
1566
1567 responseData["loaded"] = true;
1568 }
1569 catch (Exception e)
1570 {
1571 responseData["loaded"] = false;
1572 responseData["switched"] = false;
1573
1574 throw e;
1575 }
1576
1577 m_log.Info("[RADMIN]: Load XML Administrator Request complete");
1578 }
1579 }
1580
1581 private void XmlRpcSaveXMLMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
1582 {
1583 m_log.Info("[RADMIN]: Received Save XML Administrator Request");
1584
1585 Hashtable responseData = (Hashtable)response.Value;
1586 Hashtable requestData = (Hashtable)request.Params[0];
1587
1588 try
1589 {
1590 CheckStringParameters(requestData, responseData, new string[] {"filename"});
1591
1592 string filename = (string) requestData["filename"];
1593 if (requestData.Contains("region_uuid"))
1594 {
1595 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
1596 if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
1597 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
1598 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
1599 }
1600 else if (requestData.Contains("region_name"))
1601 {
1602 string region_name = (string) requestData["region_name"];
1603 if (!m_application.SceneManager.TrySetCurrentScene(region_name))
1604 throw new Exception(String.Format("failed to switch to region {0}", region_name));
1605 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
1606 }
1607 else throw new Exception("neither region_name nor region_uuid given");
1608
1609 responseData["switched"] = true;
1610
1611 string xml_version = "1";
1612 if (requestData.Contains("xml_version"))
1613 {
1614 xml_version = (string) requestData["xml_version"];
1615 }
1616
1617 switch (xml_version)
1618 {
1619 case "1":
1620 m_application.SceneManager.SaveCurrentSceneToXml(filename);
1621 break;
1622
1623 case "2":
1624 m_application.SceneManager.SaveCurrentSceneToXml2(filename);
1625 break;
1626
1627 default:
1628 throw new Exception(String.Format("unknown Xml{0} format", xml_version));
1629 }
1630
1631 responseData["saved"] = true;
1632 }
1633 catch (Exception e)
1634 {
1635 responseData["saved"] = false;
1636 responseData["switched"] = false;
1637
1638 throw e;
1639 }
1640
1641 m_log.Info("[RADMIN]: Save XML Administrator Request complete");
1642 }
1643
1644 private void XmlRpcRegionQueryMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
1645 {
1646 m_log.Info("[RADMIN]: Received Query XML Administrator Request");
1647
1648 Hashtable responseData = (Hashtable)response.Value;
1649 Hashtable requestData = (Hashtable)request.Params[0];
1650
1651 responseData["success"] = true;
1652
1653 if (requestData.Contains("region_uuid"))
1654 {
1655 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
1656 if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
1657 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
1658
1659 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
1660 }
1661 else if (requestData.Contains("region_name"))
1662 {
1663 string region_name = (string) requestData["region_name"];
1664 if (!m_application.SceneManager.TrySetCurrentScene(region_name))
1665 throw new Exception(String.Format("failed to switch to region {0}", region_name));
1666
1667 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
1668 }
1669 else
1670 {
1671 throw new Exception("neither region_name nor region_uuid given");
1672 }
1673
1674 Scene scene = m_application.SceneManager.CurrentScene;
1675 int health = scene.GetHealth();
1676 responseData["health"] = health;
1677
1678 m_log.Info("[RADMIN]: Query XML Administrator Request complete");
1679 }
1680
1681 private void XmlRpcConsoleCommandMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
1682 {
1683 m_log.Info("[RADMIN]: Received Command XML Administrator Request");
1684
1685 Hashtable responseData = (Hashtable)response.Value;
1686 Hashtable requestData = (Hashtable)request.Params[0];
1687
1688 CheckStringParameters(requestData, responseData, new string[] {"command"});
1689
1690 MainConsole.Instance.RunCommand(requestData["command"].ToString());
1691
1692 m_log.Info("[RADMIN]: Command XML Administrator Request complete");
1693 }
1694
1695 private void XmlRpcAccessListClear(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
1696 {
1697 m_log.Info("[RADMIN]: Received Access List Clear Request");
1698
1699 Hashtable responseData = (Hashtable)response.Value;
1700 Hashtable requestData = (Hashtable)request.Params[0];
1701
1702 responseData["success"] = true;
1703
1704 if (requestData.Contains("region_uuid"))
1705 {
1706 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
1707 if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
1708 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
1709 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
1710 }
1711 else if (requestData.Contains("region_name"))
1712 {
1713 string region_name = (string) requestData["region_name"];
1714 if (!m_application.SceneManager.TrySetCurrentScene(region_name))
1715 throw new Exception(String.Format("failed to switch to region {0}", region_name));
1716
1717 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
1718 }
1719 else throw new Exception("neither region_name nor region_uuid given");
1720
1721 Scene scene = m_application.SceneManager.CurrentScene;
1722 scene.RegionInfo.EstateSettings.EstateAccess = new UUID[]{};
1723
1724 if (scene.RegionInfo.Persistent)
1725 scene.RegionInfo.EstateSettings.Save();
1726
1727 m_log.Info("[RADMIN]: Access List Clear Request complete");
1728 }
1729
1730 private void XmlRpcAccessListAdd(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
1731 {
1732 m_log.Info("[RADMIN]: Received Access List Add Request");
1733
1734 Hashtable responseData = (Hashtable)response.Value;
1735 Hashtable requestData = (Hashtable)request.Params[0];
1736
1737 if (requestData.Contains("region_uuid"))
1738 {
1739 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
1740 if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
1741 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
1742 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
1743 }
1744 else if (requestData.Contains("region_name"))
1745 {
1746 string region_name = (string) requestData["region_name"];
1747 if (!m_application.SceneManager.TrySetCurrentScene(region_name))
1748 throw new Exception(String.Format("failed to switch to region {0}", region_name));
1749 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
1750 }
1751 else
1752 {
1753 throw new Exception("neither region_name nor region_uuid given");
1754 }
1755
1756 int addedUsers = 0;
1757
1758 if (requestData.Contains("users"))
1759 {
1760 UUID scopeID = m_application.SceneManager.CurrentOrFirstScene.RegionInfo.ScopeID;
1761 IUserAccountService userService = m_application.SceneManager.CurrentOrFirstScene.UserAccountService;
1762 Scene scene = m_application.SceneManager.CurrentScene;
1763 Hashtable users = (Hashtable) requestData["users"];
1764 List<UUID> uuids = new List<UUID>();
1765 foreach (string name in users.Values)
1766 {
1767 string[] parts = name.Split();
1768 UserAccount account = userService.GetUserAccount(scopeID, parts[0], parts[1]);
1769 if (account != null)
1770 {
1771 uuids.Add(account.PrincipalID);
1772 m_log.DebugFormat("[RADMIN]: adding \"{0}\" to ACL for \"{1}\"", name, scene.RegionInfo.RegionName);
1773 }
1774 }
1775 List<UUID> accessControlList = new List<UUID>(scene.RegionInfo.EstateSettings.EstateAccess);
1776 foreach (UUID uuid in uuids)
1777 {
1778 if (!accessControlList.Contains(uuid))
1779 {
1780 accessControlList.Add(uuid);
1781 addedUsers++;
1782 }
1783 }
1784 scene.RegionInfo.EstateSettings.EstateAccess = accessControlList.ToArray();
1785 if (scene.RegionInfo.Persistent)
1786 scene.RegionInfo.EstateSettings.Save();
1787 }
1788
1789 responseData["added"] = addedUsers;
1790
1791 m_log.Info("[RADMIN]: Access List Add Request complete");
1792 }
1793
1794 private void XmlRpcAccessListRemove(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
1795 {
1796 m_log.Info("[RADMIN]: Received Access List Remove Request");
1797
1798 Hashtable responseData = (Hashtable)response.Value;
1799 Hashtable requestData = (Hashtable)request.Params[0];
1800
1801 responseData["success"] = true;
1802
1803 if (requestData.Contains("region_uuid"))
1804 {
1805 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
1806 if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
1807 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
1808 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
1809 }
1810 else if (requestData.Contains("region_name"))
1811 {
1812 string region_name = (string) requestData["region_name"];
1813 if (!m_application.SceneManager.TrySetCurrentScene(region_name))
1814 throw new Exception(String.Format("failed to switch to region {0}", region_name));
1815 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
1816 }
1817 else throw new Exception("neither region_name nor region_uuid given");
1818
1819 int removedUsers = 0;
1820
1821 if (requestData.Contains("users"))
1822 {
1823 UUID scopeID = m_application.SceneManager.CurrentOrFirstScene.RegionInfo.ScopeID;
1824 IUserAccountService userService = m_application.SceneManager.CurrentOrFirstScene.UserAccountService;
1825 //UserProfileCacheService ups = m_application.CommunicationsManager.UserProfileCacheService;
1826 Scene scene = m_application.SceneManager.CurrentScene;
1827 Hashtable users = (Hashtable) requestData["users"];
1828 List<UUID> uuids = new List<UUID>();
1829 foreach (string name in users.Values)
1830 {
1831 string[] parts = name.Split();
1832 UserAccount account = userService.GetUserAccount(scopeID, parts[0], parts[1]);
1833 if (account != null)
1834 {
1835 uuids.Add(account.PrincipalID);
1836 }
1837 }
1838 List<UUID> accessControlList = new List<UUID>(scene.RegionInfo.EstateSettings.EstateAccess);
1839 foreach (UUID uuid in uuids)
1840 {
1841 if (accessControlList.Contains(uuid))
1842 {
1843 accessControlList.Remove(uuid);
1844 removedUsers++;
1845 }
1846 }
1847 scene.RegionInfo.EstateSettings.EstateAccess = accessControlList.ToArray();
1848 if (scene.RegionInfo.Persistent)
1849 scene.RegionInfo.EstateSettings.Save();
1850 }
1851
1852 responseData["removed"] = removedUsers;
1853
1854 m_log.Info("[RADMIN]: Access List Remove Request complete");
1855 }
1856
1857 private void XmlRpcAccessListList(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
1858 {
1859 m_log.Info("[RADMIN]: Received Access List List Request");
1860
1861 Hashtable responseData = (Hashtable)response.Value;
1862 Hashtable requestData = (Hashtable)request.Params[0];
1863
1864 responseData["success"] = true;
1865
1866 if (requestData.Contains("region_uuid"))
1867 {
1868 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
1869 if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
1870 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
1871 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
1872 }
1873 else if (requestData.Contains("region_name"))
1874 {
1875 string region_name = (string) requestData["region_name"];
1876 if (!m_application.SceneManager.TrySetCurrentScene(region_name))
1877 throw new Exception(String.Format("failed to switch to region {0}", region_name));
1878 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
1879 }
1880 else throw new Exception("neither region_name nor region_uuid given");
1881
1882 Scene scene = m_application.SceneManager.CurrentScene;
1883 UUID[] accessControlList = scene.RegionInfo.EstateSettings.EstateAccess;
1884 Hashtable users = new Hashtable();
1885
1886 foreach (UUID user in accessControlList)
1887 {
1888 UUID scopeID = m_application.SceneManager.CurrentOrFirstScene.RegionInfo.ScopeID;
1889 UserAccount account = m_application.SceneManager.CurrentOrFirstScene.UserAccountService.GetUserAccount(scopeID, user);
1890 if (account != null)
1891 {
1892 users[user.ToString()] = account.FirstName + " " + account.LastName;
1893 }
1894 }
1895
1896 responseData["users"] = users;
1897
1898 m_log.Info("[RADMIN]: Access List List Request complete");
1899 }
1900
1901 private void XmlRpcTeleportAgentMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
1902 {
1903 Hashtable responseData = (Hashtable)response.Value;
1904 Hashtable requestData = (Hashtable)request.Params[0];
1905
1906 UUID agentId;
1907 string regionName = null;
1908 Vector3 pos, lookAt;
1909 ScenePresence sp = null;
1910
1911 if (requestData.Contains("agent_first_name") && requestData.Contains("agent_last_name"))
1912 {
1913 string firstName = requestData["agent_first_name"].ToString();
1914 string lastName = requestData["agent_last_name"].ToString();
1915 m_application.SceneManager.TryGetRootScenePresenceByName(firstName, lastName, out sp);
1916
1917 if (sp == null)
1918 throw new Exception(
1919 string.Format(
1920 "No agent found with agent_first_name {0} and agent_last_name {1}", firstName, lastName));
1921 }
1922 else if (requestData.Contains("agent_id"))
1923 {
1924 string rawAgentId = (string)requestData["agent_id"];
1925
1926 if (!UUID.TryParse(rawAgentId, out agentId))
1927 throw new Exception(string.Format("agent_id {0} does not have the correct id format", rawAgentId));
1928
1929 m_application.SceneManager.TryGetRootScenePresence(agentId, out sp);
1930
1931 if (sp == null)
1932 throw new Exception(string.Format("No agent with agent_id {0} found in this simulator", agentId));
1933 }
1934 else
1935 {
1936 throw new Exception("No agent_id or agent_first_name and agent_last_name parameters specified");
1937 }
1938
1939 if (requestData.Contains("region_name"))
1940 regionName = (string)requestData["region_name"];
1941
1942 pos.X = ParseFloat(requestData, "pos_x", sp.AbsolutePosition.X);
1943 pos.Y = ParseFloat(requestData, "pos_y", sp.AbsolutePosition.Y);
1944 pos.Z = ParseFloat(requestData, "pos_z", sp.AbsolutePosition.Z);
1945 lookAt.X = ParseFloat(requestData, "lookat_x", sp.Lookat.X);
1946 lookAt.Y = ParseFloat(requestData, "lookat_y", sp.Lookat.Y);
1947 lookAt.Z = ParseFloat(requestData, "lookat_z", sp.Lookat.Z);
1948
1949 sp.Scene.RequestTeleportLocation(
1950 sp.ControllingClient, regionName, pos, lookAt, (uint)Constants.TeleportFlags.ViaLocation);
1951
1952 // We have no way of telling the failure of the actual teleport
1953 responseData["success"] = true;
1954 }
1955
1956 /// <summary>
1957 /// Parse a float with the given parameter name from a request data hash table.
1958 /// </summary>
1959 /// <remarks>
1960 /// Will throw an exception if parameter is not a float.
1961 /// Will not throw if parameter is not found, passes back default value instead.
1962 /// </remarks>
1963 /// <param name="requestData"></param>
1964 /// <param name="paramName"></param>
1965 /// <param name="defaultVal"></param>
1966 /// <returns></returns>
1967 private static float ParseFloat(Hashtable requestData, string paramName, float defaultVal)
1968 {
1969 if (requestData.Contains(paramName))
1970 {
1971 string rawVal = (string)requestData[paramName];
1972 float val;
1973
1974 if (!float.TryParse(rawVal, out val))
1975 throw new Exception(string.Format("{0} {1} is not a valid float", paramName, rawVal));
1976 else
1977 return val;
1978 }
1979 else
1980 {
1981 return defaultVal;
1982 }
1983 }
1984
1985 private static void CheckStringParameters(Hashtable requestData, Hashtable responseData, string[] param)
1986 {
1987 foreach (string parameter in param)
1988 {
1989 if (!requestData.Contains(parameter))
1990 {
1991 responseData["accepted"] = false;
1992 throw new Exception(String.Format("missing string parameter {0}", parameter));
1993 }
1994 if (String.IsNullOrEmpty((string) requestData[parameter]))
1995 {
1996 responseData["accepted"] = false;
1997 throw new Exception(String.Format("parameter {0} is empty", parameter));
1998 }
1999 }
2000 }
2001
2002 private static void CheckIntegerParams(Hashtable requestData, Hashtable responseData, string[] param)
2003 {
2004 foreach (string parameter in param)
2005 {
2006 if (!requestData.Contains(parameter))
2007 {
2008 responseData["accepted"] = false;
2009 throw new Exception(String.Format("missing integer parameter {0}", parameter));
2010 }
2011 }
2012 }
2013
2014 private bool GetBoolean(Hashtable requestData, string tag, bool defaultValue)
2015 {
2016 // If an access value has been provided, apply it.
2017 if (requestData.Contains(tag))
2018 {
2019 switch (((string)requestData[tag]).ToLower())
2020 {
2021 case "true" :
2022 case "t" :
2023 case "1" :
2024 return true;
2025 case "false" :
2026 case "f" :
2027 case "0" :
2028 return false;
2029 default :
2030 return defaultValue;
2031 }
2032 }
2033 else
2034 return defaultValue;
2035 }
2036
2037 private int GetIntegerAttribute(XmlNode node, string attribute, int defaultValue)
2038 {
2039 try { return Convert.ToInt32(node.Attributes[attribute].Value); } catch{}
2040 return defaultValue;
2041 }
2042
2043 private uint GetUnsignedAttribute(XmlNode node, string attribute, uint defaultValue)
2044 {
2045 try { return Convert.ToUInt32(node.Attributes[attribute].Value); } catch{}
2046 return defaultValue;
2047 }
2048
2049 private string GetStringAttribute(XmlNode node, string attribute, string defaultValue)
2050 {
2051 try { return node.Attributes[attribute].Value; } catch{}
2052 return defaultValue;
2053 }
2054
2055 public void Dispose()
2056 {
2057 }
2058
2059 /// <summary>
2060 /// Create a user
2061 /// </summary>
2062 /// <param name="scopeID"></param>
2063 /// <param name="firstName"></param>
2064 /// <param name="lastName"></param>
2065 /// <param name="password"></param>
2066 /// <param name="email"></param>
2067 private UserAccount CreateUser(UUID scopeID, string firstName, string lastName, string password, string email)
2068 {
2069 Scene scene = m_application.SceneManager.CurrentOrFirstScene;
2070 IUserAccountService userAccountService = scene.UserAccountService;
2071 IGridService gridService = scene.GridService;
2072 IAuthenticationService authenticationService = scene.AuthenticationService;
2073 IGridUserService gridUserService = scene.GridUserService;
2074 IInventoryService inventoryService = scene.InventoryService;
2075
2076 UserAccount account = userAccountService.GetUserAccount(scopeID, firstName, lastName);
2077 if (null == account)
2078 {
2079 account = new UserAccount(scopeID, UUID.Random(), firstName, lastName, email);
2080 if (account.ServiceURLs == null || (account.ServiceURLs != null && account.ServiceURLs.Count == 0))
2081 {
2082 account.ServiceURLs = new Dictionary<string, object>();
2083 account.ServiceURLs["HomeURI"] = string.Empty;
2084 account.ServiceURLs["GatekeeperURI"] = string.Empty;
2085 account.ServiceURLs["InventoryServerURI"] = string.Empty;
2086 account.ServiceURLs["AssetServerURI"] = string.Empty;
2087 }
2088
2089 if (userAccountService.StoreUserAccount(account))
2090 {
2091 bool success;
2092 if (authenticationService != null)
2093 {
2094 success = authenticationService.SetPassword(account.PrincipalID, password);
2095 if (!success)
2096 m_log.WarnFormat("[RADMIN]: Unable to set password for account {0} {1}.",
2097 firstName, lastName);
2098 }
2099
2100 GridRegion home = null;
2101 if (gridService != null)
2102 {
2103 List<GridRegion> defaultRegions = gridService.GetDefaultRegions(UUID.Zero);
2104 if (defaultRegions != null && defaultRegions.Count >= 1)
2105 home = defaultRegions[0];
2106
2107 if (gridUserService != null && home != null)
2108 gridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
2109 else
2110 m_log.WarnFormat("[RADMIN]: Unable to set home for account {0} {1}.",
2111 firstName, lastName);
2112 }
2113 else
2114 m_log.WarnFormat("[RADMIN]: Unable to retrieve home region for account {0} {1}.",
2115 firstName, lastName);
2116
2117 if (inventoryService != null)
2118 {
2119 success = inventoryService.CreateUserInventory(account.PrincipalID);
2120 if (!success)
2121 m_log.WarnFormat("[RADMIN]: Unable to create inventory for account {0} {1}.",
2122 firstName, lastName);
2123 }
2124
2125 m_log.InfoFormat("[RADMIN]: Account {0} {1} created successfully", firstName, lastName);
2126 return account;
2127 } else {
2128 m_log.ErrorFormat("[RADMIN]: Account creation failed for account {0} {1}", firstName, lastName);
2129 }
2130 }
2131 else
2132 {
2133 m_log.ErrorFormat("[RADMIN]: A user with the name {0} {1} already exists!", firstName, lastName);
2134 }
2135 return null;
2136 }
2137
2138 /// <summary>
2139 /// Change password
2140 /// </summary>
2141 /// <param name="firstName"></param>
2142 /// <param name="lastName"></param>
2143 /// <param name="password"></param>
2144 private bool ChangeUserPassword(string firstName, string lastName, string password)
2145 {
2146 Scene scene = m_application.SceneManager.CurrentOrFirstScene;
2147 IUserAccountService userAccountService = scene.UserAccountService;
2148 IAuthenticationService authenticationService = scene.AuthenticationService;
2149
2150 UserAccount account = userAccountService.GetUserAccount(UUID.Zero, firstName, lastName);
2151 if (null != account)
2152 {
2153 bool success = false;
2154 if (authenticationService != null)
2155 success = authenticationService.SetPassword(account.PrincipalID, password);
2156
2157 if (!success)
2158 {
2159 m_log.WarnFormat("[RADMIN]: Unable to set password for account {0} {1}.",
2160 firstName, lastName);
2161 return false;
2162 }
2163 return true;
2164 }
2165 else
2166 {
2167 m_log.ErrorFormat("[RADMIN]: No such user");
2168 return false;
2169 }
2170 }
2171
2172 private bool LoadHeightmap(string file, UUID regionID)
2173 {
2174 m_log.InfoFormat("[RADMIN]: Terrain Loading: {0}", file);
2175
2176 Scene region = null;
2177
2178 if (!m_application.SceneManager.TryGetScene(regionID, out region))
2179 {
2180 m_log.InfoFormat("[RADMIN]: unable to get a scene with that name: {0}", regionID.ToString());
2181 return false;
2182 }
2183
2184 ITerrainModule terrainModule = region.RequestModuleInterface<ITerrainModule>();
2185 if (null == terrainModule) throw new Exception("terrain module not available");
2186 if (Uri.IsWellFormedUriString(file, UriKind.Absolute))
2187 {
2188 m_log.Info("[RADMIN]: Terrain path is URL");
2189 Uri result;
2190 if (Uri.TryCreate(file, UriKind.RelativeOrAbsolute, out result))
2191 {
2192 // the url is valid
2193 string fileType = file.Substring(file.LastIndexOf('/') + 1);
2194 terrainModule.LoadFromStream(fileType, result);
2195 }
2196 }
2197 else
2198 {
2199 terrainModule.LoadFromFile(file);
2200 }
2201
2202 m_log.Info("[RADMIN]: Load height maps request complete");
2203
2204 return true;
2205 }
2206
2207
2208 /// <summary>
1451 /// This method is called by the user-create and user-modify methods to establish 2209 /// This method is called by the user-create and user-modify methods to establish
1452 /// or change, the user's appearance. Default avatar names can be specified via 2210 /// or change, the user's appearance. Default avatar names can be specified via
1453 /// the config file, but must correspond to avatars in the default appearance 2211 /// the config file, but must correspond to avatars in the default appearance
@@ -2192,1104 +2950,5 @@ namespace OpenSim.ApplicationPlugins.RemoteController
2192 2950
2193 return true; 2951 return true;
2194 } 2952 }
2195
2196 /// <summary>
2197 /// Load an OAR file into a region..
2198 /// <summary>
2199 /// <param name="request">incoming XML RPC request</param>
2200 /// <remarks>
2201 /// XmlRpcLoadOARMethod takes the following XMLRPC
2202 /// parameters
2203 /// <list type="table">
2204 /// <listheader><term>parameter name</term><description>description</description></listheader>
2205 /// <item><term>password</term>
2206 /// <description>admin password as set in OpenSim.ini</description></item>
2207 /// <item><term>filename</term>
2208 /// <description>file name of the OAR file</description></item>
2209 /// <item><term>region_uuid</term>
2210 /// <description>UUID of the region</description></item>
2211 /// <item><term>region_name</term>
2212 /// <description>region name</description></item>
2213 /// <item><term>merge</term>
2214 /// <description>true if oar should be merged</description></item>
2215 /// <item><term>skip-assets</term>
2216 /// <description>true if assets should be skiped</description></item>
2217 /// </list>
2218 ///
2219 /// <code>region_uuid</code> takes precedence over
2220 /// <code>region_name</code> if both are present; one of both
2221 /// must be present.
2222 ///
2223 /// XmlRpcLoadOARMethod returns
2224 /// <list type="table">
2225 /// <listheader><term>name</term><description>description</description></listheader>
2226 /// <item><term>success</term>
2227 /// <description>true or false</description></item>
2228 /// <item><term>error</term>
2229 /// <description>error message if success is false</description></item>
2230 /// </list>
2231 /// </remarks>
2232 public XmlRpcResponse XmlRpcLoadOARMethod(XmlRpcRequest request, IPEndPoint remoteClient)
2233 {
2234 m_log.Info("[RADMIN]: Received Load OAR Administrator Request");
2235
2236 XmlRpcResponse response = new XmlRpcResponse();
2237 Hashtable responseData = new Hashtable();
2238
2239 lock (m_requestLock)
2240 {
2241 try
2242 {
2243 Hashtable requestData = (Hashtable) request.Params[0];
2244
2245 CheckStringParameters(request, new string[] {
2246 "password", "filename"});
2247
2248 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
2249
2250 string filename = (string) requestData["filename"];
2251 Scene scene = null;
2252 if (requestData.Contains("region_uuid"))
2253 {
2254 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
2255 if (!m_application.SceneManager.TryGetScene(region_uuid, out scene))
2256 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
2257 }
2258 else if (requestData.Contains("region_name"))
2259 {
2260 string region_name = (string) requestData["region_name"];
2261 if (!m_application.SceneManager.TryGetScene(region_name, out scene))
2262 throw new Exception(String.Format("failed to switch to region {0}", region_name));
2263 }
2264 else throw new Exception("neither region_name nor region_uuid given");
2265
2266 bool mergeOar = false;
2267 bool skipAssets = false;
2268
2269 if ((string)requestData["merge"] == "true")
2270 {
2271 mergeOar = true;
2272 }
2273 if ((string)requestData["skip-assets"] == "true")
2274 {
2275 skipAssets = true;
2276 }
2277
2278 IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
2279 if (archiver != null)
2280 archiver.DearchiveRegion(filename, mergeOar, skipAssets, Guid.Empty);
2281 else
2282 throw new Exception("Archiver module not present for scene");
2283
2284 responseData["loaded"] = true;
2285
2286 response.Value = responseData;
2287 }
2288 catch (Exception e)
2289 {
2290 m_log.ErrorFormat("[RADMIN]: LoadOAR: {0} {1}", e.Message, e.StackTrace);
2291
2292 responseData["loaded"] = false;
2293 responseData["error"] = e.Message;
2294
2295 response.Value = responseData;
2296 }
2297
2298 m_log.Info("[RADMIN]: Load OAR Administrator Request complete");
2299 return response;
2300 }
2301 }
2302
2303 /// <summary>
2304 /// Save a region to an OAR file
2305 /// <summary>
2306 /// <param name="request">incoming XML RPC request</param>
2307 /// <remarks>
2308 /// XmlRpcSaveOARMethod takes the following XMLRPC
2309 /// parameters
2310 /// <list type="table">
2311 /// <listheader><term>parameter name</term><description>description</description></listheader>
2312 /// <item><term>password</term>
2313 /// <description>admin password as set in OpenSim.ini</description></item>
2314 /// <item><term>filename</term>
2315 /// <description>file name for the OAR file</description></item>
2316 /// <item><term>region_uuid</term>
2317 /// <description>UUID of the region</description></item>
2318 /// <item><term>region_name</term>
2319 /// <description>region name</description></item>
2320 /// <item><term>profile</term>
2321 /// <description>profile url</description></item>
2322 /// <item><term>noassets</term>
2323 /// <description>true if no assets should be saved</description></item>
2324 /// <item><term>perm</term>
2325 /// <description>C and/or T</description></item>
2326 /// </list>
2327 ///
2328 /// <code>region_uuid</code> takes precedence over
2329 /// <code>region_name</code> if both are present; one of both
2330 /// must be present.
2331 ///
2332 /// XmlRpcLoadOARMethod returns
2333 /// <list type="table">
2334 /// <listheader><term>name</term><description>description</description></listheader>
2335 /// <item><term>success</term>
2336 /// <description>true or false</description></item>
2337 /// <item><term>error</term>
2338 /// <description>error message if success is false</description></item>
2339 /// </list>
2340 /// </remarks>
2341 public XmlRpcResponse XmlRpcSaveOARMethod(XmlRpcRequest request, IPEndPoint remoteClient)
2342 {
2343 m_log.Info("[RADMIN]: Received Save OAR Administrator Request");
2344
2345 XmlRpcResponse response = new XmlRpcResponse();
2346 Hashtable responseData = new Hashtable();
2347
2348 try
2349 {
2350 Hashtable requestData = (Hashtable) request.Params[0];
2351
2352 CheckStringParameters(request, new string[] {
2353 "password", "filename"});
2354
2355 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
2356
2357 string filename = (string) requestData["filename"];
2358 Scene scene = null;
2359 if (requestData.Contains("region_uuid"))
2360 {
2361 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
2362 if (!m_application.SceneManager.TryGetScene(region_uuid, out scene))
2363 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
2364 }
2365 else if (requestData.Contains("region_name"))
2366 {
2367 string region_name = (string) requestData["region_name"];
2368 if (!m_application.SceneManager.TryGetScene(region_name, out scene))
2369 throw new Exception(String.Format("failed to switch to region {0}", region_name));
2370 }
2371 else throw new Exception("neither region_name nor region_uuid given");
2372
2373 Dictionary<string, object> options = new Dictionary<string, object>();
2374
2375 //if (requestData.Contains("version"))
2376 //{
2377 // options["version"] = (string)requestData["version"];
2378 //}
2379
2380 if (requestData.Contains("profile"))
2381 {
2382 options["profile"] = (string)requestData["profile"];
2383 }
2384
2385 if (requestData["noassets"] == "true")
2386 {
2387 options["noassets"] = (string)requestData["noassets"] ;
2388 }
2389
2390 if (requestData.Contains("perm"))
2391 {
2392 options["checkPermissions"] = (string)requestData["perm"];
2393 }
2394
2395 IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
2396
2397 if (archiver != null)
2398 {
2399 scene.EventManager.OnOarFileSaved += RemoteAdminOarSaveCompleted;
2400 archiver.ArchiveRegion(filename, options);
2401
2402 lock (m_saveOarLock)
2403 Monitor.Wait(m_saveOarLock,5000);
2404
2405 scene.EventManager.OnOarFileSaved -= RemoteAdminOarSaveCompleted;
2406 }
2407 else
2408 {
2409 throw new Exception("Archiver module not present for scene");
2410 }
2411
2412 responseData["saved"] = true;
2413
2414 response.Value = responseData;
2415 }
2416 catch (Exception e)
2417 {
2418 m_log.ErrorFormat("[RADMIN]: SaveOAR: {0} {1}", e.Message, e.StackTrace);
2419
2420 responseData["saved"] = false;
2421 responseData["error"] = e.Message;
2422
2423 response.Value = responseData;
2424 }
2425
2426 m_log.Info("[RADMIN]: Save OAR Administrator Request complete");
2427 return response;
2428 }
2429
2430 private void RemoteAdminOarSaveCompleted(Guid uuid, string name)
2431 {
2432 m_log.DebugFormat("[RADMIN]: File processing complete for {0}", name);
2433 lock (m_saveOarLock) Monitor.Pulse(m_saveOarLock);
2434 }
2435
2436 public XmlRpcResponse XmlRpcLoadXMLMethod(XmlRpcRequest request, IPEndPoint remoteClient)
2437 {
2438 m_log.Info("[RADMIN]: Received Load XML Administrator Request");
2439
2440 XmlRpcResponse response = new XmlRpcResponse();
2441 Hashtable responseData = new Hashtable();
2442
2443 lock (m_requestLock)
2444 {
2445 try
2446 {
2447 Hashtable requestData = (Hashtable) request.Params[0];
2448
2449 CheckStringParameters(request, new string[] {
2450 "password", "filename"});
2451
2452 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
2453
2454 string filename = (string) requestData["filename"];
2455 if (requestData.Contains("region_uuid"))
2456 {
2457 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
2458 if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
2459 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
2460
2461 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
2462 }
2463 else if (requestData.Contains("region_name"))
2464 {
2465 string region_name = (string) requestData["region_name"];
2466 if (!m_application.SceneManager.TrySetCurrentScene(region_name))
2467 throw new Exception(String.Format("failed to switch to region {0}", region_name));
2468
2469 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
2470 }
2471 else throw new Exception("neither region_name nor region_uuid given");
2472
2473 responseData["switched"] = true;
2474
2475 string xml_version = "1";
2476 if (requestData.Contains("xml_version"))
2477 {
2478 xml_version = (string) requestData["xml_version"];
2479 }
2480
2481 switch (xml_version)
2482 {
2483 case "1":
2484 m_application.SceneManager.LoadCurrentSceneFromXml(filename, true, new Vector3(0, 0, 0));
2485 break;
2486
2487 case "2":
2488 m_application.SceneManager.LoadCurrentSceneFromXml2(filename);
2489 break;
2490
2491 default:
2492 throw new Exception(String.Format("unknown Xml{0} format", xml_version));
2493 }
2494
2495 responseData["loaded"] = true;
2496 response.Value = responseData;
2497 }
2498 catch (Exception e)
2499 {
2500 m_log.ErrorFormat("[RADMIN] LoadXml: {0} {1}", e.Message, e.StackTrace);
2501
2502 responseData["loaded"] = false;
2503 responseData["switched"] = false;
2504 responseData["error"] = e.Message;
2505
2506 response.Value = responseData;
2507 }
2508
2509 m_log.Info("[RADMIN]: Load XML Administrator Request complete");
2510 return response;
2511 }
2512 }
2513
2514 public XmlRpcResponse XmlRpcSaveXMLMethod(XmlRpcRequest request, IPEndPoint remoteClient)
2515 {
2516 m_log.Info("[RADMIN]: Received Save XML Administrator Request");
2517
2518 XmlRpcResponse response = new XmlRpcResponse();
2519 Hashtable responseData = new Hashtable();
2520
2521 try
2522 {
2523 Hashtable requestData = (Hashtable) request.Params[0];
2524
2525 CheckStringParameters(request, new string[] {
2526 "password", "filename"});
2527
2528 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
2529
2530 string filename = (string) requestData["filename"];
2531 if (requestData.Contains("region_uuid"))
2532 {
2533 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
2534 if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
2535 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
2536 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
2537 }
2538 else if (requestData.Contains("region_name"))
2539 {
2540 string region_name = (string) requestData["region_name"];
2541 if (!m_application.SceneManager.TrySetCurrentScene(region_name))
2542 throw new Exception(String.Format("failed to switch to region {0}", region_name));
2543 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
2544 }
2545 else throw new Exception("neither region_name nor region_uuid given");
2546
2547 responseData["switched"] = true;
2548
2549 string xml_version = "1";
2550 if (requestData.Contains("xml_version"))
2551 {
2552 xml_version = (string) requestData["xml_version"];
2553 }
2554
2555 switch (xml_version)
2556 {
2557 case "1":
2558 m_application.SceneManager.SaveCurrentSceneToXml(filename);
2559 break;
2560
2561 case "2":
2562 m_application.SceneManager.SaveCurrentSceneToXml2(filename);
2563 break;
2564
2565 default:
2566 throw new Exception(String.Format("unknown Xml{0} format", xml_version));
2567 }
2568
2569 responseData["saved"] = true;
2570
2571 response.Value = responseData;
2572 }
2573 catch (Exception e)
2574 {
2575 m_log.ErrorFormat("[RADMIN]: SaveXml: {0} {1}", e.Message, e.StackTrace);
2576
2577 responseData["saved"] = false;
2578 responseData["switched"] = false;
2579 responseData["error"] = e.Message;
2580
2581 response.Value = responseData;
2582 }
2583
2584 m_log.Info("[RADMIN]: Save XML Administrator Request complete");
2585 return response;
2586 }
2587
2588 public XmlRpcResponse XmlRpcRegionQueryMethod(XmlRpcRequest request, IPEndPoint remoteClient)
2589 {
2590 m_log.Info("[RADMIN]: Received Query XML Administrator Request");
2591
2592 XmlRpcResponse response = new XmlRpcResponse();
2593 Hashtable responseData = new Hashtable();
2594
2595 try
2596 {
2597 responseData["success"] = true;
2598
2599 Hashtable requestData = (Hashtable) request.Params[0];
2600
2601 CheckStringParameters(request, new string[] {
2602 "password"});
2603
2604 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
2605
2606 if (requestData.Contains("region_uuid"))
2607 {
2608 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
2609 if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
2610 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
2611
2612 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
2613 }
2614 else if (requestData.Contains("region_name"))
2615 {
2616 string region_name = (string) requestData["region_name"];
2617 if (!m_application.SceneManager.TrySetCurrentScene(region_name))
2618 throw new Exception(String.Format("failed to switch to region {0}", region_name));
2619
2620 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
2621 }
2622 else throw new Exception("neither region_name nor region_uuid given");
2623
2624 Scene scene = m_application.SceneManager.CurrentScene;
2625 int health = scene.GetHealth();
2626 responseData["health"] = health;
2627
2628 response.Value = responseData;
2629 }
2630 catch (Exception e)
2631 {
2632 m_log.InfoFormat("[RADMIN]: RegionQuery: {0}", e.Message);
2633
2634 responseData["success"] = false;
2635 responseData["error"] = e.Message;
2636
2637 response.Value = responseData;
2638 }
2639
2640 m_log.Info("[RADMIN]: Query XML Administrator Request complete");
2641
2642 return response;
2643 }
2644
2645 public XmlRpcResponse XmlRpcConsoleCommandMethod(XmlRpcRequest request, IPEndPoint remoteClient)
2646 {
2647 m_log.Info("[RADMIN]: Received Command XML Administrator Request");
2648
2649 XmlRpcResponse response = new XmlRpcResponse();
2650 Hashtable responseData = new Hashtable();
2651
2652 try
2653 {
2654 responseData["success"] = true;
2655
2656 Hashtable requestData = (Hashtable) request.Params[0];
2657
2658 CheckStringParameters(request, new string[] {
2659 "password", "command"});
2660
2661 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
2662
2663 MainConsole.Instance.RunCommand(requestData["command"].ToString());
2664
2665 response.Value = responseData;
2666 }
2667 catch (Exception e)
2668 {
2669 m_log.InfoFormat("[RADMIN]: ConsoleCommand: {0}", e.Message);
2670
2671 responseData["success"] = false;
2672 responseData["error"] = e.Message;
2673
2674 response.Value = responseData;
2675 }
2676
2677 m_log.Info("[RADMIN]: Command XML Administrator Request complete");
2678 return response;
2679 }
2680
2681 public XmlRpcResponse XmlRpcAccessListClear(XmlRpcRequest request, IPEndPoint remoteClient)
2682 {
2683 m_log.Info("[RADMIN]: Received Access List Clear Request");
2684
2685 XmlRpcResponse response = new XmlRpcResponse();
2686 Hashtable responseData = new Hashtable();
2687
2688 try
2689 {
2690 responseData["success"] = true;
2691
2692 Hashtable requestData = (Hashtable) request.Params[0];
2693
2694 CheckStringParameters(request, new string[] {
2695 "password"});
2696
2697 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
2698
2699 if (requestData.Contains("region_uuid"))
2700 {
2701 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
2702 if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
2703 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
2704 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
2705 }
2706 else if (requestData.Contains("region_name"))
2707 {
2708 string region_name = (string) requestData["region_name"];
2709 if (!m_application.SceneManager.TrySetCurrentScene(region_name))
2710 throw new Exception(String.Format("failed to switch to region {0}", region_name));
2711
2712 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
2713 }
2714 else throw new Exception("neither region_name nor region_uuid given");
2715
2716 Scene scene = m_application.SceneManager.CurrentScene;
2717 scene.RegionInfo.EstateSettings.EstateAccess = new UUID[]{};
2718
2719 if (scene.RegionInfo.Persistent)
2720 scene.RegionInfo.EstateSettings.Save();
2721 }
2722 catch (Exception e)
2723 {
2724 m_log.ErrorFormat("[RADMIN]: Access List Clear Request: {0} {1}", e.Message, e.StackTrace);
2725
2726 responseData["success"] = false;
2727 responseData["error"] = e.Message;
2728 }
2729 finally
2730 {
2731 response.Value = responseData;
2732 }
2733
2734 m_log.Info("[RADMIN]: Access List Clear Request complete");
2735 return response;
2736 }
2737
2738 public XmlRpcResponse XmlRpcAccessListAdd(XmlRpcRequest request, IPEndPoint remoteClient)
2739 {
2740 m_log.Info("[RADMIN]: Received Access List Add Request");
2741
2742 XmlRpcResponse response = new XmlRpcResponse();
2743 Hashtable responseData = new Hashtable();
2744
2745 try
2746 {
2747 responseData["success"] = true;
2748
2749 Hashtable requestData = (Hashtable) request.Params[0];
2750
2751 CheckStringParameters(request, new string[] {
2752 "password"});
2753
2754 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
2755
2756 if (requestData.Contains("region_uuid"))
2757 {
2758 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
2759 if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
2760 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
2761 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
2762 }
2763 else if (requestData.Contains("region_name"))
2764 {
2765 string region_name = (string) requestData["region_name"];
2766 if (!m_application.SceneManager.TrySetCurrentScene(region_name))
2767 throw new Exception(String.Format("failed to switch to region {0}", region_name));
2768 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
2769 }
2770 else throw new Exception("neither region_name nor region_uuid given");
2771
2772 int addedUsers = 0;
2773
2774 if (requestData.Contains("users"))
2775 {
2776 UUID scopeID = m_application.SceneManager.CurrentOrFirstScene.RegionInfo.ScopeID;
2777 IUserAccountService userService = m_application.SceneManager.CurrentOrFirstScene.UserAccountService;
2778 Scene scene = m_application.SceneManager.CurrentScene;
2779 Hashtable users = (Hashtable) requestData["users"];
2780 List<UUID> uuids = new List<UUID>();
2781 foreach (string name in users.Values)
2782 {
2783 string[] parts = name.Split();
2784 UserAccount account = userService.GetUserAccount(scopeID, parts[0], parts[1]);
2785 if (account != null)
2786 {
2787 uuids.Add(account.PrincipalID);
2788 m_log.DebugFormat("[RADMIN]: adding \"{0}\" to ACL for \"{1}\"", name, scene.RegionInfo.RegionName);
2789 }
2790 }
2791 List<UUID> accessControlList = new List<UUID>(scene.RegionInfo.EstateSettings.EstateAccess);
2792 foreach (UUID uuid in uuids)
2793 {
2794 if (!accessControlList.Contains(uuid))
2795 {
2796 accessControlList.Add(uuid);
2797 addedUsers++;
2798 }
2799 }
2800 scene.RegionInfo.EstateSettings.EstateAccess = accessControlList.ToArray();
2801 if (scene.RegionInfo.Persistent)
2802 scene.RegionInfo.EstateSettings.Save();
2803 }
2804
2805 responseData["added"] = addedUsers;
2806 }
2807 catch (Exception e)
2808 {
2809 m_log.ErrorFormat("[RADMIN]: Access List Add Request: {0} {1}", e.Message, e.StackTrace);
2810
2811 responseData["success"] = false;
2812 responseData["error"] = e.Message;
2813 }
2814 finally
2815 {
2816 response.Value = responseData;
2817 }
2818
2819 m_log.Info("[RADMIN]: Access List Add Request complete");
2820 return response;
2821 }
2822
2823 public XmlRpcResponse XmlRpcAccessListRemove(XmlRpcRequest request, IPEndPoint remoteClient)
2824 {
2825 m_log.Info("[RADMIN]: Received Access List Remove Request");
2826
2827 XmlRpcResponse response = new XmlRpcResponse();
2828 Hashtable responseData = new Hashtable();
2829
2830 try
2831 {
2832 responseData["success"] = true;
2833
2834 Hashtable requestData = (Hashtable) request.Params[0];
2835
2836 CheckStringParameters(request, new string[] {
2837 "password"});
2838
2839 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
2840
2841 if (requestData.Contains("region_uuid"))
2842 {
2843 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
2844 if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
2845 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
2846 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
2847 }
2848 else if (requestData.Contains("region_name"))
2849 {
2850 string region_name = (string) requestData["region_name"];
2851 if (!m_application.SceneManager.TrySetCurrentScene(region_name))
2852 throw new Exception(String.Format("failed to switch to region {0}", region_name));
2853 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
2854 }
2855 else throw new Exception("neither region_name nor region_uuid given");
2856
2857 int removedUsers = 0;
2858
2859 if (requestData.Contains("users"))
2860 {
2861 UUID scopeID = m_application.SceneManager.CurrentOrFirstScene.RegionInfo.ScopeID;
2862 IUserAccountService userService = m_application.SceneManager.CurrentOrFirstScene.UserAccountService;
2863 //UserProfileCacheService ups = m_application.CommunicationsManager.UserProfileCacheService;
2864 Scene scene = m_application.SceneManager.CurrentScene;
2865 Hashtable users = (Hashtable) requestData["users"];
2866 List<UUID> uuids = new List<UUID>();
2867 foreach (string name in users.Values)
2868 {
2869 string[] parts = name.Split();
2870 UserAccount account = userService.GetUserAccount(scopeID, parts[0], parts[1]);
2871 if (account != null)
2872 {
2873 uuids.Add(account.PrincipalID);
2874 }
2875 }
2876 List<UUID> accessControlList = new List<UUID>(scene.RegionInfo.EstateSettings.EstateAccess);
2877 foreach (UUID uuid in uuids)
2878 {
2879 if (accessControlList.Contains(uuid))
2880 {
2881 accessControlList.Remove(uuid);
2882 removedUsers++;
2883 }
2884 }
2885 scene.RegionInfo.EstateSettings.EstateAccess = accessControlList.ToArray();
2886 if (scene.RegionInfo.Persistent)
2887 scene.RegionInfo.EstateSettings.Save();
2888 }
2889
2890 responseData["removed"] = removedUsers;
2891 }
2892 catch (Exception e)
2893 {
2894 m_log.ErrorFormat("[RADMIN]: Access List Remove Request: {0} {1}", e.Message, e.StackTrace);
2895
2896 responseData["success"] = false;
2897 responseData["error"] = e.Message;
2898 }
2899 finally
2900 {
2901 response.Value = responseData;
2902 }
2903
2904 m_log.Info("[RADMIN]: Access List Remove Request complete");
2905 return response;
2906 }
2907
2908 public XmlRpcResponse XmlRpcAccessListList(XmlRpcRequest request, IPEndPoint remoteClient)
2909 {
2910 m_log.Info("[RADMIN]: Received Access List List Request");
2911
2912 XmlRpcResponse response = new XmlRpcResponse();
2913 Hashtable responseData = new Hashtable();
2914
2915 try
2916 {
2917 responseData["success"] = true;
2918
2919 Hashtable requestData = (Hashtable) request.Params[0];
2920
2921 CheckStringParameters(request, new string[] {
2922 "password"});
2923
2924 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
2925
2926 if (requestData.Contains("region_uuid"))
2927 {
2928 UUID region_uuid = (UUID) (string) requestData["region_uuid"];
2929 if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
2930 throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
2931 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
2932 }
2933 else if (requestData.Contains("region_name"))
2934 {
2935 string region_name = (string) requestData["region_name"];
2936 if (!m_application.SceneManager.TrySetCurrentScene(region_name))
2937 throw new Exception(String.Format("failed to switch to region {0}", region_name));
2938 m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
2939 }
2940 else throw new Exception("neither region_name nor region_uuid given");
2941
2942 Scene scene = m_application.SceneManager.CurrentScene;
2943 UUID[] accessControlList = scene.RegionInfo.EstateSettings.EstateAccess;
2944 Hashtable users = new Hashtable();
2945
2946 foreach (UUID user in accessControlList)
2947 {
2948 UUID scopeID = m_application.SceneManager.CurrentOrFirstScene.RegionInfo.ScopeID;
2949 UserAccount account = m_application.SceneManager.CurrentOrFirstScene.UserAccountService.GetUserAccount(scopeID, user);
2950 if (account != null)
2951 {
2952 users[user.ToString()] = account.FirstName + " " + account.LastName;
2953 }
2954 }
2955
2956 responseData["users"] = users;
2957 }
2958 catch (Exception e)
2959 {
2960 m_log.ErrorFormat("[RADMIN]: Access List List: {0} {1}", e.Message, e.StackTrace);
2961
2962 responseData["success"] = false;
2963 responseData["error"] = e.Message;
2964 }
2965 finally
2966 {
2967 response.Value = responseData;
2968 }
2969
2970 m_log.Info("[RADMIN]: Access List List Request complete");
2971 return response;
2972 }
2973
2974 public XmlRpcResponse XmlRpcTeleportAgentMethod(XmlRpcRequest request, IPEndPoint remoteClient)
2975 {
2976 XmlRpcResponse response = new XmlRpcResponse();
2977 Hashtable responseData = new Hashtable();
2978
2979 try
2980 {
2981 responseData["success"] = true;
2982
2983 Hashtable requestData = (Hashtable)request.Params[0];
2984
2985 CheckStringParameters(request, new string[] {"password"});
2986
2987 FailIfRemoteAdminNotAllowed((string)requestData["password"], remoteClient.Address.ToString());
2988
2989 UUID agentId;
2990 string regionName = null;
2991 Vector3 pos, lookAt;
2992 bool agentSpecified = false;
2993 ScenePresence sp = null;
2994
2995 if (requestData.Contains("agent_first_name") && requestData.Contains("agent_last_name"))
2996 {
2997 string firstName = requestData["agent_first_name"].ToString();
2998 string lastName = requestData["agent_last_name"].ToString();
2999 m_application.SceneManager.TryGetRootScenePresenceByName(firstName, lastName, out sp);
3000
3001 if (sp == null)
3002 throw new Exception(
3003 string.Format(
3004 "No agent found with agent_first_name {0} and agent_last_name {1}", firstName, lastName));
3005 }
3006 else if (requestData.Contains("agent_id"))
3007 {
3008 string rawAgentId = (string)requestData["agent_id"];
3009
3010 if (!UUID.TryParse(rawAgentId, out agentId))
3011 throw new Exception(string.Format("agent_id {0} does not have the correct id format", rawAgentId));
3012
3013 m_application.SceneManager.TryGetRootScenePresence(agentId, out sp);
3014
3015 if (sp == null)
3016 throw new Exception(string.Format("No agent with agent_id {0} found in this simulator", agentId));
3017 }
3018 else
3019 {
3020 throw new Exception("No agent_id or agent_first_name and agent_last_name parameters specified");
3021 }
3022
3023 if (requestData.Contains("region_name"))
3024 regionName = (string)requestData["region_name"];
3025
3026 pos.X = ParseFloat(requestData, "pos_x", sp.AbsolutePosition.X);
3027 pos.Y = ParseFloat(requestData, "pos_y", sp.AbsolutePosition.Y);
3028 pos.Z = ParseFloat(requestData, "pos_z", sp.AbsolutePosition.Z);
3029 lookAt.X = ParseFloat(requestData, "lookat_x", sp.Lookat.X);
3030 lookAt.Y = ParseFloat(requestData, "lookat_y", sp.Lookat.Y);
3031 lookAt.Z = ParseFloat(requestData, "lookat_z", sp.Lookat.Z);
3032
3033 sp.Scene.RequestTeleportLocation(
3034 sp.ControllingClient, regionName, pos, lookAt, (uint)Constants.TeleportFlags.ViaLocation);
3035 }
3036 catch (Exception e)
3037 {
3038 m_log.ErrorFormat("[RADMIN]: admin_teleport_agent exception: {0}{1}", e.Message, e.StackTrace);
3039
3040 responseData["success"] = false;
3041 responseData["error"] = e.Message;
3042 }
3043 finally
3044 {
3045 response.Value = responseData;
3046 }
3047
3048 return response;
3049 }
3050
3051 /// <summary>
3052 /// Parse a float with the given parameter name from a request data hash table.
3053 /// </summary>
3054 /// <remarks>
3055 /// Will throw an exception if parameter is not a float.
3056 /// Will not throw if parameter is not found, passes back default value instead.
3057 /// </remarks>
3058 /// <param name="requestData"></param>
3059 /// <param name="paramName"></param>
3060 /// <param name="defaultVal"></param>
3061 /// <returns></returns>
3062 private static float ParseFloat(Hashtable requestData, string paramName, float defaultVal)
3063 {
3064 if (requestData.Contains(paramName))
3065 {
3066 string rawVal = (string)requestData[paramName];
3067 float val;
3068
3069 if (!float.TryParse(rawVal, out val))
3070 throw new Exception(string.Format("{0} {1} is not a valid float", paramName, rawVal));
3071 else
3072 return val;
3073 }
3074 else
3075 {
3076 return defaultVal;
3077 }
3078 }
3079
3080 private static void CheckStringParameters(XmlRpcRequest request, string[] param)
3081 {
3082 Hashtable requestData = (Hashtable) request.Params[0];
3083 foreach (string parameter in param)
3084 {
3085 if (!requestData.Contains(parameter))
3086 throw new Exception(String.Format("missing string parameter {0}", parameter));
3087 if (String.IsNullOrEmpty((string) requestData[parameter]))
3088 throw new Exception(String.Format("parameter {0} is empty", parameter));
3089 }
3090 }
3091
3092 private static void CheckIntegerParams(XmlRpcRequest request, string[] param)
3093 {
3094 Hashtable requestData = (Hashtable) request.Params[0];
3095 foreach (string parameter in param)
3096 {
3097 if (!requestData.Contains(parameter))
3098 throw new Exception(String.Format("missing integer parameter {0}", parameter));
3099 }
3100 }
3101
3102 private bool GetBoolean(Hashtable requestData, string tag, bool defaultValue)
3103 {
3104 // If an access value has been provided, apply it.
3105 if (requestData.Contains(tag))
3106 {
3107 switch (((string)requestData[tag]).ToLower())
3108 {
3109 case "true" :
3110 case "t" :
3111 case "1" :
3112 return true;
3113 case "false" :
3114 case "f" :
3115 case "0" :
3116 return false;
3117 default :
3118 return defaultValue;
3119 }
3120 }
3121 else
3122 return defaultValue;
3123 }
3124
3125 private int GetIntegerAttribute(XmlNode node, string attribute, int defaultValue)
3126 {
3127 try { return Convert.ToInt32(node.Attributes[attribute].Value); } catch{}
3128 return defaultValue;
3129 }
3130
3131 private uint GetUnsignedAttribute(XmlNode node, string attribute, uint defaultValue)
3132 {
3133 try { return Convert.ToUInt32(node.Attributes[attribute].Value); } catch{}
3134 return defaultValue;
3135 }
3136
3137 private string GetStringAttribute(XmlNode node, string attribute, string defaultValue)
3138 {
3139 try { return node.Attributes[attribute].Value; } catch{}
3140 return defaultValue;
3141 }
3142
3143 public void Dispose()
3144 {
3145 }
3146
3147 /// <summary>
3148 /// Create a user
3149 /// </summary>
3150 /// <param name="scopeID"></param>
3151 /// <param name="firstName"></param>
3152 /// <param name="lastName"></param>
3153 /// <param name="password"></param>
3154 /// <param name="email"></param>
3155 private UserAccount CreateUser(UUID scopeID, string firstName, string lastName, string password, string email)
3156 {
3157 Scene scene = m_application.SceneManager.CurrentOrFirstScene;
3158 IUserAccountService userAccountService = scene.UserAccountService;
3159 IGridService gridService = scene.GridService;
3160 IAuthenticationService authenticationService = scene.AuthenticationService;
3161 IGridUserService gridUserService = scene.GridUserService;
3162 IInventoryService inventoryService = scene.InventoryService;
3163
3164 UserAccount account = userAccountService.GetUserAccount(scopeID, firstName, lastName);
3165 if (null == account)
3166 {
3167 account = new UserAccount(scopeID, UUID.Random(), firstName, lastName, email);
3168 if (account.ServiceURLs == null || (account.ServiceURLs != null && account.ServiceURLs.Count == 0))
3169 {
3170 account.ServiceURLs = new Dictionary<string, object>();
3171 account.ServiceURLs["HomeURI"] = string.Empty;
3172 account.ServiceURLs["GatekeeperURI"] = string.Empty;
3173 account.ServiceURLs["InventoryServerURI"] = string.Empty;
3174 account.ServiceURLs["AssetServerURI"] = string.Empty;
3175 }
3176
3177 if (userAccountService.StoreUserAccount(account))
3178 {
3179 bool success;
3180 if (authenticationService != null)
3181 {
3182 success = authenticationService.SetPassword(account.PrincipalID, password);
3183 if (!success)
3184 m_log.WarnFormat("[RADMIN]: Unable to set password for account {0} {1}.",
3185 firstName, lastName);
3186 }
3187
3188 GridRegion home = null;
3189 if (gridService != null)
3190 {
3191 List<GridRegion> defaultRegions = gridService.GetDefaultRegions(UUID.Zero);
3192 if (defaultRegions != null && defaultRegions.Count >= 1)
3193 home = defaultRegions[0];
3194
3195 if (gridUserService != null && home != null)
3196 gridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
3197 else
3198 m_log.WarnFormat("[RADMIN]: Unable to set home for account {0} {1}.",
3199 firstName, lastName);
3200 }
3201 else
3202 m_log.WarnFormat("[RADMIN]: Unable to retrieve home region for account {0} {1}.",
3203 firstName, lastName);
3204
3205 if (inventoryService != null)
3206 {
3207 success = inventoryService.CreateUserInventory(account.PrincipalID);
3208 if (!success)
3209 m_log.WarnFormat("[RADMIN]: Unable to create inventory for account {0} {1}.",
3210 firstName, lastName);
3211 }
3212
3213 m_log.InfoFormat("[RADMIN]: Account {0} {1} created successfully", firstName, lastName);
3214 return account;
3215 } else {
3216 m_log.ErrorFormat("[RADMIN]: Account creation failed for account {0} {1}", firstName, lastName);
3217 }
3218 }
3219 else
3220 {
3221 m_log.ErrorFormat("[RADMIN]: A user with the name {0} {1} already exists!", firstName, lastName);
3222 }
3223 return null;
3224 }
3225
3226 /// <summary>
3227 /// Change password
3228 /// </summary>
3229 /// <param name="firstName"></param>
3230 /// <param name="lastName"></param>
3231 /// <param name="password"></param>
3232 private bool ChangeUserPassword(string firstName, string lastName, string password)
3233 {
3234 Scene scene = m_application.SceneManager.CurrentOrFirstScene;
3235 IUserAccountService userAccountService = scene.UserAccountService;
3236 IAuthenticationService authenticationService = scene.AuthenticationService;
3237
3238 UserAccount account = userAccountService.GetUserAccount(UUID.Zero, firstName, lastName);
3239 if (null != account)
3240 {
3241 bool success = false;
3242 if (authenticationService != null)
3243 success = authenticationService.SetPassword(account.PrincipalID, password);
3244
3245 if (!success)
3246 {
3247 m_log.WarnFormat("[RADMIN]: Unable to set password for account {0} {1}.",
3248 firstName, lastName);
3249 return false;
3250 }
3251 return true;
3252 }
3253 else
3254 {
3255 m_log.ErrorFormat("[RADMIN]: No such user");
3256 return false;
3257 }
3258 }
3259
3260 private bool LoadHeightmap(string file, UUID regionID)
3261 {
3262 m_log.InfoFormat("[RADMIN]: Terrain Loading: {0}", file);
3263
3264 Scene region = null;
3265
3266 if (!m_application.SceneManager.TryGetScene(regionID, out region))
3267 {
3268 m_log.InfoFormat("[RADMIN]: unable to get a scene with that name: {0}", regionID.ToString());
3269 return false;
3270 }
3271
3272 ITerrainModule terrainModule = region.RequestModuleInterface<ITerrainModule>();
3273 if (null == terrainModule) throw new Exception("terrain module not available");
3274 if (Uri.IsWellFormedUriString(file, UriKind.Absolute))
3275 {
3276 m_log.Info("[RADMIN]: Terrain path is URL");
3277 Uri result;
3278 if (Uri.TryCreate(file, UriKind.RelativeOrAbsolute, out result))
3279 {
3280 // the url is valid
3281 string fileType = file.Substring(file.LastIndexOf('/') + 1);
3282 terrainModule.LoadFromStream(fileType, result);
3283 }
3284 }
3285 else
3286 {
3287 terrainModule.LoadFromFile(file);
3288 }
3289
3290 m_log.Info("[RADMIN]: Load height maps request complete");
3291
3292 return true;
3293 }
3294 } 2953 }
3295} \ No newline at end of file 2954} \ No newline at end of file