AgentPreferencesModule.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using System.IO;
  31. using log4net;
  32. using Mono.Addins;
  33. using Nini.Config;
  34. using OpenMetaverse;
  35. using OpenMetaverse.StructuredData;
  36. using OpenSim.Framework.Console;
  37. using OpenSim.Framework.Servers;
  38. using OpenSim.Framework.Servers.HttpServer;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes;
  41. using OpenSim.Services.Interfaces;
  42. using Caps = OpenSim.Framework.Capabilities.Caps;
  43. using OpenSim.Capabilities.Handlers;
  44. namespace OpenSim.Region.ClientStack.LindenCaps
  45. {
  46. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AgentPreferencesModule")]
  47. public class AgentPreferencesModule : ISharedRegionModule
  48. {
  49. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. private List<Scene> m_scenes = new List<Scene>();
  51. public void Initialise(IConfigSource source)
  52. {
  53. }
  54. #region Region module
  55. public void AddRegion(Scene scene)
  56. {
  57. lock (m_scenes) m_scenes.Add(scene);
  58. }
  59. public void RemoveRegion(Scene scene)
  60. {
  61. lock (m_scenes) m_scenes.Remove(scene);
  62. scene.EventManager.OnRegisterCaps -= RegisterCaps;
  63. scene = null;
  64. }
  65. public void RegionLoaded(Scene scene)
  66. {
  67. scene.EventManager.OnRegisterCaps += delegate(UUID agentID, OpenSim.Framework.Capabilities.Caps caps)
  68. {
  69. RegisterCaps(agentID, caps);
  70. };
  71. }
  72. public void PostInitialise() {}
  73. public void Close() {}
  74. public string Name { get { return "AgentPreferencesModule"; } }
  75. public Type ReplaceableInterface
  76. {
  77. get { return null; }
  78. }
  79. public void RegisterCaps(UUID agent, Caps caps)
  80. {
  81. UUID capId = UUID.Random();
  82. caps.RegisterHandler("AgentPreferences",
  83. new RestStreamHandler("POST", "/CAPS/" + capId,
  84. delegate(string request, string path, string param,
  85. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  86. {
  87. return UpdateAgentPreferences(request, path, param, agent);
  88. }));
  89. caps.RegisterHandler("UpdateAgentLanguage",
  90. new RestStreamHandler("POST", "/CAPS/" + capId,
  91. delegate(string request, string path, string param,
  92. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  93. {
  94. return UpdateAgentPreferences(request, path, param, agent);
  95. }));
  96. caps.RegisterHandler("UpdateAgentInformation",
  97. new RestStreamHandler("POST", "/CAPS/" + capId,
  98. delegate(string request, string path, string param,
  99. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  100. {
  101. return UpdateAgentPreferences(request, path, param, agent);
  102. }));
  103. }
  104. public string UpdateAgentPreferences(string request, string path, string param, UUID agent)
  105. {
  106. OSDMap resp = new OSDMap();
  107. // The viewer doesn't do much with the return value, so for now, if there is no preference service,
  108. // we'll return a null llsd block for debugging purposes. This may change if someone knows what the
  109. // correct server response would be here.
  110. if (m_scenes[0].AgentPreferencesService == null)
  111. {
  112. return OSDParser.SerializeLLSDXmlString(resp);
  113. }
  114. m_log.DebugFormat("[AgentPrefs]: UpdateAgentPreferences for {0}", agent.ToString());
  115. OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request);
  116. AgentPrefs data = m_scenes[0].AgentPreferencesService.GetAgentPreferences(agent);
  117. if (data == null)
  118. {
  119. data = new AgentPrefs(agent);
  120. }
  121. if (req.ContainsKey("access_prefs"))
  122. {
  123. OSDMap accessPrefs = (OSDMap)req["access_prefs"]; // We could check with ContainsKey...
  124. data.AccessPrefs = accessPrefs["max"].AsString();
  125. }
  126. if (req.ContainsKey("default_object_perm_masks"))
  127. {
  128. OSDMap permsMap = (OSDMap)req["default_object_perm_masks"];
  129. data.PermEveryone = permsMap["Everyone"].AsInteger();
  130. data.PermGroup = permsMap["Group"].AsInteger();
  131. data.PermNextOwner = permsMap["NextOwner"].AsInteger();
  132. }
  133. if (req.ContainsKey("hover_height"))
  134. {
  135. data.HoverHeight = req["hover_height"].AsReal();
  136. }
  137. if (req.ContainsKey("language"))
  138. {
  139. data.Language = req["language"].AsString();
  140. }
  141. if (req.ContainsKey("language_is_public"))
  142. {
  143. data.LanguageIsPublic = req["language_is_public"].AsBoolean();
  144. }
  145. m_scenes[0].AgentPreferencesService.StoreAgentPreferences(data);
  146. OSDMap respAccessPrefs = new OSDMap();
  147. respAccessPrefs["max"] = data.AccessPrefs;
  148. resp["access_prefs"] = respAccessPrefs;
  149. OSDMap respDefaultPerms = new OSDMap();
  150. respDefaultPerms["Everyone"] = data.PermEveryone;
  151. respDefaultPerms["Group"] = data.PermGroup;
  152. respDefaultPerms["NextOwner"] = data.PermNextOwner;
  153. resp["default_object_perm_masks"] = respDefaultPerms;
  154. resp["god_level"] = 0; // *TODO: Add this
  155. resp["hover_height"] = data.HoverHeight;
  156. resp["language"] = data.Language;
  157. resp["language_is_public"] = data.LanguageIsPublic;
  158. string response = OSDParser.SerializeLLSDXmlString(resp);
  159. return response;
  160. }
  161. #endregion Region module
  162. }
  163. }