1
0

AgentPreferencesModule.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. ISimulatorFeaturesModule simFeatures = scene.RequestModuleInterface<ISimulatorFeaturesModule>();
  72. if(simFeatures != null)
  73. simFeatures.AddFeature("AvatarHoverHeightEnabled",OSD.FromBoolean(true));
  74. }
  75. public void PostInitialise() {}
  76. public void Close() {}
  77. public string Name { get { return "AgentPreferencesModule"; } }
  78. public Type ReplaceableInterface
  79. {
  80. get { return null; }
  81. }
  82. public void RegisterCaps(UUID agent, Caps caps)
  83. {
  84. UUID capId = UUID.Random();
  85. caps.RegisterHandler("AgentPreferences",
  86. new RestStreamHandler("POST", "/CAPS/" + capId,
  87. delegate(string request, string path, string param,
  88. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  89. {
  90. return UpdateAgentPreferences(request, path, param, agent);
  91. }));
  92. caps.RegisterHandler("UpdateAgentLanguage",
  93. new RestStreamHandler("POST", "/CAPS/" + capId,
  94. delegate(string request, string path, string param,
  95. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  96. {
  97. return UpdateAgentPreferences(request, path, param, agent);
  98. }));
  99. caps.RegisterHandler("UpdateAgentInformation",
  100. new RestStreamHandler("POST", "/CAPS/" + capId,
  101. delegate(string request, string path, string param,
  102. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  103. {
  104. return UpdateAgentPreferences(request, path, param, agent);
  105. }));
  106. }
  107. public string UpdateAgentPreferences(string request, string path, string param, UUID agent)
  108. {
  109. OSDMap resp = new OSDMap();
  110. // if there is no preference service,
  111. // we'll return a null llsd block for debugging purposes. This may change if someone knows what the
  112. // correct server response would be here.
  113. if (m_scenes[0].AgentPreferencesService == null)
  114. {
  115. return OSDParser.SerializeLLSDXmlString(resp);
  116. }
  117. m_log.DebugFormat("[AgentPrefs]: UpdateAgentPreferences for {0}", agent.ToString());
  118. OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request);
  119. AgentPrefs data = m_scenes[0].AgentPreferencesService.GetAgentPreferences(agent);
  120. if (data == null)
  121. {
  122. data = new AgentPrefs(agent);
  123. }
  124. if (req.ContainsKey("access_prefs"))
  125. {
  126. OSDMap accessPrefs = (OSDMap)req["access_prefs"]; // We could check with ContainsKey...
  127. data.AccessPrefs = accessPrefs["max"].AsString();
  128. }
  129. if (req.ContainsKey("default_object_perm_masks"))
  130. {
  131. OSDMap permsMap = (OSDMap)req["default_object_perm_masks"];
  132. data.PermEveryone = permsMap["Everyone"].AsInteger();
  133. data.PermGroup = permsMap["Group"].AsInteger();
  134. data.PermNextOwner = permsMap["NextOwner"].AsInteger();
  135. }
  136. if (req.ContainsKey("hover_height"))
  137. {
  138. data.HoverHeight = (float)req["hover_height"].AsReal();
  139. }
  140. if (req.ContainsKey("language"))
  141. {
  142. data.Language = req["language"].AsString();
  143. }
  144. if (req.ContainsKey("language_is_public"))
  145. {
  146. data.LanguageIsPublic = req["language_is_public"].AsBoolean();
  147. }
  148. m_scenes[0].AgentPreferencesService.StoreAgentPreferences(data);
  149. OSDMap respAccessPrefs = new OSDMap();
  150. respAccessPrefs["max"] = data.AccessPrefs;
  151. resp["access_prefs"] = respAccessPrefs;
  152. OSDMap respDefaultPerms = new OSDMap();
  153. respDefaultPerms["Everyone"] = data.PermEveryone;
  154. respDefaultPerms["Group"] = data.PermGroup;
  155. respDefaultPerms["NextOwner"] = data.PermNextOwner;
  156. resp["default_object_perm_masks"] = respDefaultPerms;
  157. resp["god_level"] = 0; // *TODO: Add this
  158. resp["hover_height"] = data.HoverHeight;
  159. resp["language"] = data.Language;
  160. resp["language_is_public"] = data.LanguageIsPublic;
  161. IAvatarFactoryModule afm = m_scenes[0].RequestModuleInterface<IAvatarFactoryModule>();
  162. afm?.SetPreferencesHoverZ(agent, (float)data.HoverHeight);
  163. string response = OSDParser.SerializeLLSDXmlString(resp);
  164. return response;
  165. }
  166. #endregion Region module
  167. }
  168. }