PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/Aurora/Services/DataService/Connectors/Local/LocalAgentConnector.cs

https://bitbucket.org/VirtualReality/aurora-sim
C# | 163 lines | 99 code | 23 blank | 41 comment | 15 complexity | c25315811ffe866036163a91205cb88d MD5 | raw file
  1. /*
  2. * Copyright (c) Contributors, http://aurora-sim.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 Aurora-Sim 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.Collections.Generic;
  28. using System.Reflection;
  29. using Aurora.Framework;
  30. using Nini.Config;
  31. using OpenMetaverse;
  32. using OpenMetaverse.StructuredData;
  33. namespace Aurora.Services.DataService
  34. {
  35. public class LocalAgentConnector : ConnectorBase, IAgentConnector
  36. {
  37. private IGenericData GD;
  38. private GenericAccountCache<IAgentInfo> m_cache = new GenericAccountCache<IAgentInfo>();
  39. #region IAgentConnector Members
  40. public void Initialize(IGenericData GenericData, IConfigSource source, IRegistryCore simBase,
  41. string defaultConnectionString)
  42. {
  43. GD = GenericData;
  44. if (source.Configs[Name] != null)
  45. defaultConnectionString = source.Configs[Name].GetString("ConnectionString", defaultConnectionString);
  46. GD.ConnectToDatabase(defaultConnectionString, "Agent",
  47. source.Configs["AuroraConnectors"].GetBoolean("ValidateTables", true));
  48. DataManager.DataManager.RegisterPlugin(Name + "Local", this);
  49. if (source.Configs["AuroraConnectors"].GetString("AgentConnector", "LocalConnector") == "LocalConnector")
  50. {
  51. DataManager.DataManager.RegisterPlugin(this);
  52. }
  53. Init(simBase, Name);
  54. }
  55. public string Name
  56. {
  57. get { return "IAgentConnector"; }
  58. }
  59. /// <summary>
  60. /// Gets the info about the agent (TOS data, maturity info, language, etc)
  61. /// </summary>
  62. /// <param name = "agentID"></param>
  63. /// <returns></returns>
  64. [CanBeReflected(ThreatLevel=OpenSim.Services.Interfaces.ThreatLevel.Low)]
  65. public IAgentInfo GetAgent(UUID agentID)
  66. {
  67. IAgentInfo agent = new IAgentInfo();
  68. if (m_cache.Get(agentID, out agent))
  69. return agent;
  70. else
  71. agent = new IAgentInfo();
  72. object remoteValue = DoRemoteForUser(agentID, agentID);
  73. if (remoteValue != null || m_doRemoteOnly)
  74. {
  75. m_cache.Cache(agentID, (IAgentInfo)remoteValue);
  76. return (IAgentInfo)remoteValue;
  77. }
  78. List<string> query = null;
  79. try
  80. {
  81. QueryFilter filter = new QueryFilter();
  82. filter.andFilters["ID"] = agentID;
  83. filter.andFilters["`Key`"] = "AgentInfo";
  84. query = GD.Query(new string[1] { "`Value`" }, "userdata", filter, null, null, null);
  85. }
  86. catch
  87. {
  88. }
  89. if (query == null || query.Count == 0)
  90. {
  91. m_cache.Cache(agentID, null);
  92. return null; //Couldn't find it, return null then.
  93. }
  94. OSDMap agentInfo = (OSDMap) OSDParser.DeserializeLLSDXml(query[0]);
  95. agent.FromOSD(agentInfo);
  96. agent.PrincipalID = agentID;
  97. m_cache.Cache(agentID, agent);
  98. return agent;
  99. }
  100. /// <summary>
  101. /// Updates the language and maturity params of the agent.
  102. /// Note: we only allow for this on the grid side
  103. /// </summary>
  104. /// <param name = "agent"></param>
  105. [CanBeReflected(ThreatLevel = OpenSim.Services.Interfaces.ThreatLevel.Full)]
  106. public void UpdateAgent(IAgentInfo agent)
  107. {
  108. CacheAgent(agent);
  109. object remoteValue = DoRemoteForUser(agent.PrincipalID, agent.ToOSD());
  110. if (remoteValue != null || m_doRemoteOnly)
  111. return;
  112. Dictionary<string, object> values = new Dictionary<string, object>(1);
  113. values["Value"] = OSDParser.SerializeLLSDXmlString(agent.ToOSD());
  114. QueryFilter filter = new QueryFilter();
  115. filter.andFilters["ID"] = agent.PrincipalID;
  116. filter.andFilters["`Key`"] = "AgentInfo";
  117. GD.Update("userdata", values, null, filter, null, null);
  118. }
  119. public void CacheAgent(IAgentInfo agent)
  120. {
  121. m_cache.Cache(agent.PrincipalID, agent);
  122. }
  123. /// <summary>
  124. /// Creates a new database entry for the agent.
  125. /// Note: we only allow for this on the grid side
  126. /// </summary>
  127. /// <param name = "agentID"></param>
  128. public void CreateNewAgent(UUID agentID)
  129. {
  130. List<object> values = new List<object> {agentID, "AgentInfo"};
  131. IAgentInfo info = new IAgentInfo {PrincipalID = agentID};
  132. values.Add(OSDParser.SerializeLLSDXmlString(info.ToOSD())); //Value which is a default Profile
  133. GD.Insert("userdata", values.ToArray());
  134. }
  135. #endregion
  136. public void Dispose()
  137. {
  138. }
  139. }
  140. }