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