LocalUserProfilesServiceConnector.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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",
  103. String.Empty);
  104. if (serviceDll == String.Empty)
  105. {
  106. m_log.Error("[LOCAL USERPROFILES SERVICE CONNECTOR]: No LocalServiceModule named in section UserProfilesService");
  107. return;
  108. }
  109. Object[] args = new Object[] { source, ConfigName };
  110. ServiceModule =
  111. ServerUtils.LoadPlugin<IUserProfilesService>(serviceDll,
  112. args);
  113. if (ServiceModule == null)
  114. {
  115. m_log.Error("[LOCAL USERPROFILES SERVICE CONNECTOR]: Can't load user profiles service");
  116. return;
  117. }
  118. Enabled = true;
  119. JsonRpcProfileHandlers handler = new JsonRpcProfileHandlers(ServiceModule);
  120. Server.AddJsonRPCHandler("avatarclassifiedsrequest", handler.AvatarClassifiedsRequest);
  121. Server.AddJsonRPCHandler("classified_update", handler.ClassifiedUpdate);
  122. Server.AddJsonRPCHandler("classifieds_info_query", handler.ClassifiedInfoRequest);
  123. Server.AddJsonRPCHandler("classified_delete", handler.ClassifiedDelete);
  124. Server.AddJsonRPCHandler("avatarpicksrequest", handler.AvatarPicksRequest);
  125. Server.AddJsonRPCHandler("pickinforequest", handler.PickInfoRequest);
  126. Server.AddJsonRPCHandler("picks_update", handler.PicksUpdate);
  127. Server.AddJsonRPCHandler("picks_delete", handler.PicksDelete);
  128. Server.AddJsonRPCHandler("avatarnotesrequest", handler.AvatarNotesRequest);
  129. Server.AddJsonRPCHandler("avatar_notes_update", handler.NotesUpdate);
  130. Server.AddJsonRPCHandler("avatar_properties_request", handler.AvatarPropertiesRequest);
  131. Server.AddJsonRPCHandler("avatar_properties_update", handler.AvatarPropertiesUpdate);
  132. Server.AddJsonRPCHandler("avatar_interests_update", handler.AvatarInterestsUpdate);
  133. Server.AddJsonRPCHandler("user_preferences_update", handler.UserPreferenecesUpdate);
  134. Server.AddJsonRPCHandler("user_preferences_request", handler.UserPreferencesRequest);
  135. Server.AddJsonRPCHandler("image_assets_request", handler.AvatarImageAssetsRequest);
  136. Server.AddJsonRPCHandler("user_data_request", handler.RequestUserAppData);
  137. Server.AddJsonRPCHandler("user_data_update", handler.UpdateUserAppData);
  138. }
  139. #region ISharedRegionModule implementation
  140. public void PostInitialise()
  141. {
  142. if(!Enabled)
  143. return;
  144. }
  145. #endregion
  146. #region IRegionModuleBase implementation
  147. public void Initialise(IConfigSource source)
  148. {
  149. IConfig moduleConfig = source.Configs["Modules"];
  150. if (moduleConfig != null)
  151. {
  152. string name = moduleConfig.GetString("UserProfilesServices", "");
  153. if (name == Name)
  154. {
  155. InitialiseService(source);
  156. m_log.Info("[LOCAL USERPROFILES SERVICE CONNECTOR]: Local user profiles connector enabled");
  157. }
  158. }
  159. }
  160. public void Close()
  161. {
  162. return;
  163. }
  164. public void AddRegion(Scene scene)
  165. {
  166. if (!Enabled)
  167. return;
  168. lock (regions)
  169. {
  170. if (regions.ContainsKey(scene.RegionInfo.RegionID))
  171. m_log.ErrorFormat("[LOCAL USERPROFILES SERVICE CONNECTOR]: simulator seems to have more than one region with the same UUID. Please correct this!");
  172. else
  173. regions.Add(scene.RegionInfo.RegionID, scene);
  174. }
  175. }
  176. public void RemoveRegion(Scene scene)
  177. {
  178. if (!Enabled)
  179. return;
  180. lock (regions)
  181. {
  182. if (regions.ContainsKey(scene.RegionInfo.RegionID))
  183. regions.Remove(scene.RegionInfo.RegionID);
  184. }
  185. }
  186. public void RegionLoaded(Scene scene)
  187. {
  188. if (!Enabled)
  189. return;
  190. }
  191. #endregion
  192. }
  193. }