agent preferences needs to work without backend storage

master
UbitUmarov 2020-05-30 14:13:07 +01:00
parent 8f39405380
commit 9896224605
1 changed files with 23 additions and 29 deletions

View File

@ -62,12 +62,14 @@ namespace OpenSim.Region.ClientStack.LindenCaps
public void AddRegion(Scene scene) public void AddRegion(Scene scene)
{ {
lock (m_scenes) m_scenes.Add(scene); lock (m_scenes)
m_scenes.Add(scene);
} }
public void RemoveRegion(Scene scene) public void RemoveRegion(Scene scene)
{ {
lock (m_scenes) m_scenes.Remove(scene); lock (m_scenes)
m_scenes.Remove(scene);
scene.EventManager.OnRegisterCaps -= RegisterCaps; scene.EventManager.OnRegisterCaps -= RegisterCaps;
scene = null; scene = null;
} }
@ -121,18 +123,8 @@ namespace OpenSim.Region.ClientStack.LindenCaps
return; return;
} }
httpResponse.KeepAlive = false; //m_log.DebugFormat("[AgentPrefs]: UpdateAgentPreferences for {0}", agent.ToString());
// if there is no preference service,
// we'll return a null llsd block for debugging purposes. This may change if someone knows what the
// correct server response would be here.
if (m_scenes[0].AgentPreferencesService == null)
{
httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
m_log.DebugFormat("[AgentPrefs]: UpdateAgentPreferences for {0}", agent.ToString());
OSDMap req; OSDMap req;
try try
{ {
req = (OSDMap)OSDParser.DeserializeLLSDXml(httpRequest.InputStream); req = (OSDMap)OSDParser.DeserializeLLSDXml(httpRequest.InputStream);
@ -143,45 +135,48 @@ namespace OpenSim.Region.ClientStack.LindenCaps
return; return;
} }
AgentPrefs data = m_scenes[0].AgentPreferencesService.GetAgentPreferences(agent); IAgentPreferencesService aps = m_scenes[0].AgentPreferencesService;
AgentPrefs data = null;
if(aps != null)
data = aps.GetAgentPreferences(agent);
if (data == null) if (data == null)
{
data = new AgentPrefs(agent); data = new AgentPrefs(agent);
}
bool changed = false; bool changed = false;
if (req.ContainsKey("access_prefs")) OSD tmp;
if (req.TryGetValue("access_prefs", out tmp) && tmp is OSDMap)
{ {
OSDMap accessPrefs = (OSDMap)req["access_prefs"]; // We could check with ContainsKey... OSDMap accessPrefs = (OSDMap)tmp; // We could check with ContainsKey...
data.AccessPrefs = accessPrefs["max"].AsString(); data.AccessPrefs = accessPrefs["max"].AsString();
changed = true; changed = true;
} }
if (req.ContainsKey("default_object_perm_masks")) if (req.TryGetValue("default_object_perm_masks", out tmp) && tmp is OSDMap)
{ {
OSDMap permsMap = (OSDMap)req["default_object_perm_masks"]; OSDMap permsMap = (OSDMap)tmp;
data.PermEveryone = permsMap["Everyone"].AsInteger(); data.PermEveryone = permsMap["Everyone"].AsInteger();
data.PermGroup = permsMap["Group"].AsInteger(); data.PermGroup = permsMap["Group"].AsInteger();
data.PermNextOwner = permsMap["NextOwner"].AsInteger(); data.PermNextOwner = permsMap["NextOwner"].AsInteger();
changed = true; changed = true;
} }
if (req.ContainsKey("hover_height")) if (req.TryGetValue("hover_height", out tmp))
{ {
data.HoverHeight = (float)req["hover_height"].AsReal(); data.HoverHeight = (float)tmp.AsReal();
changed = true; changed = true;
} }
if (req.ContainsKey("language")) if (req.TryGetValue("language", out tmp))
{ {
data.Language = req["language"].AsString(); data.Language = tmp.AsString();
changed = true; changed = true;
} }
if (req.ContainsKey("language_is_public")) if (req.TryGetValue("language_is_public", out tmp))
{ {
data.LanguageIsPublic = req["language_is_public"].AsBoolean(); data.LanguageIsPublic = tmp.AsBoolean();
changed = true; changed = true;
} }
if(changed) if(changed)
m_scenes[0].AgentPreferencesService.StoreAgentPreferences(data); aps?.StoreAgentPreferences(data);
IAvatarFactoryModule afm = m_scenes[0].RequestModuleInterface<IAvatarFactoryModule>(); IAvatarFactoryModule afm = m_scenes[0].RequestModuleInterface<IAvatarFactoryModule>();
afm?.SetPreferencesHoverZ(agent, (float)data.HoverHeight); afm?.SetPreferencesHoverZ(agent, (float)data.HoverHeight);
@ -202,8 +197,7 @@ namespace OpenSim.Region.ClientStack.LindenCaps
resp["language"] = data.Language; resp["language"] = data.Language;
resp["language_is_public"] = data.LanguageIsPublic; resp["language_is_public"] = data.LanguageIsPublic;
string response = OSDParser.SerializeLLSDXmlString(resp); httpResponse.RawBuffer = OSDParser.SerializeLLSDXmlBytes(resp);
httpResponse.RawBuffer = Encoding.UTF8.GetBytes(response);
httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.StatusCode = (int)HttpStatusCode.OK;
} }
#endregion Region module #endregion Region module