LocalUserProfilesServiceConnector.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 log4net;
  28. using Mono.Addins;
  29. using Nini.Config;
  30. using System;
  31. using System.Collections.Generic;
  32. using System.Reflection;
  33. using OpenSim.Framework;
  34. using OpenSim.Framework.Console;
  35. using OpenSim.Server.Base;
  36. using OpenSim.Server.Handlers;
  37. using OpenSim.Region.Framework.Interfaces;
  38. using OpenSim.Framework.Servers.HttpServer;
  39. using OpenSim.Framework.Servers;
  40. using OpenSim.Region.Framework.Scenes;
  41. using OpenSim.Services.Interfaces;
  42. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  43. using OpenMetaverse;
  44. namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Profile
  45. {
  46. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LocalUserProfilesServicesConnector")]
  47. public class LocalUserProfilesServicesConnector : ISharedRegionModule
  48. {
  49. private static readonly ILog m_log =
  50. LogManager.GetLogger(
  51. MethodBase.GetCurrentMethod().DeclaringType);
  52. private Dictionary<UUID, Scene> regions = new Dictionary<UUID, Scene>();
  53. public IUserProfilesService ServiceModule
  54. {
  55. get; private set;
  56. }
  57. public bool Enabled
  58. {
  59. get; private set;
  60. }
  61. public string Name
  62. {
  63. get
  64. {
  65. return "LocalUserProfilesServicesConnector";
  66. }
  67. }
  68. public string ConfigName
  69. {
  70. get; private set;
  71. }
  72. public Type ReplaceableInterface
  73. {
  74. get { return null; }
  75. }
  76. public LocalUserProfilesServicesConnector()
  77. {
  78. //m_log.Debug("[LOCAL USERPROFILES SERVICE CONNECTOR]: LocalUserProfileServicesConnector no params");
  79. }
  80. public LocalUserProfilesServicesConnector(IConfigSource source)
  81. {
  82. //m_log.Debug("[LOCAL USERPROFILES SERVICE CONNECTOR]: LocalUserProfileServicesConnector instantiated directly.");
  83. InitialiseService(source);
  84. }
  85. public void InitialiseService(IConfigSource source)
  86. {
  87. ConfigName = "UserProfilesService";
  88. // Instantiate the request handler
  89. IHttpServer Server = MainServer.Instance;
  90. IConfig config = source.Configs[ConfigName];
  91. if (config == null)
  92. {
  93. //m_log.Error("[LOCAL USERPROFILES SERVICE CONNECTOR]: UserProfilesService missing from OpenSim.ini");
  94. return;
  95. }
  96. if(!config.GetBoolean("Enabled",false))
  97. {
  98. Enabled = false;
  99. return;
  100. }
  101. Enabled = true;
  102. string serviceDll = config.GetString("LocalServiceModule", String.Empty);
  103. if (serviceDll == String.Empty)
  104. {
  105. m_log.Error("[LOCAL USERPROFILES SERVICE CONNECTOR]: No LocalServiceModule named in section UserProfilesService");
  106. return;
  107. }
  108. Object[] args = new Object[] { source, ConfigName };
  109. ServiceModule = ServerUtils.LoadPlugin<IUserProfilesService>(serviceDll, args);
  110. if (ServiceModule == null)
  111. {
  112. m_log.Error("[LOCAL USERPROFILES SERVICE CONNECTOR]: Can't load user profiles service");
  113. return;
  114. }
  115. Enabled = true;
  116. JsonRpcProfileHandlers handler = new JsonRpcProfileHandlers(ServiceModule);
  117. Server.AddJsonRPCHandler("avatarclassifiedsrequest", handler.AvatarClassifiedsRequest);
  118. Server.AddJsonRPCHandler("classified_update", handler.ClassifiedUpdate);
  119. Server.AddJsonRPCHandler("classifieds_info_query", handler.ClassifiedInfoRequest);
  120. Server.AddJsonRPCHandler("classified_delete", handler.ClassifiedDelete);
  121. Server.AddJsonRPCHandler("avatarpicksrequest", handler.AvatarPicksRequest);
  122. Server.AddJsonRPCHandler("pickinforequest", handler.PickInfoRequest);
  123. Server.AddJsonRPCHandler("picks_update", handler.PicksUpdate);
  124. Server.AddJsonRPCHandler("picks_delete", handler.PicksDelete);
  125. Server.AddJsonRPCHandler("avatarnotesrequest", handler.AvatarNotesRequest);
  126. Server.AddJsonRPCHandler("avatar_notes_update", handler.NotesUpdate);
  127. Server.AddJsonRPCHandler("avatar_properties_request", handler.AvatarPropertiesRequest);
  128. Server.AddJsonRPCHandler("avatar_properties_update", handler.AvatarPropertiesUpdate);
  129. Server.AddJsonRPCHandler("avatar_interests_update", handler.AvatarInterestsUpdate);
  130. Server.AddJsonRPCHandler("user_preferences_update", handler.UserPreferenecesUpdate);
  131. Server.AddJsonRPCHandler("user_preferences_request", handler.UserPreferencesRequest);
  132. Server.AddJsonRPCHandler("image_assets_request", handler.AvatarImageAssetsRequest);
  133. Server.AddJsonRPCHandler("user_data_request", handler.RequestUserAppData);
  134. Server.AddJsonRPCHandler("user_data_update", handler.UpdateUserAppData);
  135. }
  136. #region ISharedRegionModule implementation
  137. public void PostInitialise()
  138. {
  139. if(!Enabled)
  140. return;
  141. }
  142. #endregion
  143. #region IRegionModuleBase implementation
  144. public void Initialise(IConfigSource source)
  145. {
  146. IConfig moduleConfig = source.Configs["Modules"];
  147. if (moduleConfig != null)
  148. {
  149. string name = moduleConfig.GetString("UserProfilesServices", "");
  150. if (name == Name)
  151. {
  152. InitialiseService(source);
  153. m_log.Info("[LOCAL USERPROFILES SERVICE CONNECTOR]: Local user profiles connector enabled");
  154. }
  155. }
  156. }
  157. public void Close()
  158. {
  159. return;
  160. }
  161. public void AddRegion(Scene scene)
  162. {
  163. if (!Enabled)
  164. return;
  165. lock (regions)
  166. {
  167. if (regions.ContainsKey(scene.RegionInfo.RegionID))
  168. m_log.ErrorFormat("[LOCAL USERPROFILES SERVICE CONNECTOR]: simulator seems to have more than one region with the same UUID. Please correct this!");
  169. else
  170. regions.Add(scene.RegionInfo.RegionID, scene);
  171. }
  172. }
  173. public void RemoveRegion(Scene scene)
  174. {
  175. if (!Enabled)
  176. return;
  177. lock (regions)
  178. {
  179. if (regions.ContainsKey(scene.RegionInfo.RegionID))
  180. regions.Remove(scene.RegionInfo.RegionID);
  181. }
  182. }
  183. public void RegionLoaded(Scene scene)
  184. {
  185. if (!Enabled)
  186. return;
  187. }
  188. #endregion
  189. }
  190. }