OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
AgentPreferencesModule.cs
Go to the documentation of this file.
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.Generic;
30 using System.Reflection;
31 using System.IO;
32 using log4net;
33 using Mono.Addins;
34 using Nini.Config;
35 using OpenMetaverse;
36 using OpenMetaverse.StructuredData;
37 using OpenSim.Framework.Console;
38 using OpenSim.Framework.Servers;
39 using OpenSim.Framework.Servers.HttpServer;
40 using OpenSim.Region.Framework.Interfaces;
41 using OpenSim.Region.Framework.Scenes;
42 using OpenSim.Services.Interfaces;
44 using OpenSim.Capabilities.Handlers;
45 
46 namespace OpenSim.Region.ClientStack.LindenCaps
47 {
48  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AgentPreferencesModule")]
50  {
51  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 
53  private List<Scene> m_scenes = new List<Scene>();
54 
55  public void Initialise(IConfigSource source)
56  {
57 
58  }
59 
60  #region Region module
61 
62  public void AddRegion(Scene scene)
63  {
64  lock (m_scenes) m_scenes.Add(scene);
65  }
66 
67  public void RemoveRegion(Scene scene)
68  {
69  lock (m_scenes) m_scenes.Remove(scene);
70  scene.EventManager.OnRegisterCaps -= RegisterCaps;
71  scene = null;
72  }
73 
74  public void RegionLoaded(Scene scene)
75  {
76  scene.EventManager.OnRegisterCaps += delegate(UUID agentID, OpenSim.Framework.Capabilities.Caps caps)
77  {
78  RegisterCaps(agentID, caps);
79  };
80  }
81 
82  public void PostInitialise() {}
83 
84  public void Close() {}
85 
86  public string Name { get { return "AgentPreferencesModule"; } }
87 
88  public Type ReplaceableInterface
89  {
90  get { return null; }
91  }
92 
93  public void RegisterCaps(UUID agent, Caps caps)
94  {
95  UUID capId = UUID.Random();
96  caps.RegisterHandler("AgentPreferences",
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  caps.RegisterHandler("UpdateAgentLanguage",
104  new RestStreamHandler("POST", "/CAPS/" + capId,
105  delegate(string request, string path, string param,
106  IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
107  {
108  return UpdateAgentPreferences(request, path, param, agent);
109  }));
110  caps.RegisterHandler("UpdateAgentInformation",
111  new RestStreamHandler("POST", "/CAPS/" + capId,
112  delegate(string request, string path, string param,
113  IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
114  {
115  return UpdateAgentPreferences(request, path, param, agent);
116  }));
117  }
118 
119  public string UpdateAgentPreferences(string request, string path, string param, UUID agent)
120  {
121  OSDMap resp = new OSDMap();
122  // The viewer doesn't do much with the return value, so for now, if there is no preference service,
123  // we'll return a null llsd block for debugging purposes. This may change if someone knows what the
124  // correct server response would be here.
125  if (m_scenes[0].AgentPreferencesService == null)
126  {
127  return OSDParser.SerializeLLSDXmlString(resp);
128  }
129  m_log.DebugFormat("[AgentPrefs]: UpdateAgentPreferences for {0}", agent.ToString());
130  OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request);
131  AgentPrefs data = m_scenes[0].AgentPreferencesService.GetAgentPreferences(agent);
132  if (data == null)
133  {
134  data = new AgentPrefs(agent);
135  }
136 
137  if (req.ContainsKey("access_prefs"))
138  {
139  OSDMap accessPrefs = (OSDMap)req["access_prefs"]; // We could check with ContainsKey...
140  data.AccessPrefs = accessPrefs["max"].AsString();
141  }
142  if (req.ContainsKey("default_object_perm_masks"))
143  {
144  OSDMap permsMap = (OSDMap)req["default_object_perm_masks"];
145  data.PermEveryone = permsMap["Everyone"].AsInteger();
146  data.PermGroup = permsMap["Group"].AsInteger();
147  data.PermNextOwner = permsMap["NextOwner"].AsInteger();
148  }
149  if (req.ContainsKey("hover_height"))
150  {
151  data.HoverHeight = req["hover_height"].AsReal();
152  }
153  if (req.ContainsKey("language"))
154  {
155  data.Language = req["language"].AsString();
156  }
157  if (req.ContainsKey("language_is_public"))
158  {
159  data.LanguageIsPublic = req["language_is_public"].AsBoolean();
160  }
161  m_scenes[0].AgentPreferencesService.StoreAgentPreferences(data);
162  OSDMap respAccessPrefs = new OSDMap();
163  respAccessPrefs["max"] = data.AccessPrefs;
164  resp["access_prefs"] = respAccessPrefs;
165  OSDMap respDefaultPerms = new OSDMap();
166  respDefaultPerms["Everyone"] = data.PermEveryone;
167  respDefaultPerms["Group"] = data.PermGroup;
168  respDefaultPerms["NextOwner"] = data.PermNextOwner;
169  resp["default_object_perm_masks"] = respDefaultPerms;
170  resp["god_level"] = 0; // *TODO: Add this
171  resp["hover_height"] = data.HoverHeight;
172  resp["language"] = data.Language;
173  resp["language_is_public"] = data.LanguageIsPublic;
174 
175  string response = OSDParser.SerializeLLSDXmlString(resp);
176  return response;
177  }
178 
179  #endregion Region module
180  }
181 }
182 
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
string UpdateAgentPreferences(string request, string path, string param, UUID agent)
OpenSim.Framework.Capabilities.Caps Caps
OpenMetaverse.StructuredData.OSDMap OSDMap
OpenSim.Framework.Capabilities.Caps Caps
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
Interactive OpenSim region server
Definition: OpenSim.cs:55
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...