clockwerk-opensim-stable – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ |
||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions are met: |
||
7 | * * Redistributions of source code must retain the above copyright |
||
8 | * notice, this list of conditions and the following disclaimer. |
||
9 | * * Redistributions in binary form must reproduce the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer in the |
||
11 | * documentation and/or other materials provided with the distribution. |
||
12 | * * Neither the name of the OpenSimulator Project nor the |
||
13 | * names of its contributors may be used to endorse or promote products |
||
14 | * derived from this software without specific prior written permission. |
||
15 | * |
||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
26 | */ |
||
27 | |||
28 | using System; |
||
29 | using System.Collections; |
||
30 | using System.Collections.Generic; |
||
31 | using System.IO; |
||
32 | using System.Xml; |
||
33 | using System.Net; |
||
34 | using System.Reflection; |
||
35 | using System.Timers; |
||
36 | using System.Threading; |
||
37 | using log4net; |
||
38 | using Nini.Config; |
||
39 | using Nwc.XmlRpc; |
||
40 | using OpenMetaverse; |
||
41 | using OpenSim; |
||
42 | using OpenSim.Framework; |
||
43 | using OpenSim.Framework.Communications; |
||
44 | using OpenSim.Framework.Console; |
||
45 | using OpenSim.Framework.Servers; |
||
46 | using OpenSim.Framework.Servers.HttpServer; |
||
47 | using OpenSim.Region.CoreModules.World.Terrain; |
||
48 | using OpenSim.Region.Framework.Interfaces; |
||
49 | using OpenSim.Region.Framework.Scenes; |
||
50 | using OpenSim.Services.Interfaces; |
||
51 | using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; |
||
52 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
||
53 | using PermissionMask = OpenSim.Framework.PermissionMask; |
||
54 | |||
55 | namespace OpenSim.ApplicationPlugins.RemoteController |
||
56 | { |
||
57 | public class RemoteAdminPlugin : IApplicationPlugin |
||
58 | { |
||
59 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
60 | |||
61 | private static bool m_defaultAvatarsLoaded = false; |
||
62 | private static Object m_requestLock = new Object(); |
||
63 | private static Object m_saveOarLock = new Object(); |
||
64 | |||
65 | private OpenSimBase m_application; |
||
66 | private IHttpServer m_httpServer; |
||
67 | private IConfig m_config; |
||
68 | private IConfigSource m_configSource; |
||
69 | private string m_requiredPassword = String.Empty; |
||
70 | private HashSet<string> m_accessIP; |
||
71 | |||
72 | private string m_name = "RemoteAdminPlugin"; |
||
73 | private string m_version = "0.0"; |
||
74 | |||
75 | public string Version |
||
76 | { |
||
77 | get { return m_version; } |
||
78 | } |
||
79 | |||
80 | public string Name |
||
81 | { |
||
82 | get { return m_name; } |
||
83 | } |
||
84 | |||
85 | public void Initialise() |
||
86 | { |
||
87 | m_log.Error("[RADMIN]: " + Name + " cannot be default-initialized!"); |
||
88 | throw new PluginNotInitialisedException(Name); |
||
89 | } |
||
90 | |||
91 | public void Initialise(OpenSimBase openSim) |
||
92 | { |
||
93 | m_configSource = openSim.ConfigSource.Source; |
||
94 | try |
||
95 | { |
||
96 | if (m_configSource.Configs["RemoteAdmin"] == null || |
||
97 | !m_configSource.Configs["RemoteAdmin"].GetBoolean("enabled", false)) |
||
98 | { |
||
99 | // No config or disabled |
||
100 | } |
||
101 | else |
||
102 | { |
||
103 | m_config = m_configSource.Configs["RemoteAdmin"]; |
||
104 | m_log.Debug("[RADMIN]: Remote Admin Plugin Enabled"); |
||
105 | m_requiredPassword = m_config.GetString("access_password", String.Empty); |
||
106 | int port = m_config.GetInt("port", 0); |
||
107 | |||
108 | string accessIP = m_config.GetString("access_ip_addresses", String.Empty); |
||
109 | m_accessIP = new HashSet<string>(); |
||
110 | if (accessIP != String.Empty) |
||
111 | { |
||
112 | string[] ips = accessIP.Split(new char[] { ',' }); |
||
113 | foreach (string ip in ips) |
||
114 | { |
||
115 | string current = ip.Trim(); |
||
116 | |||
117 | if (current != String.Empty) |
||
118 | m_accessIP.Add(current); |
||
119 | } |
||
120 | } |
||
121 | |||
122 | m_application = openSim; |
||
123 | string bind_ip_address = m_config.GetString("bind_ip_address", "0.0.0.0"); |
||
124 | IPAddress ipaddr = IPAddress.Parse(bind_ip_address); |
||
125 | m_httpServer = MainServer.GetHttpServer((uint)port,ipaddr); |
||
126 | |||
127 | Dictionary<string, XmlRpcMethod> availableMethods = new Dictionary<string, XmlRpcMethod>(); |
||
128 | availableMethods["admin_create_region"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcCreateRegionMethod); |
||
129 | availableMethods["admin_delete_region"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcDeleteRegionMethod); |
||
130 | availableMethods["admin_close_region"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcCloseRegionMethod); |
||
131 | availableMethods["admin_modify_region"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcModifyRegionMethod); |
||
132 | availableMethods["admin_region_query"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcRegionQueryMethod); |
||
133 | availableMethods["admin_shutdown"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcShutdownMethod); |
||
134 | availableMethods["admin_broadcast"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcAlertMethod); |
||
135 | availableMethods["admin_restart"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcRestartMethod); |
||
136 | availableMethods["admin_load_heightmap"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcLoadHeightmapMethod); |
||
137 | availableMethods["admin_save_heightmap"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcSaveHeightmapMethod); |
||
138 | |||
139 | // Agent management |
||
140 | availableMethods["admin_get_agents"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcGetAgentsMethod); |
||
141 | availableMethods["admin_teleport_agent"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcTeleportAgentMethod); |
||
142 | |||
143 | // User management |
||
144 | availableMethods["admin_create_user"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcCreateUserMethod); |
||
145 | availableMethods["admin_create_user_email"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcCreateUserMethod); |
||
146 | availableMethods["admin_exists_user"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcUserExistsMethod); |
||
147 | availableMethods["admin_update_user"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcUpdateUserAccountMethod); |
||
148 | |||
149 | // Region state management |
||
150 | availableMethods["admin_load_xml"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcLoadXMLMethod); |
||
151 | availableMethods["admin_save_xml"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcSaveXMLMethod); |
||
152 | availableMethods["admin_load_oar"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcLoadOARMethod); |
||
153 | availableMethods["admin_save_oar"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcSaveOARMethod); |
||
154 | |||
155 | // Estate access list management |
||
156 | availableMethods["admin_acl_clear"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcAccessListClear); |
||
157 | availableMethods["admin_acl_add"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcAccessListAdd); |
||
158 | availableMethods["admin_acl_remove"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcAccessListRemove); |
||
159 | availableMethods["admin_acl_list"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcAccessListList); |
||
160 | availableMethods["admin_estate_reload"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcEstateReload); |
||
161 | |||
162 | // Either enable full remote functionality or just selected features |
||
163 | string enabledMethods = m_config.GetString("enabled_methods", "all"); |
||
164 | |||
165 | // To get this, you must explicitly specify "all" or |
||
166 | // mention it in a whitelist. It won't be available |
||
167 | // If you just leave the option out! |
||
168 | // |
||
169 | if (!String.IsNullOrEmpty(enabledMethods)) |
||
170 | availableMethods["admin_console_command"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcConsoleCommandMethod); |
||
171 | |||
172 | // The assumption here is that simply enabling Remote Admin as before will produce the same |
||
173 | // behavior - enable all methods unless the whitelist is in place for backward-compatibility. |
||
174 | if (enabledMethods.ToLower() == "all" || String.IsNullOrEmpty(enabledMethods)) |
||
175 | { |
||
176 | foreach (string method in availableMethods.Keys) |
||
177 | { |
||
178 | m_httpServer.AddXmlRPCHandler(method, availableMethods[method], false); |
||
179 | } |
||
180 | } |
||
181 | else |
||
182 | { |
||
183 | foreach (string enabledMethod in enabledMethods.Split('|')) |
||
184 | { |
||
185 | m_httpServer.AddXmlRPCHandler(enabledMethod, availableMethods[enabledMethod], false); |
||
186 | } |
||
187 | } |
||
188 | } |
||
189 | } |
||
190 | catch (NullReferenceException) |
||
191 | { |
||
192 | // Ignore. |
||
193 | } |
||
194 | } |
||
195 | |||
196 | public void PostInitialise() |
||
197 | { |
||
198 | if (!CreateDefaultAvatars()) |
||
199 | { |
||
200 | m_log.Info("[RADMIN]: Default avatars not loaded"); |
||
201 | } |
||
202 | } |
||
203 | |||
204 | /// <summary> |
||
205 | /// Invoke an XmlRpc method with the standard actions (password check, etc.) |
||
206 | /// </summary> |
||
207 | /// <param name="method"></param> |
||
208 | private XmlRpcResponse InvokeXmlRpcMethod( |
||
209 | XmlRpcRequest request, IPEndPoint remoteClient, Action<XmlRpcRequest, XmlRpcResponse, IPEndPoint> method) |
||
210 | { |
||
211 | XmlRpcResponse response = new XmlRpcResponse(); |
||
212 | Hashtable responseData = new Hashtable(); |
||
213 | response.Value = responseData; |
||
214 | |||
215 | try |
||
216 | { |
||
217 | Hashtable requestData = (Hashtable) request.Params[0]; |
||
218 | |||
219 | CheckStringParameters(requestData, responseData, new string[] {"password"}); |
||
220 | |||
221 | FailIfRemoteAdminNotAllowed((string)requestData["password"], responseData, remoteClient.Address.ToString()); |
||
222 | |||
223 | method(request, response, remoteClient); |
||
224 | } |
||
225 | catch (Exception e) |
||
226 | { |
||
227 | m_log.ErrorFormat( |
||
228 | "[RADMIN]: Method {0} failed. Exception {1}{2}", request.MethodName, e.Message, e.StackTrace); |
||
229 | |||
230 | responseData["success"] = false; |
||
231 | responseData["error"] = e.Message; |
||
232 | } |
||
233 | |||
234 | return response; |
||
235 | } |
||
236 | |||
237 | private void FailIfRemoteAdminNotAllowed(string password, Hashtable responseData, string check_ip_address) |
||
238 | { |
||
239 | if (m_accessIP.Count > 0 && !m_accessIP.Contains(check_ip_address)) |
||
240 | { |
||
241 | m_log.WarnFormat("[RADMIN]: Unauthorized access blocked from IP {0}", check_ip_address); |
||
242 | responseData["accepted"] = false; |
||
243 | throw new Exception("not authorized"); |
||
244 | } |
||
245 | |||
246 | if (m_requiredPassword != String.Empty && password != m_requiredPassword) |
||
247 | { |
||
248 | m_log.WarnFormat("[RADMIN]: Wrong password, blocked access from IP {0}", check_ip_address); |
||
249 | responseData["accepted"] = false; |
||
250 | throw new Exception("wrong password"); |
||
251 | } |
||
252 | } |
||
253 | |||
254 | private void XmlRpcRestartMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
255 | { |
||
256 | Hashtable responseData = (Hashtable)response.Value; |
||
257 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
258 | |||
259 | try |
||
260 | { |
||
261 | m_log.Info("[RADMIN]: Request to restart Region."); |
||
262 | |||
263 | CheckRegionParams(requestData, responseData); |
||
264 | |||
265 | Scene rebootedScene = null; |
||
266 | GetSceneFromRegionParams(requestData, responseData, out rebootedScene); |
||
267 | |||
268 | responseData["success"] = false; |
||
269 | responseData["accepted"] = true; |
||
270 | responseData["rebooting"] = true; |
||
271 | |||
272 | IRestartModule restartModule = rebootedScene.RequestModuleInterface<IRestartModule>(); |
||
273 | if (restartModule != null) |
||
274 | { |
||
275 | List<int> times = new List<int> { 30, 15 }; |
||
276 | |||
277 | restartModule.ScheduleRestart(UUID.Zero, "Region will restart in {0}", times.ToArray(), true); |
||
278 | responseData["success"] = true; |
||
279 | } |
||
280 | } |
||
281 | catch (Exception e) |
||
282 | { |
||
283 | // m_log.ErrorFormat("[RADMIN]: Restart region: failed: {0} {1}", e.Message, e.StackTrace); |
||
284 | responseData["rebooting"] = false; |
||
285 | |||
286 | throw e; |
||
287 | } |
||
288 | |||
289 | m_log.Info("[RADMIN]: Restart Region request complete"); |
||
290 | } |
||
291 | |||
292 | private void XmlRpcAlertMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
293 | { |
||
294 | m_log.Info("[RADMIN]: Alert request started"); |
||
295 | |||
296 | Hashtable responseData = (Hashtable)response.Value; |
||
297 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
298 | |||
299 | string message = (string) requestData["message"]; |
||
300 | m_log.InfoFormat("[RADMIN]: Broadcasting: {0}", message); |
||
301 | |||
302 | responseData["accepted"] = true; |
||
303 | responseData["success"] = true; |
||
304 | |||
305 | m_application.SceneManager.ForEachScene( |
||
306 | delegate(Scene scene) |
||
307 | { |
||
308 | IDialogModule dialogModule = scene.RequestModuleInterface<IDialogModule>(); |
||
309 | if (dialogModule != null) |
||
310 | dialogModule.SendGeneralAlert(message); |
||
311 | }); |
||
312 | |||
313 | m_log.Info("[RADMIN]: Alert request complete"); |
||
314 | } |
||
315 | |||
316 | private void XmlRpcLoadHeightmapMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
317 | { |
||
318 | m_log.Info("[RADMIN]: Load height maps request started"); |
||
319 | |||
320 | Hashtable responseData = (Hashtable)response.Value; |
||
321 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
322 | |||
323 | // m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}", request); |
||
324 | // foreach (string k in requestData.Keys) |
||
325 | // { |
||
326 | // m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}: >{1}< {2}", |
||
327 | // k, (string)requestData[k], ((string)requestData[k]).Length); |
||
328 | // } |
||
329 | |||
330 | CheckStringParameters(requestData, responseData, new string[] { "filename" }); |
||
331 | CheckRegionParams(requestData, responseData); |
||
332 | |||
333 | Scene scene = null; |
||
334 | GetSceneFromRegionParams(requestData, responseData, out scene); |
||
335 | |||
336 | if (scene != null) |
||
337 | { |
||
338 | string file = (string)requestData["filename"]; |
||
339 | |||
340 | responseData["accepted"] = true; |
||
341 | |||
342 | LoadHeightmap(file, scene.RegionInfo.RegionID); |
||
343 | |||
344 | responseData["success"] = true; |
||
345 | } |
||
346 | else |
||
347 | { |
||
348 | responseData["success"] = false; |
||
349 | } |
||
350 | |||
351 | m_log.Info("[RADMIN]: Load height maps request complete"); |
||
352 | } |
||
353 | |||
354 | private void XmlRpcSaveHeightmapMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
355 | { |
||
356 | m_log.Info("[RADMIN]: Save height maps request started"); |
||
357 | |||
358 | Hashtable responseData = (Hashtable)response.Value; |
||
359 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
360 | |||
361 | // m_log.DebugFormat("[RADMIN]: Save Terrain: XmlRpc {0}", request.ToString()); |
||
362 | |||
363 | CheckStringParameters(requestData, responseData, new string[] { "filename" }); |
||
364 | CheckRegionParams(requestData, responseData); |
||
365 | |||
366 | Scene scene = null; |
||
367 | GetSceneFromRegionParams(requestData, responseData, out scene); |
||
368 | |||
369 | if (scene != null) |
||
370 | { |
||
371 | string file = (string)requestData["filename"]; |
||
372 | m_log.InfoFormat("[RADMIN]: Terrain Saving: {0}", file); |
||
373 | |||
374 | responseData["accepted"] = true; |
||
375 | |||
376 | ITerrainModule terrainModule = scene.RequestModuleInterface<ITerrainModule>(); |
||
377 | if (null == terrainModule) throw new Exception("terrain module not available"); |
||
378 | |||
379 | terrainModule.SaveToFile(file); |
||
380 | |||
381 | responseData["success"] = true; |
||
382 | } |
||
383 | else |
||
384 | { |
||
385 | responseData["success"] = false; |
||
386 | } |
||
387 | |||
388 | m_log.Info("[RADMIN]: Save height maps request complete"); |
||
389 | } |
||
390 | |||
391 | private void XmlRpcShutdownMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
392 | { |
||
393 | m_log.Info("[RADMIN]: Received Shutdown Administrator Request"); |
||
394 | |||
395 | Hashtable responseData = (Hashtable)response.Value; |
||
396 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
397 | |||
398 | responseData["accepted"] = true; |
||
399 | response.Value = responseData; |
||
400 | |||
401 | int timeout = 2000; |
||
402 | string message; |
||
403 | |||
404 | if (requestData.ContainsKey("shutdown") |
||
405 | && ((string) requestData["shutdown"] == "delayed") |
||
406 | && requestData.ContainsKey("milliseconds")) |
||
407 | { |
||
408 | timeout = Int32.Parse(requestData["milliseconds"].ToString()); |
||
409 | |||
410 | message |
||
411 | = "Region is going down in " + ((int) (timeout/1000)).ToString() |
||
412 | + " second(s). Please save what you are doing and log out."; |
||
413 | } |
||
414 | else |
||
415 | { |
||
416 | message = "Region is going down now."; |
||
417 | } |
||
418 | |||
419 | m_application.SceneManager.ForEachScene( |
||
420 | delegate(Scene scene) |
||
421 | { |
||
422 | IDialogModule dialogModule = scene.RequestModuleInterface<IDialogModule>(); |
||
423 | if (dialogModule != null) |
||
424 | dialogModule.SendGeneralAlert(message); |
||
425 | }); |
||
426 | |||
427 | // Perform shutdown |
||
428 | System.Timers.Timer shutdownTimer = new System.Timers.Timer(timeout); // Wait before firing |
||
429 | shutdownTimer.AutoReset = false; |
||
430 | shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed); |
||
431 | lock (shutdownTimer) |
||
432 | { |
||
433 | shutdownTimer.Start(); |
||
434 | } |
||
435 | |||
436 | responseData["success"] = true; |
||
437 | |||
438 | m_log.Info("[RADMIN]: Shutdown Administrator Request complete"); |
||
439 | } |
||
440 | |||
441 | private void shutdownTimer_Elapsed(object sender, ElapsedEventArgs e) |
||
442 | { |
||
443 | m_application.Shutdown(); |
||
444 | } |
||
445 | |||
446 | /// <summary> |
||
447 | /// Create a new region. |
||
448 | /// <summary> |
||
449 | /// <param name="request">incoming XML RPC request</param> |
||
450 | /// <remarks> |
||
451 | /// XmlRpcCreateRegionMethod takes the following XMLRPC |
||
452 | /// parameters |
||
453 | /// <list type="table"> |
||
454 | /// <listheader><term>parameter name</term><description>description</description></listheader> |
||
455 | /// <item><term>password</term> |
||
456 | /// <description>admin password as set in OpenSim.ini</description></item> |
||
457 | /// <item><term>region_name</term> |
||
458 | /// <description>desired region name</description></item> |
||
459 | /// <item><term>region_id</term> |
||
460 | /// <description>(optional) desired region UUID</description></item> |
||
461 | /// <item><term>region_x</term> |
||
462 | /// <description>desired region X coordinate (integer)</description></item> |
||
463 | /// <item><term>region_y</term> |
||
464 | /// <description>desired region Y coordinate (integer)</description></item> |
||
465 | /// <item><term>estate_owner_first</term> |
||
466 | /// <description>firstname of estate owner (formerly region master) |
||
467 | /// (required if new estate is being created, optional otherwise)</description></item> |
||
468 | /// <item><term>estate_owner_last</term> |
||
469 | /// <description>lastname of estate owner (formerly region master) |
||
470 | /// (required if new estate is being created, optional otherwise)</description></item> |
||
471 | /// <item><term>estate_owner_uuid</term> |
||
472 | /// <description>explicit UUID to use for estate owner (optional)</description></item> |
||
473 | /// <item><term>listen_ip</term> |
||
474 | /// <description>internal IP address (dotted quad)</description></item> |
||
475 | /// <item><term>listen_port</term> |
||
476 | /// <description>internal port (integer)</description></item> |
||
477 | /// <item><term>external_address</term> |
||
478 | /// <description>external IP address</description></item> |
||
479 | /// <item><term>persist</term> |
||
480 | /// <description>if true, persist the region info |
||
481 | /// ('true' or 'false')</description></item> |
||
482 | /// <item><term>public</term> |
||
483 | /// <description>if true, the region is public |
||
484 | /// ('true' or 'false') (optional, default: true)</description></item> |
||
485 | /// <item><term>enable_voice</term> |
||
486 | /// <description>if true, enable voice on all parcels, |
||
487 | /// ('true' or 'false') (optional, default: false)</description></item> |
||
488 | /// <item><term>estate_name</term> |
||
489 | /// <description>the name of the estate to join (or to create if it doesn't |
||
490 | /// already exist)</description></item> |
||
491 | /// <item><term>region_file</term> |
||
492 | /// <description>The name of the file to persist the region specifications to. |
||
493 | /// If omitted, the region_file_template setting from OpenSim.ini will be used. (optional)</description></item> |
||
494 | /// </list> |
||
495 | /// |
||
496 | /// XmlRpcCreateRegionMethod returns |
||
497 | /// <list type="table"> |
||
498 | /// <listheader><term>name</term><description>description</description></listheader> |
||
499 | /// <item><term>success</term> |
||
500 | /// <description>true or false</description></item> |
||
501 | /// <item><term>error</term> |
||
502 | /// <description>error message if success is false</description></item> |
||
503 | /// <item><term>region_uuid</term> |
||
504 | /// <description>UUID of the newly created region</description></item> |
||
505 | /// <item><term>region_name</term> |
||
506 | /// <description>name of the newly created region</description></item> |
||
507 | /// </list> |
||
508 | /// </remarks> |
||
509 | private void XmlRpcCreateRegionMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
510 | { |
||
511 | m_log.Info("[RADMIN]: CreateRegion: new request"); |
||
512 | |||
513 | Hashtable responseData = (Hashtable)response.Value; |
||
514 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
515 | |||
516 | lock (m_requestLock) |
||
517 | { |
||
518 | int m_regionLimit = m_config.GetInt("region_limit", 0); |
||
519 | bool m_enableVoiceForNewRegions = m_config.GetBoolean("create_region_enable_voice", false); |
||
520 | bool m_publicAccess = m_config.GetBoolean("create_region_public", true); |
||
521 | |||
522 | CheckStringParameters(requestData, responseData, new string[] |
||
523 | { |
||
524 | "region_name", |
||
525 | "listen_ip", "external_address", |
||
526 | "estate_name" |
||
527 | }); |
||
528 | CheckIntegerParams(requestData, responseData, new string[] {"region_x", "region_y", "listen_port"}); |
||
529 | |||
530 | // check whether we still have space left (iff we are using limits) |
||
531 | if (m_regionLimit != 0 && m_application.SceneManager.Scenes.Count >= m_regionLimit) |
||
532 | throw new Exception(String.Format("cannot instantiate new region, server capacity {0} already reached; delete regions first", |
||
533 | m_regionLimit)); |
||
534 | // extract or generate region ID now |
||
535 | Scene scene = null; |
||
536 | UUID regionID = UUID.Zero; |
||
537 | if (requestData.ContainsKey("region_id") && |
||
538 | !String.IsNullOrEmpty((string) requestData["region_id"])) |
||
539 | { |
||
540 | regionID = (UUID) (string) requestData["region_id"]; |
||
541 | if (m_application.SceneManager.TryGetScene(regionID, out scene)) |
||
542 | throw new Exception( |
||
543 | String.Format("region UUID already in use by region {0}, UUID {1}, <{2},{3}>", |
||
544 | scene.RegionInfo.RegionName, scene.RegionInfo.RegionID, |
||
545 | scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY)); |
||
546 | } |
||
547 | else |
||
548 | { |
||
549 | regionID = UUID.Random(); |
||
550 | m_log.DebugFormat("[RADMIN] CreateRegion: new region UUID {0}", regionID); |
||
551 | } |
||
552 | |||
553 | // create volatile or persistent region info |
||
554 | RegionInfo region = new RegionInfo(); |
||
555 | |||
556 | region.RegionID = regionID; |
||
557 | region.originRegionID = regionID; |
||
558 | region.RegionName = (string) requestData["region_name"]; |
||
559 | region.RegionLocX = Convert.ToUInt32(requestData["region_x"]); |
||
560 | region.RegionLocY = Convert.ToUInt32(requestData["region_y"]); |
||
561 | |||
562 | // check for collisions: region name, region UUID, |
||
563 | // region location |
||
564 | if (m_application.SceneManager.TryGetScene(region.RegionName, out scene)) |
||
565 | throw new Exception( |
||
566 | String.Format("region name already in use by region {0}, UUID {1}, <{2},{3}>", |
||
567 | scene.RegionInfo.RegionName, scene.RegionInfo.RegionID, |
||
568 | scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY)); |
||
569 | |||
570 | if (m_application.SceneManager.TryGetScene(region.RegionLocX, region.RegionLocY, out scene)) |
||
571 | throw new Exception( |
||
572 | String.Format("region location <{0},{1}> already in use by region {2}, UUID {3}, <{4},{5}>", |
||
573 | region.RegionLocX, region.RegionLocY, |
||
574 | scene.RegionInfo.RegionName, scene.RegionInfo.RegionID, |
||
575 | scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY)); |
||
576 | |||
577 | region.InternalEndPoint = |
||
578 | new IPEndPoint(IPAddress.Parse((string) requestData["listen_ip"]), 0); |
||
579 | |||
580 | region.InternalEndPoint.Port = Convert.ToInt32(requestData["listen_port"]); |
||
581 | if (0 == region.InternalEndPoint.Port) throw new Exception("listen_port is 0"); |
||
582 | if (m_application.SceneManager.TryGetScene(region.InternalEndPoint, out scene)) |
||
583 | throw new Exception( |
||
584 | String.Format( |
||
585 | "region internal IP {0} and port {1} already in use by region {2}, UUID {3}, <{4},{5}>", |
||
586 | region.InternalEndPoint.Address, |
||
587 | region.InternalEndPoint.Port, |
||
588 | scene.RegionInfo.RegionName, scene.RegionInfo.RegionID, |
||
589 | scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY)); |
||
590 | |||
591 | region.ExternalHostName = (string) requestData["external_address"]; |
||
592 | |||
593 | bool persist = Convert.ToBoolean(requestData["persist"]); |
||
594 | if (persist) |
||
595 | { |
||
596 | // default place for region configuration files is in the |
||
597 | // Regions directory of the config dir (aka /bin) |
||
598 | string regionConfigPath = Path.Combine(Util.configDir(), "Regions"); |
||
599 | try |
||
600 | { |
||
601 | // OpenSim.ini can specify a different regions dir |
||
602 | IConfig startupConfig = (IConfig) m_configSource.Configs["Startup"]; |
||
603 | regionConfigPath = startupConfig.GetString("regionload_regionsdir", regionConfigPath).Trim(); |
||
604 | } |
||
605 | catch (Exception) |
||
606 | { |
||
607 | // No INI setting recorded. |
||
608 | } |
||
609 | |||
610 | string regionIniPath; |
||
611 | |||
612 | if (requestData.Contains("region_file")) |
||
613 | { |
||
614 | // Make sure that the file to be created is in a subdirectory of the region storage directory. |
||
615 | string requestedFilePath = Path.Combine(regionConfigPath, (string) requestData["region_file"]); |
||
616 | string requestedDirectory = Path.GetDirectoryName(Path.GetFullPath(requestedFilePath)); |
||
617 | if (requestedDirectory.StartsWith(Path.GetFullPath(regionConfigPath))) |
||
618 | regionIniPath = requestedFilePath; |
||
619 | else |
||
620 | throw new Exception("Invalid location for region file."); |
||
621 | } |
||
622 | else |
||
623 | { |
||
624 | regionIniPath = Path.Combine(regionConfigPath, |
||
625 | String.Format( |
||
626 | m_config.GetString("region_file_template", |
||
627 | "{0}x{1}-{2}.ini"), |
||
628 | region.RegionLocX.ToString(), |
||
629 | region.RegionLocY.ToString(), |
||
630 | regionID.ToString(), |
||
631 | region.InternalEndPoint.Port.ToString(), |
||
632 | region.RegionName.Replace(" ", "_").Replace(":", "_"). |
||
633 | Replace("/", "_"))); |
||
634 | } |
||
635 | |||
636 | m_log.DebugFormat("[RADMIN] CreateRegion: persisting region {0} to {1}", |
||
637 | region.RegionID, regionIniPath); |
||
638 | region.SaveRegionToFile("dynamic region", regionIniPath); |
||
639 | } |
||
640 | else |
||
641 | { |
||
642 | region.Persistent = false; |
||
643 | } |
||
644 | |||
645 | // Set the estate |
||
646 | |||
647 | // Check for an existing estate |
||
648 | List<int> estateIDs = m_application.EstateDataService.GetEstates((string) requestData["estate_name"]); |
||
649 | if (estateIDs.Count < 1) |
||
650 | { |
||
651 | UUID userID = UUID.Zero; |
||
652 | if (requestData.ContainsKey("estate_owner_uuid")) |
||
653 | { |
||
654 | // ok, client wants us to use an explicit UUID |
||
655 | // regardless of what the avatar name provided |
||
656 | userID = new UUID((string) requestData["estate_owner_uuid"]); |
||
657 | |||
658 | // Check that the specified user exists |
||
659 | Scene currentOrFirst = m_application.SceneManager.CurrentOrFirstScene; |
||
660 | IUserAccountService accountService = currentOrFirst.UserAccountService; |
||
661 | UserAccount user = accountService.GetUserAccount(currentOrFirst.RegionInfo.ScopeID, userID); |
||
662 | |||
663 | if (user == null) |
||
664 | throw new Exception("Specified user was not found."); |
||
665 | } |
||
666 | else if (requestData.ContainsKey("estate_owner_first") & requestData.ContainsKey("estate_owner_last")) |
||
667 | { |
||
668 | // We need to look up the UUID for the avatar with the provided name. |
||
669 | string ownerFirst = (string) requestData["estate_owner_first"]; |
||
670 | string ownerLast = (string) requestData["estate_owner_last"]; |
||
671 | |||
672 | Scene currentOrFirst = m_application.SceneManager.CurrentOrFirstScene; |
||
673 | IUserAccountService accountService = currentOrFirst.UserAccountService; |
||
674 | UserAccount user = accountService.GetUserAccount(currentOrFirst.RegionInfo.ScopeID, |
||
675 | ownerFirst, ownerLast); |
||
676 | |||
677 | // Check that the specified user exists |
||
678 | if (user == null) |
||
679 | throw new Exception("Specified user was not found."); |
||
680 | |||
681 | userID = user.PrincipalID; |
||
682 | } |
||
683 | else |
||
684 | { |
||
685 | throw new Exception("Estate owner details not provided."); |
||
686 | } |
||
687 | |||
688 | // Create a new estate with the name provided |
||
689 | region.EstateSettings = m_application.EstateDataService.CreateNewEstate(); |
||
690 | |||
691 | region.EstateSettings.EstateName = (string) requestData["estate_name"]; |
||
692 | region.EstateSettings.EstateOwner = userID; |
||
693 | // Persistence does not seem to effect the need to save a new estate |
||
694 | region.EstateSettings.Save(); |
||
695 | |||
696 | if (!m_application.EstateDataService.LinkRegion(region.RegionID, (int) region.EstateSettings.EstateID)) |
||
697 | throw new Exception("Failed to join estate."); |
||
698 | } |
||
699 | else |
||
700 | { |
||
701 | int estateID = estateIDs[0]; |
||
702 | |||
703 | region.EstateSettings = m_application.EstateDataService.LoadEstateSettings(region.RegionID, false); |
||
704 | |||
705 | if (region.EstateSettings.EstateID != estateID) |
||
706 | { |
||
707 | // The region is already part of an estate, but not the one we want. |
||
708 | region.EstateSettings = m_application.EstateDataService.LoadEstateSettings(estateID); |
||
709 | |||
710 | if (!m_application.EstateDataService.LinkRegion(region.RegionID, estateID)) |
||
711 | throw new Exception("Failed to join estate."); |
||
712 | } |
||
713 | } |
||
714 | |||
715 | // Create the region and perform any initial initialization |
||
716 | |||
717 | IScene newScene; |
||
718 | m_application.CreateRegion(region, out newScene); |
||
719 | newScene.Start(); |
||
720 | |||
721 | // If an access specification was provided, use it. |
||
722 | // Otherwise accept the default. |
||
723 | newScene.RegionInfo.EstateSettings.PublicAccess = GetBoolean(requestData, "public", m_publicAccess); |
||
724 | newScene.RegionInfo.EstateSettings.Save(); |
||
725 | |||
726 | // enable voice on newly created region if |
||
727 | // requested by either the XmlRpc request or the |
||
728 | // configuration |
||
729 | if (GetBoolean(requestData, "enable_voice", m_enableVoiceForNewRegions)) |
||
730 | { |
||
731 | List<ILandObject> parcels = ((Scene)newScene).LandChannel.AllParcels(); |
||
732 | |||
733 | foreach (ILandObject parcel in parcels) |
||
734 | { |
||
735 | parcel.LandData.Flags |= (uint) ParcelFlags.AllowVoiceChat; |
||
736 | parcel.LandData.Flags |= (uint) ParcelFlags.UseEstateVoiceChan; |
||
737 | ((Scene)newScene).LandChannel.UpdateLandObject(parcel.LandData.LocalID, parcel.LandData); |
||
738 | } |
||
739 | } |
||
740 | |||
741 | //Load Heightmap if specified to new region |
||
742 | if (requestData.Contains("heightmap_file")) |
||
743 | { |
||
744 | LoadHeightmap((string)requestData["heightmap_file"], region.RegionID); |
||
745 | } |
||
746 | |||
747 | responseData["success"] = true; |
||
748 | responseData["region_name"] = region.RegionName; |
||
749 | responseData["region_id"] = region.RegionID.ToString(); |
||
750 | |||
751 | m_log.Info("[RADMIN]: CreateRegion: request complete"); |
||
752 | } |
||
753 | } |
||
754 | |||
755 | /// <summary> |
||
756 | /// Delete a new region. |
||
757 | /// <summary> |
||
758 | /// <param name="request">incoming XML RPC request</param> |
||
759 | /// <remarks> |
||
760 | /// XmlRpcDeleteRegionMethod takes the following XMLRPC |
||
761 | /// parameters |
||
762 | /// <list type="table"> |
||
763 | /// <listheader><term>parameter name</term><description>description</description></listheader> |
||
764 | /// <item><term>password</term> |
||
765 | /// <description>admin password as set in OpenSim.ini</description></item> |
||
766 | /// <item><term>region_name</term> |
||
767 | /// <description>desired region name</description></item> |
||
768 | /// <item><term>region_id</term> |
||
769 | /// <description>(optional) desired region UUID</description></item> |
||
770 | /// </list> |
||
771 | /// |
||
772 | /// XmlRpcDeleteRegionMethod returns |
||
773 | /// <list type="table"> |
||
774 | /// <listheader><term>name</term><description>description</description></listheader> |
||
775 | /// <item><term>success</term> |
||
776 | /// <description>true or false</description></item> |
||
777 | /// <item><term>error</term> |
||
778 | /// <description>error message if success is false</description></item> |
||
779 | /// </list> |
||
780 | /// </remarks> |
||
781 | private void XmlRpcDeleteRegionMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
782 | { |
||
783 | m_log.Info("[RADMIN]: DeleteRegion: new request"); |
||
784 | |||
785 | Hashtable responseData = (Hashtable)response.Value; |
||
786 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
787 | |||
788 | lock (m_requestLock) |
||
789 | { |
||
790 | CheckStringParameters(requestData, responseData, new string[] {"region_name"}); |
||
791 | CheckRegionParams(requestData, responseData); |
||
792 | |||
793 | Scene scene = null; |
||
794 | GetSceneFromRegionParams(requestData, responseData, out scene); |
||
795 | |||
796 | m_application.RemoveRegion(scene, true); |
||
797 | |||
798 | responseData["success"] = true; |
||
799 | responseData["region_name"] = scene.RegionInfo.RegionName; |
||
800 | responseData["region_id"] = scene.RegionInfo.RegionID; |
||
801 | |||
802 | m_log.Info("[RADMIN]: DeleteRegion: request complete"); |
||
803 | } |
||
804 | } |
||
805 | |||
806 | /// <summary> |
||
807 | /// Close a region. |
||
808 | /// <summary> |
||
809 | /// <param name="request">incoming XML RPC request</param> |
||
810 | /// <remarks> |
||
811 | /// XmlRpcCloseRegionMethod takes the following XMLRPC |
||
812 | /// parameters |
||
813 | /// <list type="table"> |
||
814 | /// <listheader><term>parameter name</term><description>description</description></listheader> |
||
815 | /// <item><term>password</term> |
||
816 | /// <description>admin password as set in OpenSim.ini</description></item> |
||
817 | /// <item><term>region_name</term> |
||
818 | /// <description>desired region name</description></item> |
||
819 | /// <item><term>region_id</term> |
||
820 | /// <description>(optional) desired region UUID</description></item> |
||
821 | /// </list> |
||
822 | /// |
||
823 | /// XmlRpcShutdownRegionMethod returns |
||
824 | /// <list type="table"> |
||
825 | /// <listheader><term>name</term><description>description</description></listheader> |
||
826 | /// <item><term>success</term> |
||
827 | /// <description>true or false</description></item> |
||
828 | /// <item><term>region_name</term> |
||
829 | /// <description>the region name if success is true</description></item> |
||
830 | /// <item><term>error</term> |
||
831 | /// <description>error message if success is false</description></item> |
||
832 | /// </list> |
||
833 | /// </remarks> |
||
834 | private void XmlRpcCloseRegionMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
835 | { |
||
836 | m_log.Info("[RADMIN]: CloseRegion: new request"); |
||
837 | |||
838 | Hashtable responseData = (Hashtable)response.Value; |
||
839 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
840 | |||
841 | lock (m_requestLock) |
||
842 | { |
||
843 | CheckRegionParams(requestData, responseData); |
||
844 | |||
845 | Scene scene = null; |
||
846 | GetSceneFromRegionParams(requestData, responseData, out scene); |
||
847 | |||
848 | m_application.CloseRegion(scene); |
||
849 | |||
850 | responseData["success"] = true; |
||
851 | responseData["region_name"] = scene.RegionInfo.RegionName; |
||
852 | responseData["region_id"] = scene.RegionInfo.RegionID; |
||
853 | |||
854 | response.Value = responseData; |
||
855 | |||
856 | m_log.Info("[RADMIN]: CloseRegion: request complete"); |
||
857 | } |
||
858 | } |
||
859 | |||
860 | /// <summary> |
||
861 | /// Change characteristics of an existing region. |
||
862 | /// <summary> |
||
863 | /// <param name="request">incoming XML RPC request</param> |
||
864 | /// <remarks> |
||
865 | /// XmlRpcModifyRegionMethod takes the following XMLRPC |
||
866 | /// parameters |
||
867 | /// <list type="table"> |
||
868 | /// <listheader><term>parameter name</term><description>description</description></listheader> |
||
869 | /// <item><term>password</term> |
||
870 | /// <description>admin password as set in OpenSim.ini</description></item> |
||
871 | /// <item><term>region_name</term> |
||
872 | /// <description>desired region name</description></item> |
||
873 | /// <item><term>region_id</term> |
||
874 | /// <description>(optional) desired region UUID</description></item> |
||
875 | /// <item><term>public</term> |
||
876 | /// <description>if true, set the region to public |
||
877 | /// ('true' or 'false'), else to private</description></item> |
||
878 | /// <item><term>enable_voice</term> |
||
879 | /// <description>if true, enable voice on all parcels of |
||
880 | /// the region, else disable</description></item> |
||
881 | /// </list> |
||
882 | /// |
||
883 | /// XmlRpcModifyRegionMethod returns |
||
884 | /// <list type="table"> |
||
885 | /// <listheader><term>name</term><description>description</description></listheader> |
||
886 | /// <item><term>success</term> |
||
887 | /// <description>true or false</description></item> |
||
888 | /// <item><term>error</term> |
||
889 | /// <description>error message if success is false</description></item> |
||
890 | /// </list> |
||
891 | /// </remarks> |
||
892 | private void XmlRpcModifyRegionMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
893 | { |
||
894 | m_log.Info("[RADMIN]: ModifyRegion: new request"); |
||
895 | |||
896 | Hashtable responseData = (Hashtable)response.Value; |
||
897 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
898 | |||
899 | lock (m_requestLock) |
||
900 | { |
||
901 | CheckRegionParams(requestData, responseData); |
||
902 | |||
903 | Scene scene = null; |
||
904 | GetSceneFromRegionParams(requestData, responseData, out scene); |
||
905 | |||
906 | // Modify access |
||
907 | scene.RegionInfo.EstateSettings.PublicAccess = |
||
908 | GetBoolean(requestData,"public", scene.RegionInfo.EstateSettings.PublicAccess); |
||
909 | if (scene.RegionInfo.Persistent) |
||
910 | scene.RegionInfo.EstateSettings.Save(); |
||
911 | |||
912 | if (requestData.ContainsKey("enable_voice")) |
||
913 | { |
||
914 | bool enableVoice = GetBoolean(requestData, "enable_voice", true); |
||
915 | List<ILandObject> parcels = ((Scene)scene).LandChannel.AllParcels(); |
||
916 | |||
917 | foreach (ILandObject parcel in parcels) |
||
918 | { |
||
919 | if (enableVoice) |
||
920 | { |
||
921 | parcel.LandData.Flags |= (uint)ParcelFlags.AllowVoiceChat; |
||
922 | parcel.LandData.Flags |= (uint)ParcelFlags.UseEstateVoiceChan; |
||
923 | } |
||
924 | else |
||
925 | { |
||
926 | parcel.LandData.Flags &= ~(uint)ParcelFlags.AllowVoiceChat; |
||
927 | parcel.LandData.Flags &= ~(uint)ParcelFlags.UseEstateVoiceChan; |
||
928 | } |
||
929 | scene.LandChannel.UpdateLandObject(parcel.LandData.LocalID, parcel.LandData); |
||
930 | } |
||
931 | } |
||
932 | |||
933 | responseData["success"] = true; |
||
934 | responseData["region_name"] = scene.RegionInfo.RegionName; |
||
935 | responseData["region_id"] = scene.RegionInfo.RegionID; |
||
936 | |||
937 | m_log.Info("[RADMIN]: ModifyRegion: request complete"); |
||
938 | } |
||
939 | } |
||
940 | |||
941 | /// <summary> |
||
942 | /// Create a new user account. |
||
943 | /// <summary> |
||
944 | /// <param name="request">incoming XML RPC request</param> |
||
945 | /// <remarks> |
||
946 | /// XmlRpcCreateUserMethod takes the following XMLRPC |
||
947 | /// parameters |
||
948 | /// <list type="table"> |
||
949 | /// <listheader><term>parameter name</term><description>description</description></listheader> |
||
950 | /// <item><term>password</term> |
||
951 | /// <description>admin password as set in OpenSim.ini</description></item> |
||
952 | /// <item><term>user_firstname</term> |
||
953 | /// <description>avatar's first name</description></item> |
||
954 | /// <item><term>user_lastname</term> |
||
955 | /// <description>avatar's last name</description></item> |
||
956 | /// <item><term>user_password</term> |
||
957 | /// <description>avatar's password</description></item> |
||
958 | /// <item><term>user_email</term> |
||
959 | /// <description>email of the avatar's owner (optional)</description></item> |
||
960 | /// <item><term>start_region_x</term> |
||
961 | /// <description>avatar's start region coordinates, X value</description></item> |
||
962 | /// <item><term>start_region_y</term> |
||
963 | /// <description>avatar's start region coordinates, Y value</description></item> |
||
964 | /// </list> |
||
965 | /// |
||
966 | /// XmlRpcCreateUserMethod returns |
||
967 | /// <list type="table"> |
||
968 | /// <listheader><term>name</term><description>description</description></listheader> |
||
969 | /// <item><term>success</term> |
||
970 | /// <description>true or false</description></item> |
||
971 | /// <item><term>error</term> |
||
972 | /// <description>error message if success is false</description></item> |
||
973 | /// <item><term>avatar_uuid</term> |
||
974 | /// <description>UUID of the newly created avatar |
||
975 | /// account; UUID.Zero if failed. |
||
976 | /// </description></item> |
||
977 | /// </list> |
||
978 | /// </remarks> |
||
979 | private void XmlRpcCreateUserMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
980 | { |
||
981 | m_log.Info("[RADMIN]: CreateUser: new request"); |
||
982 | |||
983 | Hashtable responseData = (Hashtable)response.Value; |
||
984 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
985 | |||
986 | lock (m_requestLock) |
||
987 | { |
||
988 | try |
||
989 | { |
||
990 | // check completeness |
||
991 | CheckStringParameters(requestData, responseData, new string[] |
||
992 | { |
||
993 | "user_firstname", |
||
994 | "user_lastname", "user_password", |
||
995 | }); |
||
996 | CheckIntegerParams(requestData, responseData, new string[] {"start_region_x", "start_region_y"}); |
||
997 | |||
998 | // do the job |
||
999 | string firstName = (string) requestData["user_firstname"]; |
||
1000 | string lastName = (string) requestData["user_lastname"]; |
||
1001 | string password = (string) requestData["user_password"]; |
||
1002 | |||
1003 | uint regionXLocation = Convert.ToUInt32(requestData["start_region_x"]); |
||
1004 | uint regionYLocation = Convert.ToUInt32(requestData["start_region_y"]); |
||
1005 | |||
1006 | string email = ""; // empty string for email |
||
1007 | if (requestData.Contains("user_email")) |
||
1008 | email = (string)requestData["user_email"]; |
||
1009 | |||
1010 | Scene scene = m_application.SceneManager.CurrentOrFirstScene; |
||
1011 | UUID scopeID = scene.RegionInfo.ScopeID; |
||
1012 | |||
1013 | UserAccount account = CreateUser(scopeID, firstName, lastName, password, email); |
||
1014 | |||
1015 | if (null == account) |
||
1016 | throw new Exception(String.Format("failed to create new user {0} {1}", |
||
1017 | firstName, lastName)); |
||
1018 | |||
1019 | // Set home position |
||
1020 | |||
1021 | GridRegion home = scene.GridService.GetRegionByPosition(scopeID, |
||
1022 | (int)(regionXLocation * Constants.RegionSize), (int)(regionYLocation * Constants.RegionSize)); |
||
1023 | if (null == home) |
||
1024 | { |
||
1025 | m_log.WarnFormat("[RADMIN]: Unable to set home region for newly created user account {0} {1}", firstName, lastName); |
||
1026 | } |
||
1027 | else |
||
1028 | { |
||
1029 | scene.GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0)); |
||
1030 | m_log.DebugFormat("[RADMIN]: Set home region {0} for updated user account {1} {2}", home.RegionID, firstName, lastName); |
||
1031 | } |
||
1032 | |||
1033 | // Establish the avatar's initial appearance |
||
1034 | |||
1035 | UpdateUserAppearance(responseData, requestData, account.PrincipalID); |
||
1036 | |||
1037 | responseData["success"] = true; |
||
1038 | responseData["avatar_uuid"] = account.PrincipalID.ToString(); |
||
1039 | |||
1040 | m_log.InfoFormat("[RADMIN]: CreateUser: User {0} {1} created, UUID {2}", firstName, lastName, account.PrincipalID); |
||
1041 | } |
||
1042 | catch (Exception e) |
||
1043 | { |
||
1044 | responseData["avatar_uuid"] = UUID.Zero.ToString(); |
||
1045 | |||
1046 | throw e; |
||
1047 | } |
||
1048 | |||
1049 | m_log.Info("[RADMIN]: CreateUser: request complete"); |
||
1050 | } |
||
1051 | } |
||
1052 | |||
1053 | /// <summary> |
||
1054 | /// Check whether a certain user account exists. |
||
1055 | /// <summary> |
||
1056 | /// <param name="request">incoming XML RPC request</param> |
||
1057 | /// <remarks> |
||
1058 | /// XmlRpcUserExistsMethod takes the following XMLRPC |
||
1059 | /// parameters |
||
1060 | /// <list type="table"> |
||
1061 | /// <listheader><term>parameter name</term><description>description</description></listheader> |
||
1062 | /// <item><term>password</term> |
||
1063 | /// <description>admin password as set in OpenSim.ini</description></item> |
||
1064 | /// <item><term>user_firstname</term> |
||
1065 | /// <description>avatar's first name</description></item> |
||
1066 | /// <item><term>user_lastname</term> |
||
1067 | /// <description>avatar's last name</description></item> |
||
1068 | /// </list> |
||
1069 | /// |
||
1070 | /// XmlRpcCreateUserMethod returns |
||
1071 | /// <list type="table"> |
||
1072 | /// <listheader><term>name</term><description>description</description></listheader> |
||
1073 | /// <item><term>user_firstname</term> |
||
1074 | /// <description>avatar's first name</description></item> |
||
1075 | /// <item><term>user_lastname</term> |
||
1076 | /// <description>avatar's last name</description></item> |
||
1077 | /// <item><term>user_lastlogin</term> |
||
1078 | /// <description>avatar's last login time (secs since UNIX epoch)</description></item> |
||
1079 | /// <item><term>success</term> |
||
1080 | /// <description>true or false</description></item> |
||
1081 | /// <item><term>error</term> |
||
1082 | /// <description>error message if success is false</description></item> |
||
1083 | /// </list> |
||
1084 | /// </remarks> |
||
1085 | private void XmlRpcUserExistsMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
1086 | { |
||
1087 | m_log.Info("[RADMIN]: UserExists: new request"); |
||
1088 | |||
1089 | Hashtable responseData = (Hashtable)response.Value; |
||
1090 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
1091 | |||
1092 | // check completeness |
||
1093 | CheckStringParameters(requestData, responseData, new string[] {"user_firstname", "user_lastname"}); |
||
1094 | |||
1095 | string firstName = (string) requestData["user_firstname"]; |
||
1096 | string lastName = (string) requestData["user_lastname"]; |
||
1097 | |||
1098 | responseData["user_firstname"] = firstName; |
||
1099 | responseData["user_lastname"] = lastName; |
||
1100 | |||
1101 | UUID scopeID = m_application.SceneManager.CurrentOrFirstScene.RegionInfo.ScopeID; |
||
1102 | |||
1103 | UserAccount account = m_application.SceneManager.CurrentOrFirstScene.UserAccountService.GetUserAccount(scopeID, firstName, lastName); |
||
1104 | |||
1105 | if (null == account) |
||
1106 | { |
||
1107 | responseData["success"] = false; |
||
1108 | responseData["lastlogin"] = 0; |
||
1109 | } |
||
1110 | else |
||
1111 | { |
||
1112 | GridUserInfo userInfo = m_application.SceneManager.CurrentOrFirstScene.GridUserService.GetGridUserInfo(account.PrincipalID.ToString()); |
||
1113 | if (userInfo != null) |
||
1114 | responseData["lastlogin"] = Util.ToUnixTime(userInfo.Login); |
||
1115 | else |
||
1116 | responseData["lastlogin"] = 0; |
||
1117 | |||
1118 | responseData["success"] = true; |
||
1119 | } |
||
1120 | |||
1121 | m_log.Info("[RADMIN]: UserExists: request complete"); |
||
1122 | } |
||
1123 | |||
1124 | /// <summary> |
||
1125 | /// Update a user account. |
||
1126 | /// <summary> |
||
1127 | /// <param name="request">incoming XML RPC request</param> |
||
1128 | /// <remarks> |
||
1129 | /// XmlRpcUpdateUserAccountMethod takes the following XMLRPC |
||
1130 | /// parameters (changeable ones are optional) |
||
1131 | /// <list type="table"> |
||
1132 | /// <listheader><term>parameter name</term><description>description</description></listheader> |
||
1133 | /// <item><term>password</term> |
||
1134 | /// <description>admin password as set in OpenSim.ini</description></item> |
||
1135 | /// <item><term>user_firstname</term> |
||
1136 | /// <description>avatar's first name (cannot be changed)</description></item> |
||
1137 | /// <item><term>user_lastname</term> |
||
1138 | /// <description>avatar's last name (cannot be changed)</description></item> |
||
1139 | /// <item><term>user_password</term> |
||
1140 | /// <description>avatar's password (changeable)</description></item> |
||
1141 | /// <item><term>start_region_x</term> |
||
1142 | /// <description>avatar's start region coordinates, X |
||
1143 | /// value (changeable)</description></item> |
||
1144 | /// <item><term>start_region_y</term> |
||
1145 | /// <description>avatar's start region coordinates, Y |
||
1146 | /// value (changeable)</description></item> |
||
1147 | /// <item><term>about_real_world (not implemented yet)</term> |
||
1148 | /// <description>"about" text of avatar owner (changeable)</description></item> |
||
1149 | /// <item><term>about_virtual_world (not implemented yet)</term> |
||
1150 | /// <description>"about" text of avatar (changeable)</description></item> |
||
1151 | /// </list> |
||
1152 | /// |
||
1153 | /// XmlRpcCreateUserMethod returns |
||
1154 | /// <list type="table"> |
||
1155 | /// <listheader><term>name</term><description>description</description></listheader> |
||
1156 | /// <item><term>success</term> |
||
1157 | /// <description>true or false</description></item> |
||
1158 | /// <item><term>error</term> |
||
1159 | /// <description>error message if success is false</description></item> |
||
1160 | /// <item><term>avatar_uuid</term> |
||
1161 | /// <description>UUID of the updated avatar |
||
1162 | /// account; UUID.Zero if failed. |
||
1163 | /// </description></item> |
||
1164 | /// </list> |
||
1165 | /// </remarks> |
||
1166 | private void XmlRpcUpdateUserAccountMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
1167 | { |
||
1168 | m_log.Info("[RADMIN]: UpdateUserAccount: new request"); |
||
1169 | m_log.Warn("[RADMIN]: This method needs update for 0.7"); |
||
1170 | |||
1171 | Hashtable responseData = (Hashtable)response.Value; |
||
1172 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
1173 | |||
1174 | lock (m_requestLock) |
||
1175 | { |
||
1176 | try |
||
1177 | { |
||
1178 | // check completeness |
||
1179 | CheckStringParameters(requestData, responseData, new string[] { |
||
1180 | "user_firstname", |
||
1181 | "user_lastname"}); |
||
1182 | |||
1183 | // do the job |
||
1184 | string firstName = (string) requestData["user_firstname"]; |
||
1185 | string lastName = (string) requestData["user_lastname"]; |
||
1186 | |||
1187 | string password = String.Empty; |
||
1188 | uint? regionXLocation = null; |
||
1189 | uint? regionYLocation = null; |
||
1190 | // uint? ulaX = null; |
||
1191 | // uint? ulaY = null; |
||
1192 | // uint? ulaZ = null; |
||
1193 | // uint? usaX = null; |
||
1194 | // uint? usaY = null; |
||
1195 | // uint? usaZ = null; |
||
1196 | // string aboutFirstLive = String.Empty; |
||
1197 | // string aboutAvatar = String.Empty; |
||
1198 | |||
1199 | if (requestData.ContainsKey("user_password")) password = (string) requestData["user_password"]; |
||
1200 | if (requestData.ContainsKey("start_region_x")) |
||
1201 | regionXLocation = Convert.ToUInt32(requestData["start_region_x"]); |
||
1202 | if (requestData.ContainsKey("start_region_y")) |
||
1203 | regionYLocation = Convert.ToUInt32(requestData["start_region_y"]); |
||
1204 | |||
1205 | // if (requestData.ContainsKey("start_lookat_x")) |
||
1206 | // ulaX = Convert.ToUInt32((Int32) requestData["start_lookat_x"]); |
||
1207 | // if (requestData.ContainsKey("start_lookat_y")) |
||
1208 | // ulaY = Convert.ToUInt32((Int32) requestData["start_lookat_y"]); |
||
1209 | // if (requestData.ContainsKey("start_lookat_z")) |
||
1210 | // ulaZ = Convert.ToUInt32((Int32) requestData["start_lookat_z"]); |
||
1211 | |||
1212 | // if (requestData.ContainsKey("start_standat_x")) |
||
1213 | // usaX = Convert.ToUInt32((Int32) requestData["start_standat_x"]); |
||
1214 | // if (requestData.ContainsKey("start_standat_y")) |
||
1215 | // usaY = Convert.ToUInt32((Int32) requestData["start_standat_y"]); |
||
1216 | // if (requestData.ContainsKey("start_standat_z")) |
||
1217 | // usaZ = Convert.ToUInt32((Int32) requestData["start_standat_z"]); |
||
1218 | // if (requestData.ContainsKey("about_real_world")) |
||
1219 | // aboutFirstLive = (string)requestData["about_real_world"]; |
||
1220 | // if (requestData.ContainsKey("about_virtual_world")) |
||
1221 | // aboutAvatar = (string)requestData["about_virtual_world"]; |
||
1222 | |||
1223 | Scene scene = m_application.SceneManager.CurrentOrFirstScene; |
||
1224 | UUID scopeID = scene.RegionInfo.ScopeID; |
||
1225 | UserAccount account = scene.UserAccountService.GetUserAccount(scopeID, firstName, lastName); |
||
1226 | |||
1227 | if (null == account) |
||
1228 | throw new Exception(String.Format("avatar {0} {1} does not exist", firstName, lastName)); |
||
1229 | |||
1230 | if (!String.IsNullOrEmpty(password)) |
||
1231 | { |
||
1232 | m_log.DebugFormat("[RADMIN]: UpdateUserAccount: updating password for avatar {0} {1}", firstName, lastName); |
||
1233 | ChangeUserPassword(firstName, lastName, password); |
||
1234 | } |
||
1235 | |||
1236 | // if (null != usaX) userProfile.HomeLocationX = (uint) usaX; |
||
1237 | // if (null != usaY) userProfile.HomeLocationY = (uint) usaY; |
||
1238 | // if (null != usaZ) userProfile.HomeLocationZ = (uint) usaZ; |
||
1239 | |||
1240 | // if (null != ulaX) userProfile.HomeLookAtX = (uint) ulaX; |
||
1241 | // if (null != ulaY) userProfile.HomeLookAtY = (uint) ulaY; |
||
1242 | // if (null != ulaZ) userProfile.HomeLookAtZ = (uint) ulaZ; |
||
1243 | |||
1244 | // if (String.Empty != aboutFirstLive) userProfile.FirstLifeAboutText = aboutFirstLive; |
||
1245 | // if (String.Empty != aboutAvatar) userProfile.AboutText = aboutAvatar; |
||
1246 | |||
1247 | // Set home position |
||
1248 | |||
1249 | if ((null != regionXLocation) && (null != regionYLocation)) |
||
1250 | { |
||
1251 | GridRegion home = scene.GridService.GetRegionByPosition(scopeID, |
||
1252 | (int)(regionXLocation * Constants.RegionSize), (int)(regionYLocation * Constants.RegionSize)); |
||
1253 | if (null == home) { |
||
1254 | m_log.WarnFormat("[RADMIN]: Unable to set home region for updated user account {0} {1}", firstName, lastName); |
||
1255 | } else { |
||
1256 | scene.GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0)); |
||
1257 | m_log.DebugFormat("[RADMIN]: Set home region {0} for updated user account {1} {2}", home.RegionID, firstName, lastName); |
||
1258 | } |
||
1259 | } |
||
1260 | |||
1261 | // User has been created. Now establish gender and appearance. |
||
1262 | |||
1263 | UpdateUserAppearance(responseData, requestData, account.PrincipalID); |
||
1264 | |||
1265 | responseData["success"] = true; |
||
1266 | responseData["avatar_uuid"] = account.PrincipalID.ToString(); |
||
1267 | |||
1268 | m_log.InfoFormat("[RADMIN]: UpdateUserAccount: account for user {0} {1} updated, UUID {2}", |
||
1269 | firstName, lastName, |
||
1270 | account.PrincipalID); |
||
1271 | } |
||
1272 | catch (Exception e) |
||
1273 | { |
||
1274 | responseData["avatar_uuid"] = UUID.Zero.ToString(); |
||
1275 | |||
1276 | throw e; |
||
1277 | } |
||
1278 | |||
1279 | m_log.Info("[RADMIN]: UpdateUserAccount: request complete"); |
||
1280 | } |
||
1281 | } |
||
1282 | |||
1283 | /// <summary> |
||
1284 | /// Load an OAR file into a region.. |
||
1285 | /// <summary> |
||
1286 | /// <param name="request">incoming XML RPC request</param> |
||
1287 | /// <remarks> |
||
1288 | /// XmlRpcLoadOARMethod takes the following XMLRPC |
||
1289 | /// parameters |
||
1290 | /// <list type="table"> |
||
1291 | /// <listheader><term>parameter name</term><description>description</description></listheader> |
||
1292 | /// <item><term>password</term> |
||
1293 | /// <description>admin password as set in OpenSim.ini</description></item> |
||
1294 | /// <item><term>filename</term> |
||
1295 | /// <description>file name of the OAR file</description></item> |
||
1296 | /// <item><term>region_uuid</term> |
||
1297 | /// <description>UUID of the region</description></item> |
||
1298 | /// <item><term>region_name</term> |
||
1299 | /// <description>region name</description></item> |
||
1300 | /// <item><term>merge</term> |
||
1301 | /// <description>true if oar should be merged</description></item> |
||
1302 | /// <item><term>skip-assets</term> |
||
1303 | /// <description>true if assets should be skiped</description></item> |
||
1304 | /// </list> |
||
1305 | /// |
||
1306 | /// <code>region_uuid</code> takes precedence over |
||
1307 | /// <code>region_name</code> if both are present; one of both |
||
1308 | /// must be present. |
||
1309 | /// |
||
1310 | /// XmlRpcLoadOARMethod returns |
||
1311 | /// <list type="table"> |
||
1312 | /// <listheader><term>name</term><description>description</description></listheader> |
||
1313 | /// <item><term>success</term> |
||
1314 | /// <description>true or false</description></item> |
||
1315 | /// <item><term>error</term> |
||
1316 | /// <description>error message if success is false</description></item> |
||
1317 | /// </list> |
||
1318 | /// </remarks> |
||
1319 | private void XmlRpcLoadOARMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
1320 | { |
||
1321 | m_log.Info("[RADMIN]: Received Load OAR Administrator Request"); |
||
1322 | |||
1323 | Hashtable responseData = (Hashtable)response.Value; |
||
1324 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
1325 | |||
1326 | lock (m_requestLock) |
||
1327 | { |
||
1328 | try |
||
1329 | { |
||
1330 | CheckStringParameters(requestData, responseData, new string[] {"filename"}); |
||
1331 | CheckRegionParams(requestData, responseData); |
||
1332 | |||
1333 | Scene scene = null; |
||
1334 | GetSceneFromRegionParams(requestData, responseData, out scene); |
||
1335 | |||
1336 | string filename = (string) requestData["filename"]; |
||
1337 | |||
1338 | bool mergeOar = false; |
||
1339 | bool skipAssets = false; |
||
1340 | |||
1341 | if ((string)requestData["merge"] == "true") |
||
1342 | { |
||
1343 | mergeOar = true; |
||
1344 | } |
||
1345 | if ((string)requestData["skip-assets"] == "true") |
||
1346 | { |
||
1347 | skipAssets = true; |
||
1348 | } |
||
1349 | |||
1350 | IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>(); |
||
1351 | if (archiver != null) |
||
1352 | archiver.DearchiveRegion(filename, mergeOar, skipAssets, Guid.Empty); |
||
1353 | else |
||
1354 | throw new Exception("Archiver module not present for scene"); |
||
1355 | |||
1356 | responseData["loaded"] = true; |
||
1357 | } |
||
1358 | catch (Exception e) |
||
1359 | { |
||
1360 | responseData["loaded"] = false; |
||
1361 | |||
1362 | throw e; |
||
1363 | } |
||
1364 | |||
1365 | m_log.Info("[RADMIN]: Load OAR Administrator Request complete"); |
||
1366 | } |
||
1367 | } |
||
1368 | |||
1369 | /// <summary> |
||
1370 | /// Save a region to an OAR file |
||
1371 | /// <summary> |
||
1372 | /// <param name="request">incoming XML RPC request</param> |
||
1373 | /// <remarks> |
||
1374 | /// XmlRpcSaveOARMethod takes the following XMLRPC |
||
1375 | /// parameters |
||
1376 | /// <list type="table"> |
||
1377 | /// <listheader><term>parameter name</term><description>description</description></listheader> |
||
1378 | /// <item><term>password</term> |
||
1379 | /// <description>admin password as set in OpenSim.ini</description></item> |
||
1380 | /// <item><term>filename</term> |
||
1381 | /// <description>file name for the OAR file</description></item> |
||
1382 | /// <item><term>region_uuid</term> |
||
1383 | /// <description>UUID of the region</description></item> |
||
1384 | /// <item><term>region_name</term> |
||
1385 | /// <description>region name</description></item> |
||
1386 | /// <item><term>profile</term> |
||
1387 | /// <description>profile url</description></item> |
||
1388 | /// <item><term>noassets</term> |
||
1389 | /// <description>true if no assets should be saved</description></item> |
||
1390 | /// <item><term>all</term> |
||
1391 | /// <description>true to save all the regions in the simulator</description></item> |
||
1392 | /// <item><term>perm</term> |
||
1393 | /// <description>C and/or T</description></item> |
||
1394 | /// </list> |
||
1395 | /// |
||
1396 | /// <code>region_uuid</code> takes precedence over |
||
1397 | /// <code>region_name</code> if both are present; one of both |
||
1398 | /// must be present. |
||
1399 | /// |
||
1400 | /// XmlRpcLoadOARMethod returns |
||
1401 | /// <list type="table"> |
||
1402 | /// <listheader><term>name</term><description>description</description></listheader> |
||
1403 | /// <item><term>success</term> |
||
1404 | /// <description>true or false</description></item> |
||
1405 | /// <item><term>error</term> |
||
1406 | /// <description>error message if success is false</description></item> |
||
1407 | /// </list> |
||
1408 | /// </remarks> |
||
1409 | private void XmlRpcSaveOARMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
1410 | { |
||
1411 | m_log.Info("[RADMIN]: Received Save OAR Administrator Request"); |
||
1412 | |||
1413 | Hashtable responseData = (Hashtable)response.Value; |
||
1414 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
1415 | |||
1416 | try |
||
1417 | { |
||
1418 | CheckStringParameters(requestData, responseData, new string[] {"filename"}); |
||
1419 | CheckRegionParams(requestData, responseData); |
||
1420 | |||
1421 | Scene scene = null; |
||
1422 | GetSceneFromRegionParams(requestData, responseData, out scene); |
||
1423 | |||
1424 | string filename = (string)requestData["filename"]; |
||
1425 | |||
1426 | Dictionary<string, object> options = new Dictionary<string, object>(); |
||
1427 | |||
1428 | //if (requestData.Contains("version")) |
||
1429 | //{ |
||
1430 | // options["version"] = (string)requestData["version"]; |
||
1431 | //} |
||
1432 | |||
1433 | if (requestData.Contains("home")) |
||
1434 | { |
||
1435 | options["home"] = (string)requestData["home"]; |
||
1436 | } |
||
1437 | |||
1438 | if ((string)requestData["noassets"] == "true") |
||
1439 | { |
||
1440 | options["noassets"] = (string)requestData["noassets"] ; |
||
1441 | } |
||
1442 | |||
1443 | if (requestData.Contains("perm")) |
||
1444 | { |
||
1445 | options["checkPermissions"] = (string)requestData["perm"]; |
||
1446 | } |
||
1447 | |||
1448 | if ((string)requestData["all"] == "true") |
||
1449 | { |
||
1450 | options["all"] = (string)requestData["all"]; |
||
1451 | } |
||
1452 | |||
1453 | IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>(); |
||
1454 | |||
1455 | if (archiver != null) |
||
1456 | { |
||
1457 | scene.EventManager.OnOarFileSaved += RemoteAdminOarSaveCompleted; |
||
1458 | archiver.ArchiveRegion(filename, options); |
||
1459 | |||
1460 | lock (m_saveOarLock) |
||
1461 | Monitor.Wait(m_saveOarLock,5000); |
||
1462 | |||
1463 | scene.EventManager.OnOarFileSaved -= RemoteAdminOarSaveCompleted; |
||
1464 | } |
||
1465 | else |
||
1466 | { |
||
1467 | throw new Exception("Archiver module not present for scene"); |
||
1468 | } |
||
1469 | |||
1470 | responseData["saved"] = true; |
||
1471 | } |
||
1472 | catch (Exception e) |
||
1473 | { |
||
1474 | responseData["saved"] = false; |
||
1475 | |||
1476 | throw e; |
||
1477 | } |
||
1478 | |||
1479 | m_log.Info("[RADMIN]: Save OAR Administrator Request complete"); |
||
1480 | } |
||
1481 | |||
1482 | private void RemoteAdminOarSaveCompleted(Guid uuid, string name) |
||
1483 | { |
||
1484 | m_log.DebugFormat("[RADMIN]: File processing complete for {0}", name); |
||
1485 | lock (m_saveOarLock) |
||
1486 | Monitor.Pulse(m_saveOarLock); |
||
1487 | } |
||
1488 | |||
1489 | private void XmlRpcLoadXMLMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
1490 | { |
||
1491 | m_log.Info("[RADMIN]: Received Load XML Administrator Request"); |
||
1492 | |||
1493 | Hashtable responseData = (Hashtable)response.Value; |
||
1494 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
1495 | |||
1496 | lock (m_requestLock) |
||
1497 | { |
||
1498 | try |
||
1499 | { |
||
1500 | CheckStringParameters(requestData, responseData, new string[] {"filename"}); |
||
1501 | CheckRegionParams(requestData, responseData); |
||
1502 | |||
1503 | Scene scene = null; |
||
1504 | GetSceneFromRegionParams(requestData, responseData, out scene); |
||
1505 | |||
1506 | string filename = (string) requestData["filename"]; |
||
1507 | |||
1508 | responseData["switched"] = true; |
||
1509 | |||
1510 | string xml_version = "1"; |
||
1511 | if (requestData.Contains("xml_version")) |
||
1512 | { |
||
1513 | xml_version = (string) requestData["xml_version"]; |
||
1514 | } |
||
1515 | |||
1516 | switch (xml_version) |
||
1517 | { |
||
1518 | case "1": |
||
1519 | m_application.SceneManager.LoadCurrentSceneFromXml(filename, true, new Vector3(0, 0, 0)); |
||
1520 | break; |
||
1521 | |||
1522 | case "2": |
||
1523 | m_application.SceneManager.LoadCurrentSceneFromXml2(filename); |
||
1524 | break; |
||
1525 | |||
1526 | default: |
||
1527 | throw new Exception(String.Format("unknown Xml{0} format", xml_version)); |
||
1528 | } |
||
1529 | |||
1530 | responseData["loaded"] = true; |
||
1531 | } |
||
1532 | catch (Exception e) |
||
1533 | { |
||
1534 | responseData["loaded"] = false; |
||
1535 | responseData["switched"] = false; |
||
1536 | |||
1537 | throw e; |
||
1538 | } |
||
1539 | |||
1540 | m_log.Info("[RADMIN]: Load XML Administrator Request complete"); |
||
1541 | } |
||
1542 | } |
||
1543 | |||
1544 | private void XmlRpcSaveXMLMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
1545 | { |
||
1546 | m_log.Info("[RADMIN]: Received Save XML Administrator Request"); |
||
1547 | |||
1548 | Hashtable responseData = (Hashtable)response.Value; |
||
1549 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
1550 | |||
1551 | try |
||
1552 | { |
||
1553 | CheckStringParameters(requestData, responseData, new string[] {"filename"}); |
||
1554 | CheckRegionParams(requestData, responseData); |
||
1555 | |||
1556 | Scene scene = null; |
||
1557 | GetSceneFromRegionParams(requestData, responseData, out scene); |
||
1558 | |||
1559 | string filename = (string) requestData["filename"]; |
||
1560 | |||
1561 | responseData["switched"] = true; |
||
1562 | |||
1563 | string xml_version = "1"; |
||
1564 | if (requestData.Contains("xml_version")) |
||
1565 | { |
||
1566 | xml_version = (string) requestData["xml_version"]; |
||
1567 | } |
||
1568 | |||
1569 | switch (xml_version) |
||
1570 | { |
||
1571 | case "1": |
||
1572 | m_application.SceneManager.SaveCurrentSceneToXml(filename); |
||
1573 | break; |
||
1574 | |||
1575 | case "2": |
||
1576 | m_application.SceneManager.SaveCurrentSceneToXml2(filename); |
||
1577 | break; |
||
1578 | |||
1579 | default: |
||
1580 | throw new Exception(String.Format("unknown Xml{0} format", xml_version)); |
||
1581 | } |
||
1582 | |||
1583 | responseData["saved"] = true; |
||
1584 | } |
||
1585 | catch (Exception e) |
||
1586 | { |
||
1587 | responseData["saved"] = false; |
||
1588 | responseData["switched"] = false; |
||
1589 | |||
1590 | throw e; |
||
1591 | } |
||
1592 | |||
1593 | m_log.Info("[RADMIN]: Save XML Administrator Request complete"); |
||
1594 | } |
||
1595 | |||
1596 | private void XmlRpcRegionQueryMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
1597 | { |
||
1598 | m_log.Info("[RADMIN]: Received Query XML Administrator Request"); |
||
1599 | |||
1600 | Hashtable responseData = (Hashtable)response.Value; |
||
1601 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
1602 | |||
1603 | CheckRegionParams(requestData, responseData); |
||
1604 | |||
1605 | Scene scene = null; |
||
1606 | GetSceneFromRegionParams(requestData, responseData, out scene); |
||
1607 | |||
1608 | int health = scene.GetHealth(); |
||
1609 | responseData["health"] = health; |
||
1610 | |||
1611 | responseData["success"] = true; |
||
1612 | m_log.Info("[RADMIN]: Query XML Administrator Request complete"); |
||
1613 | } |
||
1614 | |||
1615 | private void XmlRpcConsoleCommandMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
1616 | { |
||
1617 | m_log.Info("[RADMIN]: Received Command XML Administrator Request"); |
||
1618 | |||
1619 | Hashtable responseData = (Hashtable)response.Value; |
||
1620 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
1621 | |||
1622 | CheckStringParameters(requestData, responseData, new string[] {"command"}); |
||
1623 | |||
1624 | MainConsole.Instance.RunCommand(requestData["command"].ToString()); |
||
1625 | |||
1626 | m_log.Info("[RADMIN]: Command XML Administrator Request complete"); |
||
1627 | } |
||
1628 | |||
1629 | private void XmlRpcAccessListClear(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
1630 | { |
||
1631 | m_log.Info("[RADMIN]: Received Access List Clear Request"); |
||
1632 | |||
1633 | Hashtable responseData = (Hashtable)response.Value; |
||
1634 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
1635 | |||
1636 | responseData["success"] = true; |
||
1637 | |||
1638 | CheckRegionParams(requestData, responseData); |
||
1639 | |||
1640 | Scene scene = null; |
||
1641 | GetSceneFromRegionParams(requestData, responseData, out scene); |
||
1642 | |||
1643 | scene.RegionInfo.EstateSettings.EstateAccess = new UUID[]{}; |
||
1644 | |||
1645 | if (scene.RegionInfo.Persistent) |
||
1646 | scene.RegionInfo.EstateSettings.Save(); |
||
1647 | |||
1648 | m_log.Info("[RADMIN]: Access List Clear Request complete"); |
||
1649 | } |
||
1650 | |||
1651 | private void XmlRpcAccessListAdd(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
1652 | { |
||
1653 | m_log.Info("[RADMIN]: Received Access List Add Request"); |
||
1654 | |||
1655 | Hashtable responseData = (Hashtable)response.Value; |
||
1656 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
1657 | |||
1658 | CheckRegionParams(requestData, responseData); |
||
1659 | |||
1660 | Scene scene = null; |
||
1661 | GetSceneFromRegionParams(requestData, responseData, out scene); |
||
1662 | |||
1663 | int addedUsers = 0; |
||
1664 | |||
1665 | if (requestData.Contains("users")) |
||
1666 | { |
||
1667 | UUID scopeID = scene.RegionInfo.ScopeID; |
||
1668 | IUserAccountService userService = scene.UserAccountService; |
||
1669 | Hashtable users = (Hashtable) requestData["users"]; |
||
1670 | List<UUID> uuids = new List<UUID>(); |
||
1671 | foreach (string name in users.Values) |
||
1672 | { |
||
1673 | string[] parts = name.Split(); |
||
1674 | UserAccount account = userService.GetUserAccount(scopeID, parts[0], parts[1]); |
||
1675 | if (account != null) |
||
1676 | { |
||
1677 | uuids.Add(account.PrincipalID); |
||
1678 | m_log.DebugFormat("[RADMIN]: adding \"{0}\" to ACL for \"{1}\"", name, scene.RegionInfo.RegionName); |
||
1679 | } |
||
1680 | } |
||
1681 | List<UUID> accessControlList = new List<UUID>(scene.RegionInfo.EstateSettings.EstateAccess); |
||
1682 | foreach (UUID uuid in uuids) |
||
1683 | { |
||
1684 | if (!accessControlList.Contains(uuid)) |
||
1685 | { |
||
1686 | accessControlList.Add(uuid); |
||
1687 | addedUsers++; |
||
1688 | } |
||
1689 | } |
||
1690 | scene.RegionInfo.EstateSettings.EstateAccess = accessControlList.ToArray(); |
||
1691 | if (scene.RegionInfo.Persistent) |
||
1692 | scene.RegionInfo.EstateSettings.Save(); |
||
1693 | } |
||
1694 | |||
1695 | responseData["added"] = addedUsers; |
||
1696 | |||
1697 | m_log.Info("[RADMIN]: Access List Add Request complete"); |
||
1698 | } |
||
1699 | |||
1700 | private void XmlRpcAccessListRemove(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
1701 | { |
||
1702 | m_log.Info("[RADMIN]: Received Access List Remove Request"); |
||
1703 | |||
1704 | Hashtable responseData = (Hashtable)response.Value; |
||
1705 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
1706 | |||
1707 | CheckRegionParams(requestData, responseData); |
||
1708 | |||
1709 | Scene scene = null; |
||
1710 | GetSceneFromRegionParams(requestData, responseData, out scene); |
||
1711 | |||
1712 | int removedUsers = 0; |
||
1713 | |||
1714 | if (requestData.Contains("users")) |
||
1715 | { |
||
1716 | UUID scopeID = scene.RegionInfo.ScopeID; |
||
1717 | IUserAccountService userService = scene.UserAccountService; |
||
1718 | //UserProfileCacheService ups = m_application.CommunicationsManager.UserProfileCacheService; |
||
1719 | Hashtable users = (Hashtable) requestData["users"]; |
||
1720 | List<UUID> uuids = new List<UUID>(); |
||
1721 | foreach (string name in users.Values) |
||
1722 | { |
||
1723 | string[] parts = name.Split(); |
||
1724 | UserAccount account = userService.GetUserAccount(scopeID, parts[0], parts[1]); |
||
1725 | if (account != null) |
||
1726 | { |
||
1727 | uuids.Add(account.PrincipalID); |
||
1728 | } |
||
1729 | } |
||
1730 | List<UUID> accessControlList = new List<UUID>(scene.RegionInfo.EstateSettings.EstateAccess); |
||
1731 | foreach (UUID uuid in uuids) |
||
1732 | { |
||
1733 | if (accessControlList.Contains(uuid)) |
||
1734 | { |
||
1735 | accessControlList.Remove(uuid); |
||
1736 | removedUsers++; |
||
1737 | } |
||
1738 | } |
||
1739 | scene.RegionInfo.EstateSettings.EstateAccess = accessControlList.ToArray(); |
||
1740 | if (scene.RegionInfo.Persistent) |
||
1741 | scene.RegionInfo.EstateSettings.Save(); |
||
1742 | } |
||
1743 | |||
1744 | responseData["removed"] = removedUsers; |
||
1745 | responseData["success"] = true; |
||
1746 | |||
1747 | m_log.Info("[RADMIN]: Access List Remove Request complete"); |
||
1748 | } |
||
1749 | |||
1750 | private void XmlRpcAccessListList(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
1751 | { |
||
1752 | m_log.Info("[RADMIN]: Received Access List List Request"); |
||
1753 | |||
1754 | Hashtable responseData = (Hashtable)response.Value; |
||
1755 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
1756 | |||
1757 | CheckRegionParams(requestData, responseData); |
||
1758 | |||
1759 | Scene scene = null; |
||
1760 | GetSceneFromRegionParams(requestData, responseData, out scene); |
||
1761 | |||
1762 | UUID[] accessControlList = scene.RegionInfo.EstateSettings.EstateAccess; |
||
1763 | Hashtable users = new Hashtable(); |
||
1764 | |||
1765 | foreach (UUID user in accessControlList) |
||
1766 | { |
||
1767 | UUID scopeID = scene.RegionInfo.ScopeID; |
||
1768 | UserAccount account = scene.UserAccountService.GetUserAccount(scopeID, user); |
||
1769 | if (account != null) |
||
1770 | { |
||
1771 | users[user.ToString()] = account.FirstName + " " + account.LastName; |
||
1772 | } |
||
1773 | } |
||
1774 | |||
1775 | responseData["users"] = users; |
||
1776 | responseData["success"] = true; |
||
1777 | |||
1778 | m_log.Info("[RADMIN]: Access List List Request complete"); |
||
1779 | } |
||
1780 | |||
1781 | private void XmlRpcEstateReload(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
1782 | { |
||
1783 | m_log.Info("[RADMIN]: Received Estate Reload Request"); |
||
1784 | |||
1785 | Hashtable responseData = (Hashtable)response.Value; |
||
1786 | // Hashtable requestData = (Hashtable)request.Params[0]; |
||
1787 | |||
1788 | m_application.SceneManager.ForEachScene(s => |
||
1789 | s.RegionInfo.EstateSettings = m_application.EstateDataService.LoadEstateSettings(s.RegionInfo.RegionID, false) |
||
1790 | ); |
||
1791 | |||
1792 | responseData["success"] = true; |
||
1793 | |||
1794 | m_log.Info("[RADMIN]: Estate Reload Request complete"); |
||
1795 | } |
||
1796 | |||
1797 | private void XmlRpcGetAgentsMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
1798 | { |
||
1799 | Hashtable responseData = (Hashtable)response.Value; |
||
1800 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
1801 | |||
1802 | bool includeChildren = false; |
||
1803 | |||
1804 | if (requestData.Contains("include_children")) |
||
1805 | bool.TryParse((string)requestData["include_children"], out includeChildren); |
||
1806 | |||
1807 | Scene scene; |
||
1808 | GetSceneFromRegionParams(requestData, responseData, out scene); |
||
1809 | |||
1810 | ArrayList xmlRpcRegions = new ArrayList(); |
||
1811 | responseData["regions"] = xmlRpcRegions; |
||
1812 | |||
1813 | Hashtable xmlRpcRegion = new Hashtable(); |
||
1814 | xmlRpcRegions.Add(xmlRpcRegion); |
||
1815 | |||
1816 | xmlRpcRegion["name"] = scene.Name; |
||
1817 | xmlRpcRegion["id"] = scene.RegionInfo.RegionID.ToString(); |
||
1818 | |||
1819 | List<ScenePresence> agents = scene.GetScenePresences(); |
||
1820 | ArrayList xmlrpcAgents = new ArrayList(); |
||
1821 | |||
1822 | foreach (ScenePresence agent in agents) |
||
1823 | { |
||
1824 | if (agent.IsChildAgent && !includeChildren) |
||
1825 | continue; |
||
1826 | |||
1827 | Hashtable xmlRpcAgent = new Hashtable(); |
||
1828 | xmlRpcAgent.Add("name", agent.Name); |
||
1829 | xmlRpcAgent.Add("id", agent.UUID.ToString()); |
||
1830 | xmlRpcAgent.Add("type", agent.PresenceType.ToString()); |
||
1831 | xmlRpcAgent.Add("current_parcel_id", agent.currentParcelUUID.ToString()); |
||
1832 | |||
1833 | Vector3 pos = agent.AbsolutePosition; |
||
1834 | xmlRpcAgent.Add("pos_x", pos.X.ToString()); |
||
1835 | xmlRpcAgent.Add("pos_y", pos.Y.ToString()); |
||
1836 | xmlRpcAgent.Add("pos_z", pos.Z.ToString()); |
||
1837 | |||
1838 | Vector3 lookAt = agent.Lookat; |
||
1839 | xmlRpcAgent.Add("lookat_x", lookAt.X.ToString()); |
||
1840 | xmlRpcAgent.Add("lookat_y", lookAt.Y.ToString()); |
||
1841 | xmlRpcAgent.Add("lookat_z", lookAt.Z.ToString()); |
||
1842 | |||
1843 | Vector3 vel = agent.Velocity; |
||
1844 | xmlRpcAgent.Add("vel_x", vel.X.ToString()); |
||
1845 | xmlRpcAgent.Add("vel_y", vel.Y.ToString()); |
||
1846 | xmlRpcAgent.Add("vel_z", vel.Z.ToString()); |
||
1847 | |||
1848 | xmlRpcAgent.Add("is_flying", agent.Flying.ToString()); |
||
1849 | xmlRpcAgent.Add("is_sat_on_ground", agent.SitGround.ToString()); |
||
1850 | xmlRpcAgent.Add("is_sat_on_object", agent.IsSatOnObject.ToString()); |
||
1851 | |||
1852 | xmlrpcAgents.Add(xmlRpcAgent); |
||
1853 | } |
||
1854 | |||
1855 | m_log.DebugFormat( |
||
1856 | "[REMOTE ADMIN]: XmlRpcGetAgents found {0} agents in {1}", xmlrpcAgents.Count, scene.Name); |
||
1857 | |||
1858 | xmlRpcRegion["agents"] = xmlrpcAgents; |
||
1859 | responseData["success"] = true; |
||
1860 | } |
||
1861 | |||
1862 | private void XmlRpcTeleportAgentMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient) |
||
1863 | { |
||
1864 | Hashtable responseData = (Hashtable)response.Value; |
||
1865 | Hashtable requestData = (Hashtable)request.Params[0]; |
||
1866 | |||
1867 | UUID agentId; |
||
1868 | string regionName = null; |
||
1869 | Vector3 pos, lookAt; |
||
1870 | ScenePresence sp = null; |
||
1871 | |||
1872 | if (requestData.Contains("agent_first_name") && requestData.Contains("agent_last_name")) |
||
1873 | { |
||
1874 | string firstName = requestData["agent_first_name"].ToString(); |
||
1875 | string lastName = requestData["agent_last_name"].ToString(); |
||
1876 | m_application.SceneManager.TryGetRootScenePresenceByName(firstName, lastName, out sp); |
||
1877 | |||
1878 | if (sp == null) |
||
1879 | throw new Exception( |
||
1880 | string.Format( |
||
1881 | "No agent found with agent_first_name {0} and agent_last_name {1}", firstName, lastName)); |
||
1882 | } |
||
1883 | else if (requestData.Contains("agent_id")) |
||
1884 | { |
||
1885 | string rawAgentId = (string)requestData["agent_id"]; |
||
1886 | |||
1887 | if (!UUID.TryParse(rawAgentId, out agentId)) |
||
1888 | throw new Exception(string.Format("agent_id {0} does not have the correct id format", rawAgentId)); |
||
1889 | |||
1890 | m_application.SceneManager.TryGetRootScenePresence(agentId, out sp); |
||
1891 | |||
1892 | if (sp == null) |
||
1893 | throw new Exception(string.Format("No agent with agent_id {0} found in this simulator", agentId)); |
||
1894 | } |
||
1895 | else |
||
1896 | { |
||
1897 | throw new Exception("No agent_id or agent_first_name and agent_last_name parameters specified"); |
||
1898 | } |
||
1899 | |||
1900 | if (requestData.Contains("region_name")) |
||
1901 | regionName = (string)requestData["region_name"]; |
||
1902 | |||
1903 | pos.X = ParseFloat(requestData, "pos_x", sp.AbsolutePosition.X); |
||
1904 | pos.Y = ParseFloat(requestData, "pos_y", sp.AbsolutePosition.Y); |
||
1905 | pos.Z = ParseFloat(requestData, "pos_z", sp.AbsolutePosition.Z); |
||
1906 | lookAt.X = ParseFloat(requestData, "lookat_x", sp.Lookat.X); |
||
1907 | lookAt.Y = ParseFloat(requestData, "lookat_y", sp.Lookat.Y); |
||
1908 | lookAt.Z = ParseFloat(requestData, "lookat_z", sp.Lookat.Z); |
||
1909 | |||
1910 | sp.Scene.RequestTeleportLocation( |
||
1911 | sp.ControllingClient, regionName, pos, lookAt, (uint)Constants.TeleportFlags.ViaLocation); |
||
1912 | |||
1913 | // We have no way of telling the failure of the actual teleport |
||
1914 | responseData["success"] = true; |
||
1915 | } |
||
1916 | |||
1917 | /// <summary> |
||
1918 | /// Parse a float with the given parameter name from a request data hash table. |
||
1919 | /// </summary> |
||
1920 | /// <remarks> |
||
1921 | /// Will throw an exception if parameter is not a float. |
||
1922 | /// Will not throw if parameter is not found, passes back default value instead. |
||
1923 | /// </remarks> |
||
1924 | /// <param name="requestData"></param> |
||
1925 | /// <param name="paramName"></param> |
||
1926 | /// <param name="defaultVal"></param> |
||
1927 | /// <returns></returns> |
||
1928 | private static float ParseFloat(Hashtable requestData, string paramName, float defaultVal) |
||
1929 | { |
||
1930 | if (requestData.Contains(paramName)) |
||
1931 | { |
||
1932 | string rawVal = (string)requestData[paramName]; |
||
1933 | float val; |
||
1934 | |||
1935 | if (!float.TryParse(rawVal, out val)) |
||
1936 | throw new Exception(string.Format("{0} {1} is not a valid float", paramName, rawVal)); |
||
1937 | else |
||
1938 | return val; |
||
1939 | } |
||
1940 | else |
||
1941 | { |
||
1942 | return defaultVal; |
||
1943 | } |
||
1944 | } |
||
1945 | |||
1946 | private static void CheckStringParameters(Hashtable requestData, Hashtable responseData, string[] param) |
||
1947 | { |
||
1948 | foreach (string parameter in param) |
||
1949 | { |
||
1950 | if (!requestData.Contains(parameter)) |
||
1951 | { |
||
1952 | responseData["accepted"] = false; |
||
1953 | throw new Exception(String.Format("missing string parameter {0}", parameter)); |
||
1954 | } |
||
1955 | if (String.IsNullOrEmpty((string) requestData[parameter])) |
||
1956 | { |
||
1957 | responseData["accepted"] = false; |
||
1958 | throw new Exception(String.Format("parameter {0} is empty", parameter)); |
||
1959 | } |
||
1960 | } |
||
1961 | } |
||
1962 | |||
1963 | private static void CheckIntegerParams(Hashtable requestData, Hashtable responseData, string[] param) |
||
1964 | { |
||
1965 | foreach (string parameter in param) |
||
1966 | { |
||
1967 | if (!requestData.Contains(parameter)) |
||
1968 | { |
||
1969 | responseData["accepted"] = false; |
||
1970 | throw new Exception(String.Format("missing integer parameter {0}", parameter)); |
||
1971 | } |
||
1972 | } |
||
1973 | } |
||
1974 | |||
1975 | private void CheckRegionParams(Hashtable requestData, Hashtable responseData) |
||
1976 | { |
||
1977 | //Checks if region parameters exist and gives exeption if no parameters are given |
||
1978 | if ((requestData.ContainsKey("region_id") && !String.IsNullOrEmpty((string)requestData["region_id"])) || |
||
1979 | (requestData.ContainsKey("region_name") && !String.IsNullOrEmpty((string)requestData["region_name"]))) |
||
1980 | { |
||
1981 | return; |
||
1982 | } |
||
1983 | else |
||
1984 | { |
||
1985 | responseData["accepted"] = false; |
||
1986 | throw new Exception("no region_name or region_id given"); |
||
1987 | } |
||
1988 | } |
||
1989 | |||
1990 | private void GetSceneFromRegionParams(Hashtable requestData, Hashtable responseData, out Scene scene) |
||
1991 | { |
||
1992 | scene = null; |
||
1993 | |||
1994 | if (requestData.ContainsKey("region_id") && |
||
1995 | !String.IsNullOrEmpty((string)requestData["region_id"])) |
||
1996 | { |
||
1997 | UUID regionID = (UUID)(string)requestData["region_id"]; |
||
1998 | if (!m_application.SceneManager.TryGetScene(regionID, out scene)) |
||
1999 | { |
||
2000 | responseData["error"] = String.Format("Region ID {0} not found", regionID); |
||
2001 | throw new Exception(String.Format("Region ID {0} not found", regionID)); |
||
2002 | } |
||
2003 | } |
||
2004 | else if (requestData.ContainsKey("region_name") && |
||
2005 | !String.IsNullOrEmpty((string)requestData["region_name"])) |
||
2006 | { |
||
2007 | string regionName = (string)requestData["region_name"]; |
||
2008 | if (!m_application.SceneManager.TryGetScene(regionName, out scene)) |
||
2009 | { |
||
2010 | responseData["error"] = String.Format("Region {0} not found", regionName); |
||
2011 | throw new Exception(String.Format("Region {0} not found", regionName)); |
||
2012 | } |
||
2013 | } |
||
2014 | else |
||
2015 | { |
||
2016 | responseData["error"] = "no region_name or region_id given"; |
||
2017 | throw new Exception("no region_name or region_id given"); |
||
2018 | } |
||
2019 | return; |
||
2020 | } |
||
2021 | |||
2022 | private bool GetBoolean(Hashtable requestData, string tag, bool defaultValue) |
||
2023 | { |
||
2024 | // If an access value has been provided, apply it. |
||
2025 | if (requestData.Contains(tag)) |
||
2026 | { |
||
2027 | switch (((string)requestData[tag]).ToLower()) |
||
2028 | { |
||
2029 | case "true" : |
||
2030 | case "t" : |
||
2031 | case "1" : |
||
2032 | return true; |
||
2033 | case "false" : |
||
2034 | case "f" : |
||
2035 | case "0" : |
||
2036 | return false; |
||
2037 | default : |
||
2038 | return defaultValue; |
||
2039 | } |
||
2040 | } |
||
2041 | else |
||
2042 | return defaultValue; |
||
2043 | } |
||
2044 | |||
2045 | private int GetIntegerAttribute(XmlNode node, string attribute, int defaultValue) |
||
2046 | { |
||
2047 | try { return Convert.ToInt32(node.Attributes[attribute].Value); } catch{} |
||
2048 | return defaultValue; |
||
2049 | } |
||
2050 | |||
2051 | private uint GetUnsignedAttribute(XmlNode node, string attribute, uint defaultValue) |
||
2052 | { |
||
2053 | try { return Convert.ToUInt32(node.Attributes[attribute].Value); } catch{} |
||
2054 | return defaultValue; |
||
2055 | } |
||
2056 | |||
2057 | private string GetStringAttribute(XmlNode node, string attribute, string defaultValue) |
||
2058 | { |
||
2059 | try { return node.Attributes[attribute].Value; } catch{} |
||
2060 | return defaultValue; |
||
2061 | } |
||
2062 | |||
2063 | public void Dispose() |
||
2064 | { |
||
2065 | } |
||
2066 | |||
2067 | /// <summary> |
||
2068 | /// Create a user |
||
2069 | /// </summary> |
||
2070 | /// <param name="scopeID"></param> |
||
2071 | /// <param name="firstName"></param> |
||
2072 | /// <param name="lastName"></param> |
||
2073 | /// <param name="password"></param> |
||
2074 | /// <param name="email"></param> |
||
2075 | private UserAccount CreateUser(UUID scopeID, string firstName, string lastName, string password, string email) |
||
2076 | { |
||
2077 | Scene scene = m_application.SceneManager.CurrentOrFirstScene; |
||
2078 | IUserAccountService userAccountService = scene.UserAccountService; |
||
2079 | IGridService gridService = scene.GridService; |
||
2080 | IAuthenticationService authenticationService = scene.AuthenticationService; |
||
2081 | IGridUserService gridUserService = scene.GridUserService; |
||
2082 | IInventoryService inventoryService = scene.InventoryService; |
||
2083 | |||
2084 | UserAccount account = userAccountService.GetUserAccount(scopeID, firstName, lastName); |
||
2085 | if (null == account) |
||
2086 | { |
||
2087 | account = new UserAccount(scopeID, UUID.Random(), firstName, lastName, email); |
||
2088 | if (account.ServiceURLs == null || (account.ServiceURLs != null && account.ServiceURLs.Count == 0)) |
||
2089 | { |
||
2090 | account.ServiceURLs = new Dictionary<string, object>(); |
||
2091 | account.ServiceURLs["HomeURI"] = string.Empty; |
||
2092 | account.ServiceURLs["GatekeeperURI"] = string.Empty; |
||
2093 | account.ServiceURLs["InventoryServerURI"] = string.Empty; |
||
2094 | account.ServiceURLs["AssetServerURI"] = string.Empty; |
||
2095 | } |
||
2096 | |||
2097 | if (userAccountService.StoreUserAccount(account)) |
||
2098 | { |
||
2099 | bool success; |
||
2100 | if (authenticationService != null) |
||
2101 | { |
||
2102 | success = authenticationService.SetPassword(account.PrincipalID, password); |
||
2103 | if (!success) |
||
2104 | m_log.WarnFormat("[RADMIN]: Unable to set password for account {0} {1}.", |
||
2105 | firstName, lastName); |
||
2106 | } |
||
2107 | |||
2108 | GridRegion home = null; |
||
2109 | if (gridService != null) |
||
2110 | { |
||
2111 | List<GridRegion> defaultRegions = gridService.GetDefaultRegions(UUID.Zero); |
||
2112 | if (defaultRegions != null && defaultRegions.Count >= 1) |
||
2113 | home = defaultRegions[0]; |
||
2114 | |||
2115 | if (gridUserService != null && home != null) |
||
2116 | gridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0)); |
||
2117 | else |
||
2118 | m_log.WarnFormat("[RADMIN]: Unable to set home for account {0} {1}.", |
||
2119 | firstName, lastName); |
||
2120 | } |
||
2121 | else |
||
2122 | m_log.WarnFormat("[RADMIN]: Unable to retrieve home region for account {0} {1}.", |
||
2123 | firstName, lastName); |
||
2124 | |||
2125 | if (inventoryService != null) |
||
2126 | { |
||
2127 | success = inventoryService.CreateUserInventory(account.PrincipalID); |
||
2128 | if (!success) |
||
2129 | m_log.WarnFormat("[RADMIN]: Unable to create inventory for account {0} {1}.", |
||
2130 | firstName, lastName); |
||
2131 | } |
||
2132 | |||
2133 | m_log.InfoFormat("[RADMIN]: Account {0} {1} created successfully", firstName, lastName); |
||
2134 | return account; |
||
2135 | } else { |
||
2136 | m_log.ErrorFormat("[RADMIN]: Account creation failed for account {0} {1}", firstName, lastName); |
||
2137 | } |
||
2138 | } |
||
2139 | else |
||
2140 | { |
||
2141 | m_log.ErrorFormat("[RADMIN]: A user with the name {0} {1} already exists!", firstName, lastName); |
||
2142 | } |
||
2143 | return null; |
||
2144 | } |
||
2145 | |||
2146 | /// <summary> |
||
2147 | /// Change password |
||
2148 | /// </summary> |
||
2149 | /// <param name="firstName"></param> |
||
2150 | /// <param name="lastName"></param> |
||
2151 | /// <param name="password"></param> |
||
2152 | private bool ChangeUserPassword(string firstName, string lastName, string password) |
||
2153 | { |
||
2154 | Scene scene = m_application.SceneManager.CurrentOrFirstScene; |
||
2155 | IUserAccountService userAccountService = scene.UserAccountService; |
||
2156 | IAuthenticationService authenticationService = scene.AuthenticationService; |
||
2157 | |||
2158 | UserAccount account = userAccountService.GetUserAccount(UUID.Zero, firstName, lastName); |
||
2159 | if (null != account) |
||
2160 | { |
||
2161 | bool success = false; |
||
2162 | if (authenticationService != null) |
||
2163 | success = authenticationService.SetPassword(account.PrincipalID, password); |
||
2164 | |||
2165 | if (!success) |
||
2166 | { |
||
2167 | m_log.WarnFormat("[RADMIN]: Unable to set password for account {0} {1}.", |
||
2168 | firstName, lastName); |
||
2169 | return false; |
||
2170 | } |
||
2171 | return true; |
||
2172 | } |
||
2173 | else |
||
2174 | { |
||
2175 | m_log.ErrorFormat("[RADMIN]: No such user"); |
||
2176 | return false; |
||
2177 | } |
||
2178 | } |
||
2179 | |||
2180 | private bool LoadHeightmap(string file, UUID regionID) |
||
2181 | { |
||
2182 | m_log.InfoFormat("[RADMIN]: Terrain Loading: {0}", file); |
||
2183 | |||
2184 | Scene region = null; |
||
2185 | |||
2186 | if (!m_application.SceneManager.TryGetScene(regionID, out region)) |
||
2187 | { |
||
2188 | m_log.InfoFormat("[RADMIN]: unable to get a scene with that name: {0}", regionID.ToString()); |
||
2189 | return false; |
||
2190 | } |
||
2191 | |||
2192 | ITerrainModule terrainModule = region.RequestModuleInterface<ITerrainModule>(); |
||
2193 | if (null == terrainModule) throw new Exception("terrain module not available"); |
||
2194 | if (Uri.IsWellFormedUriString(file, UriKind.Absolute)) |
||
2195 | { |
||
2196 | m_log.Info("[RADMIN]: Terrain path is URL"); |
||
2197 | Uri result; |
||
2198 | if (Uri.TryCreate(file, UriKind.RelativeOrAbsolute, out result)) |
||
2199 | { |
||
2200 | // the url is valid |
||
2201 | string fileType = file.Substring(file.LastIndexOf('/') + 1); |
||
2202 | terrainModule.LoadFromStream(fileType, result); |
||
2203 | } |
||
2204 | } |
||
2205 | else |
||
2206 | { |
||
2207 | terrainModule.LoadFromFile(file); |
||
2208 | } |
||
2209 | |||
2210 | m_log.Info("[RADMIN]: Load height maps request complete"); |
||
2211 | |||
2212 | return true; |
||
2213 | } |
||
2214 | |||
2215 | |||
2216 | /// <summary> |
||
2217 | /// This method is called by the user-create and user-modify methods to establish |
||
2218 | /// or change, the user's appearance. Default avatar names can be specified via |
||
2219 | /// the config file, but must correspond to avatars in the default appearance |
||
2220 | /// file, or pre-existing in the user database. |
||
2221 | /// This should probably get moved into somewhere more core eventually. |
||
2222 | /// </summary> |
||
2223 | private void UpdateUserAppearance(Hashtable responseData, Hashtable requestData, UUID userid) |
||
2224 | { |
||
2225 | m_log.DebugFormat("[RADMIN]: updateUserAppearance"); |
||
2226 | |||
2227 | string defaultMale = m_config.GetString("default_male", "Default Male"); |
||
2228 | string defaultFemale = m_config.GetString("default_female", "Default Female"); |
||
2229 | string defaultNeutral = m_config.GetString("default_female", "Default Default"); |
||
2230 | string model = String.Empty; |
||
2231 | |||
2232 | // Has a gender preference been supplied? |
||
2233 | |||
2234 | if (requestData.Contains("gender")) |
||
2235 | { |
||
2236 | switch ((string)requestData["gender"]) |
||
2237 | { |
||
2238 | case "m" : |
||
2239 | case "male" : |
||
2240 | model = defaultMale; |
||
2241 | break; |
||
2242 | case "f" : |
||
2243 | case "female" : |
||
2244 | model = defaultFemale; |
||
2245 | break; |
||
2246 | case "n" : |
||
2247 | case "neutral" : |
||
2248 | default : |
||
2249 | model = defaultNeutral; |
||
2250 | break; |
||
2251 | } |
||
2252 | } |
||
2253 | |||
2254 | // Has an explicit model been specified? |
||
2255 | |||
2256 | if (requestData.Contains("model") && (String.IsNullOrEmpty((string)requestData["gender"]))) |
||
2257 | { |
||
2258 | model = (string)requestData["model"]; |
||
2259 | } |
||
2260 | |||
2261 | // No appearance attributes were set |
||
2262 | |||
2263 | if (String.IsNullOrEmpty(model)) |
||
2264 | { |
||
2265 | m_log.DebugFormat("[RADMIN]: Appearance update not requested"); |
||
2266 | return; |
||
2267 | } |
||
2268 | |||
2269 | m_log.DebugFormat("[RADMIN]: Setting appearance for avatar {0}, using model <{1}>", userid, model); |
||
2270 | |||
2271 | string[] modelSpecifiers = model.Split(); |
||
2272 | if (modelSpecifiers.Length != 2) |
||
2273 | { |
||
2274 | m_log.WarnFormat("[RADMIN]: User appearance not set for {0}. Invalid model name : <{1}>", userid, model); |
||
2275 | // modelSpecifiers = dmodel.Split(); |
||
2276 | return; |
||
2277 | } |
||
2278 | |||
2279 | Scene scene = m_application.SceneManager.CurrentOrFirstScene; |
||
2280 | UUID scopeID = scene.RegionInfo.ScopeID; |
||
2281 | UserAccount modelProfile = scene.UserAccountService.GetUserAccount(scopeID, modelSpecifiers[0], modelSpecifiers[1]); |
||
2282 | |||
2283 | if (modelProfile == null) |
||
2284 | { |
||
2285 | m_log.WarnFormat("[RADMIN]: Requested model ({0}) not found. Appearance unchanged", model); |
||
2286 | return; |
||
2287 | } |
||
2288 | |||
2289 | // Set current user's appearance. This bit is easy. The appearance structure is populated with |
||
2290 | // actual asset ids, however to complete the magic we need to populate the inventory with the |
||
2291 | // assets in question. |
||
2292 | |||
2293 | EstablishAppearance(userid, modelProfile.PrincipalID); |
||
2294 | |||
2295 | m_log.DebugFormat("[RADMIN]: Finished setting appearance for avatar {0}, using model {1}", |
||
2296 | userid, model); |
||
2297 | } |
||
2298 | |||
2299 | /// <summary> |
||
2300 | /// This method is called by updateAvatarAppearance once any specified model has been |
||
2301 | /// ratified, or an appropriate default value has been adopted. The intended prototype |
||
2302 | /// is known to exist, as is the target avatar. |
||
2303 | /// </summary> |
||
2304 | private void EstablishAppearance(UUID destination, UUID source) |
||
2305 | { |
||
2306 | m_log.DebugFormat("[RADMIN]: Initializing inventory for {0} from {1}", destination, source); |
||
2307 | Scene scene = m_application.SceneManager.CurrentOrFirstScene; |
||
2308 | |||
2309 | // If the model has no associated appearance we're done. |
||
2310 | AvatarAppearance avatarAppearance = scene.AvatarService.GetAppearance(source); |
||
2311 | if (avatarAppearance == null) |
||
2312 | return; |
||
2313 | |||
2314 | // Simple appearance copy or copy Clothing and Bodyparts folders? |
||
2315 | bool copyFolders = m_config.GetBoolean("copy_folders", false); |
||
2316 | |||
2317 | if (!copyFolders) |
||
2318 | { |
||
2319 | // Simple copy of wearables and appearance update |
||
2320 | try |
||
2321 | { |
||
2322 | CopyWearablesAndAttachments(destination, source, avatarAppearance); |
||
2323 | |||
2324 | scene.AvatarService.SetAppearance(destination, avatarAppearance); |
||
2325 | } |
||
2326 | catch (Exception e) |
||
2327 | { |
||
2328 | m_log.WarnFormat("[RADMIN]: Error transferring appearance for {0} : {1}", |
||
2329 | destination, e.Message); |
||
2330 | } |
||
2331 | |||
2332 | return; |
||
2333 | } |
||
2334 | |||
2335 | // Copy Clothing and Bodypart folders and appearance update |
||
2336 | try |
||
2337 | { |
||
2338 | Dictionary<UUID,UUID> inventoryMap = new Dictionary<UUID,UUID>(); |
||
2339 | CopyInventoryFolders(destination, source, AssetType.Clothing, inventoryMap, avatarAppearance); |
||
2340 | CopyInventoryFolders(destination, source, AssetType.Bodypart, inventoryMap, avatarAppearance); |
||
2341 | |||
2342 | AvatarWearable[] wearables = avatarAppearance.Wearables; |
||
2343 | |||
2344 | for (int i=0; i<wearables.Length; i++) |
||
2345 | { |
||
2346 | if (inventoryMap.ContainsKey(wearables[i][0].ItemID)) |
||
2347 | { |
||
2348 | AvatarWearable wearable = new AvatarWearable(); |
||
2349 | wearable.Wear(inventoryMap[wearables[i][0].ItemID], |
||
2350 | wearables[i][0].AssetID); |
||
2351 | avatarAppearance.SetWearable(i, wearable); |
||
2352 | } |
||
2353 | } |
||
2354 | |||
2355 | scene.AvatarService.SetAppearance(destination, avatarAppearance); |
||
2356 | } |
||
2357 | catch (Exception e) |
||
2358 | { |
||
2359 | m_log.WarnFormat("[RADMIN]: Error transferring appearance for {0} : {1}", |
||
2360 | destination, e.Message); |
||
2361 | } |
||
2362 | |||
2363 | return; |
||
2364 | } |
||
2365 | |||
2366 | /// <summary> |
||
2367 | /// This method is called by establishAppearance to do a copy all inventory items |
||
2368 | /// worn or attached to the Clothing inventory folder of the receiving avatar. |
||
2369 | /// In parallel the avatar wearables and attachments are updated. |
||
2370 | /// </summary> |
||
2371 | private void CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance) |
||
2372 | { |
||
2373 | IInventoryService inventoryService = m_application.SceneManager.CurrentOrFirstScene.InventoryService; |
||
2374 | |||
2375 | // Get Clothing folder of receiver |
||
2376 | InventoryFolderBase destinationFolder = inventoryService.GetFolderForType(destination, AssetType.Clothing); |
||
2377 | |||
2378 | if (destinationFolder == null) |
||
2379 | throw new Exception("Cannot locate folder(s)"); |
||
2380 | |||
2381 | // Missing destination folder? This should *never* be the case |
||
2382 | if (destinationFolder.Type != (short)AssetType.Clothing) |
||
2383 | { |
||
2384 | destinationFolder = new InventoryFolderBase(); |
||
2385 | |||
2386 | destinationFolder.ID = UUID.Random(); |
||
2387 | destinationFolder.Name = "Clothing"; |
||
2388 | destinationFolder.Owner = destination; |
||
2389 | destinationFolder.Type = (short)AssetType.Clothing; |
||
2390 | destinationFolder.ParentID = inventoryService.GetRootFolder(destination).ID; |
||
2391 | destinationFolder.Version = 1; |
||
2392 | inventoryService.AddFolder(destinationFolder); // store base record |
||
2393 | m_log.ErrorFormat("[RADMIN]: Created folder for destination {0}", source); |
||
2394 | } |
||
2395 | |||
2396 | // Wearables |
||
2397 | AvatarWearable[] wearables = avatarAppearance.Wearables; |
||
2398 | AvatarWearable wearable; |
||
2399 | |||
2400 | for (int i = 0; i<wearables.Length; i++) |
||
2401 | { |
||
2402 | wearable = wearables[i]; |
||
2403 | if (wearable[0].ItemID != UUID.Zero) |
||
2404 | { |
||
2405 | // Get inventory item and copy it |
||
2406 | InventoryItemBase item = new InventoryItemBase(wearable[0].ItemID, source); |
||
2407 | item = inventoryService.GetItem(item); |
||
2408 | |||
2409 | if (item != null) |
||
2410 | { |
||
2411 | InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination); |
||
2412 | destinationItem.Name = item.Name; |
||
2413 | destinationItem.Owner = destination; |
||
2414 | destinationItem.Description = item.Description; |
||
2415 | destinationItem.InvType = item.InvType; |
||
2416 | destinationItem.CreatorId = item.CreatorId; |
||
2417 | destinationItem.CreatorData = item.CreatorData; |
||
2418 | destinationItem.NextPermissions = item.NextPermissions; |
||
2419 | destinationItem.CurrentPermissions = item.CurrentPermissions; |
||
2420 | destinationItem.BasePermissions = item.BasePermissions; |
||
2421 | destinationItem.EveryOnePermissions = item.EveryOnePermissions; |
||
2422 | destinationItem.GroupPermissions = item.GroupPermissions; |
||
2423 | destinationItem.AssetType = item.AssetType; |
||
2424 | destinationItem.AssetID = item.AssetID; |
||
2425 | destinationItem.GroupID = item.GroupID; |
||
2426 | destinationItem.GroupOwned = item.GroupOwned; |
||
2427 | destinationItem.SalePrice = item.SalePrice; |
||
2428 | destinationItem.SaleType = item.SaleType; |
||
2429 | destinationItem.Flags = item.Flags; |
||
2430 | destinationItem.CreationDate = item.CreationDate; |
||
2431 | destinationItem.Folder = destinationFolder.ID; |
||
2432 | ApplyNextOwnerPermissions(destinationItem); |
||
2433 | |||
2434 | m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(destinationItem); |
||
2435 | m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID); |
||
2436 | |||
2437 | // Wear item |
||
2438 | AvatarWearable newWearable = new AvatarWearable(); |
||
2439 | newWearable.Wear(destinationItem.ID, wearable[0].AssetID); |
||
2440 | avatarAppearance.SetWearable(i, newWearable); |
||
2441 | } |
||
2442 | else |
||
2443 | { |
||
2444 | m_log.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", wearable[0].ItemID, destinationFolder.ID); |
||
2445 | } |
||
2446 | } |
||
2447 | } |
||
2448 | |||
2449 | // Attachments |
||
2450 | List<AvatarAttachment> attachments = avatarAppearance.GetAttachments(); |
||
2451 | |||
2452 | foreach (AvatarAttachment attachment in attachments) |
||
2453 | { |
||
2454 | int attachpoint = attachment.AttachPoint; |
||
2455 | UUID itemID = attachment.ItemID; |
||
2456 | |||
2457 | if (itemID != UUID.Zero) |
||
2458 | { |
||
2459 | // Get inventory item and copy it |
||
2460 | InventoryItemBase item = new InventoryItemBase(itemID, source); |
||
2461 | item = inventoryService.GetItem(item); |
||
2462 | |||
2463 | if (item != null) |
||
2464 | { |
||
2465 | InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination); |
||
2466 | destinationItem.Name = item.Name; |
||
2467 | destinationItem.Owner = destination; |
||
2468 | destinationItem.Description = item.Description; |
||
2469 | destinationItem.InvType = item.InvType; |
||
2470 | destinationItem.CreatorId = item.CreatorId; |
||
2471 | destinationItem.CreatorData = item.CreatorData; |
||
2472 | destinationItem.NextPermissions = item.NextPermissions; |
||
2473 | destinationItem.CurrentPermissions = item.CurrentPermissions; |
||
2474 | destinationItem.BasePermissions = item.BasePermissions; |
||
2475 | destinationItem.EveryOnePermissions = item.EveryOnePermissions; |
||
2476 | destinationItem.GroupPermissions = item.GroupPermissions; |
||
2477 | destinationItem.AssetType = item.AssetType; |
||
2478 | destinationItem.AssetID = item.AssetID; |
||
2479 | destinationItem.GroupID = item.GroupID; |
||
2480 | destinationItem.GroupOwned = item.GroupOwned; |
||
2481 | destinationItem.SalePrice = item.SalePrice; |
||
2482 | destinationItem.SaleType = item.SaleType; |
||
2483 | destinationItem.Flags = item.Flags; |
||
2484 | destinationItem.CreationDate = item.CreationDate; |
||
2485 | destinationItem.Folder = destinationFolder.ID; |
||
2486 | ApplyNextOwnerPermissions(destinationItem); |
||
2487 | |||
2488 | m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(destinationItem); |
||
2489 | m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID); |
||
2490 | |||
2491 | // Attach item |
||
2492 | avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID); |
||
2493 | m_log.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID); |
||
2494 | } |
||
2495 | else |
||
2496 | { |
||
2497 | m_log.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID); |
||
2498 | } |
||
2499 | } |
||
2500 | } |
||
2501 | } |
||
2502 | |||
2503 | /// <summary> |
||
2504 | /// This method is called by establishAppearance to copy inventory folders to make |
||
2505 | /// copies of Clothing and Bodyparts inventory folders and attaches worn attachments |
||
2506 | /// </summary> |
||
2507 | private void CopyInventoryFolders(UUID destination, UUID source, AssetType assetType, Dictionary<UUID,UUID> inventoryMap, |
||
2508 | AvatarAppearance avatarAppearance) |
||
2509 | { |
||
2510 | IInventoryService inventoryService = m_application.SceneManager.CurrentOrFirstScene.InventoryService; |
||
2511 | |||
2512 | InventoryFolderBase sourceFolder = inventoryService.GetFolderForType(source, assetType); |
||
2513 | InventoryFolderBase destinationFolder = inventoryService.GetFolderForType(destination, assetType); |
||
2514 | |||
2515 | if (sourceFolder == null || destinationFolder == null) |
||
2516 | throw new Exception("Cannot locate folder(s)"); |
||
2517 | |||
2518 | // Missing source folder? This should *never* be the case |
||
2519 | if (sourceFolder.Type != (short)assetType) |
||
2520 | { |
||
2521 | sourceFolder = new InventoryFolderBase(); |
||
2522 | sourceFolder.ID = UUID.Random(); |
||
2523 | if (assetType == AssetType.Clothing) { |
||
2524 | sourceFolder.Name = "Clothing"; |
||
2525 | } else { |
||
2526 | sourceFolder.Name = "Body Parts"; |
||
2527 | } |
||
2528 | sourceFolder.Owner = source; |
||
2529 | sourceFolder.Type = (short)assetType; |
||
2530 | sourceFolder.ParentID = inventoryService.GetRootFolder(source).ID; |
||
2531 | sourceFolder.Version = 1; |
||
2532 | inventoryService.AddFolder(sourceFolder); // store base record |
||
2533 | m_log.ErrorFormat("[RADMIN] Created folder for source {0}", source); |
||
2534 | } |
||
2535 | |||
2536 | // Missing destination folder? This should *never* be the case |
||
2537 | if (destinationFolder.Type != (short)assetType) |
||
2538 | { |
||
2539 | destinationFolder = new InventoryFolderBase(); |
||
2540 | destinationFolder.ID = UUID.Random(); |
||
2541 | if (assetType == AssetType.Clothing) |
||
2542 | { |
||
2543 | destinationFolder.Name = "Clothing"; |
||
2544 | } |
||
2545 | else |
||
2546 | { |
||
2547 | destinationFolder.Name = "Body Parts"; |
||
2548 | } |
||
2549 | destinationFolder.Owner = destination; |
||
2550 | destinationFolder.Type = (short)assetType; |
||
2551 | destinationFolder.ParentID = inventoryService.GetRootFolder(destination).ID; |
||
2552 | destinationFolder.Version = 1; |
||
2553 | inventoryService.AddFolder(destinationFolder); // store base record |
||
2554 | m_log.ErrorFormat("[RADMIN]: Created folder for destination {0}", source); |
||
2555 | } |
||
2556 | |||
2557 | InventoryFolderBase extraFolder; |
||
2558 | List<InventoryFolderBase> folders = inventoryService.GetFolderContent(source, sourceFolder.ID).Folders; |
||
2559 | |||
2560 | foreach (InventoryFolderBase folder in folders) |
||
2561 | { |
||
2562 | extraFolder = new InventoryFolderBase(); |
||
2563 | extraFolder.ID = UUID.Random(); |
||
2564 | extraFolder.Name = folder.Name; |
||
2565 | extraFolder.Owner = destination; |
||
2566 | extraFolder.Type = folder.Type; |
||
2567 | extraFolder.Version = folder.Version; |
||
2568 | extraFolder.ParentID = destinationFolder.ID; |
||
2569 | inventoryService.AddFolder(extraFolder); |
||
2570 | |||
2571 | m_log.DebugFormat("[RADMIN]: Added folder {0} to folder {1}", extraFolder.ID, sourceFolder.ID); |
||
2572 | |||
2573 | List<InventoryItemBase> items = inventoryService.GetFolderContent(source, folder.ID).Items; |
||
2574 | |||
2575 | foreach (InventoryItemBase item in items) |
||
2576 | { |
||
2577 | InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination); |
||
2578 | destinationItem.Name = item.Name; |
||
2579 | destinationItem.Owner = destination; |
||
2580 | destinationItem.Description = item.Description; |
||
2581 | destinationItem.InvType = item.InvType; |
||
2582 | destinationItem.CreatorId = item.CreatorId; |
||
2583 | destinationItem.CreatorData = item.CreatorData; |
||
2584 | destinationItem.NextPermissions = item.NextPermissions; |
||
2585 | destinationItem.CurrentPermissions = item.CurrentPermissions; |
||
2586 | destinationItem.BasePermissions = item.BasePermissions; |
||
2587 | destinationItem.EveryOnePermissions = item.EveryOnePermissions; |
||
2588 | destinationItem.GroupPermissions = item.GroupPermissions; |
||
2589 | destinationItem.AssetType = item.AssetType; |
||
2590 | destinationItem.AssetID = item.AssetID; |
||
2591 | destinationItem.GroupID = item.GroupID; |
||
2592 | destinationItem.GroupOwned = item.GroupOwned; |
||
2593 | destinationItem.SalePrice = item.SalePrice; |
||
2594 | destinationItem.SaleType = item.SaleType; |
||
2595 | destinationItem.Flags = item.Flags; |
||
2596 | destinationItem.CreationDate = item.CreationDate; |
||
2597 | destinationItem.Folder = extraFolder.ID; |
||
2598 | ApplyNextOwnerPermissions(destinationItem); |
||
2599 | |||
2600 | m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(destinationItem); |
||
2601 | inventoryMap.Add(item.ID, destinationItem.ID); |
||
2602 | m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, extraFolder.ID); |
||
2603 | |||
2604 | // Attach item, if original is attached |
||
2605 | int attachpoint = avatarAppearance.GetAttachpoint(item.ID); |
||
2606 | if (attachpoint != 0) |
||
2607 | { |
||
2608 | avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID); |
||
2609 | m_log.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID); |
||
2610 | } |
||
2611 | } |
||
2612 | } |
||
2613 | } |
||
2614 | |||
2615 | /// <summary> |
||
2616 | /// Apply next owner permissions. |
||
2617 | /// </summary> |
||
2618 | private void ApplyNextOwnerPermissions(InventoryItemBase item) |
||
2619 | { |
||
2620 | if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) |
||
2621 | { |
||
2622 | if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) |
||
2623 | item.CurrentPermissions &= ~(uint)PermissionMask.Copy; |
||
2624 | if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) |
||
2625 | item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; |
||
2626 | if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) |
||
2627 | item.CurrentPermissions &= ~(uint)PermissionMask.Modify; |
||
2628 | } |
||
2629 | item.CurrentPermissions &= item.NextPermissions; |
||
2630 | item.BasePermissions &= item.NextPermissions; |
||
2631 | item.EveryOnePermissions &= item.NextPermissions; |
||
2632 | // item.OwnerChanged = true; |
||
2633 | // item.PermsMask = 0; |
||
2634 | // item.PermsGranter = UUID.Zero; |
||
2635 | } |
||
2636 | |||
2637 | /// <summary> |
||
2638 | /// This method is called if a given model avatar name can not be found. If the external |
||
2639 | /// file has already been loaded once, then control returns immediately. If not, then it |
||
2640 | /// looks for a default appearance file. This file contains XML definitions of zero or more named |
||
2641 | /// avatars, each avatar can specify zero or more "outfits". Each outfit is a collection |
||
2642 | /// of items that together, define a particular ensemble for the avatar. Each avatar should |
||
2643 | /// indicate which outfit is the default, and this outfit will be automatically worn. The |
||
2644 | /// other outfits are provided to allow "real" avatars a way to easily change their outfits. |
||
2645 | /// </summary> |
||
2646 | private bool CreateDefaultAvatars() |
||
2647 | { |
||
2648 | // Only load once |
||
2649 | if (m_defaultAvatarsLoaded) |
||
2650 | { |
||
2651 | return false; |
||
2652 | } |
||
2653 | |||
2654 | m_log.DebugFormat("[RADMIN]: Creating default avatar entries"); |
||
2655 | |||
2656 | m_defaultAvatarsLoaded = true; |
||
2657 | |||
2658 | // Load processing starts here... |
||
2659 | |||
2660 | try |
||
2661 | { |
||
2662 | string defaultAppearanceFileName = null; |
||
2663 | |||
2664 | //m_config may be null if RemoteAdmin configuration secition is missing or disabled in OpenSim.ini |
||
2665 | if (m_config != null) |
||
2666 | { |
||
2667 | defaultAppearanceFileName = m_config.GetString("default_appearance", "default_appearance.xml"); |
||
2668 | } |
||
2669 | |||
2670 | if (File.Exists(defaultAppearanceFileName)) |
||
2671 | { |
||
2672 | XmlDocument doc = new XmlDocument(); |
||
2673 | string name = "*unknown*"; |
||
2674 | string email = "anon@anon"; |
||
2675 | uint regionXLocation = 1000; |
||
2676 | uint regionYLocation = 1000; |
||
2677 | string password = UUID.Random().ToString(); // No requirement to sign-in. |
||
2678 | UUID ID = UUID.Zero; |
||
2679 | AvatarAppearance avatarAppearance; |
||
2680 | XmlNodeList avatars; |
||
2681 | XmlNodeList assets; |
||
2682 | XmlNode perms = null; |
||
2683 | bool include = false; |
||
2684 | bool select = false; |
||
2685 | |||
2686 | Scene scene = m_application.SceneManager.CurrentOrFirstScene; |
||
2687 | IInventoryService inventoryService = scene.InventoryService; |
||
2688 | IAssetService assetService = scene.AssetService; |
||
2689 | |||
2690 | doc.LoadXml(File.ReadAllText(defaultAppearanceFileName)); |
||
2691 | |||
2692 | // Load up any included assets. Duplicates will be ignored |
||
2693 | assets = doc.GetElementsByTagName("RequiredAsset"); |
||
2694 | foreach (XmlNode assetNode in assets) |
||
2695 | { |
||
2696 | AssetBase asset = new AssetBase(UUID.Random(), GetStringAttribute(assetNode, "name", ""), SByte.Parse(GetStringAttribute(assetNode, "type", "")), UUID.Zero.ToString()); |
||
2697 | asset.Description = GetStringAttribute(assetNode,"desc",""); |
||
2698 | asset.Local = Boolean.Parse(GetStringAttribute(assetNode,"local","")); |
||
2699 | asset.Temporary = Boolean.Parse(GetStringAttribute(assetNode,"temporary","")); |
||
2700 | asset.Data = Convert.FromBase64String(assetNode.InnerText); |
||
2701 | assetService.Store(asset); |
||
2702 | } |
||
2703 | |||
2704 | avatars = doc.GetElementsByTagName("Avatar"); |
||
2705 | |||
2706 | // The document may contain multiple avatars |
||
2707 | |||
2708 | foreach (XmlElement avatar in avatars) |
||
2709 | { |
||
2710 | m_log.DebugFormat("[RADMIN]: Loading appearance for {0}, gender = {1}", |
||
2711 | GetStringAttribute(avatar,"name","?"), GetStringAttribute(avatar,"gender","?")); |
||
2712 | |||
2713 | // Create the user identified by the avatar entry |
||
2714 | |||
2715 | try |
||
2716 | { |
||
2717 | // Only the name value is mandatory |
||
2718 | name = GetStringAttribute(avatar,"name",name); |
||
2719 | email = GetStringAttribute(avatar,"email",email); |
||
2720 | regionXLocation = GetUnsignedAttribute(avatar,"regx",regionXLocation); |
||
2721 | regionYLocation = GetUnsignedAttribute(avatar,"regy",regionYLocation); |
||
2722 | password = GetStringAttribute(avatar,"password",password); |
||
2723 | |||
2724 | string[] names = name.Split(); |
||
2725 | UUID scopeID = scene.RegionInfo.ScopeID; |
||
2726 | UserAccount account = scene.UserAccountService.GetUserAccount(scopeID, names[0], names[1]); |
||
2727 | if (null == account) |
||
2728 | { |
||
2729 | account = CreateUser(scopeID, names[0], names[1], password, email); |
||
2730 | if (null == account) |
||
2731 | { |
||
2732 | m_log.ErrorFormat("[RADMIN]: Avatar {0} {1} was not created", names[0], names[1]); |
||
2733 | return false; |
||
2734 | } |
||
2735 | } |
||
2736 | |||
2737 | // Set home position |
||
2738 | |||
2739 | GridRegion home = scene.GridService.GetRegionByPosition(scopeID, |
||
2740 | (int)(regionXLocation * Constants.RegionSize), (int)(regionYLocation * Constants.RegionSize)); |
||
2741 | if (null == home) { |
||
2742 | m_log.WarnFormat("[RADMIN]: Unable to set home region for newly created user account {0} {1}", names[0], names[1]); |
||
2743 | } else { |
||
2744 | scene.GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0)); |
||
2745 | m_log.DebugFormat("[RADMIN]: Set home region {0} for updated user account {1} {2}", home.RegionID, names[0], names[1]); |
||
2746 | } |
||
2747 | |||
2748 | ID = account.PrincipalID; |
||
2749 | |||
2750 | m_log.DebugFormat("[RADMIN]: User {0}[{1}] created or retrieved", name, ID); |
||
2751 | include = true; |
||
2752 | } |
||
2753 | catch (Exception e) |
||
2754 | { |
||
2755 | m_log.DebugFormat("[RADMIN]: Error creating user {0} : {1}", name, e.Message); |
||
2756 | include = false; |
||
2757 | } |
||
2758 | |||
2759 | // OK, User has been created OK, now we can install the inventory. |
||
2760 | // First retrieve the current inventory (the user may already exist) |
||
2761 | // Note that althought he inventory is retrieved, the hierarchy has |
||
2762 | // not been interpreted at all. |
||
2763 | |||
2764 | if (include) |
||
2765 | { |
||
2766 | // Setup for appearance processing |
||
2767 | avatarAppearance = scene.AvatarService.GetAppearance(ID); |
||
2768 | if (avatarAppearance == null) |
||
2769 | avatarAppearance = new AvatarAppearance(); |
||
2770 | |||
2771 | AvatarWearable[] wearables = avatarAppearance.Wearables; |
||
2772 | for (int i=0; i<wearables.Length; i++) |
||
2773 | { |
||
2774 | wearables[i] = new AvatarWearable(); |
||
2775 | } |
||
2776 | |||
2777 | try |
||
2778 | { |
||
2779 | // m_log.DebugFormat("[RADMIN] {0} folders, {1} items in inventory", |
||
2780 | // uic.folders.Count, uic.items.Count); |
||
2781 | |||
2782 | InventoryFolderBase clothingFolder = inventoryService.GetFolderForType(ID, AssetType.Clothing); |
||
2783 | |||
2784 | // This should *never* be the case |
||
2785 | if (clothingFolder == null || clothingFolder.Type != (short)AssetType.Clothing) |
||
2786 | { |
||
2787 | clothingFolder = new InventoryFolderBase(); |
||
2788 | clothingFolder.ID = UUID.Random(); |
||
2789 | clothingFolder.Name = "Clothing"; |
||
2790 | clothingFolder.Owner = ID; |
||
2791 | clothingFolder.Type = (short)AssetType.Clothing; |
||
2792 | clothingFolder.ParentID = inventoryService.GetRootFolder(ID).ID; |
||
2793 | clothingFolder.Version = 1; |
||
2794 | inventoryService.AddFolder(clothingFolder); // store base record |
||
2795 | m_log.ErrorFormat("[RADMIN]: Created clothing folder for {0}/{1}", name, ID); |
||
2796 | } |
||
2797 | |||
2798 | // OK, now we have an inventory for the user, read in the outfits from the |
||
2799 | // default appearance XMl file. |
||
2800 | |||
2801 | XmlNodeList outfits = avatar.GetElementsByTagName("Ensemble"); |
||
2802 | InventoryFolderBase extraFolder; |
||
2803 | string outfitName; |
||
2804 | UUID assetid; |
||
2805 | |||
2806 | foreach (XmlElement outfit in outfits) |
||
2807 | { |
||
2808 | m_log.DebugFormat("[RADMIN]: Loading outfit {0} for {1}", |
||
2809 | GetStringAttribute(outfit,"name","?"), GetStringAttribute(avatar,"name","?")); |
||
2810 | |||
2811 | outfitName = GetStringAttribute(outfit,"name",""); |
||
2812 | select = (GetStringAttribute(outfit,"default","no") == "yes"); |
||
2813 | |||
2814 | // If the folder already exists, re-use it. The defaults may |
||
2815 | // change over time. Augment only. |
||
2816 | |||
2817 | List<InventoryFolderBase> folders = inventoryService.GetFolderContent(ID, clothingFolder.ID).Folders; |
||
2818 | extraFolder = null; |
||
2819 | |||
2820 | foreach (InventoryFolderBase folder in folders) |
||
2821 | { |
||
2822 | if (folder.Name == outfitName) |
||
2823 | { |
||
2824 | extraFolder = folder; |
||
2825 | break; |
||
2826 | } |
||
2827 | } |
||
2828 | |||
2829 | // Otherwise, we must create the folder. |
||
2830 | if (extraFolder == null) |
||
2831 | { |
||
2832 | m_log.DebugFormat("[RADMIN]: Creating outfit folder {0} for {1}", outfitName, name); |
||
2833 | extraFolder = new InventoryFolderBase(); |
||
2834 | extraFolder.ID = UUID.Random(); |
||
2835 | extraFolder.Name = outfitName; |
||
2836 | extraFolder.Owner = ID; |
||
2837 | extraFolder.Type = (short)AssetType.Clothing; |
||
2838 | extraFolder.Version = 1; |
||
2839 | extraFolder.ParentID = clothingFolder.ID; |
||
2840 | inventoryService.AddFolder(extraFolder); |
||
2841 | m_log.DebugFormat("[RADMIN]: Adding outfile folder {0} to folder {1}", extraFolder.ID, clothingFolder.ID); |
||
2842 | } |
||
2843 | |||
2844 | // Now get the pieces that make up the outfit |
||
2845 | XmlNodeList items = outfit.GetElementsByTagName("Item"); |
||
2846 | |||
2847 | foreach (XmlElement item in items) |
||
2848 | { |
||
2849 | assetid = UUID.Zero; |
||
2850 | XmlNodeList children = item.ChildNodes; |
||
2851 | foreach (XmlNode child in children) |
||
2852 | { |
||
2853 | switch (child.Name) |
||
2854 | { |
||
2855 | case "Permissions" : |
||
2856 | m_log.DebugFormat("[RADMIN]: Permissions specified"); |
||
2857 | perms = child; |
||
2858 | break; |
||
2859 | case "Asset" : |
||
2860 | assetid = new UUID(child.InnerText); |
||
2861 | break; |
||
2862 | } |
||
2863 | } |
||
2864 | |||
2865 | InventoryItemBase inventoryItem = null; |
||
2866 | |||
2867 | // Check if asset is in inventory already |
||
2868 | inventoryItem = null; |
||
2869 | List<InventoryItemBase> inventoryItems = inventoryService.GetFolderContent(ID, extraFolder.ID).Items; |
||
2870 | |||
2871 | foreach (InventoryItemBase listItem in inventoryItems) |
||
2872 | { |
||
2873 | if (listItem.AssetID == assetid) |
||
2874 | { |
||
2875 | inventoryItem = listItem; |
||
2876 | break; |
||
2877 | } |
||
2878 | } |
||
2879 | |||
2880 | // Create inventory item |
||
2881 | if (inventoryItem == null) |
||
2882 | { |
||
2883 | inventoryItem = new InventoryItemBase(UUID.Random(), ID); |
||
2884 | inventoryItem.Name = GetStringAttribute(item,"name",""); |
||
2885 | inventoryItem.Description = GetStringAttribute(item,"desc",""); |
||
2886 | inventoryItem.InvType = GetIntegerAttribute(item,"invtype",-1); |
||
2887 | inventoryItem.CreatorId = GetStringAttribute(item,"creatorid",""); |
||
2888 | inventoryItem.CreatorData = GetStringAttribute(item, "creatordata", ""); |
||
2889 | inventoryItem.NextPermissions = GetUnsignedAttribute(perms, "next", 0x7fffffff); |
||
2890 | inventoryItem.CurrentPermissions = GetUnsignedAttribute(perms,"current",0x7fffffff); |
||
2891 | inventoryItem.BasePermissions = GetUnsignedAttribute(perms,"base",0x7fffffff); |
||
2892 | inventoryItem.EveryOnePermissions = GetUnsignedAttribute(perms,"everyone",0x7fffffff); |
||
2893 | inventoryItem.GroupPermissions = GetUnsignedAttribute(perms,"group",0x7fffffff); |
||
2894 | inventoryItem.AssetType = GetIntegerAttribute(item,"assettype",-1); |
||
2895 | inventoryItem.AssetID = assetid; // associated asset |
||
2896 | inventoryItem.GroupID = (UUID)GetStringAttribute(item,"groupid",""); |
||
2897 | inventoryItem.GroupOwned = (GetStringAttribute(item,"groupowned","false") == "true"); |
||
2898 | inventoryItem.SalePrice = GetIntegerAttribute(item,"saleprice",0); |
||
2899 | inventoryItem.SaleType = (byte)GetIntegerAttribute(item,"saletype",0); |
||
2900 | inventoryItem.Flags = GetUnsignedAttribute(item,"flags",0); |
||
2901 | inventoryItem.CreationDate = GetIntegerAttribute(item,"creationdate",Util.UnixTimeSinceEpoch()); |
||
2902 | inventoryItem.Folder = extraFolder.ID; // Parent folder |
||
2903 | |||
2904 | m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(inventoryItem); |
||
2905 | m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", inventoryItem.ID, extraFolder.ID); |
||
2906 | } |
||
2907 | |||
2908 | // Attach item, if attachpoint is specified |
||
2909 | int attachpoint = GetIntegerAttribute(item,"attachpoint",0); |
||
2910 | if (attachpoint != 0) |
||
2911 | { |
||
2912 | avatarAppearance.SetAttachment(attachpoint, inventoryItem.ID, inventoryItem.AssetID); |
||
2913 | m_log.DebugFormat("[RADMIN]: Attached {0}", inventoryItem.ID); |
||
2914 | } |
||
2915 | |||
2916 | // Record whether or not the item is to be initially worn |
||
2917 | try |
||
2918 | { |
||
2919 | if (select && (GetStringAttribute(item, "wear", "false") == "true")) |
||
2920 | { |
||
2921 | avatarAppearance.Wearables[inventoryItem.Flags].Wear(inventoryItem.ID, inventoryItem.AssetID); |
||
2922 | } |
||
2923 | } |
||
2924 | catch (Exception e) |
||
2925 | { |
||
2926 | m_log.WarnFormat("[RADMIN]: Error wearing item {0} : {1}", inventoryItem.ID, e.Message); |
||
2927 | } |
||
2928 | } // foreach item in outfit |
||
2929 | m_log.DebugFormat("[RADMIN]: Outfit {0} load completed", outfitName); |
||
2930 | } // foreach outfit |
||
2931 | m_log.DebugFormat("[RADMIN]: Inventory update complete for {0}", name); |
||
2932 | scene.AvatarService.SetAppearance(ID, avatarAppearance); |
||
2933 | } |
||
2934 | catch (Exception e) |
||
2935 | { |
||
2936 | m_log.WarnFormat("[RADMIN]: Inventory processing incomplete for user {0} : {1}", |
||
2937 | name, e.Message); |
||
2938 | } |
||
2939 | } // End of include |
||
2940 | } |
||
2941 | m_log.DebugFormat("[RADMIN]: Default avatar loading complete"); |
||
2942 | } |
||
2943 | else |
||
2944 | { |
||
2945 | m_log.DebugFormat("[RADMIN]: No default avatar information available"); |
||
2946 | return false; |
||
2947 | } |
||
2948 | } |
||
2949 | catch (Exception e) |
||
2950 | { |
||
2951 | m_log.WarnFormat("[RADMIN]: Exception whilst loading default avatars ; {0}", e.Message); |
||
2952 | return false; |
||
2953 | } |
||
2954 | |||
2955 | return true; |
||
2956 | } |
||
2957 | } |
||
2958 | } |